Package gov.usgs.earthquake.distribution
Class ProductBuilder
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.distribution.ProductBuilder
-
- All Implemented Interfaces:
Configurable
- Direct Known Subclasses:
EIDSInputWedge
,EIDSProductBuilder
public class ProductBuilder extends DefaultConfigurable
Essentials for building/sending products. This is the base class for other builders. Supported configurable properties:- senders
- A comma delimited list of product senders to use when sending products.
- trackerURL
- Default tracker URL to assign to products that don't already have one.
- privateKeyFile
- Path to a private key that can be used to sign products.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_PARALLEL_SEND
Bool for parallel sendstatic java.lang.String
DEFAULT_PARALLEL_SEND_TIMEOUT
time in ms for parallel send timemoutstatic java.net.URL
DEFAULT_TRACKER_URL
Default tracker url.static java.lang.String
PARALLEL_SEND_PROPERTY
Send in parallel.static java.lang.String
PARALLEL_SEND_TIMEOUT_PROPERTY
Timeout in seconds for parallel send.protected boolean
parallelSend
Whether to send in parallel.protected long
parallelSendTimeout
How long to wait before parallel send timeout.static java.lang.String
PRIVATE_KEY_PROPERTY
Private key filename configuration property.static java.lang.String
SENDERS_PROPERTY
Configurable property for senders.static java.lang.String
SIGNATURE_VERSION_PROPERTY
Signature version property.static java.lang.String
TRACKER_URL_PROPERTY
Property name used for configuring a tracker url.
-
Constructor Summary
Constructors Constructor Description ProductBuilder()
Default product builder constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProductSender(ProductSender sender)
Add a ProductSender.void
configure(Config config)
Process configuration settings.java.security.PrivateKey
getPrivateKey()
java.util.List<ProductSender>
getProductSenders()
CryptoUtils.Version
getSignatureVersion()
java.net.URL
getTrackerURL()
static java.util.Map<ProductSender,java.lang.Exception>
parallelSendProduct(java.util.List<ProductSender> senders, Product product, long timeoutSeconds)
Send a product to all ProductSenders concurrently.void
removeProductSender(ProductSender sender)
Remove a previously added ProductSender.java.util.Map<ProductSender,java.lang.Exception>
sendProduct(Product product)
Send a product.void
setPrivateKey(java.security.PrivateKey privateKey)
void
setSignatureVersion(CryptoUtils.Version signatureVersion)
void
setTrackerURL(java.net.URL trackerURL)
void
shutdown()
Stop any processing/background threads.void
startup()
Start any processing/background threads.-
Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setName
-
-
-
-
Field Detail
-
SENDERS_PROPERTY
public static final java.lang.String SENDERS_PROPERTY
Configurable property for senders.- See Also:
- Constant Field Values
-
TRACKER_URL_PROPERTY
public static final java.lang.String TRACKER_URL_PROPERTY
Property name used for configuring a tracker url.- See Also:
- Constant Field Values
-
PRIVATE_KEY_PROPERTY
public static final java.lang.String PRIVATE_KEY_PROPERTY
Private key filename configuration property.- See Also:
- Constant Field Values
-
SIGNATURE_VERSION_PROPERTY
public static final java.lang.String SIGNATURE_VERSION_PROPERTY
Signature version property.- See Also:
- Constant Field Values
-
PARALLEL_SEND_PROPERTY
public static final java.lang.String PARALLEL_SEND_PROPERTY
Send in parallel.- See Also:
- Constant Field Values
-
DEFAULT_PARALLEL_SEND
public static final java.lang.String DEFAULT_PARALLEL_SEND
Bool for parallel send- See Also:
- Constant Field Values
-
PARALLEL_SEND_TIMEOUT_PROPERTY
public static final java.lang.String PARALLEL_SEND_TIMEOUT_PROPERTY
Timeout in seconds for parallel send.- See Also:
- Constant Field Values
-
DEFAULT_PARALLEL_SEND_TIMEOUT
public static final java.lang.String DEFAULT_PARALLEL_SEND_TIMEOUT
time in ms for parallel send timemout- See Also:
- Constant Field Values
-
DEFAULT_TRACKER_URL
public static final java.net.URL DEFAULT_TRACKER_URL
Default tracker url.
-
parallelSend
protected boolean parallelSend
Whether to send in parallel.
-
parallelSendTimeout
protected long parallelSendTimeout
How long to wait before parallel send timeout.
-
-
Method Detail
-
sendProduct
public java.util.Map<ProductSender,java.lang.Exception> sendProduct(Product product) throws java.lang.Exception
Send a product. If the product doesn't yet have a tracker URL, assigns current tracker URL to product. If the product has not yet been signed, and a privateKey is configured, signs the product before sending.- Parameters:
product
- the product to send.- Returns:
- map of all exceptions thrown, from Sender to corresponding Exception.
- Throws:
java.lang.Exception
- if an error occurs while signing product.
-
getProductSenders
public java.util.List<ProductSender> getProductSenders()
- Returns:
- list of product senders
-
addProductSender
public void addProductSender(ProductSender sender)
Add a ProductSender.- Parameters:
sender
- to add
-
removeProductSender
public void removeProductSender(ProductSender sender)
Remove a previously added ProductSender.- Parameters:
sender
- to remove
-
getTrackerURL
public java.net.URL getTrackerURL()
- Returns:
- trackerURL
-
setTrackerURL
public void setTrackerURL(java.net.URL trackerURL)
- Parameters:
trackerURL
- to set
-
getPrivateKey
public java.security.PrivateKey getPrivateKey()
- Returns:
- privateKey
-
setPrivateKey
public void setPrivateKey(java.security.PrivateKey privateKey)
- Parameters:
privateKey
- to set
-
getSignatureVersion
public CryptoUtils.Version getSignatureVersion()
- Returns:
- signatureVersion
-
setSignatureVersion
public void setSignatureVersion(CryptoUtils.Version signatureVersion)
- Parameters:
signatureVersion
- to set
-
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.
-
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 classDefaultConfigurable
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
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 classDefaultConfigurable
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
parallelSendProduct
public static java.util.Map<ProductSender,java.lang.Exception> parallelSendProduct(java.util.List<ProductSender> senders, Product product, long timeoutSeconds)
Send a product to all ProductSenders concurrently.- Parameters:
senders
- the senders to receive product.product
- the product to send.timeoutSeconds
- number of seconds before timing out, interrupting any pending send.- Returns:
- exceptions that occured while sending. If map is empty, there were no exceptions.
-
-