public abstract class AbstractRPCService extends Object implements RPCService, org.picocontainer.Startable, org.jgroups.blocks.RequestHandler, org.jgroups.MembershipListener
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.| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractRPCService.MemberHasLeftException |
static class |
AbstractRPCService.MessageBody
This intern class will be used to
|
static class |
AbstractRPCService.State
All the potential states of the
RPCServiceImpl |
| Modifier and Type | Field and Description |
|---|---|
protected org.jgroups.Channel |
channel
The JGroups Channel used to communicate with other nodes
|
protected static String |
CLUSTER_NAME
The default value of the cluster name
|
protected org.jgroups.conf.ProtocolStackConfigurator |
configurator
The configurator used to create the JGroups Channel
|
protected org.jgroups.Address |
coordinator
The address of the current coordinator
|
protected static int |
DEFAULT_RETRY_TIMEOUT
The value of the default retry timeout
|
protected static int |
DEFAULT_TIMEOUT
The value of the default timeout
|
protected org.jgroups.blocks.MessageDispatcher |
dispatcher
The dispatcher used to launch the command of the cluster nodes
|
protected boolean |
isCoordinator
Indicates whether the current node is the coordinator of the cluster or not
|
protected List<org.jgroups.Address> |
members
The current list of all the members of the cluster
|
protected static String |
PARAM_ALLOW_FAILOVER
The name of the parameter to allow the failover
|
protected static String |
PARAM_CLUSTER_NAME
The name of the parameter for the name of the cluster.
|
protected static String |
PARAM_DEFAULT_TIMEOUT
The name of the parameter for the default timeout
|
protected static String |
PARAM_JGROUPS_CONFIG
The name of the parameter for the location of the JGroups configuration.
|
protected static String |
PARAM_RETRY_TIMEOUT
The name of the parameter for the retry timeout
|
ACCESS_RPC_SERVICE_PERMISSION| Constructor and Description |
|---|
AbstractRPCService(ExoContainerContext ctx,
InitParams params,
ConfigurationManager configManager)
The public constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
block() |
protected abstract org.jgroups.util.RspList |
castMessage(List<org.jgroups.Address> dests,
org.jgroups.Message msg,
boolean synchronous,
long timeout)
Cast a message to all the given members
|
protected abstract org.jgroups.Channel |
createChannel()
Create a channel
|
protected List<Object> |
excecuteCommand(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.
|
List<Object> |
executeCommandOnAllNodes(RemoteCommand command,
boolean synchronous,
Serializable... args)
Executes a command on all the cluster nodes.
|
List<Object> |
executeCommandOnAllNodes(RemoteCommand command,
long timeout,
Serializable... args)
Executes a command synchronously on all the cluster nodes.
|
protected List<Object> |
executeCommandOnAllNodesMain(RemoteCommand command,
boolean synchronous,
long timeout,
Serializable... args)
Executes a command on all the cluster nodes.
|
Object |
executeCommandOnCoordinator(RemoteCommand command,
boolean synchronous,
Serializable... args)
Executes a command on the coordinator only.
|
Object |
executeCommandOnCoordinator(RemoteCommand command,
long timeout,
Serializable... args)
Executes a command synchronously on the coordinator only.
|
protected Object |
executeCommandOnCoordinatorMain(RemoteCommand command,
boolean synchronous,
long timeout,
Serializable... args)
Executes a command on the coordinator only.
|
protected String |
getClusterName()
Gives the name of the cluster
|
protected RemoteCommand |
getCommand(String commandId)
Gives the
RemoteCommand corresponding to the given id |
protected long |
getDefaultTimeout()
Gives the value of the default timeout
|
protected abstract org.jgroups.Address |
getLocalAddress()
Returns 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 long |
getRetryTimeout()
Gives the value of the retry timeout
|
Object |
handle(org.jgroups.Message msg) |
protected boolean |
isAllowFailover()
Indicates whether the failover capabilities are enabled or not
|
boolean |
isCoordinator()
Indicates whether the local node is the coordinator of the cluster
|
RemoteCommand |
registerCommand(RemoteCommand command)
Register a new
RemoteCommand instance, it will be mapped to its id. |
void |
registerTopologyChangeListener(TopologyChangeListener listener)
Register a new
TopologyChangeListener |
protected abstract void |
setObject(org.jgroups.Message m,
Object o)
Takes an object and uses Java serialization to generate the byte[] buffer which
is set in the message.
|
void |
start() |
void |
stop() |
void |
suspect(org.jgroups.Address suspectedMbr) |
void |
unregisterCommand(RemoteCommand command)
Unregister a
RemoteCommand instance, if the id is known or the instance itself is known
otherwise it will be ignored |
void |
unregisterTopologyChangeListener(TopologyChangeListener listener)
Unregister a
TopologyChangeListener if it exists |
void |
viewAccepted(org.jgroups.View view) |
protected static final String PARAM_JGROUPS_CONFIG
protected static final String PARAM_CLUSTER_NAME
protected static final String PARAM_DEFAULT_TIMEOUT
protected static final String PARAM_ALLOW_FAILOVER
protected static final String PARAM_RETRY_TIMEOUT
protected static final int DEFAULT_TIMEOUT
protected static final int DEFAULT_RETRY_TIMEOUT
protected static final String CLUSTER_NAME
protected final org.jgroups.conf.ProtocolStackConfigurator configurator
protected org.jgroups.Channel channel
protected volatile List<org.jgroups.Address> members
protected volatile org.jgroups.Address coordinator
protected volatile boolean isCoordinator
protected org.jgroups.blocks.MessageDispatcher dispatcher
public AbstractRPCService(ExoContainerContext ctx, InitParams params, ConfigurationManager configManager)
ctx - the ExoContainerContext from which we will extract the corresponding
ExoContainerparams - the list of initial parametersconfigManager - the configuration manager used to get the configuration
of JGroupspublic List<Object> executeCommandOnAllNodes(RemoteCommand command, boolean synchronous, Serializable... args) throws RPCException
RPCException will be thrown.executeCommandOnAllNodes in interface RPCServicecommand - The command to execute on each cluster nodesynchronous - if true, sets group request mode to GroupRequest.GET_ALL,
and if false sets it to GroupRequest.GET_NONE.args - an array of Serializable objects corresponding to parameters of the command
to execute remotelyRPCException - in the event of problems.public List<Object> executeCommandOnAllNodes(RemoteCommand command, long timeout, Serializable... args) throws RPCException
RPCException will be thrown.executeCommandOnAllNodes in interface RPCServicecommand - The command to execute on each cluster nodetimeout - a timeout after which to throw a replication exception.args - an array of Serializable objects corresponding to parameters of the command
to execute remotelyRPCException - in the event of problems.protected List<Object> executeCommandOnAllNodesMain(RemoteCommand command, boolean synchronous, long timeout, Serializable... args) throws RPCException
RPCException will be thrown.command - The command to execute on each cluster nodesynchronous - if true, sets group request mode to GroupRequest.GET_ALL,
and if false sets it to GroupRequest.GET_NONE.timeout - a timeout after which to throw a replication exception.args - an array of Serializable objects corresponding to parameters of the command
to execute remotelyRPCException - in the event of problems.public Object executeCommandOnCoordinator(RemoteCommand command, boolean synchronous, Serializable... args) throws RPCException
RPCException will be thrown.executeCommandOnCoordinator in interface RPCServicecommand - The command to execute on the coordinator nodesynchronous - if true, sets group request mode to GroupRequest.GET_ALL,
and if false sets it to GroupRequest.GET_NONE.args - an array of Serializable objects corresponding to parameters of the command
to execute remotelyRPCException - in the event of problems.public Object executeCommandOnCoordinator(RemoteCommand command, long timeout, Serializable... args) throws RPCException
RPCException will be thrown.executeCommandOnCoordinator in interface RPCServicecommand - The command to execute on the coordinator nodetimeout - a timeout after which to throw a replication exception.args - an array of Serializable objects corresponding to parameters of the command
to execute remotelyRPCException - in the event of problems.protected Object executeCommandOnCoordinatorMain(RemoteCommand command, boolean synchronous, long timeout, Serializable... args) throws RPCException
RPCException will be thrown.command - The command to execute on the coordinator nodesynchronous - if true, sets group request mode to GroupRequest.GET_ALL,
and if false sets it to GroupRequest.GET_NONE.timeout - a timeout after which to throw a replication exception.args - an array of Serializable objects corresponding to parameters of the command
to execute remotelyRPCException - in the event of problems.protected List<Object> excecuteCommand(List<org.jgroups.Address> dests, RemoteCommand command, boolean synchronous, long timeout, Serializable... args) throws RPCException
dests - the list of members on which the command needs to be executedcommand - the command to executesynchronous - if true, sets group request mode to GroupRequest.GET_ALL, and if false sets
it to GroupRequest.GET_NONE.timeout - a timeout after which to throw a replication exception.args - the list of parametersRPCException - in the event of problems.public Object handle(org.jgroups.Message msg)
handle in interface org.jgroups.blocks.RequestHandlerpublic void block()
block in interface org.jgroups.MembershipListenerpublic void suspect(org.jgroups.Address suspectedMbr)
suspect in interface org.jgroups.MembershipListenerpublic void viewAccepted(org.jgroups.View view)
viewAccepted in interface org.jgroups.MembershipListenerpublic RemoteCommand registerCommand(RemoteCommand command)
RemoteCommand instance, 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.registerCommand in interface RPCServicecommand - the instance of the RemoteCommand to registerpublic void unregisterCommand(RemoteCommand command)
RemoteCommand instance, if the id is known or the instance itself is known
otherwise it will be ignoredunregisterCommand in interface RPCServicecommand - the command to unregisterpublic boolean isCoordinator()
throws RPCException
isCoordinator in interface RPCServicetrue if the coordinator is the coordinator, false otherwise
throws RPCException in case the RPCService is in an illegal stateRPCExceptionpublic void registerTopologyChangeListener(TopologyChangeListener listener) throws SecurityException
TopologyChangeListenerregisterTopologyChangeListener in interface RPCServicelistener - the listener to be registeredSecurityException - if the SecurityManager is installed and the call method
doesn't have the RuntimePermission ACCESS_RPC_SERVICE_PERMISSIONpublic void unregisterTopologyChangeListener(TopologyChangeListener listener) throws SecurityException
TopologyChangeListener if it existsunregisterTopologyChangeListener in interface RPCServicelistener - the listener to unregisterSecurityException - if the SecurityManager is installed and the call method
doesn't have the RuntimePermission ACCESS_RPC_SERVICE_PERMISSIONprotected RemoteCommand getCommand(String commandId)
RemoteCommand corresponding to the given idcommandId - the command id of the command to retrieveRemoteCommandpublic void start()
start in interface org.picocontainer.Startablepublic void stop()
stop in interface org.picocontainer.Startableprotected long getDefaultTimeout()
protected String getClusterName()
protected long getRetryTimeout()
protected boolean isAllowFailover()
true if the failover capabilities are allowed, false
otherwiseprotected abstract org.jgroups.Address getLocalAddress()
#getAddress(). Addresses can be used as destination
in the send() operation.protected abstract org.jgroups.util.RspList castMessage(List<org.jgroups.Address> dests, org.jgroups.Message msg, boolean synchronous, long timeout) throws Exception
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.Object and associated to its sender.Exception - if any error occur while casting the messageprotected abstract org.jgroups.Channel createChannel()
throws Exception
Exception - if any error occur while creating the channelprotected abstract List<org.jgroups.Address> getMembers(org.jgroups.View view)
protected abstract void setObject(org.jgroups.Message m,
Object o)
Copyright © 2015 eXo Platform SAS. All Rights Reserved.