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.StringATTRIBUTE_DATAattribute for datastatic java.lang.StringCONNECT_ATTEMPTS_PROPERTYProperty for connectAttemptsstatic java.lang.StringCONNECT_TIMEOUT_PROPERTYProperty for connectTimeoutstatic java.lang.StringDEFAULT_CONNECT_ATTEMPTSDefault number of connect attemptsstatic java.lang.StringDEFAULT_CONNECT_TIMEOUTDefault timeout in msstatic java.lang.StringDEFAULT_RETRY_ON_CLOSEDefault condiction for retry on closestatic java.lang.StringDEFAULT_SERVER_HOSTDefault server hoststatic java.lang.StringDEFAULT_SERVER_PATHDefault server pathstatic java.lang.StringDEFAULT_SERVER_PORTDefault server portstatic java.lang.StringDEFAULT_TRACKING_FILE_NAMEDefault tracking filestatic java.util.logging.LoggerLOGGERLogger for use in the filestatic java.lang.StringRETRY_ON_CLOSE_PROPERTYProperty for retryOnClosestatic java.lang.StringSEQUENCE_PROPERTYProperty for sequencestatic java.lang.StringSERVER_HOST_PROPERTYProperty for serverHoststatic java.lang.StringSERVER_PATH_PROPERTYProperty for serverPathstatic java.lang.StringSERVER_PORT_PROPERTYProperty for serverPortstatic java.lang.StringTIMESTAMP_PROPERTYProperty for timestampstatic java.lang.StringTRACKING_FILE_NAME_PROPERTYProperty 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 voidconfigure(Config config)Process configuration settings.intgetAttempts()java.lang.StringgetSequence()java.lang.StringgetServerHost()java.lang.StringgetServerPath()java.lang.StringgetServerPort()longgetTimeout()java.lang.StringgetTrackingFileName()voidonClose(javax.websocket.Session session, javax.websocket.CloseReason closeReason)Interface method to be overriden by WebSocket files and AwsProductReceivervoidonConnectFail()Interface method to be overriden by WebSocket files and AwsProductReceivervoidonMessage(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.voidonOpen(javax.websocket.Session session)Interface method to be overriden by WebSocket files and AwsProductReceivervoidonReconnectFail()Interface method to be overriden by WebSocket files and AwsProductReceiverjavax.json.JsonObjectreadTrackingFile()Reads tracking file from discvoidsetAttempts(int attempts)voidsetSequence(java.lang.String sequence)voidsetServerHost(java.lang.String serverHost)voidsetServerPath(java.lang.String serverPath)voidsetServerPort(java.lang.String serverPort)voidsetTimeout(long timeout)voidsetTrackingFileName(java.lang.String trackingFileName)voidshutdown()Closes web socketvoidstartup()Reads a sequence from a tracking file if it exists.voidwriteTrackingFile()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:DefaultConfigurableProcess configuration settings. Called before startup().- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultNotificationReceiver- Parameters:
config- the Config object with settings.- Throws:
java.lang.Exception- if configuration exceptions occur.
-
startup
public void startup() throws java.lang.ExceptionReads 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:
java.lang.Exception- if error occurs
-
shutdown
public void shutdown() throws java.lang.ExceptionCloses web socket- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultNotificationReceiver- Throws:
java.lang.Exception- if error occurs
-
writeTrackingFile
public void writeTrackingFile() throws java.lang.ExceptionWrites tracking file to disc, storing latest sequence- Throws:
java.lang.Exception- if error occurs
-
readTrackingFile
public javax.json.JsonObject readTrackingFile() throws java.lang.ExceptionReads 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:WebSocketListenerInterface method to be overriden by WebSocket files and AwsProductReceiver- Specified by:
onOpenin 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:
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
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
-
-