org.modeshape.jcr.clustering

## Class ClusteringService

- java.lang.Object
- - org.modeshape.jcr.clustering.ClusteringService

-     @ThreadSafe
      public abstract class ClusteringService
      extends Object

  ModeShape service which handles sending/receiving messages in a cluster via JGroups

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ClusteringService.Listener`
    `protected class` | `ClusteringService.Receiver`

  - ### Field Summary

    Fields
    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.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ClusteringService(String clusterName)`

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### LOGGER

          protected static final Logger LOGGER

    - #### listener

          protected final ClusteringService.Listener listener

      The listener for channel changes.

    - #### receiver

          protected final ClusteringService.Receiver receiver

      The component that will receive the JGroups messages.

    - #### clusterName

          protected final String clusterName

      The name of the cluster (in standalone mode) or the ID of the fork stack (in forked mode)

    - #### channel

          protected org.jgroups.JChannel channel

      The JGroups channel which will be used to send/receive event across the cluster

    - #### lockService

          protected org.jgroups.blocks.locking.LockService lockService

      The service used for cluster-wide locking

  - ### Constructor Detail

    - #### ClusteringService

          protected ClusteringService(String clusterName)

  - ### Method Detail

    - #### restart

          public void restart()
                       throws Exception

      Performs a shutdown/startup sequence.
      Throws:
        `Exception` - if anything unexpected fails

    - #### addConsumer

          public void addConsumer(MessageConsumer<? extends Serializable> consumer)

      Adds a new message consumer to this service.
      Parameters:
        `consumer` - a `MessageConsumer` instance.

    - #### shutdown

          public boolean shutdown()

      Shuts down and clears resources held by this service.
      Returns:
        `true` if the service has been shutdown or `false` if it had already been shut down.

    - #### tryLock

          public boolean tryLock(long time,
                        TimeUnit unit)

      Acquires a cluster-wide lock, waiting a maximum amount of time for it.
      Parameters:
        `time` - an amount of time
        `unit` - a `TimeUnit`; may not be null
      Returns:
        `true` if the lock was successfully acquired, `false` otherwise
      See Also:
        `Lock.tryLock(long, java.util.concurrent.TimeUnit)`

    - #### unlock

          public void unlock()

      Unlocks a previously acquired cluster-wide lock.
      See Also:
        `Lock.unlock()`

    - #### isOpen

          public boolean isOpen()

      Checks if this instance is open or not (open means the JGroups channel has been connected).
      Returns:
        `true` if the service is open, `false` otherwise.

    - #### multipleMembersInCluster

          public boolean multipleMembersInCluster()

      Checks if the cluster has multiple members.
      Returns:
        `true` if the cluster has multiple members, `false` otherwise.

    - #### membersInCluster

          public int membersInCluster()

      Returns the number of members in the cluster.
      Returns:
        the number of active members

    - #### clusterName

          public String clusterName()

      Returns the name of the cluster which has been configured for this service.
      Returns:
        a `String` the name of the cluster; never `null`

    - #### getMaxAllowedClockDelayMillis

          public long getMaxAllowedClockDelayMillis()

      Returns the maximum accepted delay in clock time between cluster members.
      Returns:
        the number of milliseconds representing the maximum accepted delay.

    - #### sendMessage

          public boolean sendMessage(Serializable payload)

      Sends a message of a given type across a cluster.
      Parameters:
        `payload` - the main body of the message; must not be `null`
      Returns:
        `true` if the send operation was successful, `false` otherwise

    - #### startStandalone

          public static ClusteringService startStandalone(String clusterName,
                                          String jgroupsConfig)

      Starts a standalone clustering service which in turn will start & connect its own JGroup channel.
      Parameters:
        `clusterName` - the name of the cluster to which the JGroups channel should connect; may not be null
        `jgroupsConfig` - either the path or the XML content of a JGroups configuration file; may not be null
      Returns:
        a `ClusteringService` instance, never null

    - #### startForked

          public static ClusteringService startForked(String forkStackId,
                                      org.jgroups.Channel mainChannel)

      Starts a new clustering service by forking a channel of an existing JGroups channel.
      Parameters:
        `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 null
        `mainChannel` - a `Channel` instance; may not be null.
      Returns:
        a `ClusteringService` instance, never null

    - #### fromByteArray

          protected Serializable fromByteArray(byte[] data,
                                   ClassLoader classLoader)
                                        throws IOException,
                                               ClassNotFoundException

      Throws:
        `IOException`
        `ClassNotFoundException`

    - #### getChannel

          protected org.jgroups.JChannel getChannel()

    - #### init

          protected abstract void init()

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.