@ThreadSafe public abstract class ClusteringService extends Object
LockingService when running in a cluster, relying on JGroups' CENTRAL_LOCK protocol.| Modifier and Type | Class and Description |
|---|---|
protected class |
ClusteringService.Listener |
protected class |
ClusteringService.Receiver |
| Modifier and Type | Field and Description |
|---|---|
protected org.jgroups.Channel |
channel
The JGroups channel which will be used to send/receive event across the cluster
|
protected String |
clusterName
The name of the cluster (in standalone mode) or the ID of the fork stack (in forked mode)
|
protected ClusteringService.Listener |
listener
The listener for channel changes.
|
protected static Logger |
LOGGER |
protected ClusteringService.Receiver |
receiver
The component that will receive the JGroups messages.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ClusteringService(String clusterName) |
| Modifier and Type | Method and Description |
|---|---|
void |
addConsumer(MessageConsumer<? extends Serializable> consumer)
Adds a new message consumer to this service.
|
String |
clusterName()
Returns the name of the cluster which has been configured for this service.
|
protected Serializable |
fromByteArray(byte[] data,
ClassLoader classLoader) |
org.jgroups.Channel |
getChannel()
Returns the JGroups channel used for clustered communication.
|
long |
getMaxAllowedClockDelayMillis()
Returns the maximum accepted delay in clock time between cluster members.
|
protected abstract void |
init() |
boolean |
isOpen()
Checks if this instance is open or not (open means the JGroups channel has been connected).
|
int |
membersInCluster()
Returns the number of members in the cluster.
|
boolean |
multipleMembersInCluster()
Checks if the cluster has multiple members.
|
void |
restart()
Performs a shutdown/startup sequence.
|
boolean |
sendMessage(Serializable payload)
Sends a message of a given type across a cluster.
|
boolean |
shutdown()
Shuts down and clears resources held by this service.
|
static ClusteringService |
startForked(org.jgroups.Channel mainChannel)
Starts a new clustering service by forking a channel of an existing JGroups channel.
|
static ClusteringService |
startStandalone(String clusterName,
org.jgroups.Channel channel)
Starts a standalone clustering service which uses the supplied channel.
|
static ClusteringService |
startStandalone(String clusterName,
String jgroupsConfig)
Starts a standalone clustering service which in turn will start & connect its own JGroup channel.
|
String |
toString() |
protected static final Logger LOGGER
protected final ClusteringService.Listener listener
protected final ClusteringService.Receiver receiver
protected final String clusterName
protected org.jgroups.Channel channel
protected ClusteringService(String clusterName)
public void restart()
throws Exception
Exception - if anything unexpected failspublic void addConsumer(MessageConsumer<? extends Serializable> consumer)
consumer - a MessageConsumer instance.public boolean shutdown()
true if the service has been shutdown or false if it had already been shut down.public boolean isOpen()
true if the service is open, false otherwise.public boolean multipleMembersInCluster()
true if the cluster has multiple members, false otherwise.public int membersInCluster()
public String clusterName()
String the name of the cluster; never nullpublic long getMaxAllowedClockDelayMillis()
public boolean sendMessage(Serializable payload)
payload - the main body of the message; must not be nulltrue if the send operation was successful, false otherwisepublic static ClusteringService startStandalone(String clusterName, String jgroupsConfig)
clusterName - the name of the cluster to which the JGroups channel should connect; may not be nulljgroupsConfig - either the path or the XML content of a JGroups configuration file; may not be nullClusteringService instance, never nullpublic static ClusteringService startStandalone(String clusterName, org.jgroups.Channel channel)
clusterName - the name of the cluster to which the JGroups channel should connect; may not be nullchannel - a Channel instance, may not be nullClusteringService instance, never nullpublic static ClusteringService startForked(org.jgroups.Channel mainChannel)
mainChannel - a Channel instance; may not be null.ClusteringService instance, never nullprotected Serializable fromByteArray(byte[] data, ClassLoader classLoader) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionpublic org.jgroups.Channel getChannel()
Channel instance, never nullprotected abstract void init()
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.