Class ClusterNode

All Implemented Interfaces:
ADEPT2Service, LogService, ServiceThreadHandling, ClusterService, ClusterCommPoller, ClusterDbPoller

Deprecated.
This class is subject of change and must not be used yet except for testing purpose. Its interface and implementation may change any time!
This class represents a node in an AristaFlow cluster. It is used for bootstrapping a node which either bootstraps as server or as client. In one cluster only one node will be the server, all other nodes will be clients. In case the server terminates, another node will take its place. This will be handled automatically.
To allow for nodes to switch roles between client and server, each node needs a server as well as a client configuration. Both are provided in the constructor of a cluster node.

Use this class instead of AristaFlowPlatform for bootstrapping in a cluster environment.

This class handles all cluster stuff automatically, that is, if the server is not available any more or there are any problems reaching the server, the cluster node restarts. In case of problems it also may restart or even terminate in case of unrecoverable problems. However, this requires to run asynchronously, so bootstrap(), restart(long) and terminate() return early. You will have to check the status via ClusterNodeState.getStatus() or ClusterNodeState.awaitStatus(long, Status...) to make sure that the cluster is in the appropriate state.

Nevertheless, make sure that you terminate() the cluster node (and await Status.TERMINATED) to properly terminate the platform! Otherwise your JVM may not exit properly or not exit at all.

  • Field Details

    • dbServer

      protected ClusterNodeInformation dbServer
      Deprecated.
      Data related to the current server as retrieved from the database. This will be null until a server is retrieved from the database. Afterwards this information refers to the last server retrieved from the database. This data may be stale.
    • commServer

      protected final de.aristaflow.adept2.core.registry.cluster.ServerData commServer
      Deprecated.
      Data related to the current server like URIs and the amount of lost connections.
    • nodeState

      protected final ClusterNodeState nodeState
      Deprecated.
      The state of this cluster node encapsulated in a separate object.
    • heartBeatControl

      protected final HeartBeatControl heartBeatControl
      Deprecated.
      The control for the heartbeats of this cluster node.
    • nodeControl

      protected final de.aristaflow.adept2.core.registry.cluster.NodeControl nodeControl
      Deprecated.
      The thread controlling this node, that is it handles the complete node lifecycle including restarting and thus changing roles.
    • controlLock

      protected final Lock controlLock
      Deprecated.
      The lock required to control this cluster node. This includes starting, terminating and restarting but also polling. Polling relies on the current cluster node status and update times so this must not happen concurrently while another thread performs another control operation.
    • serviceStateTracker

      protected final ServiceStateTracker serviceStateTracker
      Deprecated.
      The service state tracker coupled to the lifecycle of this cluster node instead of the internal platform. This allows for service state tracking independent from the current state of the internal platform.
    • registry

      protected Registry registry
      Deprecated.
      The registry used to access the communication service of the cluster server.
  • Constructor Details

    • ClusterNode

      public ClusterNode(Configuration serverConf, Configuration clientConf, int servAvailPoolSize, long servAvailPollRate, Logger logger)
      Deprecated.
      Creates a new ClusterNode having the designated configurations.
      Parameters:
      serverConf - The configuration to be provided when booted as server. This may either be a complete root configuration (without additional configuration directories), a delta configuration complementing or overriding the configurations from the configuration directories or even null. If this is null, only configurations from the configuration directories will be used but this requires a valid rootConfFileName.
      clientConf - The configuration to be provided when booted as client. This may either be a complete root configuration (without additional configuration directories), a delta configuration complementing or overriding the configurations from the configuration directories or even null. If this is null, only configurations from the configuration directories will be used but this requires a valid rootConfFileName.
      The URI of the global registry will be set to the one of the server of this cluster.
      servAvailPoolSize - The amount of threads used for the service availability tracking.
      servAvailPollRate - The rate in milliseconds at which to poll the availability of services.
      logger - The logger which to use for information that is happening asynchronously that is critical or worth knowing. This has to be configured separately since it is used outside of the platform lifecycle.
      See Also:
    • ClusterNode

      public ClusterNode(ConfigurationPropertyProvider serverProvider, ConfigurationPropertyProvider clientProvider, int servAvailPoolSize, long servAvailPollRate, Logger logger)
      Deprecated.
      Creates a new ClusterNode having the designated configuration providers.
      Parameters:
      serverProvider - The configuration provider to be used when booted as server. This can be null and it can be the same as the clientProvider.
      clientProvider - The configuration provider to be used when booted as client. This can be null and it can be the same as the serverProvider.
      servAvailPoolSize - The amount of threads used for the service availability tracking.
      servAvailPollRate - The rate in milliseconds at which to poll the availability of services.
      logger - The logger which to use for information that is happening asynchronously that is critical or worth knowing. This has to be configured separately since it is used outside of the platform lifecycle.
      See Also:
    • ClusterNode

      public ClusterNode(Configuration serverConf, ConfigurationPropertyProvider serverProvider, Configuration clientConf, ConfigurationPropertyProvider clientProvider, int servAvailPoolSize, long servAvailPollRate, Logger logger)
      Deprecated.
      Creates a new ClusterNode having the designated configurations and the designated configuration providers.
      Parameters:
      serverConf - The configuration to be provided when booted as server. This may either be a complete root configuration (without additional configuration directories), a delta configuration complementing or overriding the configurations from the configuration directories or even null. If this is null, only configurations from the configuration directories will be used but this requires a valid rootConfFileName.
      serverProvider - The configuration provider to be used when booted as server. This can be null and it can be the same as the clientProvider.
      clientConf - The configuration to be provided when booted as client. This may either be a complete root configuration (without additional configuration directories), a delta configuration complementing or overriding the configurations from the configuration directories or even null. If this is null, only configurations from the configuration directories will be used but this requires a valid rootConfFileName.
      The URI of the global registry will be set to the one of the server of this cluster.
      clientProvider - The configuration provider to be used when booted as client. This can be null and it can be the same as the serverProvider.
      servAvailPoolSize - The amount of threads used for the service availability tracking.
      servAvailPollRate - The rate in milliseconds at which to poll the availability of services.
      logger - The logger which to use for information that is happening asynchronously that is critical or worth knowing. This has to be configured separately since it is used outside of the platform lifecycle.
      See Also:
  • Method Details

    • bootstrap

      public void bootstrap()
      Deprecated.
      Bootstraps this cluster node asynchronously. You might want to await a specific status or the client service or the registry.

      Only one platform may be running at a time. You need to terminate a platform before you can bootstrap another one. Note that terminating is done asynchronously so you need to wait for this cluster node to be terminated.

      Throws:
      IllegalThreadStateException - If this cluster node has already been bootstrapped, an IllegalThreadStateException will be thrown.
    • getServiceStateTracker

      public ServiceStateTracker getServiceStateTracker()
      Deprecated.
      Gets the service state tracker coupled to the lifecycle of this cluster node instead of the internal platform. This allows for service state tracking independent from the current state of the internal platform.
      Returns:
      The service state tracker coupled to the lifecycle of this cluster node instead of the internal platform.
    • getClientService

      public ClientService getClientService(long timeout) throws AbortServiceException, InterruptedException
      Deprecated.
      Gets the client service providing convenient access to the services provided by the platform and needed by client components. The client service will be retrieved with waiting for the platform for the designated amount of time if it is currently not available.
      Parameters:
      timeout - The time in milliseconds to wait for the platform if it is not available.
      Returns:
      The client service for usage by client components.
      Throws:
      InterruptedException - If the current thread is interrupted while waiting for the platform to become available, an InterruptedException will be thrown.
      ServiceNotKnownException - If there are problems retrieving the client service, a ServiceNotKnownException will be thrown.
      AbortServiceException - If the platform has not been bootstrapped or terminated or a non-recoverable problem has occurred, an AbortServiceException will be thrown.
    • getRegistry

      public Registry getRegistry(long timeout) throws AbortServiceException, InterruptedException
      Deprecated.
      Gets the wrapper for accessing the platform via the Registry -interface waiting for the designated amount of time if the platform is currently not available. The registry is used by (server) services to access the registry. Clients should always use an appropriate client service. Only use this registry for very special purposes.
      Parameters:
      timeout - The time in milliseconds to wait for the platform if it is not available.
      Returns:
      The registry providing generic access to the platform or null if the timeout elapsed before the platform becomes available.
      Throws:
      InterruptedException - If the current thread is interrupted while waiting for the platform to become available, an InterruptedException will be thrown.
      ServiceNotKnownException - If there are problems loading the model factory registry, a ServiceNotKnownException will be thrown.
      AbortServiceException - If the platform has not been bootstrapped or terminated or a non-recoverable problem has occurred, an AbortServiceException will be thrown.
    • getRootConfiguration

      public Configuration getRootConfiguration(long timeout) throws AbortServiceException, InterruptedException
      Deprecated.
      Gets the root configuration used for this cluster node as clone waiting for the designated amount of time if the platform is currently not available. Note that the root configuration need not contain all configuration values. Configurations from referenced configuration files will not be part of it.
      Note that the root configuration does not contain the default values added by the configuration description of a service. Additionally, it is not validated yet, that is, some required values may be missing leading to problems when starting the corresponding service.
      Parameters:
      timeout - The time in milliseconds to wait for the platform if it is not available.
      Returns:
      A clone of the root configuration after bootstrapping and null after terminating.
      Throws:
      InterruptedException - If the current thread is interrupted while waiting for the platform to become available, an InterruptedException will be thrown.
      ServiceNotKnownException - If there are problems loading the model factory registry, a ServiceNotKnownException will be thrown.
      AbortServiceException - If the platform has not been bootstrapped or terminated or a non-recoverable problem has occurred, an AbortServiceException will be thrown.
    • restart

      public Status restart(long timeout) throws InterruptedException, AbortServiceException
      Deprecated.
      Sends a restart request to this cluster node and waits the designated time for the restart.
      Parameters:
      timeout - The time in milliseconds to wait for the cluster node to be restarted or terminated. reach one of the designated statuses. Use 0 to not wait at all or a negative value to wait without time limit.
      Returns:
      The status this node reached after restarting ( Status.RUNNING_SERVER, Status.CONNECTED_CLIENT or Status.TERMINATED) or null in case the time elapsed before the status is reached.
      Throws:
      InterruptedException - If the current thread is interrupted while waiting for the restart, an InterruptedException will be thrown.
      AbortServiceException - If there are non-recoverable problems with the cluster especially when bootstrapping, an AbortServiceException will be thrown.
    • terminate

      public void terminate()
      Deprecated.
      Sends a terminate request to this cluster node. This will terminate the platform by shutting down the bootstrap registry and signalling this to the cluster asynchronously. You have to call this method before exiting the JVM. Otherwise the services will not be terminated correctly and may have inconsistent persisted data. This especially applies to the cluster DB service.
      If there are problems when terminating, they will be logged.
      You should wait for this cluster node to be Status.TERMINATED before really shutting down or exiting the JVM.

      Terminating the platform several times will be ignored. The same applies to terminating before loading.

    • getAllClusterNodes

      public Set<ClusterNodeInformation> getAllClusterNodes()
      Deprecated.
      Retrieves the set of all known Cluster Nodes (dead or alive).
      Returns:
      The set of all known Cluster Nodes (dead or alive) or null in case no cluster DB is available.
    • pollServerDb

      public boolean pollServerDb(long timeout, ClusterInteractionRequest request) throws InterruptedException, TimeoutException, SQLException
      Deprecated.
      Description copied from interface: ClusterDbPoller
      Polls the server of this cluster and sends an alive signal to the cluster DB service. If the server is no longer available or it changed, a restart should be executed. This is indicated by the return value.

      If the control of the cluster node cannot be acquired in the designated time, this method will do nothing.

      Specified by:
      pollServerDb in interface ClusterDbPoller
      Parameters:
      timeout - The time in milliseconds to wait for the cluster control lock.
      request - Whether to simply poll or to restart the server. A restart request contains the cluster name, the node name as well as the time since when the server has been running. If this is null, the current server will just be polled.
      Returns:
      Whether the cluster node needs to restart since another server has been elected or is about to be elected.
      Throws:
      InterruptedException - If the calling thread is interrupted while waiting for the node control or has been interrupted before, an InterruptedException will be thrown.
      TimeoutException - If the table for updating the status cannot be locked in time, a TimeoutException will be thrown.
      SQLException - If there are problems updating the status in the cluster table, an SQLException will be thrown.
    • restartInternal

      public void restartInternal()
      Deprecated.
      Description copied from interface: ClusterDbPoller
      Signals a restart of this cluster node. This may be for instance due to the cluster requiring a new server (ClusterDbPoller.pollServerDb(long, ClusterInteractionRequest)) or polling fails too often.
      Specified by:
      restartInternal in interface ClusterDbPoller
    • getServerCommService

      public URI[] getServerCommService()
      Deprecated.
      Description copied from interface: ClusterCommPoller
      Gets the URIs of the cluster service of the server for inter node communication.
      Specified by:
      getServerCommService in interface ClusterCommPoller
      Returns:
      The URIs of the cluster service of the server for inter node communication or null if no global registry URIs are set.
    • pollServerComm

      public void pollServerComm(long timeout, boolean serverDoubtful) throws InterruptedException
      Deprecated.
      Description copied from interface: ClusterCommPoller
      Polls the server of this cluster via communication. If the server cannot be reached via communication, the corresponding lost count will be increased. Afterwards the cluster heartbeat using the database will be notified. It will also be notified if the state of the server changes.

      If the control of the cluster node cannot be acquired in the designated time, this method will do nothing.

      Specified by:
      pollServerComm in interface ClusterCommPoller
      Parameters:
      timeout - The time in milliseconds to wait for the cluster control lock.
      serverDoubtful - Whether the server is doubtful and should be notified appropriately.
      Throws:
      InterruptedException - If the calling thread is interrupted while waiting for the node control or has been interrupted before, an InterruptedException will be thrown.
    • getState

      public ClusterNodeState getState()
      Deprecated.
      Gets the node state of this cluster node. This reflects the current state of the cluster node all the time.
      Returns:
      The node state of this cluster node.
    • initPlatform

      public void initPlatform(Configuration conf, Registry reg) throws AbortServiceException
      Deprecated.
      Description copied from class: AuthenticatedInjectedService
      Creates a wrapped AbstractAuthenticatedService.
      Overrides:
      initPlatform in class AuthenticatedInjectedService
      Parameters:
      conf - The configuration provided by the platform.
      reg - The registry allowing to access the platform.
      Throws:
      AbortServiceException - If there are problems initialising this service, an AbortServiceException will be thrown.
    • init

      public void init(URI[] localExportedUris, URI[] globalExportedUris) throws AbortServiceException
      Deprecated.
      Checks the licence for failover cluster and starts the heartbeat using the communication.
      Specified by:
      init in interface ADEPT2Service
      Overrides:
      init in class InitialisedInjectedService
      Parameters:
      localExportedUris - The URIs with which this service is exported locally or a local URI or an empty array for internal services.
      globalExportedUris - The URIs with which this service is published globally or null in case the service is not published.
      Throws:
      AbortServiceException - If this service cannot be initialised due to a severe problem, an AbortServiceException will be thrown. ADEPT2Service.shutdown(boolean) will not be called when aborting; the service has to shut down itself/clean up before throwing the exception.
      See Also:
    • start

      public void start() throws AbortServiceException
      Deprecated.
      Start the service state tracker after starting this injected service. This service is used to track the platform state and should be started when starting the service state tracker.
      Specified by:
      start in interface ADEPT2Service
      Overrides:
      start in class InitialisedInjectedService
      Throws:
      AbortServiceException - If this service cannot be started due to a severe problem, an AbortServiceException will be thrown. ADEPT2Service.shutdown(boolean) will not be called when aborting; the service has to shut down itself/clean up before throwing the exception.
      See Also:
    • shutdown

      public void shutdown(boolean emergency)
      Deprecated.
      Description copied from interface: ADEPT2Service
      Signals this service that it is being shut down. While this method is called, the service is no longer (remotely) available. It should terminate and close all activities and connections. Since the service is in an inconsistent state while shutting down, access should be restricted to the threads relevant for shutting down. All other requests should be blocked (see ServiceThreadHandling.
      All startup required services are available in shutdown, runtime services may already be shut down.
      In case of an emergency shutdown, even startup required services may not be available. Additionally, shutting down should be rather fast, so cleanup should concentrate on the really important things and use brief timeouts when waiting.
      Specified by:
      shutdown in interface ADEPT2Service
      Overrides:
      shutdown in class InitialisedInjectedService
      Parameters:
      emergency - Whether the shutdown will be an emergency shutdown.
      See Also:
    • getNodeInformation

      public SimpleClusterNodeInformation getNodeInformation(SessionToken session)
      Deprecated.
      Description copied from interface: ClusterService
      Gets information on the cluster node implementing this cluster service.
      Specified by:
      getNodeInformation in interface ClusterService
      Parameters:
      session - The session which is used to check for access rights on this method.
      Returns:
      The simple information for this cluster node, that is name, address, status, last update time and running since. Status and last update time may differ from the values in the database, e. g. a node has changed its status but cannot access the database.
    • doubtfulStatus

      public SimpleClusterNodeInformation doubtfulStatus(SessionToken session, String requestingNode, long lastRequesterUpdate, long lastServerUpdate, long serverRunningSince)
      Deprecated.
      Description copied from interface: ClusterService
      Gets information on the cluster node implementing this cluster service and signals this cluster node, that its status is doubtful. This urges this cluster node to update the database shortly. In case of problems accessing the database, it may even signal its termination.
      Specified by:
      doubtfulStatus in interface ClusterService
      Parameters:
      session - The session which is used to check for access rights on this method.
      requestingNode - The name of the node notifying the doubtful status.
      lastRequesterUpdate - The last time the requester has updated its status (which is the same as checking for the server status.
      lastServerUpdate - The last time the server has updated its status in the database according to the requester. If this is older than the last update time of the server, the requester has not the latest status, thus the notified doubtful status is not valid (any more).
      serverRunningSince - The time the server has switched to running in the database according to the requester. If this is older than the current running since time, the requester has not the latest status, thus the notified doubtful status is not valid (any more).
      Returns:
      The simple information for this cluster node, that is name, address, status, last update time and running since. Status and last update time may differ from the values in the database, e. g. a node has changed its status but cannot access the database.