Package gov.usgs.earthquake.distribution
Class ReplicationStorageListener
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.distribution.DefaultStorageListener
-
- gov.usgs.earthquake.distribution.ReplicationStorageListener
-
- All Implemented Interfaces:
StorageListener
,Configurable
public class ReplicationStorageListener extends DefaultStorageListener
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ReplicationStorageListener.ReplicationTask
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ARCHIVE_FLAG_PROPERTY
Name of the property specifying whether to use archive flag on the replication.static java.lang.String
REPL_CMD_PROPERTY
Name of the property specifying the replication command on the host system.static java.lang.String
REPL_HOSTS_PROPERTY
Name of property specifying to which hosts the storage should be replicated.static java.lang.String
REPL_MAX_TRIES_PROPERTY
Name of property indicating how many times the replication should be attempted before considering it a failure.static java.lang.String
REPL_TIMEOUT_PROPERTY
Name of the property specifying how long to wait for the replication to complete successfully.
-
Constructor Summary
Constructors Constructor Description ReplicationStorageListener()
Default constructor used when this object is instantiated via configuration.ReplicationStorageListener(boolean archiveFlag, java.lang.String replCmd, long replTimeout, java.util.List<java.lang.String> replHosts)
Customer initialization of the constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Config config)
Process configuration settings.protected java.util.List<java.lang.String>
createReplicationCommand(java.io.File baseDir, java.lang.String path, java.lang.String host, boolean deleting)
Create the replication command.void
onProductRemoved(StorageEvent event)
Dispatched method called when the type of event isStorageEvent.StorageEventType.PRODUCT_REMOVED
.void
onProductStored(StorageEvent event)
Dispatched method called when the type of event isStorageEvent.StorageEventType.PRODUCT_STORED
.protected void
setReplHosts(java.util.List<java.lang.String> replHosts)
Set new Replication hostsprotected void
syncProductContents(FileProductStorage storage, ProductId id, boolean deleting)
-
Methods inherited from class gov.usgs.earthquake.distribution.DefaultStorageListener
onStorageEvent, shutdown, startup
-
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
-
ARCHIVE_FLAG_PROPERTY
public static final java.lang.String ARCHIVE_FLAG_PROPERTY
Name of the property specifying whether to use archive flag on the replication.- See Also:
- Constant Field Values
-
REPL_CMD_PROPERTY
public static final java.lang.String REPL_CMD_PROPERTY
Name of the property specifying the replication command on the host system.- See Also:
- Constant Field Values
-
REPL_MAX_TRIES_PROPERTY
public static final java.lang.String REPL_MAX_TRIES_PROPERTY
Name of property indicating how many times the replication should be attempted before considering it a failure.- See Also:
- Constant Field Values
-
REPL_TIMEOUT_PROPERTY
public static final java.lang.String REPL_TIMEOUT_PROPERTY
Name of the property specifying how long to wait for the replication to complete successfully.- See Also:
- Constant Field Values
-
REPL_HOSTS_PROPERTY
public static final java.lang.String REPL_HOSTS_PROPERTY
Name of property specifying to which hosts the storage should be replicated.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ReplicationStorageListener
public ReplicationStorageListener()
Default constructor used when this object is instantiated via configuration.
-
ReplicationStorageListener
public ReplicationStorageListener(boolean archiveFlag, java.lang.String replCmd, long replTimeout, java.util.List<java.lang.String> replHosts)
Customer initialization of the constructor- Parameters:
archiveFlag
- Bool flag of what to do on archivereplCmd
- Replication command on host systemreplTimeout
- Replication in msreplHosts
- List of Replication hosts
-
-
Method Detail
-
setReplHosts
protected void setReplHosts(java.util.List<java.lang.String> replHosts)
Set new Replication hosts- Parameters:
replHosts
- string list of new hosts
-
configure
public void configure(Config config)
Description copied from class:DefaultConfigurable
Process configuration settings. Called before startup().- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultStorageListener
- Parameters:
config
- the Config object with settings.
-
onProductStored
public void onProductStored(StorageEvent event) throws java.lang.Exception
Description copied from class:DefaultStorageListener
Dispatched method called when the type of event isStorageEvent.StorageEventType.PRODUCT_STORED
.- Overrides:
onProductStored
in classDefaultStorageListener
- Parameters:
event
- The event that triggered the call- Throws:
java.lang.Exception
- if error occurs
-
onProductRemoved
public void onProductRemoved(StorageEvent event) throws java.lang.Exception
Description copied from class:DefaultStorageListener
Dispatched method called when the type of event isStorageEvent.StorageEventType.PRODUCT_REMOVED
.- Overrides:
onProductRemoved
in classDefaultStorageListener
- Parameters:
event
- The event that triggered the call- Throws:
java.lang.Exception
- if error occurs
-
syncProductContents
protected void syncProductContents(FileProductStorage storage, ProductId id, boolean deleting) throws java.io.IOException
- Parameters:
storage
- FileProductStorage to use as the base directoryid
- ID of product in storagedeleting
- Bool flag for deleting- Throws:
java.io.IOException
- if IO error occurs
-
createReplicationCommand
protected java.util.List<java.lang.String> createReplicationCommand(java.io.File baseDir, java.lang.String path, java.lang.String host, boolean deleting) throws java.io.IOException
Create the replication command.- Parameters:
baseDir
- The directory from which replication will be executed.path
- The path of the content to replicatehost
- The host string to which content should be replicated. Format = user@host:pathdeleting
- Flag whether this should be a deleting replication or not- Returns:
- The command and arguments as a list suitable for a
ProcessBuilder
. - Throws:
java.io.IOException
- if IO error occurs
-
-