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 StringVariable for anyMessageIntervalMillis stringstatic final Stringattribute for datastatic final StringProperty for connectAttemptsstatic final StringProperty for connectTimeoutstatic final StringDefault for interval for any messagestatic final StringDefault number of connect attemptsstatic final StringDefault timeout in msstatic final StringDefault for time in between pings to serverstatic final StringDefault for how long to wait for pong response to ping before closing or restarting connectionstatic final StringDefault condiction for retry on closestatic final StringDefault server hoststatic final StringDefault server pathstatic final StringDefault server portstatic final StringDefault tracking filestatic final LoggerLogger for use in the filestatic final StringVariable for pingIntervalMillis stringstatic final StringVariable for pingWait stringstatic final StringProperty for retryOnClosestatic final StringProperty for sequencestatic final StringProperty for serverHoststatic final StringProperty for serverPathstatic final StringProperty for serverPortstatic final StringProperty for timestampstatic final StringProperty 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 TypeMethodDescriptionvoidProcess configuration settings.intlongvoidonClose(javax.websocket.Session session, javax.websocket.CloseReason closeReason) Interface method to be overriden by WebSocket files and AwsProductReceivervoidInterface method to be overriden by WebSocket files and AwsProductReceivervoidMessage handler function passed to WebSocketClient Parses the message as JSON, receives the contained URL notification, and writes the tracking file.voidonOpen(javax.websocket.Session session) Interface method to be overriden by WebSocket files and AwsProductReceivervoidInterface method to be overriden by WebSocket files and AwsProductReceiverjavax.json.JsonObjectReads tracking file from discvoidsetAttempts(int attempts) voidsetSequence(String sequence) voidsetServerHost(String serverHost) voidsetServerPath(String serverPath) voidsetServerPort(String serverPort) voidsetTimeout(long timeout) voidsetTrackingFileName(String trackingFileName) voidshutdown()Closes web socketvoidstartup()Reads a sequence from a tracking file if it exists.voidWrites 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, throttleQueuesMethods inherited from class gov.usgs.util.DefaultConfigurable
getName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:DefaultConfigurableProcess configuration settings. Called before startup().- Specified by:
configurein interfaceConfigurable- Overrides:
configurein 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:
startupin interfaceConfigurable- Overrides:
startupin classDefaultNotificationReceiver- Throws:
Exception- if error occurs
-
shutdown
Closes web socket- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin 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:WebSocketListenerInterface method to be overriden by WebSocket files and AwsProductReceiver- Specified by:
onOpenin 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:
onMessagein interfaceWebSocketListener- Parameters:
message- String
-
onClose
public void onClose(javax.websocket.Session session, javax.websocket.CloseReason closeReason) Description copied from interface:WebSocketListenerInterface method to be overriden by WebSocket files and AwsProductReceiver- Specified by:
onClosein interfaceWebSocketListener- Parameters:
session- Session to closecloseReason- Reason for closing session
-
onConnectFail
public void onConnectFail()Description copied from interface:WebSocketListenerInterface method to be overriden by WebSocket files and AwsProductReceiver- Specified by:
onConnectFailin interfaceWebSocketListener
-
onReconnectFail
public void onReconnectFail()Description copied from interface:WebSocketListenerInterface method to be overriden by WebSocket files and AwsProductReceiver- Specified by:
onReconnectFailin 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
-