@ThreadSafe public final class ClusteringService extends Object
| Modifier and Type | Class and Description |
|---|---|
protected class |
ClusteringService.Listener |
protected class |
ClusteringService.Receiver |
| Modifier and Type | Field and Description |
|---|---|
protected Set<MessageConsumer<Serializable>> |
consumers
A list of message consumers which register themselves with this service.
|
protected AtomicBoolean |
isOpen
Flag that dictates whether this service has connected to the cluster.
|
protected org.jgroups.blocks.locking.LockService |
lockService
The service used for cluster-wide locking
|
protected static Logger |
LOGGER |
protected AtomicInteger |
membersInCluster
The numbers of members in the cluster
|
| Constructor and Description |
|---|
ClusteringService()
Creates an empty, not started clustering service.
|
| 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) |
long |
getMaxAllowedClockDelayMillis()
Returns the maximum accepted delay in clock time between cluster members.
|
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.
|
boolean |
sendMessage(Serializable payload)
Sends a message of a given type across a cluster.
|
void |
shutdown()
Shuts down and clears resources held by this service.
|
ClusteringService |
startForked(org.jgroups.Channel mainChannel)
Starts a new clustering service by forking a channel of an existing JGroups channel.
|
ClusteringService |
startStandalone(String clusterName,
String jgroupsConfig)
Starts a standalone clustering service which in turn will start & connect its own JGroup channel.
|
boolean |
tryLock(long time,
TimeUnit unit)
Acquires a cluster-wide lock, waiting a maximum amount of time for it.
|
void |
unlock()
Unlocks a previously acquired cluster-wide lock.
|
protected static final Logger LOGGER
protected final AtomicBoolean isOpen
protected final AtomicInteger membersInCluster
protected org.jgroups.blocks.locking.LockService lockService
protected final Set<MessageConsumer<Serializable>> consumers
public ClusteringService()
public ClusteringService startStandalone(String clusterName, String jgroupsConfig)
clusterName - the name of the cluster to which the JGroups channel should connect.jgroupsConfig - either the path or the XML content of a JGroups configuration file; may be nullpublic ClusteringService startForked(org.jgroups.Channel mainChannel)
mainChannel - a Channel instance; may not be null.public void addConsumer(MessageConsumer<? extends Serializable> consumer)
consumer - a MessageConsumer instance.public void shutdown()
public boolean tryLock(long time,
TimeUnit unit)
time - an amount of timeunit - a TimeUnit; may not be nulltrue if the lock was successfully acquired, false otherwiseLock.tryLock(long, java.util.concurrent.TimeUnit)public void unlock()
Lock.unlock()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 otherwiseprotected Serializable fromByteArray(byte[] data, ClassLoader classLoader) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionCopyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.