Package lumis.portal.cluster
Class AbstractClusterManager
- java.lang.Object
-
- lumis.portal.cluster.AbstractClusterManager
-
- All Implemented Interfaces:
IClusterManager
- Direct Known Subclasses:
JGroupsClusterManager
,SingleServerClusterManager
public abstract class AbstractClusterManager extends Object implements IClusterManager
Generic implementation forIClusterManager
, independent of communication form.- Since:
- 4.0.0
- Version:
- $Revision: 23904 $ $Date: 2020-06-16 12:23:44 -0300 (Tue, 16 Jun 2020) $
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
processTransmissionsReceived
Indicates whethertransmissionReceived(IClusterTransmission)
processes the given transmission.protected String
serverId
The identifier for this cluster node.protected static long
WAIT_LOCAL_PROCESSING_TIMEOUT_MS
Wait local processing timeout in milliseconds.
-
Constructor Summary
Constructors Constructor Description AbstractClusterManager()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends Serializable>
Map<IClusterMember,T>callAndWaitResponses(IClusterCallable<T> command, long timeout)
Calls a cluster command execution and waits all current cluster servers to respond with their result and, then, returns an unmodifiable map having the cluster member as the key and the execution result as the value.protected abstract <T extends Serializable>
Map<IClusterMember,T>callAndWaitResponsesInternal(IClusterCallable<T> command, long timeout)
IClusterCommand<Serializable>
createClusterCommand(Runnable runnable)
Creates a cluster command instance and returns it.<T extends Serializable>
IClusterCommand<T>createClusterCommand(IClusterCallable<T> callable)
Creates a cluster command instance and returns it.IClusterMessage
createClusterMessage(String group, Serializable data)
Creates a cluster message instance and returns it.void
destroy()
Destroys the cluster manager.void
init()
Initializes the cluster manager.protected <T extends Serializable>
ITransmissionResult<T>transmissionReceived(IClusterTransmission transmission)
Processes a received transmission.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface lumis.portal.cluster.IClusterManager
call, getClusterConfig, getLocalMember, getMembers, send
-
-
-
-
Field Detail
-
WAIT_LOCAL_PROCESSING_TIMEOUT_MS
protected static final long WAIT_LOCAL_PROCESSING_TIMEOUT_MS
Wait local processing timeout in milliseconds.- Since:
- 12.4.0
- See Also:
- Constant Field Values
-
serverId
protected String serverId
The identifier for this cluster node.- Since:
- 4.1.0
-
processTransmissionsReceived
protected boolean processTransmissionsReceived
Indicates whethertransmissionReceived(IClusterTransmission)
processes the given transmission.- Since:
- 4.1.0
-
-
Method Detail
-
transmissionReceived
protected <T extends Serializable> ITransmissionResult<T> transmissionReceived(IClusterTransmission transmission)
Processes a received transmission. Subclasses should call this method whenever a transmission is received.processTransmissionsReceived
may be used to disable the processing done by this method.- Parameters:
transmission
- the transmission received.- Since:
- 4.1.0
-
init
public void init()
Description copied from interface:IClusterManager
Initializes the cluster manager. This method should start the monitoring and connections necessary for the cluster manager to execute its communications.- Specified by:
init
in interfaceIClusterManager
-
destroy
public void destroy()
Description copied from interface:IClusterManager
Destroys the cluster manager. This method should close all resources used by the cluster manager.- Specified by:
destroy
in interfaceIClusterManager
-
createClusterCommand
public IClusterCommand<Serializable> createClusterCommand(Runnable runnable)
Description copied from interface:IClusterManager
Creates a cluster command instance and returns it.- Specified by:
createClusterCommand
in interfaceIClusterManager
- Parameters:
runnable
- the runnable that contains the command's execution. It must be serializable.- See Also:
IClusterCommand
-
createClusterCommand
public <T extends Serializable> IClusterCommand<T> createClusterCommand(IClusterCallable<T> callable)
Description copied from interface:IClusterManager
Creates a cluster command instance and returns it.- Specified by:
createClusterCommand
in interfaceIClusterManager
- Parameters:
callable
- theIClusterCallable
that contains the command's execution. It must be serializable.- Returns:
- the created cluster command.
-
createClusterMessage
public IClusterMessage createClusterMessage(String group, Serializable data)
Description copied from interface:IClusterManager
Creates a cluster message instance and returns it.- Specified by:
createClusterMessage
in interfaceIClusterManager
- Parameters:
group
- the destination group for the message.data
- the data sent in the message.- Returns:
- the cluster message created.
- See Also:
IClusterMessage
-
callAndWaitResponses
public <T extends Serializable> Map<IClusterMember,T> callAndWaitResponses(IClusterCallable<T> command, long timeout) throws ClusterInvocationException, TimeoutException, InterruptedException, IllegalArgumentException
Description copied from interface:IClusterManager
Calls a cluster command execution and waits all current cluster servers to respond with their result and, then, returns an unmodifiable map having the cluster member as the key and the execution result as the value.If some server raises an exception, a
ClusterInvocationException
will be raised locally on the server that called this method with all exceptions that happened in the servers as suppressed.This method has no guarantee it will execute properly if cluster members enter or leave the cluster during its execution.
If all responses couldn't be retrieved in the given timeout, a
TimeoutException
will be raised.The given command must have been created through
IClusterManager.createClusterCommand(IClusterCallable)
.- Specified by:
callAndWaitResponses
in interfaceIClusterManager
- Type Parameters:
T
- the response type. it must be serializable.- Parameters:
command
- the command to be invoked.timeout
- the timeout this method will wait the invoke finishes.- Returns:
- a map with all responses.
- Throws:
ClusterInvocationException
- if some server raises an exception during the invoke.TimeoutException
- if the timeout has been reached and not all responses were returned.InterruptedException
- if the thread that called this method was interrupted.IllegalArgumentException
- if the given command isnull
.
-
callAndWaitResponsesInternal
protected abstract <T extends Serializable> Map<IClusterMember,T> callAndWaitResponsesInternal(IClusterCallable<T> command, long timeout) throws ClusterInvocationException, TimeoutException, InterruptedException
- Throws:
ClusterInvocationException
TimeoutException
InterruptedException
- See Also:
#callAndWaitResponses(IClusterCommand, long)
-
-