@ThreadSafe public abstract 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 org.jgroups.JChannel |
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 org.jgroups.blocks.locking.LockService |
lockService
The service used for cluster-wide locking
|
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) |
protected org.jgroups.JChannel |
getChannel() |
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(String forkStackId,
org.jgroups.Channel mainChannel)
Starts a new clustering service by forking a channel of an existing JGroups channel.
|
static 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 ClusteringService.Listener listener
protected final ClusteringService.Receiver receiver
protected final String clusterName
protected org.jgroups.JChannel channel
protected org.jgroups.blocks.locking.LockService lockService
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 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 null
public long getMaxAllowedClockDelayMillis()
public boolean sendMessage(Serializable payload)
payload
- the main body of the message; must not be null
true
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 startForked(String forkStackId, org.jgroups.Channel mainChannel)
forkStackId
- a String
representing the JGroups stack ID of the fork stack. Services which are supposed to
communicate with each other should use the same stack id; may not be nullmainChannel
- a Channel
instance; may not be null.ClusteringService
instance, never nullprotected Serializable fromByteArray(byte[] data, ClassLoader classLoader) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
protected org.jgroups.JChannel getChannel()
protected abstract void init()
Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.