Class BaseConnection

java.lang.Object
com.seeq.link.sdk.BaseConnection
All Implemented Interfaces:
Connection
Direct Known Subclasses:
DatasourceConnectionV2Host

public abstract class BaseConnection extends Object implements Connection
Facilitates a consistent approach external connection establishment and monitoring. External connections can be connector datasources or the Seeq Server. Once connected, a monitoring thread will periodically call the abstract monitor() function that must be implemented in derived classes. If the monitor function() discovers a dead connection and sets the state to Disconnected, the monitoring thread will attempt reconnection at intervals that exponentially increase (to avoid flooding the log). See Connection for more documentation on the interface.
  • Field Details

    • lastException

      protected Exception lastException
  • Constructor Details

    • BaseConnection

      public BaseConnection()
  • Method Details

    • initialize

      public abstract void initialize()
      Description copied from interface: Connection
      Initializes a connection, attempting to connect if enabled.
      Specified by:
      initialize in interface Connection
    • destroy

      public abstract void destroy()
      Description copied from interface: Connection
      Disconnects from external systems and kills the monitoring thread.
      Specified by:
      destroy in interface Connection
    • getState

      public Connection.ConnectionState getState()
      Description copied from interface: Connection
      The current state of the connection.
      Specified by:
      getState in interface Connection
      Returns:
      state of the connection
    • getConnectionMessage

      public String getConnectionMessage()
      Description copied from interface: Connection
      A summary of the connection status, including any connection failure reason.
      Specified by:
      getConnectionMessage in interface Connection
      Returns:
      summary of the connection status, including any connection failure reason.
    • getLastException

      public Exception getLastException()
      The last exception that has occurred on the connection.
      Returns:
      the last exception
    • getStateChangedEvent

      public Event<Connection.StateChangedEventArgs> getStateChangedEvent()
      Description copied from interface: Connection
      Event for state changes of the connection.
      Specified by:
      getStateChangedEvent in interface Connection
      Returns:
      the state changed event
    • getConnectionId

      protected abstract String getConnectionId()
      The connection ID used to connect to the server.
      Returns:
      the connection ID
    • setState

      protected void setState(Connection.ConnectionState newState, String message)
      Set the current state of the connection. If the new state is Disconnected and automaticallyReconnect is true, an attempt will be made to reconnect within the ReconnectDelay.
      Parameters:
      newState - The new state for the connection.
      message - A message that indicates the status of the connection.
    • handleConnectionMonitorException

      protected void handleConnectionMonitorException(String methodName, Exception exception)
    • getMinReconnectDelay

      public Duration getMinReconnectDelay()
      Time to wait, default is 5 seconds. Connectors use an exponential backoff algorithm to reduce the noise in the log files when a connection is down.
      Specified by:
      getMinReconnectDelay in interface Connection
      Returns:
      minimum reconnect delay
    • setMinReconnectDelay

      public void setMinReconnectDelay(Duration value)
      Description copied from interface: Connection
      Time to wait before reconnecting. Default is 5 seconds. There is an "exponential backoff" algorithm at play that will increase the reconnect delay as repeated attempts fail. That's why this is the minimum delay.
      Specified by:
      setMinReconnectDelay in interface Connection
      Parameters:
      value - minimum reconnect delay
    • getMaxReconnectDelay

      public Duration getMaxReconnectDelay()
      Description copied from interface: Connection
      Maximum time to delay a reconnect attempt. Default is 5 minutes. There is an "exponential backoff" algorithm at play that will increase the reconnect delay as repeated attempts fail.
      Specified by:
      getMaxReconnectDelay in interface Connection
      Returns:
      maximum reconnect delay
    • setMaxReconnectDelay

      public void setMaxReconnectDelay(Duration value)
      Description copied from interface: Connection
      Maximum time to delay a reconnect attempt. Default is 5 minutes. There is an "exponential backoff" algorithm at play that will increase the reconnect delay as repeated attempts fail.
      Specified by:
      setMaxReconnectDelay in interface Connection
      Parameters:
      value - maximum reconnect delay
    • getMonitorPeriod

      public Duration getMonitorPeriod()
      Description copied from interface: Connection
      Time between testing of the connection vitality. Default should be 5 seconds.
      Specified by:
      getMonitorPeriod in interface Connection
      Returns:
      the monitor period
    • setMonitorPeriod

      public void setMonitorPeriod(Duration value)
      Description copied from interface: Connection
      Time between testing of the connection vitality. Default should be 5 seconds.
      Specified by:
      setMonitorPeriod in interface Connection
      Parameters:
      value - - the new monitor period
    • getBackgroundThreads

      public ThreadCollection getBackgroundThreads()
    • enable

      public void enable()
      Enable connections to the server and attempt to make a connection. This calls the connect method in the derived class.
      Specified by:
      enable in interface Connection
    • disable

      public void disable()
      Disable connections to the server. This calls the disconnect method in the derived class.
      Specified by:
      disable in interface Connection
    • connect

      protected abstract void connect()
      Connect to the server (implemented by derived classes).
    • monitor

      protected abstract void monitor()
      A connector-specific test to ensure the connection is alive (implemented by derived classes).
    • disconnect

      protected abstract void disconnect()
      Disconnect from the server (implemented by derived classes).