Package gov.usgs.earthquake.aws
Class FileTrackingListener
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.aws.FileTrackingListener
-
- All Implemented Interfaces:
NotificationListener
,Configurable
public class FileTrackingListener extends DefaultConfigurable implements NotificationListener
This class is a stop-gap to store file-based tracking information in a TrackingIndex. It implements the NotificationListener interface so it can hook into startup/shutdown lifecycle calls used by ProductClient. Listeners are started before and shutdown after Receivers, and can put a tracking file in place before the receiver starts and save its state after a receiver stops.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
TRACKING_FILE_PROEPRTY
Tracking file propertystatic java.lang.String
TRACKING_INDEX_FILE_PROPERTY
Tracking index file propertystatic java.lang.String
TRACKING_INDEX_PROPERTY
Tracking index property
-
Constructor Summary
Constructors Constructor Description FileTrackingListener()
FileTrackingListener constructorFileTrackingListener(java.io.File trackingFile, TrackingIndex trackingIndex)
Initializable FileTrackingListener
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Config config)
Process configuration settings.int
getMaxTries()
A NotificationReceiver that generates a NotificationEvent will attempt to deliver the event up to this many times, if the listener throws an Exception while processing.long
getTimeout()
A NotificationListener has this many milliseconds to process a notification before being interrupted.java.io.File
getTrackingFile()
Getter for trackingFileTrackingIndex
getTrackingIndex()
Getter for trackingIndexvoid
loadTrackingFile()
Read trackingIndex and write trackingFile.void
onNotification(NotificationEvent event)
Notification Listener method stubs.void
setTrackingFile(java.io.File trackingFile)
Setter for trackingFilevoid
setTrackingIndex(TrackingIndex trackingIndex)
Setter for trackingIndexvoid
shutdown()
When shutting down, call storeTrackingFile to read from file on disk.void
startup()
When starting, call loadTrackingFile to create/update file on disk.void
storeTrackingFile()
Read trackingFile and write into trackingIndex.-
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
-
TRACKING_INDEX_PROPERTY
public static final java.lang.String TRACKING_INDEX_PROPERTY
Tracking index property- See Also:
- Constant Field Values
-
TRACKING_INDEX_FILE_PROPERTY
public static final java.lang.String TRACKING_INDEX_FILE_PROPERTY
Tracking index file property- See Also:
- Constant Field Values
-
TRACKING_FILE_PROEPRTY
public static final java.lang.String TRACKING_FILE_PROEPRTY
Tracking file property- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FileTrackingListener
public FileTrackingListener()
FileTrackingListener constructor
-
FileTrackingListener
public FileTrackingListener(java.io.File trackingFile, TrackingIndex trackingIndex)
Initializable FileTrackingListener- Parameters:
trackingFile
- file to be traackedtrackingIndex
- Index where contents are stored
-
-
Method Detail
-
getTrackingFile
public java.io.File getTrackingFile()
Getter for trackingFile- Returns:
- trackingFile
-
setTrackingFile
public void setTrackingFile(java.io.File trackingFile)
Setter for trackingFile- Parameters:
trackingFile
- File to be tracked
-
getTrackingIndex
public TrackingIndex getTrackingIndex()
Getter for trackingIndex- Returns:
- trackingIndex
-
setTrackingIndex
public void setTrackingIndex(TrackingIndex trackingIndex)
Setter for trackingIndex- Parameters:
trackingIndex
- Index where contents are stored
-
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 classDefaultConfigurable
- Parameters:
config
- the Config object with settings.- Throws:
java.lang.Exception
- if configuration exceptions occur.
-
startup
public void startup() throws java.lang.Exception
When starting, call loadTrackingFile to create/update file on disk.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultConfigurable
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
shutdown
public void shutdown() throws java.lang.Exception
When shutting down, call storeTrackingFile to read from file on disk.- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultConfigurable
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
loadTrackingFile
public void loadTrackingFile() throws java.lang.Exception
Read trackingIndex and write trackingFile.- Throws:
java.lang.Exception
- Exception
-
storeTrackingFile
public void storeTrackingFile() throws java.lang.Exception
Read trackingFile and write into trackingIndex.- Throws:
java.lang.Exception
- Exception
-
onNotification
public void onNotification(NotificationEvent event) throws java.lang.Exception
Notification Listener method stubs. These are used only to gain access to lifecycle hooks above.- Specified by:
onNotification
in interfaceNotificationListener
- Parameters:
event
- the event corresponding to the notification that is available.- Throws:
ContinuableListenerException
- if redelivery should be attempted (depending on what getAttemptCount() returns).java.lang.Exception
- See Also:
ContinuableListenerException
,InterruptedException
,NotificationListener.getMaxTries()
-
getMaxTries
public int getMaxTries()
Description copied from interface:NotificationListener
A NotificationReceiver that generates a NotificationEvent will attempt to deliver the event up to this many times, if the listener throws an Exception while processing.- Specified by:
getMaxTries
in interfaceNotificationListener
- Returns:
- A value of 1 or less means do not attempt more than once.
-
getTimeout
public long getTimeout()
Description copied from interface:NotificationListener
A NotificationListener has this many milliseconds to process a notification before being interrupted.- Specified by:
getTimeout
in interfaceNotificationListener
- Returns:
- number of milliseconds before timing out. A value of 0 or less means never time out.
-
-