Package gov.usgs.earthquake.distribution
Class SocketProductSender
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.distribution.SocketProductSender
- All Implemented Interfaces:
ProductSender
,Configurable
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
FieldsModifier and TypeFieldDescriptionstatic final String
Static var for alreadying having the productstatic final String
Default value for whether to use binary format.static final String
Property name to configure binary or xml format.static final String
property for connectTimeoutstatic final String
Default connection timeoutstatic final String
Default for enable pdl protocolstatic final String
Default read timeoutstatic final String
The default port number for SocketProductReceivers.static final String
Default write timeoutstatic final String
Default deflate levelstatic final String
property for deflateLevelstatic final String
Default value for whether to use deflate compression.static final String
Property name to configure deflate compression.static final String
Property to enablePdlProtocolstatic final byte[]
Byte array for protocl headerstatic final String
Static var for v0.1 protocolstatic final String
property for readTimeoutstatic final String
Static var for a receive errorstatic final String
property for sender hoststatic final String
property for sender portstatic final String
Static var for unknown productstatic final String
property for writeTimeout -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor for configurable interface.SocketProductSender
(Config config) Construct a new ProductSender using a Config object.SocketProductSender
(String host, int port) Construct a new ProductSender with default connection timeout.SocketProductSender
(String host, int port, int connectTimeout) Construct a new ProductSender with default read and write timeoutsSocketProductSender
(String host, int port, int connectTimeout, int readTimeout, int writeTimeout) Construct a new ProductSender -
Method Summary
Modifier and TypeMethodDescriptionvoid
Reads the host and port from config.int
int
getHost()
int
getPort()
int
int
boolean
boolean
boolean
void
sendProduct
(Product product) Implement the ProductSender interface.void
setBinaryFormat
(boolean binaryFormat) void
setConnectTimeout
(int connectTimeout) void
setDeflateLevel
(int deflateLevel) void
setEnableDeflate
(boolean enableDeflate) void
setEnablePdlProtocol
(boolean enablePdlProtocol) void
void
setPort
(int port) void
setReadTimeout
(int readTimeout) void
setWriteTimeout
(int writeTimeout) void
shutdown()
Makes sure the socket is closed.void
startup()
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 Details
-
SENDER_HOST_PROPERTY
property for sender host- See Also:
-
SENDER_PORT_PROPERTY
property for sender port- See Also:
-
DEFAULT_SENDER_PORT
The default port number for SocketProductReceivers.- See Also:
-
CONNECT_TIMEOUT_PROPERTY
property for connectTimeout- See Also:
-
DEFAULT_CONNECT_TIMEOUT
Default connection timeout- See Also:
-
READ_TIMEOUT_PROPERTY
property for readTimeout- See Also:
-
DEFAULT_READ_TIMEOUT
Default read timeout- See Also:
-
WRITE_TIMEOUT_PROPERTY
property for writeTimeout- See Also:
-
DEFAULT_WRITE_TIMEOUT
Default write timeout- See Also:
-
BINARY_FORMAT_PROPERTY
Property name to configure binary or xml format.- See Also:
-
BINARY_FORMAT_DEFAULT
Default value for whether to use binary format.- See Also:
-
ENABLE_DEFLATE_PROPERTY
Property name to configure deflate compression.- See Also:
-
ENABLE_DEFLATE_DEFAULT
Default value for whether to use deflate compression.- See Also:
-
DEFLATE_LEVEL_PROPERTY
property for deflateLevel- See Also:
-
DEFLATE_LEVEL_DEFAULT
Default deflate level- See Also:
-
ENABLE_PDL_PROTOCOL_PROPERTY
Property to enablePdlProtocol- See Also:
-
DEFAULT_ENABLE_PDL_PROTOCOL
Default for enable pdl protocol- See Also:
-
PROTOCOL_HEADER
public static final byte[] PROTOCOL_HEADERByte array for protocl header -
PROTOCOL_VERSION_0_1
Static var for v0.1 protocol- See Also:
-
UNKNOWN_PRODUCT
Static var for unknown product- See Also:
-
ALREADY_HAVE_PRODUCT
Static var for alreadying having the product- See Also:
-
RECEIVE_ERROR
Static var for a receive error- See Also:
-
-
Constructor Details
-
SocketProductSender
Construct a new ProductSender with default connection timeout.- Parameters:
host
- Host of product senderport
- Port of product sender
-
SocketProductSender
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(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
Construct a new ProductSender using a Config object.- Parameters:
config
- Config object- Throws:
Exception
- if error occurs
-
-
Method Details
-
sendProduct
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.- Specified by:
sendProduct
in interfaceProductSender
- Parameters:
product
- the product to send.- Throws:
Exception
- if any errors occur while sending.
-
configure
Reads the host and port from config.- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultConfigurable
- Parameters:
config
- a Config object with host and port properties.- Throws:
Exception
- if configuration exceptions occur.
-
shutdown
Makes sure the socket is closed.- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultConfigurable
- Throws:
Exception
- if exceptions occur while starting.
-
startup
Does nothing, a socket is opened each time a product is sent.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultConfigurable
- Throws:
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
- Returns:
- the host
-
setHost
- 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
-