Package gov.usgs.earthquake.distribution
Class SocketProductSender
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.distribution.SocketProductSender
-
- All Implemented Interfaces:
ProductSender,Configurable
public class SocketProductSender extends DefaultConfigurable implements ProductSender
Send Products to SocketProductReceivers. The SocketProductSender implements the Configurable interface and uses the following configuration parameters:- host
- (Required) The IP address or hostname of a SocketProductReceiver.
- port
- (Optional, default=11235) The port on host of a SocketProductReceiver
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringALREADY_HAVE_PRODUCTStatic var for alreadying having the productstatic java.lang.StringBINARY_FORMAT_DEFAULTDefault value for whether to use binary format.static java.lang.StringBINARY_FORMAT_PROPERTYProperty name to configure binary or xml format.static java.lang.StringCONNECT_TIMEOUT_PROPERTYproperty for connectTimeoutstatic java.lang.StringDEFAULT_CONNECT_TIMEOUTDefault connection timeoutstatic java.lang.StringDEFAULT_ENABLE_PDL_PROTOCOLDefault for enable pdl protocolstatic java.lang.StringDEFAULT_READ_TIMEOUTDefault read timeoutstatic java.lang.StringDEFAULT_SENDER_PORTThe default port number for SocketProductReceivers.static java.lang.StringDEFAULT_WRITE_TIMEOUTDefault write timeoutstatic java.lang.StringDEFLATE_LEVEL_DEFAULTDefault deflate levelstatic java.lang.StringDEFLATE_LEVEL_PROPERTYproperty for deflateLevelstatic java.lang.StringENABLE_DEFLATE_DEFAULTDefault value for whether to use deflate compression.static java.lang.StringENABLE_DEFLATE_PROPERTYProperty name to configure deflate compression.static java.lang.StringENABLE_PDL_PROTOCOL_PROPERTYProperty to enablePdlProtocolstatic byte[]PROTOCOL_HEADERByte array for protocl headerstatic java.lang.StringPROTOCOL_VERSION_0_1Static var for v0.1 protocolstatic java.lang.StringREAD_TIMEOUT_PROPERTYproperty for readTimeoutstatic java.lang.StringRECEIVE_ERRORStatic var for a receive errorstatic java.lang.StringSENDER_HOST_PROPERTYproperty for sender hoststatic java.lang.StringSENDER_PORT_PROPERTYproperty for sender portstatic java.lang.StringUNKNOWN_PRODUCTStatic var for unknown productstatic java.lang.StringWRITE_TIMEOUT_PROPERTYproperty for writeTimeout
-
Constructor Summary
Constructors Constructor Description SocketProductSender()Empty constructor for configurable interface.SocketProductSender(Config config)Construct a new ProductSender using a Config object.SocketProductSender(java.lang.String host, int port)Construct a new ProductSender with default connection timeout.SocketProductSender(java.lang.String host, int port, int connectTimeout)Construct a new ProductSender with default read and write timeoutsSocketProductSender(java.lang.String host, int port, int connectTimeout, int readTimeout, int writeTimeout)Construct a new ProductSender
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(Config config)Reads the host and port from config.intgetConnectTimeout()intgetDeflateLevel()java.lang.StringgetHost()intgetPort()intgetReadTimeout()intgetWriteTimeout()booleanisBinaryFormat()booleanisEnableDeflate()booleanisEnablePdlProtocol()voidsendProduct(Product product)Implement the ProductSender interface.voidsetBinaryFormat(boolean binaryFormat)voidsetConnectTimeout(int connectTimeout)voidsetDeflateLevel(int deflateLevel)voidsetEnableDeflate(boolean enableDeflate)voidsetEnablePdlProtocol(boolean enablePdlProtocol)voidsetHost(java.lang.String host)voidsetPort(int port)voidsetReadTimeout(int readTimeout)voidsetWriteTimeout(int writeTimeout)voidshutdown()Makes sure the socket is closed.voidstartup()Does nothing, a socket is opened each time a product is sent.-
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
-
SENDER_HOST_PROPERTY
public static final java.lang.String SENDER_HOST_PROPERTY
property for sender host- See Also:
- Constant Field Values
-
SENDER_PORT_PROPERTY
public static final java.lang.String SENDER_PORT_PROPERTY
property for sender port- See Also:
- Constant Field Values
-
DEFAULT_SENDER_PORT
public static final java.lang.String DEFAULT_SENDER_PORT
The default port number for SocketProductReceivers.- 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
-
DEFAULT_CONNECT_TIMEOUT
public static final java.lang.String DEFAULT_CONNECT_TIMEOUT
Default connection timeout- See Also:
- Constant Field Values
-
READ_TIMEOUT_PROPERTY
public static final java.lang.String READ_TIMEOUT_PROPERTY
property for readTimeout- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT
public static final java.lang.String DEFAULT_READ_TIMEOUT
Default read timeout- See Also:
- Constant Field Values
-
WRITE_TIMEOUT_PROPERTY
public static final java.lang.String WRITE_TIMEOUT_PROPERTY
property for writeTimeout- See Also:
- Constant Field Values
-
DEFAULT_WRITE_TIMEOUT
public static final java.lang.String DEFAULT_WRITE_TIMEOUT
Default write timeout- See Also:
- Constant Field Values
-
BINARY_FORMAT_PROPERTY
public static final java.lang.String BINARY_FORMAT_PROPERTY
Property name to configure binary or xml format.- See Also:
- Constant Field Values
-
BINARY_FORMAT_DEFAULT
public static final java.lang.String BINARY_FORMAT_DEFAULT
Default value for whether to use binary format.- See Also:
- Constant Field Values
-
ENABLE_DEFLATE_PROPERTY
public static final java.lang.String ENABLE_DEFLATE_PROPERTY
Property name to configure deflate compression.- See Also:
- Constant Field Values
-
ENABLE_DEFLATE_DEFAULT
public static final java.lang.String ENABLE_DEFLATE_DEFAULT
Default value for whether to use deflate compression.- See Also:
- Constant Field Values
-
DEFLATE_LEVEL_PROPERTY
public static final java.lang.String DEFLATE_LEVEL_PROPERTY
property for deflateLevel- See Also:
- Constant Field Values
-
DEFLATE_LEVEL_DEFAULT
public static final java.lang.String DEFLATE_LEVEL_DEFAULT
Default deflate level- See Also:
- Constant Field Values
-
ENABLE_PDL_PROTOCOL_PROPERTY
public static final java.lang.String ENABLE_PDL_PROTOCOL_PROPERTY
Property to enablePdlProtocol- See Also:
- Constant Field Values
-
DEFAULT_ENABLE_PDL_PROTOCOL
public static final java.lang.String DEFAULT_ENABLE_PDL_PROTOCOL
Default for enable pdl protocol- See Also:
- Constant Field Values
-
PROTOCOL_HEADER
public static final byte[] PROTOCOL_HEADER
Byte array for protocl header
-
PROTOCOL_VERSION_0_1
public static final java.lang.String PROTOCOL_VERSION_0_1
Static var for v0.1 protocol- See Also:
- Constant Field Values
-
UNKNOWN_PRODUCT
public static final java.lang.String UNKNOWN_PRODUCT
Static var for unknown product- See Also:
- Constant Field Values
-
ALREADY_HAVE_PRODUCT
public static final java.lang.String ALREADY_HAVE_PRODUCT
Static var for alreadying having the product- See Also:
- Constant Field Values
-
RECEIVE_ERROR
public static final java.lang.String RECEIVE_ERROR
Static var for a receive error- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SocketProductSender
public SocketProductSender(java.lang.String host, int port)Construct a new ProductSender with default connection timeout.- Parameters:
host- Host of product senderport- Port of product sender
-
SocketProductSender
public SocketProductSender(java.lang.String host, int port, int connectTimeout)Construct a new ProductSender with default read and write timeouts- Parameters:
host- Host of product senderport- Port of product senderconnectTimeout- Timeout in ms
-
SocketProductSender
public SocketProductSender(java.lang.String host, int port, int connectTimeout, int readTimeout, int writeTimeout)Construct a new ProductSender- Parameters:
host- Host of product senderport- Port of product senderconnectTimeout- connect timeout in msreadTimeout- read timeout in mswriteTimeout- write timeout in ms
-
SocketProductSender
public SocketProductSender()
Empty constructor for configurable interface.
-
SocketProductSender
public SocketProductSender(Config config) throws java.lang.Exception
Construct a new ProductSender using a Config object.- Parameters:
config- Config object- Throws:
java.lang.Exception- if error occurs
-
-
Method Detail
-
sendProduct
public void sendProduct(Product product) throws java.lang.Exception
Implement the ProductSender interface. Connects to host:port and sends a Deflaterped xml encoded Product. There is no direct response over the socket at this time. Updates may be retrieved from a ProductTracker.- Specified by:
sendProductin interfaceProductSender- Parameters:
product- the product to send.- Throws:
java.lang.Exception- if any errors occur while sending.
-
configure
public void configure(Config config) throws java.lang.Exception
Reads the host and port from config.- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultConfigurable- Parameters:
config- a Config object with host and port properties.- Throws:
java.lang.Exception- if configuration exceptions occur.
-
shutdown
public void shutdown() throws java.lang.ExceptionMakes sure the socket is closed.- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultConfigurable- Throws:
java.lang.Exception- if exceptions occur while starting.
-
startup
public void startup() throws java.lang.ExceptionDoes nothing, a socket is opened each time a product is sent.- Specified by:
startupin interfaceConfigurable- Overrides:
startupin classDefaultConfigurable- Throws:
java.lang.Exception- if exceptions occur while starting.
-
isBinaryFormat
public boolean isBinaryFormat()
- Returns:
- the binaryFormat
-
setBinaryFormat
public void setBinaryFormat(boolean binaryFormat)
- Parameters:
binaryFormat- the binaryFormat to set
-
isEnableDeflate
public boolean isEnableDeflate()
- Returns:
- the enableDeflate
-
setEnableDeflate
public void setEnableDeflate(boolean enableDeflate)
- Parameters:
enableDeflate- the enableDeflate to set
-
getDeflateLevel
public int getDeflateLevel()
- Returns:
- the deflateLevel
-
setDeflateLevel
public void setDeflateLevel(int deflateLevel)
- Parameters:
deflateLevel- the deflateLevel to set
-
isEnablePdlProtocol
public boolean isEnablePdlProtocol()
- Returns:
- the enablePdlProtocol
-
setEnablePdlProtocol
public void setEnablePdlProtocol(boolean enablePdlProtocol)
- Parameters:
enablePdlProtocol- the enablePdlProtocol to set
-
getConnectTimeout
public int getConnectTimeout()
- Returns:
- the connectTimeout
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
- Parameters:
connectTimeout- the connectTimeout to set
-
getReadTimeout
public int getReadTimeout()
- Returns:
- the readTimeout
-
setReadTimeout
public void setReadTimeout(int readTimeout)
- Parameters:
readTimeout- the readTimeout to set
-
getWriteTimeout
public int getWriteTimeout()
- Returns:
- the writeTimeout
-
setWriteTimeout
public void setWriteTimeout(int writeTimeout)
- Parameters:
writeTimeout- the writeTimeout to set
-
getHost
public java.lang.String getHost()
- Returns:
- the host
-
setHost
public void setHost(java.lang.String host)
- Parameters:
host- the host to set
-
getPort
public int getPort()
- Returns:
- the port
-
setPort
public void setPort(int port)
- Parameters:
port- the port to set
-
-