org.modeshape.jcr.clustering

## Class ClusteringService

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

-     @ThreadSafe
      public final 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 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 Summary

    Constructors
    Constructor and Description
    `ClusteringService()` Creates an empty, not started clustering service.

  - ### 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)`
    `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.

    - ### 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

    - #### isOpen

          protected final AtomicBoolean isOpen

      Flag that dictates whether this service has connected to the cluster.

    - #### membersInCluster

          protected final AtomicInteger membersInCluster

      The numbers of members in the cluster

    - #### lockService

          protected org.jgroups.blocks.locking.LockService lockService

      The service used for cluster-wide locking

    - #### consumers

          protected final Set<MessageConsumer<Serializable>> consumers

      A list of message consumers which register themselves with this service.

  - ### Constructor Detail

    - #### ClusteringService

          public ClusteringService()

      Creates an empty, not started clustering service.

  - ### Method Detail

    - #### startStandalone

          public 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.
        `jgroupsConfig` - either the path or the XML content of a JGroups configuration file; may be null
      Returns:
        this instance

    - #### startForked

          public ClusteringService startForked(org.jgroups.Channel mainChannel)

      Starts a new clustering service by forking a channel of an existing JGroups channel.
      Parameters:
        `mainChannel` - a `Channel` instance; may not be null.
      Returns:
        this instance

    - #### addConsumer

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

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

    - #### shutdown

          public void shutdown()

      Shuts down and clears resources held by this service.

    - #### 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

    - #### fromByteArray

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

      Throws:
        `IOException`
        `ClassNotFoundException`

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