Package gov.usgs.earthquake.distribution
Class SocketProductReceiver
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.distribution.DefaultNotificationReceiver
-
- gov.usgs.earthquake.distribution.SocketProductReceiver
-
- All Implemented Interfaces:
NotificationIndexCleanup.Listener
,NotificationReceiver
,Configurable
,SocketListenerInterface
public class SocketProductReceiver extends DefaultNotificationReceiver implements SocketListenerInterface
Receive Products directly via a Socket. The received products are sent using a SocketProductSender. A SocketProductReceiver receives products directly and notifies listeners of received notifications. These are typically used on hubs with an EIDSNotificationSender or RelayProductReceiver. The NotificationReceiver uses a NotificationIndex to track received notifications, and a ProductStorage to store retrieved products. The DefaultNotificationReceiver implements the Configurable interface and uses the following configuration parameters: Each listener has a separate queue of notifications. Each listener is allocated one thread to process notifications from this queue.
-
-
Field Summary
-
Fields inherited from class gov.usgs.earthquake.distribution.DefaultNotificationReceiver
CONNECT_TIMEOUT_PROPERTY, DEFAULT_CONNECT_TIMEOUT, 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 SocketProductReceiver()
Default constructor setting port, threads, and sizeLimit to defaultSocketProductReceiver(Config config)
Constructor based on config file
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Config config)
Process configuration settings.int
getPort()
long
getSizeLimit()
int
getThreads()
void
onSocket(java.net.Socket socket)
Called with any sockets to be read.void
setPort(int port)
void
setSizeLimit(long sizeLimit)
void
setThreads(int threads)
void
shutdown()
Stop any processing/background threads.void
startup()
Start any processing/background threads.protected java.lang.String
storeAndNotify(ProductSource source)
Stores ProductSource as a notification, tracks it, and notifies Listeners-
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
-
-
-
-
Constructor Detail
-
SocketProductReceiver
public SocketProductReceiver() throws java.lang.Exception
Default constructor setting port, threads, and sizeLimit to default- Throws:
java.lang.Exception
- if error occurs
-
SocketProductReceiver
public SocketProductReceiver(Config config) throws java.lang.Exception
Constructor based on config file- Parameters:
config
- Configuration file- Throws:
java.lang.Exception
- if error occurs
-
-
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
Description copied from class:DefaultConfigurable
Start any processing/background threads.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultNotificationReceiver
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
shutdown
public void shutdown() throws java.lang.Exception
Description copied from class:DefaultConfigurable
Stop any processing/background threads.- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultNotificationReceiver
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
onSocket
public void onSocket(java.net.Socket socket)
Description copied from interface:SocketListenerInterface
Called with any sockets to be read.- Specified by:
onSocket
in interfaceSocketListenerInterface
- Parameters:
socket
- socket to be processed.
-
storeAndNotify
protected java.lang.String storeAndNotify(ProductSource source) throws java.lang.Exception
Stores ProductSource as a notification, tracks it, and notifies Listeners- Parameters:
source
- ProductSource- Returns:
- String note for log file
- Throws:
java.lang.Exception
- if error occurs
-
getPort
public int getPort()
- Returns:
- port
-
setPort
public void setPort(int port)
- Parameters:
port
- int to set
-
getSizeLimit
public long getSizeLimit()
- Returns:
- sizeLimit
-
setSizeLimit
public void setSizeLimit(long sizeLimit)
- Parameters:
sizeLimit
- long to set
-
getThreads
public int getThreads()
- Returns:
- threads
-
setThreads
public void setThreads(int threads)
- Parameters:
threads
- int to set
-
-