Class AbstractRPCService
java.lang.Object
org.exoplatform.services.rpc.impl.AbstractRPCService
- All Implemented Interfaces:
RPCService,org.jgroups.blocks.RequestHandler,org.jgroups.MembershipListener,org.picocontainer.Startable
- Direct Known Subclasses:
RPCServiceImpl
public abstract class AbstractRPCService
extends Object
implements RPCService, org.picocontainer.Startable, org.jgroups.blocks.RequestHandler, org.jgroups.MembershipListener
This class is a basic implementation of the
RPCService, it is mainly based on the
MessageDispatcher of JGroups. This implementation is not designed to give
the best possible performances, it only aims to give a way to communicate with other nodes.- Version:
- $Id$
- Author:
- Nicolas Filotto
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classThis intern class will be used tostatic enumAll the potential states of theRPCServiceImpl -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.jgroups.ChannelThe JGroups Channel used to communicate with other nodesprotected static final StringThe default value of the cluster nameprotected final org.jgroups.conf.ProtocolStackConfiguratorThe configurator used to create the JGroups Channelprotected org.jgroups.AddressThe address of the current coordinatorprotected static final intThe value of the default retry timeoutprotected static final intThe value of the default timeoutprotected org.jgroups.blocks.MessageDispatcherThe dispatcher used to launch the command of the cluster nodesprotected booleanIndicates whether the current node is the coordinator of the cluster or notprotected static final org.exoplatform.services.log.LogConnection logger.protected List<org.jgroups.Address> The current list of all the members of the clusterprotected static final StringThe name of the parameter to allow the failoverprotected static final StringThe name of the parameter for the name of the cluster.protected static final StringThe name of the parameter for the default timeoutprotected static final StringThe name of the parameter for the location of the JGroups configuration.protected static final StringThe name of the parameter for the retry timeoutFields inherited from interface org.exoplatform.services.rpc.RPCService
ACCESS_RPC_SERVICE_PERMISSION -
Constructor Summary
ConstructorsConstructorDescriptionAbstractRPCService(org.exoplatform.container.ExoContainerContext ctx, org.exoplatform.container.xml.InitParams params, org.exoplatform.container.configuration.ConfigurationManager configManager) The public constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidblock()protected abstract org.jgroups.util.RspListcastMessage(List<org.jgroups.Address> dests, org.jgroups.Message msg, boolean synchronous, long timeout) Cast a message to all the given membersprotected abstract org.jgroups.ChannelCreate a channelexcecuteCommand(List<org.jgroups.Address> dests, RemoteCommand command, boolean synchronous, long timeout, Serializable... args) Execute the command on all the nodes corresponding to the list of destinations.executeCommandOnAllNodes(RemoteCommand command, boolean synchronous, Serializable... args) Executes a command on all the cluster nodes.executeCommandOnAllNodes(RemoteCommand command, long timeout, Serializable... args) Executes a command synchronously on all the cluster nodes.executeCommandOnAllNodesMain(RemoteCommand command, boolean synchronous, long timeout, Serializable... args) Executes a command on all the cluster nodes.executeCommandOnCoordinator(RemoteCommand command, boolean synchronous, Serializable... args) Executes a command on the coordinator only.executeCommandOnCoordinator(RemoteCommand command, long timeout, Serializable... args) Executes a command synchronously on the coordinator only.protected ObjectexecuteCommandOnCoordinatorMain(RemoteCommand command, boolean synchronous, long timeout, Serializable... args) Executes a command on the coordinator only.protected StringGives the name of the clusterprotected RemoteCommandgetCommand(String commandId) Gives theRemoteCommandcorresponding to the given idprotected longGives the value of the default timeoutabstract StringReturns the IP address of current channel.protected abstract org.jgroups.AddressReturns the channel's own address.protected abstract List<org.jgroups.Address> getMembers(org.jgroups.View view) Returns a reference to the List of members (ordered) Do NOT change this list, hence your will invalidate the view Make a copy if you have to modify it.protected longGives the value of the retry timeouthandle(org.jgroups.Message msg) protected booleanIndicates whether the failover capabilities are enabled or notbooleanIndicates whether the local node is the coordinator of the clusterregisterCommand(RemoteCommand command) Register a newRemoteCommandinstance, it will be mapped to its id.voidRegister a newTopologyChangeListenerprotected abstract voidTakes an object and uses Java serialization to generate the byte[] buffer which is set in the message.voidstart()voidstop()voidsuspect(org.jgroups.Address suspectedMbr) voidunregisterCommand(RemoteCommand command) Unregister aRemoteCommandinstance, if the id is known or the instance itself is known otherwise it will be ignoredvoidUnregister aTopologyChangeListenerif it existsvoidviewAccepted(org.jgroups.View view) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jgroups.MembershipListener
unblock
-
Field Details
-
LOG
protected static final org.exoplatform.services.log.Log LOGConnection logger. -
PARAM_JGROUPS_CONFIG
The name of the parameter for the location of the JGroups configuration.- See Also:
-
PARAM_CLUSTER_NAME
The name of the parameter for the name of the cluster.- See Also:
-
PARAM_DEFAULT_TIMEOUT
The name of the parameter for the default timeout- See Also:
-
PARAM_ALLOW_FAILOVER
The name of the parameter to allow the failover- See Also:
-
PARAM_RETRY_TIMEOUT
The name of the parameter for the retry timeout- See Also:
-
DEFAULT_TIMEOUT
protected static final int DEFAULT_TIMEOUTThe value of the default timeout- See Also:
-
DEFAULT_RETRY_TIMEOUT
protected static final int DEFAULT_RETRY_TIMEOUTThe value of the default retry timeout- See Also:
-
CLUSTER_NAME
The default value of the cluster name- See Also:
-
configurator
protected final org.jgroups.conf.ProtocolStackConfigurator configuratorThe configurator used to create the JGroups Channel -
channel
protected org.jgroups.Channel channelThe JGroups Channel used to communicate with other nodes -
members
The current list of all the members of the cluster -
coordinator
protected volatile org.jgroups.Address coordinatorThe address of the current coordinator -
isCoordinator
protected volatile boolean isCoordinatorIndicates whether the current node is the coordinator of the cluster or not -
dispatcher
protected org.jgroups.blocks.MessageDispatcher dispatcherThe dispatcher used to launch the command of the cluster nodes
-
-
Constructor Details
-
AbstractRPCService
public AbstractRPCService(org.exoplatform.container.ExoContainerContext ctx, org.exoplatform.container.xml.InitParams params, org.exoplatform.container.configuration.ConfigurationManager configManager) The public constructor- Parameters:
ctx- theExoContainerContextfrom which we will extract the correspondingExoContainerparams- the list of initial parametersconfigManager- the configuration manager used to get the configuration of JGroups
-
-
Method Details
-
executeCommandOnAllNodes
public List<Object> executeCommandOnAllNodes(RemoteCommand command, boolean synchronous, Serializable... args) throws RPCException Executes a command on all the cluster nodes. This method is equivalent to the other method of the same type but with the default timeout. The command must be registered first otherwise anRPCExceptionwill be thrown.- Specified by:
executeCommandOnAllNodesin interfaceRPCService- Parameters:
command- The command to execute on each cluster nodesynchronous- if true, sets group request mode to org.jgroups.blocks.GroupRequest#GET_ALL, and if false sets it to org.jgroups.blocks.GroupRequest#GET_NONE.args- an array ofSerializableobjects corresponding to parameters of the command to execute remotely- Returns:
- a list of responses from all the members of the cluster. If we met an exception on a given node, the RPCException will be the corresponding response of this particular node
- Throws:
RPCException- in the event of problems.
-
executeCommandOnAllNodes
public List<Object> executeCommandOnAllNodes(RemoteCommand command, long timeout, Serializable... args) throws RPCException Executes a command synchronously on all the cluster nodes. The command must be registered first otherwise anRPCExceptionwill be thrown.- Specified by:
executeCommandOnAllNodesin interfaceRPCService- Parameters:
command- The command to execute on each cluster nodetimeout- a timeout after which to throw a replication exception.args- an array ofSerializableobjects corresponding to parameters of the command to execute remotely- Returns:
- a list of responses from all the members of the cluster. If we met an exception on a given node, the RPCException will be the corresponding response of this particular node
- Throws:
RPCException- in the event of problems.
-
executeCommandOnAllNodesMain
protected List<Object> executeCommandOnAllNodesMain(RemoteCommand command, boolean synchronous, long timeout, Serializable... args) throws RPCException Executes a command on all the cluster nodes. This method is equivalent to the other method of the same type but with the default timeout. The command must be registered first otherwise anRPCExceptionwill be thrown.- Parameters:
command- The command to execute on each cluster nodesynchronous- if true, sets group request mode to org.jgroups.blocks.GroupRequest#GET_ALL, and if false sets it to org.jgroups.blocks.GroupRequest#GET_NONE.timeout- a timeout after which to throw a replication exception.args- an array ofSerializableobjects corresponding to parameters of the command to execute remotely- Returns:
- a list of responses from all the members of the cluster. If we met an exception on a given node, the RPCException will be the corresponding response of this particular node
- Throws:
RPCException- in the event of problems.
-
executeCommandOnCoordinator
public Object executeCommandOnCoordinator(RemoteCommand command, boolean synchronous, Serializable... args) throws RPCException Executes a command on the coordinator only. This method is equivalent to the other method of the same type but with the default timeout. The command must be registered first otherwise anRPCExceptionwill be thrown.- Specified by:
executeCommandOnCoordinatorin interfaceRPCService- Parameters:
command- The command to execute on the coordinator nodesynchronous- if true, sets group request mode to org.jgroups.blocks.GroupRequest#GET_ALL, and if false sets it to org.jgroups.blocks.GroupRequest#GET_NONE.args- an array ofSerializableobjects corresponding to parameters of the command to execute remotely- Returns:
- the response of the coordinator.
- Throws:
RPCException- in the event of problems.
-
executeCommandOnCoordinator
public Object executeCommandOnCoordinator(RemoteCommand command, long timeout, Serializable... args) throws RPCException Executes a command synchronously on the coordinator only. The command must be registered first otherwise anRPCExceptionwill be thrown.- Specified by:
executeCommandOnCoordinatorin interfaceRPCService- Parameters:
command- The command to execute on the coordinator nodetimeout- a timeout after which to throw a replication exception.args- an array ofSerializableobjects corresponding to parameters of the command to execute remotely- Returns:
- the response of the coordinator.
- Throws:
RPCException- in the event of problems.
-
executeCommandOnCoordinatorMain
protected Object executeCommandOnCoordinatorMain(RemoteCommand command, boolean synchronous, long timeout, Serializable... args) throws RPCException Executes a command on the coordinator only. This method is equivalent to the other method of the same type but with the default timeout. The command must be registered first otherwise anRPCExceptionwill be thrown.- Parameters:
command- The command to execute on the coordinator nodesynchronous- if true, sets group request mode to org.jgroups.blocks.GroupRequest#GET_ALL, and if false sets it to org.jgroups.blocks.GroupRequest#GET_NONE.timeout- a timeout after which to throw a replication exception.args- an array ofSerializableobjects corresponding to parameters of the command to execute remotely- Returns:
- the response of the coordinator.
- Throws:
RPCException- in the event of problems.
-
excecuteCommand
protected List<Object> excecuteCommand(List<org.jgroups.Address> dests, RemoteCommand command, boolean synchronous, long timeout, Serializable... args) throws RPCException Execute the command on all the nodes corresponding to the list of destinations.- Parameters:
dests- the list of members on which the command needs to be executedcommand- the command to executesynchronous- if true, sets group request mode to org.jgroups.blocks.GroupRequest#GET_ALL, and if false sets it to org.jgroups.blocks.GroupRequest#GET_NONE.timeout- a timeout after which to throw a replication exception.args- the list of parameters- Returns:
- a list of responses from all the targeted members of the cluster.
- Throws:
RPCException- in the event of problems.
-
handle
- Specified by:
handlein interfaceorg.jgroups.blocks.RequestHandler
-
block
public void block()- Specified by:
blockin interfaceorg.jgroups.MembershipListener
-
suspect
public void suspect(org.jgroups.Address suspectedMbr) - Specified by:
suspectin interfaceorg.jgroups.MembershipListener
-
viewAccepted
public void viewAccepted(org.jgroups.View view) - Specified by:
viewAcceptedin interfaceorg.jgroups.MembershipListener
-
registerCommand
Register a newRemoteCommandinstance, it will be mapped to its id. If a command with the same Id has already been registered, a warning will be printed into the log file and the new command will replace the old one.- Specified by:
registerCommandin interfaceRPCService- Parameters:
command- the instance of theRemoteCommandto register- Returns:
- the command itself if it could be registered null otherwise
-
unregisterCommand
Unregister aRemoteCommandinstance, if the id is known or the instance itself is known otherwise it will be ignored- Specified by:
unregisterCommandin interfaceRPCService- Parameters:
command- the command to unregister
-
isCoordinator
Indicates whether the local node is the coordinator of the cluster- Specified by:
isCoordinatorin interfaceRPCService- Returns:
trueif the coordinator is the coordinator,falseotherwise throws RPCException in case theRPCServiceis in an illegal state- Throws:
RPCException
-
registerTopologyChangeListener
public void registerTopologyChangeListener(TopologyChangeListener listener) throws SecurityException Register a newTopologyChangeListener- Specified by:
registerTopologyChangeListenerin interfaceRPCService- Parameters:
listener- the listener to be registered- Throws:
SecurityException- if theSecurityManageris installed and the call method doesn't have theRuntimePermissionACCESS_RPC_SERVICE_PERMISSION
-
unregisterTopologyChangeListener
public void unregisterTopologyChangeListener(TopologyChangeListener listener) throws SecurityException Unregister aTopologyChangeListenerif it exists- Specified by:
unregisterTopologyChangeListenerin interfaceRPCService- Parameters:
listener- the listener to unregister- Throws:
SecurityException- if theSecurityManageris installed and the call method doesn't have theRuntimePermissionACCESS_RPC_SERVICE_PERMISSION
-
getCommand
Gives theRemoteCommandcorresponding to the given id- Parameters:
commandId- the command id of the command to retrieve- Returns:
- the corresponding
RemoteCommand
-
start
public void start()- Specified by:
startin interfaceorg.picocontainer.Startable
-
stop
public void stop()- Specified by:
stopin interfaceorg.picocontainer.Startable
-
getDefaultTimeout
protected long getDefaultTimeout()Gives the value of the default timeout- Returns:
- the default timeout
-
getClusterName
Gives the name of the cluster- Returns:
- the name of the cluster
-
getRetryTimeout
protected long getRetryTimeout()Gives the value of the retry timeout- Returns:
- the value of the retry timeout
-
isAllowFailover
protected boolean isAllowFailover()Indicates whether the failover capabilities are enabled or not- Returns:
trueif the failover capabilities are allowed,falseotherwise
-
getLocalAddress
protected abstract org.jgroups.Address getLocalAddress()Returns the channel's own address. The result of calling this method on an unconnected channel is implementation defined (may return null). Calling this method on a closed channel returns null. Successor to #getAddress(). Addresses can be used as destination in thesend()operation.- Returns:
- The channel's address (opaque) or null if it cannot be found
-
getHostAddress
Returns the IP address of current channel.- Returns:
- The Host's address or null if it cannot be found
-
castMessage
protected abstract org.jgroups.util.RspList castMessage(List<org.jgroups.Address> dests, org.jgroups.Message msg, boolean synchronous, long timeout) throws Exception Cast a message to all the given members- Parameters:
dests- The members to which the message is to be sent.msg- The message to be sent to the members.synchronous- Indicates whether the message must be sent in synchronous or asynchronous mode.timeout- If 0: wait forever. Otherwise, wait for responses or timeout time.- Returns:
- A list of responses. Each response is an
Objectand associated to its sender. - Throws:
Exception- if any error occur while casting the message
-
createChannel
Create a channel- Returns:
- An initialized channel
- Throws:
Exception- if any error occur while creating the channel
-
getMembers
Returns a reference to the List of members (ordered) Do NOT change this list, hence your will invalidate the view Make a copy if you have to modify it.- Returns:
- a reference to the ordered list of members in this view
-
setObject
Takes an object and uses Java serialization to generate the byte[] buffer which is set in the message.
-