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
FieldsModifier and TypeFieldDescriptionstatic final String
Variable for anyMessageIntervalMillis stringstatic final String
attribute for datastatic final String
Property for connectAttemptsstatic final String
Property for connectTimeoutstatic final String
Default for interval for any messagestatic final String
Default number of connect attemptsstatic final String
Default timeout in msstatic final String
Default for time in between pings to serverstatic final String
Default for how long to wait for pong response to ping before closing or restarting connectionstatic final String
Default condiction for retry on closestatic final String
Default server hoststatic final String
Default server pathstatic final String
Default server portstatic final String
Default tracking filestatic final Logger
Logger for use in the filestatic final String
Variable for pingIntervalMillis stringstatic final String
Variable for pingWait stringstatic final String
Property for retryOnClosestatic final String
Property for sequencestatic final String
Property for serverHoststatic final String
Property for serverPathstatic final String
Property for serverPortstatic final String
Property for timestampstatic final String
Property for trackingFileNameFields 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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
Process configuration settings.int
long
void
onClose
(javax.websocket.Session session, javax.websocket.CloseReason closeReason) Interface method to be overriden by WebSocket files and AwsProductReceivervoid
Interface method to be overriden by WebSocket files and AwsProductReceivervoid
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
Interface method to be overriden by WebSocket files and AwsProductReceiverjavax.json.JsonObject
Reads tracking file from discvoid
setAttempts
(int attempts) void
setSequence
(String sequence) void
setServerHost
(String serverHost) void
setServerPath
(String serverPath) void
setServerPort
(String serverPort) void
setTimeout
(long timeout) void
setTrackingFileName
(String trackingFileName) void
shutdown()
Closes web socketvoid
startup()
Reads a sequence from a tracking file if it exists.void
Writes tracking file to disc, storing latest sequenceMethods 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 Details
-
LOGGER
Logger for use in the file -
SERVER_HOST_PROPERTY
Property for serverHost- See Also:
-
SERVER_PORT_PROPERTY
Property for serverPort- See Also:
-
SERVER_PATH_PROPERTY
Property for serverPath- See Also:
-
SEQUENCE_PROPERTY
Property for sequence- See Also:
-
TIMESTAMP_PROPERTY
Property for timestamp- See Also:
-
TRACKING_FILE_NAME_PROPERTY
Property for trackingFileName- See Also:
-
CONNECT_ATTEMPTS_PROPERTY
Property for connectAttempts- See Also:
-
CONNECT_TIMEOUT_PROPERTY
Property for connectTimeout- See Also:
-
RETRY_ON_CLOSE_PROPERTY
Property for retryOnClose- See Also:
-
PING_INTERVAL
Variable for pingIntervalMillis string- See Also:
-
PING_WAIT
Variable for pingWait string- See Also:
-
ANY_MESSAGE_INTERVAL
Variable for anyMessageIntervalMillis string- See Also:
-
DEFAULT_SERVER_HOST
Default server host- See Also:
-
DEFAULT_SERVER_PORT
Default server port- See Also:
-
DEFAULT_SERVER_PATH
Default server path- See Also:
-
DEFAULT_TRACKING_FILE_NAME
Default tracking file- See Also:
-
DEFAULT_CONNECT_ATTEMPTS
Default number of connect attempts- See Also:
-
DEFAULT_CONNECT_TIMEOUT
Default timeout in ms- See Also:
-
DEFAULT_RETRY_ON_CLOSE
Default condiction for retry on close- See Also:
-
ATTRIBUTE_DATA
attribute for data- See Also:
-
DEFAULT_PING_INTERVAL_MILLIS
Default for time in between pings to server- See Also:
-
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
Default for interval for any message- See Also:
-
-
Constructor Details
-
WebSocketNotificationReceiver
public WebSocketNotificationReceiver()
-
-
Method Details
-
configure
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:
Exception
- if configuration exceptions occur.
-
startup
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:
Exception
- if error occurs
-
shutdown
Closes web socket- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultNotificationReceiver
- Throws:
Exception
- if error occurs
-
writeTrackingFile
Writes tracking file to disc, storing latest sequence- Throws:
Exception
- if error occurs
-
readTrackingFile
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 interfaceWebSocketListener
- Parameters:
session
- Session to open
-
onMessage
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
- Returns:
- serverHost
-
setServerHost
- Parameters:
serverHost
- to set
-
getServerPort
- Returns:
- serverPort
-
setServerPort
- Parameters:
serverPort
- to set
-
getServerPath
- Returns:
- serverPath
-
setServerPath
- Parameters:
serverPath
- to set
-
getTrackingFileName
- Returns:
- trackingFileName
-
setTrackingFileName
- Parameters:
trackingFileName
- to set
-
getSequence
- Returns:
- sequence
-
setSequence
- 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
-