Class WebSocketNotificationReceiver

All Implemented Interfaces:
NotificationIndexCleanup.Listener, NotificationReceiver, WebSocketListener, Configurable

public class WebSocketNotificationReceiver extends DefaultNotificationReceiver implements WebSocketListener
Receives notifications from an arbitrary web socket.
  • Field Details

    • LOGGER

      public static final Logger LOGGER
      Logger for use in the file
    • SERVER_HOST_PROPERTY

      public static final String SERVER_HOST_PROPERTY
      Property for serverHost
      See Also:
    • SERVER_PORT_PROPERTY

      public static final String SERVER_PORT_PROPERTY
      Property for serverPort
      See Also:
    • SERVER_PATH_PROPERTY

      public static final String SERVER_PATH_PROPERTY
      Property for serverPath
      See Also:
    • SEQUENCE_PROPERTY

      public static final String SEQUENCE_PROPERTY
      Property for sequence
      See Also:
    • TIMESTAMP_PROPERTY

      public static final String TIMESTAMP_PROPERTY
      Property for timestamp
      See Also:
    • TRACKING_FILE_NAME_PROPERTY

      public static final String TRACKING_FILE_NAME_PROPERTY
      Property for trackingFileName
      See Also:
    • CONNECT_ATTEMPTS_PROPERTY

      public static final String CONNECT_ATTEMPTS_PROPERTY
      Property for connectAttempts
      See Also:
    • CONNECT_TIMEOUT_PROPERTY

      public static final String CONNECT_TIMEOUT_PROPERTY
      Property for connectTimeout
      See Also:
    • RETRY_ON_CLOSE_PROPERTY

      public static final String RETRY_ON_CLOSE_PROPERTY
      Property for retryOnClose
      See Also:
    • PING_INTERVAL

      public static final String PING_INTERVAL
      Variable for pingIntervalMillis string
      See Also:
    • PING_WAIT

      public static final String PING_WAIT
      Variable for pingWait string
      See Also:
    • ANY_MESSAGE_INTERVAL

      public static final String ANY_MESSAGE_INTERVAL
      Variable for anyMessageIntervalMillis string
      See Also:
    • DEFAULT_SERVER_HOST

      public static final String DEFAULT_SERVER_HOST
      Default server host
      See Also:
    • DEFAULT_SERVER_PORT

      public static final String DEFAULT_SERVER_PORT
      Default server port
      See Also:
    • DEFAULT_SERVER_PATH

      public static final String DEFAULT_SERVER_PATH
      Default server path
      See Also:
    • DEFAULT_TRACKING_FILE_NAME

      public static final String DEFAULT_TRACKING_FILE_NAME
      Default tracking file
      See Also:
    • DEFAULT_CONNECT_ATTEMPTS

      public static final String DEFAULT_CONNECT_ATTEMPTS
      Default number of connect attempts
      See Also:
    • DEFAULT_CONNECT_TIMEOUT

      public static final String DEFAULT_CONNECT_TIMEOUT
      Default timeout in ms
      See Also:
    • DEFAULT_RETRY_ON_CLOSE

      public static final String DEFAULT_RETRY_ON_CLOSE
      Default condiction for retry on close
      See Also:
    • ATTRIBUTE_DATA

      public static final String ATTRIBUTE_DATA
      attribute for data
      See Also:
    • DEFAULT_PING_INTERVAL_MILLIS

      public static final String DEFAULT_PING_INTERVAL_MILLIS
      Default for time in between pings to server
      See Also:
    • DEFAULT_PING_WAIT_MILLIS

      public static final String DEFAULT_PING_WAIT_MILLIS
      Default for how long to wait for pong response to ping before closing or restarting connection
      See Also:
    • DEFAULT_ANY_MESSAGE_INTERVAL_MILLIS

      public static final String DEFAULT_ANY_MESSAGE_INTERVAL_MILLIS
      Default for interval for any message
      See Also:
  • Constructor Details

    • WebSocketNotificationReceiver

      public WebSocketNotificationReceiver()
  • Method Details

    • configure

      public void configure(Config config) throws Exception
      Description copied from class: DefaultConfigurable
      Process configuration settings. Called before startup().
      Specified by:
      configure in interface Configurable
      Overrides:
      configure in class DefaultNotificationReceiver
      Parameters:
      config - the Config object with settings.
      Throws:
      Exception - if configuration exceptions occur.
    • startup

      public void startup() throws Exception
      Reads a sequence from a tracking file if it exists. Otherwise, starting sequence is 0. Connects to web socket
      Specified by:
      startup in interface Configurable
      Overrides:
      startup in class DefaultNotificationReceiver
      Throws:
      Exception - if error occurs
    • shutdown

      public void shutdown() throws Exception
      Closes web socket
      Specified by:
      shutdown in interface Configurable
      Overrides:
      shutdown in class DefaultNotificationReceiver
      Throws:
      Exception - if error occurs
    • writeTrackingFile

      public void writeTrackingFile() throws Exception
      Writes tracking file to disc, storing latest sequence
      Throws:
      Exception - if error occurs
    • readTrackingFile

      public javax.json.JsonObject readTrackingFile() throws Exception
      Reads tracking file from disc
      Returns:
      JsonObject tracking file
      Throws:
      Exception - if error occurs
    • onOpen

      public void onOpen(javax.websocket.Session session)
      Description copied from interface: WebSocketListener
      Interface method to be overriden by WebSocket files and AwsProductReceiver
      Specified by:
      onOpen in interface WebSocketListener
      Parameters:
      session - Session to open
    • onMessage

      public void onMessage(String message)
      Message handler function passed to WebSocketClient Parses the message as JSON, receives the contained URL notification, and writes the tracking file.
      Specified by:
      onMessage in interface WebSocketListener
      Parameters:
      message - String
    • onClose

      public void onClose(javax.websocket.Session session, javax.websocket.CloseReason closeReason)
      Description copied from interface: WebSocketListener
      Interface method to be overriden by WebSocket files and AwsProductReceiver
      Specified by:
      onClose in interface WebSocketListener
      Parameters:
      session - Session to close
      closeReason - Reason for closing session
    • onConnectFail

      public void onConnectFail()
      Description copied from interface: WebSocketListener
      Interface method to be overriden by WebSocket files and AwsProductReceiver
      Specified by:
      onConnectFail in interface WebSocketListener
    • onReconnectFail

      public void onReconnectFail()
      Description copied from interface: WebSocketListener
      Interface method to be overriden by WebSocket files and AwsProductReceiver
      Specified by:
      onReconnectFail in interface WebSocketListener
    • getServerHost

      public String getServerHost()
      Returns:
      serverHost
    • setServerHost

      public void setServerHost(String serverHost)
      Parameters:
      serverHost - to set
    • getServerPort

      public String getServerPort()
      Returns:
      serverPort
    • setServerPort

      public void setServerPort(String serverPort)
      Parameters:
      serverPort - to set
    • getServerPath

      public String getServerPath()
      Returns:
      serverPath
    • setServerPath

      public void setServerPath(String serverPath)
      Parameters:
      serverPath - to set
    • getTrackingFileName

      public String getTrackingFileName()
      Returns:
      trackingFileName
    • setTrackingFileName

      public void setTrackingFileName(String trackingFileName)
      Parameters:
      trackingFileName - to set
    • getSequence

      public String getSequence()
      Returns:
      sequence
    • setSequence

      public void setSequence(String sequence)
      Parameters:
      sequence - to set
    • getAttempts

      public int getAttempts()
      Returns:
      attempts
    • setAttempts

      public void setAttempts(int attempts)
      Parameters:
      attempts - to set
    • getTimeout

      public long getTimeout()
      Returns:
      timeout
    • setTimeout

      public void setTimeout(long timeout)
      Parameters:
      timeout - to set