Class NonClusterManager

java.lang.Object
com.atlassian.testsupport.NonClusterManager
All Implemented Interfaces:
com.atlassian.beehive.ClusterLockService, ClusterExecutionService, ClusterManager, ClusterManagerInternal

@Internal public final class NonClusterManager extends Object implements ClusterManagerInternal, com.atlassian.beehive.ClusterLockService
An implementation of ClusterManager for use when no clustering is configured. It provides sensible default implementation of some methods where appropriate, emulating a "single node cluster".
  • Constructor Details

    • NonClusterManager

      public NonClusterManager()
  • Method Details

    • init

      public void init()
    • shutdown

      public void shutdown()
    • configure

      public void configure(ClusterConfig config)
      Description copied from interface: ClusterManagerInternal
      Set a new cluster configuration.
      Specified by:
      configure in interface ClusterManagerInternal
      Parameters:
      config -
    • getClusterInformation

      public ClusterInformation getClusterInformation()
      Description copied from interface: ClusterManager
      Get information about the running cluster.
      Specified by:
      getClusterInformation in interface ClusterManager
    • getThisNodeInformation

      public ClusterNodeInformation getThisNodeInformation()
      Description copied from interface: ClusterManager

      Get the identity of this node in the cluster. ClusterNodeInformation implements equals().

      Specified by:
      getThisNodeInformation in interface ClusterManager
      Returns:
      the identity of this node in the cluster. May return null if the node is not in a cluster.
    • getAllNodesInformation

      public Collection<ClusterNodeInformation> getAllNodesInformation()
      Specified by:
      getAllNodesInformation in interface ClusterManager
    • isClustered

      public boolean isClustered()
      Specified by:
      isClustered in interface ClusterManager
      Returns:
      true if this instance is configured to allow clustering with other nodes. Note, this does not mean this instance is licensed to cluster.
    • isConfigured

      public boolean isConfigured()
      Specified by:
      isConfigured in interface ClusterManagerInternal
      Returns:
      true if ClusterManagerInternal.configure(ClusterConfig) has been called with a valid configuration, otherwise false.
    • publishEvent

      public void publishEvent(Serializable event)
      Description copied from interface: ClusterManagerInternal
      Publish an event as a ClusterEventWrapper to other nodes

      This waits for any current transaction to be committed successfully before scheduling the event for publishing.

      Specified by:
      publishEvent in interface ClusterManagerInternal
    • publishEventImmediately

      public void publishEventImmediately(Serializable event)
      Description copied from interface: ClusterManagerInternal
      Publish immediately, an event as a ClusterEventWrapper to other nodes

      This is done immediately regardless of the state of any current transactions.

      Specified by:
      publishEventImmediately in interface ClusterManagerInternal
    • reconfigure

      public void reconfigure(ClusterConfig config)
      Description copied from interface: ClusterManagerInternal
      Set a new cluster configuration and cycle the service
      Specified by:
      reconfigure in interface ClusterManagerInternal
      Parameters:
      config -
    • startCluster

      public void startCluster()
      Description copied from interface: ClusterManagerInternal
      Start the clustering service
      Specified by:
      startCluster in interface ClusterManagerInternal
    • stopCluster

      public void stopCluster()
      Description copied from interface: ClusterManagerInternal
      Stop the clustering service
      Specified by:
      stopCluster in interface ClusterManagerInternal
    • getNodeStatusMap

      public Map<ClusterNodeInformation,NodeStatus> getNodeStatusMap()
      Description copied from interface: ClusterManager
      Gets status information from all members of the cluster.
      Specified by:
      getNodeStatusMap in interface ClusterManager
    • getClusterInvariants

      public ClusterInvariants getClusterInvariants()
      Description copied from interface: ClusterManagerInternal
      Get all attributes of the server that must be consistent between the nodes of a stable cluster. They are to be retrieved from another member in the cluster. If there are no other members currently active in the cluster, then return null.
      Specified by:
      getClusterInvariants in interface ClusterManagerInternal
      Returns:
      the cluster invariants of this server
    • submitToKeyOwner

      public <T> CompletionStage<T> submitToKeyOwner(Callable<T> task, String serviceName, Object key)
      Description copied from interface: ClusterExecutionService
      Submit a task to be executed by a service given by its name on one node of the cluster that own a given key.
      Specified by:
      submitToKeyOwner in interface ClusterExecutionService
      Parameters:
      task - task to be executed on the node that owns the provided key, it must be Serializable
      serviceName - name of service used to execute the task
      key - key used to determined which node is going to execute the task, it must be Serializable
      Returns:
      CompletionStage
    • submitToNode

      public <T> ClusterNodeExecution<T> submitToNode(String nodeId, Callable<T> task, String serviceName)
      Description copied from interface: ClusterExecutionService
      Submit a task to be executed on a node with the specified ID
      Specified by:
      submitToNode in interface ClusterExecutionService
      Parameters:
      nodeId - ID of the node that should execute the task. If null, task will be executed locally.
      task - task to be executed on the specified node
      serviceName - name of service used to execute the task
      Returns:
      node execution result
    • submitToAllNodes

      public <T> List<ClusterNodeExecution<T>> submitToAllNodes(Callable<T> task, String serviceName)
      Description copied from interface: ClusterExecutionService
      Submit a task to be executed on all nodes in the cluster.
      Specified by:
      submitToAllNodes in interface ClusterExecutionService
      Parameters:
      task - task to be executed on the node that owns the provided key, it must be Serializable
      serviceName - name of service used to execute the task
      Returns:
      List of ClusterNodeExecution, one element from each node
    • getClusterUptime

      public long getClusterUptime()
      Description copied from interface: ClusterManager
      Gets the amount of time that the cluster has been running.
      Specified by:
      getClusterUptime in interface ClusterManager
      Returns:
      the time in milliseconds since the first node in the cluster came up, or the node uptime if not clustered.
    • getLockForName

      public com.atlassian.beehive.ClusterLock getLockForName(@NonNull String key)
      Specified by:
      getLockForName in interface com.atlassian.beehive.ClusterLockService
    • tryAcquire

      public boolean tryAcquire(@NonNull String name, int initialPermits, long timeout, @NonNull TimeUnit unit) throws InterruptedException
      Description copied from interface: ClusterManager
      Attempts to acquire a permit from a semaphore with the specified name. If the semaphore is not already initialized, it will be initialized with the specified number of initial permits.
      Specified by:
      tryAcquire in interface ClusterManager
      Parameters:
      name - the name of the semaphore to acquire a permit from. Must not be null.
      initialPermits - the number of permits to initialize the semaphore with if it is not already initialized.
      timeout - the maximum time to wait for a permit
      unit - the time unit of the timeout argument. Must not be null.
      Returns:
      true if a permit was acquired successfully, false if the timeout elapsed before acquiring a permit
      Throws:
      InterruptedException
    • release

      public void release(@NonNull String name)
      Description copied from interface: ClusterManager
      Releases a permit back to the semaphore with the specified name. This increases the number of available permits.
      Specified by:
      release in interface ClusterManager
      Parameters:
      name - the name of the semaphore to release a permit to. Must not be null.