Class TcpProtocol
- java.lang.Object
-
- com.gurock.smartinspect.protocols.Protocol
-
- com.gurock.smartinspect.protocols.TcpProtocol
-
- Direct Known Subclasses:
CloudProtocol
public class TcpProtocol extends Protocol
Used for sending packets to the SmartInspect Console over a TCP socket connection.This class is used for sending packets over a TCP connection to the Console. It is used when the 'tcp' protocol is specified in the
SmartInspect.setConnections(java.lang.String)connections string. Please see the isValidOption method for a list of available protocol options.Thread Safety: The public members of this class are threadsafe.
-
-
Field Summary
Fields Modifier and Type Field Description protected FormatterfFormatterprotected StringfHostNameprotected InputStreamfIstreamprotected OutputStreamfOstreamprotected intfPortprotected intfTimeout-
Fields inherited from class com.gurock.smartinspect.protocols.Protocol
fConnected
-
-
Constructor Summary
Constructors Constructor Description TcpProtocol()Creates and initializes a TcpProtocol instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildOptions(ConnectionsBuilder builder)Overridden.protected voiddoHandShake()protected StringgetName()Overridden.protected voidinternalConnect()Overridden.protected voidinternalDisconnect()Overridden.protected SocketinternalInitializeSocket()protected voidinternalValidateWritePacketAnswer(int bytesRead, byte[] answerBytes)protected voidinternalWritePacket(Packet packet)Overridden.protected booleanisValidOption(String name)Validates if a protocol option is supported.protected voidloadOptions()Overridden.protected voidreadServerBanner()protected voidsendClientBanner()-
Methods inherited from class com.gurock.smartinspect.protocols.Protocol
addListener, composeLogHeaderPacket, connect, disconnect, dispatch, dispose, doError, failed, getAppName, getAsyncEnabledDefaultValue, getAsyncQueueDefaultValue, getAsyncThrottleDefaultValue, getBooleanOption, getBytesOption, getCaption, getHostName, getIntegerOption, getLevelOption, getReconnectDefaultValue, getRotateOption, getSizeOption, getStringOption, getTimespanOption, handleException, implConnect, implDisconnect, implDispatch, implWritePacket, initialize, internalDispatch, internalReconnect, internalWriteLogHeader, isAsynchronous, removeListener, reset, scheduleWritePacket, setAppName, setHostName, writePacket
-
-
-
-
Field Detail
-
fIstream
protected InputStream fIstream
-
fOstream
protected OutputStream fOstream
-
fFormatter
protected Formatter fFormatter
-
fHostName
protected String fHostName
-
fTimeout
protected int fTimeout
-
fPort
protected int fPort
-
-
Method Detail
-
getName
protected String getName()
Overridden. Returns "tcp".
-
isValidOption
protected boolean isValidOption(String name)
Validates if a protocol option is supported. Overridden method.The following table lists all valid options, their default values and descriptions for the TCP protocol:
Tcp protocol options Valid Options Default Value Description host "127.0.0.1" Specifies the hostname where the Console is running port 4228 Specifies the Console port timeout 30000 Specifies the connect, receive and send timeout in milliseconds For further options which affect the behavior of this protocol, please have a look at the documentation of the Protocol.isValidOption method of the parent class. Example:
SiAuto.si.setConnections("tcp()"); SiAuto.si.setConnections("tcp(host=\\"localhost\\", port=4229)"); SiAuto.si.setConnections("tcp(timeout=2500)");- Overrides:
isValidOptionin classProtocol- Parameters:
name- The option name to validate- Returns:
- True if the option is supported and false otherwise
-
buildOptions
protected void buildOptions(ConnectionsBuilder builder)
Overridden. Fills a ConnectionsBuilder instance with the options currently used by this TCP protocol.- Overrides:
buildOptionsin classProtocol- Parameters:
builder- The ConnectionsBuilder object to fill with the current options of this protocol
-
loadOptions
protected void loadOptions()
Overridden. Loads and inspects TCP specific options.This method loads all relevant options and ensures their correctness. See isValidOption for a list of options which are recognized by the TCP protocol
- Overrides:
loadOptionsin classProtocol
-
doHandShake
protected void doHandShake() throws IOException, SmartInspectException- Throws:
IOExceptionSmartInspectException
-
readServerBanner
protected void readServerBanner() throws SmartInspectException, IOException- Throws:
SmartInspectExceptionIOException
-
sendClientBanner
protected void sendClientBanner() throws IOException- Throws:
IOException
-
internalConnect
protected void internalConnect() throws ExceptionOverridden. Creates and connects a TCP socket. This method tries to connect a TCP socket to a SmartInspect Console. The hostname and port can be specified by passing the "hostname" and "port" options to the initialize method. Furthermore, it is possible to specify the connect timeout by using the "timeout" option.- Specified by:
internalConnectin classProtocol- Throws:
Exception- if creating or connecting the socket failed
-
internalInitializeSocket
protected Socket internalInitializeSocket() throws Exception
- Throws:
Exception
-
internalWritePacket
protected void internalWritePacket(Packet packet) throws Exception
Overridden. Sends a packet to the Console.This method sends the supplied packet to the SmartInspect Console and waits for a valid response.
- Specified by:
internalWritePacketin classProtocol- Parameters:
packet- The packet to write- Throws:
Exception- If sending the packet to the Console failed
-
internalValidateWritePacketAnswer
protected void internalValidateWritePacketAnswer(int bytesRead, byte[] answerBytes) throws Exception- Throws:
Exception
-
internalDisconnect
protected void internalDisconnect() throws ExceptionOverridden. Closes the TCP socket connection.This method closes the underlying socket handle if previously created and disposes any supplemental objects.
- Specified by:
internalDisconnectin classProtocol- Throws:
Exception- If Closing the TCP socket failed
-
-