Package gov.usgs.earthquake.distribution
Class WebSocketNotificationReceiver
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.distribution.DefaultNotificationReceiver
-
- gov.usgs.earthquake.distribution.WebSocketNotificationReceiver
-
- All Implemented Interfaces:
NotificationIndexCleanup.Listener
,NotificationReceiver
,WebSocketListener
,Configurable
public class WebSocketNotificationReceiver extends DefaultNotificationReceiver implements WebSocketListener
Receives notifications from an arbitrary web socket.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTRIBUTE_DATA
attribute for datastatic java.lang.String
CONNECT_ATTEMPTS_PROPERTY
Property for connectAttemptsstatic java.lang.String
CONNECT_TIMEOUT_PROPERTY
Property for connectTimeoutstatic java.lang.String
DEFAULT_CONNECT_ATTEMPTS
Default number of connect attemptsstatic java.lang.String
DEFAULT_CONNECT_TIMEOUT
Default timeout in msstatic java.lang.String
DEFAULT_RETRY_ON_CLOSE
Default condiction for retry on closestatic java.lang.String
DEFAULT_SERVER_HOST
Default server hoststatic java.lang.String
DEFAULT_SERVER_PATH
Default server pathstatic java.lang.String
DEFAULT_SERVER_PORT
Default server portstatic java.lang.String
DEFAULT_TRACKING_FILE_NAME
Default tracking filestatic java.util.logging.Logger
LOGGER
Logger for use in the filestatic java.lang.String
RETRY_ON_CLOSE_PROPERTY
Property for retryOnClosestatic java.lang.String
SEQUENCE_PROPERTY
Property for sequencestatic java.lang.String
SERVER_HOST_PROPERTY
Property for serverHoststatic java.lang.String
SERVER_PATH_PROPERTY
Property for serverPathstatic java.lang.String
SERVER_PORT_PROPERTY
Property for serverPortstatic java.lang.String
TIMESTAMP_PROPERTY
Property for timestampstatic java.lang.String
TRACKING_FILE_NAME_PROPERTY
Property for trackingFileName-
Fields inherited from class gov.usgs.earthquake.distribution.DefaultNotificationReceiver
DEFAULT_PRODUCT_STORAGE_MAX_AGE, DEFAULT_READ_TIMEOUT, DEFAULT_RECEIVER_CLEANUP, EXECUTOR_LISTENER_NOTIFIER, FUTURE_LISTENER_NOTIFIER, INDEX_FILE_PROPERTY, LISTENER_NOTIFIER_PROPERTY, NOTIFICATION_INDEX_PROPERTY, PRODUCT_STORAGE_MAX_AGE_PROPERTY, PRODUCT_STORAGE_PROPERTY, READ_TIMEOUT_PROPERTY, RECEIVER_CLEANUP_PROPERTY, ROUNDROBIN_LISTENER_NOTIFIER, STORAGE_DIRECTORY_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description WebSocketNotificationReceiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Config config)
Process configuration settings.int
getAttempts()
java.lang.String
getSequence()
java.lang.String
getServerHost()
java.lang.String
getServerPath()
java.lang.String
getServerPort()
long
getTimeout()
java.lang.String
getTrackingFileName()
void
onClose(javax.websocket.Session session, javax.websocket.CloseReason closeReason)
Interface method to be overriden by WebSocket files and AwsProductReceivervoid
onConnectFail()
Interface method to be overriden by WebSocket files and AwsProductReceivervoid
onMessage(java.lang.String message)
Message handler function passed to WebSocketClient Parses the message as JSON, receives the contained URL notification, and writes the tracking file.void
onOpen(javax.websocket.Session session)
Interface method to be overriden by WebSocket files and AwsProductReceivervoid
onReconnectFail()
Interface method to be overriden by WebSocket files and AwsProductReceiverjavax.json.JsonObject
readTrackingFile()
Reads tracking file from discvoid
setAttempts(int attempts)
void
setSequence(java.lang.String sequence)
void
setServerHost(java.lang.String serverHost)
void
setServerPath(java.lang.String serverPath)
void
setServerPort(java.lang.String serverPort)
void
setTimeout(long timeout)
void
setTrackingFileName(java.lang.String trackingFileName)
void
shutdown()
Closes web socketvoid
startup()
Reads a sequence from a tracking file if it exists.void
writeTrackingFile()
Writes tracking file to disc, storing latest sequence-
Methods inherited from class gov.usgs.earthquake.distribution.DefaultNotificationReceiver
addNotificationListener, getConnectTimeout, getListenerQueueStatus, getNotificationIndex, getNotifier, getProductStorage, getProductStorageMaxAge, getQueueStatus, getReadTimeout, getReceiverCleanupInterval, notifyListeners, onExpiredNotification, receiveNotification, removeExpiredNotifications, removeNotificationListener, retrieveProduct, sendNotifications, setConnectTimeout, setNotificationIndex, setNotifier, setProductStorage, setProductStorageMaxAge, setReadTimeout, setReceiverCleanupInterval, storeProductSource, throttleQueues
-
Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.usgs.util.Configurable
getName, setName
-
-
-
-
Field Detail
-
LOGGER
public static final java.util.logging.Logger LOGGER
Logger for use in the file
-
SERVER_HOST_PROPERTY
public static final java.lang.String SERVER_HOST_PROPERTY
Property for serverHost- See Also:
- Constant Field Values
-
SERVER_PORT_PROPERTY
public static final java.lang.String SERVER_PORT_PROPERTY
Property for serverPort- See Also:
- Constant Field Values
-
SERVER_PATH_PROPERTY
public static final java.lang.String SERVER_PATH_PROPERTY
Property for serverPath- See Also:
- Constant Field Values
-
SEQUENCE_PROPERTY
public static final java.lang.String SEQUENCE_PROPERTY
Property for sequence- See Also:
- Constant Field Values
-
TIMESTAMP_PROPERTY
public static final java.lang.String TIMESTAMP_PROPERTY
Property for timestamp- See Also:
- Constant Field Values
-
TRACKING_FILE_NAME_PROPERTY
public static final java.lang.String TRACKING_FILE_NAME_PROPERTY
Property for trackingFileName- See Also:
- Constant Field Values
-
CONNECT_ATTEMPTS_PROPERTY
public static final java.lang.String CONNECT_ATTEMPTS_PROPERTY
Property for connectAttempts- See Also:
- Constant Field Values
-
CONNECT_TIMEOUT_PROPERTY
public static final java.lang.String CONNECT_TIMEOUT_PROPERTY
Property for connectTimeout- See Also:
- Constant Field Values
-
RETRY_ON_CLOSE_PROPERTY
public static final java.lang.String RETRY_ON_CLOSE_PROPERTY
Property for retryOnClose- See Also:
- Constant Field Values
-
DEFAULT_SERVER_HOST
public static final java.lang.String DEFAULT_SERVER_HOST
Default server host- See Also:
- Constant Field Values
-
DEFAULT_SERVER_PORT
public static final java.lang.String DEFAULT_SERVER_PORT
Default server port- See Also:
- Constant Field Values
-
DEFAULT_SERVER_PATH
public static final java.lang.String DEFAULT_SERVER_PATH
Default server path- See Also:
- Constant Field Values
-
DEFAULT_TRACKING_FILE_NAME
public static final java.lang.String DEFAULT_TRACKING_FILE_NAME
Default tracking file- See Also:
- Constant Field Values
-
DEFAULT_CONNECT_ATTEMPTS
public static final java.lang.String DEFAULT_CONNECT_ATTEMPTS
Default number of connect attempts- See Also:
- Constant Field Values
-
DEFAULT_CONNECT_TIMEOUT
public static final java.lang.String DEFAULT_CONNECT_TIMEOUT
Default timeout in ms- See Also:
- Constant Field Values
-
DEFAULT_RETRY_ON_CLOSE
public static final java.lang.String DEFAULT_RETRY_ON_CLOSE
Default condiction for retry on close- See Also:
- Constant Field Values
-
ATTRIBUTE_DATA
public static final java.lang.String ATTRIBUTE_DATA
attribute for data- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
public void configure(Config config) throws java.lang.Exception
Description copied from class:DefaultConfigurable
Process configuration settings. Called before startup().- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultNotificationReceiver
- Parameters:
config
- the Config object with settings.- Throws:
java.lang.Exception
- if configuration exceptions occur.
-
startup
public void startup() throws java.lang.Exception
Reads a sequence from a tracking file if it exists. Otherwise, starting sequence is 0. Connects to web socket- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultNotificationReceiver
- Throws:
java.lang.Exception
- if error occurs
-
shutdown
public void shutdown() throws java.lang.Exception
Closes web socket- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultNotificationReceiver
- Throws:
java.lang.Exception
- if error occurs
-
writeTrackingFile
public void writeTrackingFile() throws java.lang.Exception
Writes tracking file to disc, storing latest sequence- Throws:
java.lang.Exception
- if error occurs
-
readTrackingFile
public javax.json.JsonObject readTrackingFile() throws java.lang.Exception
Reads tracking file from disc- Returns:
- JsonObject tracking file
- Throws:
java.lang.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 interfaceWebSocketListener
- Parameters:
session
- Session to open
-
onMessage
public void onMessage(java.lang.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 interfaceWebSocketListener
- 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 interfaceWebSocketListener
- Parameters:
session
- Session to closecloseReason
- 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 interfaceWebSocketListener
-
onReconnectFail
public void onReconnectFail()
Description copied from interface:WebSocketListener
Interface method to be overriden by WebSocket files and AwsProductReceiver- Specified by:
onReconnectFail
in interfaceWebSocketListener
-
getServerHost
public java.lang.String getServerHost()
- Returns:
- serverHost
-
setServerHost
public void setServerHost(java.lang.String serverHost)
- Parameters:
serverHost
- to set
-
getServerPort
public java.lang.String getServerPort()
- Returns:
- serverPort
-
setServerPort
public void setServerPort(java.lang.String serverPort)
- Parameters:
serverPort
- to set
-
getServerPath
public java.lang.String getServerPath()
- Returns:
- serverPath
-
setServerPath
public void setServerPath(java.lang.String serverPath)
- Parameters:
serverPath
- to set
-
getTrackingFileName
public java.lang.String getTrackingFileName()
- Returns:
- trackingFileName
-
setTrackingFileName
public void setTrackingFileName(java.lang.String trackingFileName)
- Parameters:
trackingFileName
- to set
-
getSequence
public java.lang.String getSequence()
- Returns:
- sequence
-
setSequence
public void setSequence(java.lang.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
-
-