Class ReconnectingGateway

  • All Implemented Interfaces:
    Gateway

    public class ReconnectingGateway
    extends Object
    implements Gateway
    A Gateway which periodically attempts to connect to the server until the connection is established
    • Constructor Detail

      • ReconnectingGateway

        @Inject
        public ReconnectingGateway​(Gateway actualGateway,
                                   Timer connectTimer,
                                   org.joda.time.Duration initialReconnectDelay,
                                   org.joda.time.Duration reconnectInterval)
        Initializes a new instance of the ReconnectingGateway class.
        Parameters:
        actualGateway - The wrapped Gateway instance used for actual communication
        connectTimer - The Timer used to periodically attempt to establish a connection.
        initialReconnectDelay - The Duration specifying the initial reconnect interval.
        reconnectInterval - The Duration specifying the reconnect interval.
        Throws:
        IllegalArgumentException - The actualGateway is a null reference or a connectTimer is a null reference or a reconnectInterval is a null reference.
    • Method Detail

      • connect

        public void connect()
                     throws IOException
        Attempts to establish a connection to the remote site.
        Specified by:
        connect in interface Gateway
        Throws:
        IOException - There was an error establishing the connection.
      • disconnect

        public void disconnect​(boolean dueToError)
        Drops the established connection.
        Specified by:
        disconnect in interface Gateway
        Parameters:
        dueToError - - when false user wished to close connection; when true there was a problem and we had to close it
      • isConnected

        public boolean isConnected()
        Gets a value specifying whether the connection to the remote site is established.
        Specified by:
        isConnected in interface Gateway
        Returns:
        Value specifying whether the connection to the remote site is established.
      • getLastReceivedMsgTimestamp

        public long getLastReceivedMsgTimestamp()
        Gets last timestamp in unix millis when the last msg was received
        Specified by:
        getLastReceivedMsgTimestamp in interface Gateway
        Returns:
        timestamp when the last msg was received
      • getId

        public String getId()
        Description copied from interface: Gateway
        Gets gateway id (hostname, port, ...)
        Specified by:
        getId in interface Gateway
        Returns:
        gateway identification