Class CloudProtocol
- java.lang.Object
-
- com.gurock.smartinspect.protocols.Protocol
-
- com.gurock.smartinspect.protocols.TcpProtocol
-
- com.gurock.smartinspect.protocols.cloud.CloudProtocol
-
public class CloudProtocol extends TcpProtocol
Used for sending packets to the SmartInspect Cloud.This class is used for sending packets to the Cloud. Cloud protocol implementation in an extension of the TCP protocol. It is used when the 'cloud' protocol is specified in the SmartInspect connections string. Please see the IsValidOption method for a list of available protocol options
- See Also:
SmartInspect
-
-
Field Summary
Fields Modifier and Type Field Description static Loggerlogger-
Fields inherited from class com.gurock.smartinspect.protocols.TcpProtocol
fFormatter, fHostName, fIstream, fOstream, fPort, fTimeout
-
Fields inherited from class com.gurock.smartinspect.protocols.Protocol
fConnected
-
-
Constructor Summary
Constructors Constructor Description CloudProtocol()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildOptions(ConnectionsBuilder builder)Overridden.static StringcomposeCustomLabelsString(Map<String,String> customLabels)protected LogHeadercomposeLogHeaderPacket()Overrides TCP header packet composition, adds cloud-specific fields, such as write key, virtual file id, custom labels.voidconnect()Connects to the protocol destination.voiddisconnect()Disconnects from the protocol destination.protected voiddoHandShake()Overrides TCP protocol handshake by reversing the order, for compatibility with TLS.protected booleangetAsyncEnabledDefaultValue()Defines the default value for `async.enabled` option as `true`.protected intgetAsyncQueueDefaultValue()Defines the default value for `async.queue` option as 20 megabytes.protected booleangetAsyncThrottleDefaultValue()Defines the default value for `async.throttle` option as `false`.protected StringgetName()Overridden.protected booleangetReconnectDefaultValue()Defines the default value for `reconnect` option as `true`.protected SocketinternalInitializeSocket()protected booleaninternalReconnect()Reconnects to the protocol specific destination.protected voidinternalValidateWritePacketAnswer(int bytesRead, byte[] answerBytes)protected voidinternalWritePacket(Packet packet)Overridden.booleanisReconnectAllowed()protected booleanisValidOption(String name)Overridden.protected voidloadOptions()Overridden.voidwritePacket(Packet packet)Writes a packet to the protocol specific destination.-
Methods inherited from class com.gurock.smartinspect.protocols.TcpProtocol
internalConnect, internalDisconnect, readServerBanner, sendClientBanner
-
Methods inherited from class com.gurock.smartinspect.protocols.Protocol
addListener, dispatch, dispose, doError, failed, getAppName, getBooleanOption, getBytesOption, getCaption, getHostName, getIntegerOption, getLevelOption, getRotateOption, getSizeOption, getStringOption, getTimespanOption, handleException, implConnect, implDisconnect, implDispatch, implWritePacket, initialize, internalDispatch, internalWriteLogHeader, isAsynchronous, removeListener, reset, scheduleWritePacket, setAppName, setHostName
-
-
-
-
Field Detail
-
logger
public static final Logger logger
-
-
Method Detail
-
isReconnectAllowed
public boolean isReconnectAllowed()
-
getName
protected String getName()
Overridden. Returns 'cloud'.- Overrides:
getNamein classTcpProtocol- Returns:
- 'cloud'
-
isValidOption
protected boolean isValidOption(String name)
Overridden. Validates if a protocol option is supported.The following table lists all valid options, their default values and descriptions for the TCP protocol.
For further options which affect the behavior of this protocol, please have a look at the documentation of Protocol.isValidOption and TcpProtocol.isValidOption methods of the parent classes.Tcp protocol options Valid Options Default Value Description writekey Write key of your SmartInspect Cloud license. customlabels Up to 5 labels. See example below. region eu-central-1 SCloud region. maxsize '1 MB' Specifies the maximum size of a log file in kilobytes. When this size is reached, the current log file is closed and a new file is opened. It is possible to specify size units like this: "1 MB". Supported units are "KB", "MB" and "GB". Min value - "1 MB", max value - "50 MB". rotate none Specifies the rotate mode for log files. Please see below for a list of available values. A value of "none" disables this feature. Example:
smartInspect.setConnections( (new CloudConnectionStringBuilder()).addCloudProtocol() .setRegion("eu-central-1") .setWriteKey("INSERT_YOUR_WRITE_KEY_HERE") .addCustomLabel("User", "Bob") .addCustomLabel("Version", "0.0.1") .and().build() );- Overrides:
isValidOptionin classTcpProtocol- Parameters:
name- The option name to validate.- Returns:
- True if the option is supported and false otherwise.
-
loadOptions
protected void loadOptions()
Overridden. Loads and inspects Cloud 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 classTcpProtocol
-
getReconnectDefaultValue
protected boolean getReconnectDefaultValue()
Defines the default value for `reconnect` option as `true`.- Overrides:
getReconnectDefaultValuein classProtocol- Returns:
- true
-
getAsyncEnabledDefaultValue
protected boolean getAsyncEnabledDefaultValue()
Defines the default value for `async.enabled` option as `true`.- Overrides:
getAsyncEnabledDefaultValuein classProtocol- Returns:
- true
-
getAsyncThrottleDefaultValue
protected boolean getAsyncThrottleDefaultValue()
Defines the default value for `async.throttle` option as `false`.- Overrides:
getAsyncThrottleDefaultValuein classProtocol- Returns:
- false
-
getAsyncQueueDefaultValue
protected int getAsyncQueueDefaultValue()
Defines the default value for `async.queue` option as 20 megabytes. Double the size of the max packet size supported by the cloud. We want async queue to fit the largest packet, as have some spare space.- Overrides:
getAsyncQueueDefaultValuein classProtocol- Returns:
- 20480 KB
-
buildOptions
protected void buildOptions(ConnectionsBuilder builder)
Overridden. Fills a TSiConnectionsBuilder instance with the options currently used by this Cloud protocol.- Overrides:
buildOptionsin classTcpProtocol- Parameters:
builder- ConnectionsBuilder object to fill with the current options of this protocol.
-
composeLogHeaderPacket
protected LogHeader composeLogHeaderPacket()
Overrides TCP header packet composition, adds cloud-specific fields, such as write key, virtual file id, custom labels.- Overrides:
composeLogHeaderPacketin classProtocol- Returns:
- log header packet
-
composeCustomLabelsString
public static String composeCustomLabelsString(Map<String,String> customLabels)
-
doHandShake
protected void doHandShake() throws IOException, SmartInspectExceptionOverrides TCP protocol handshake by reversing the order, for compatibility with TLS.- Overrides:
doHandShakein classTcpProtocol- Throws:
IOException- io exceptionSmartInspectException- failed to read banner
-
writePacket
public void writePacket(Packet packet) throws ProtocolException
Description copied from class:ProtocolWrites a packet to the protocol specific destination.This method first checks if the log level of the supplied packet is sufficient to be logged. If this is not the case, this method returns immediately.
Otherwise, in normal blocking mode (see
Protocol.isValidOption(java.lang.String)), this method verifies that this protocol is successfully connected and then writes the supplied packet to the backlog queue or passes it directly to the protocol specific destination by calling the InternalWritePacket method. Calling InternalWritePacket is always done in a threadsafe and exception-safe way.When operating in asynchronous mode instead, this method schedules a write operation for asynchronous execution and returns immediately. Please note that possible exceptions which occur during the eventually executed write are not thrown directly but reported with the
error event.- Overrides:
writePacketin classProtocol- Parameters:
packet- The packet to write- Throws:
ProtocolException- Writing the packet to the destination failed. Can only occur when operating in normal blocking mode. In asynchronous mode, the error event is used for reporting exceptions instead
-
connect
public void connect() throws ProtocolExceptionDescription copied from class:ProtocolConnects to the protocol destination.In normal blocking mode (see isValidOption), this method does nothing more than to verify that the protocol is not already connected and does not use the keep-open backlog feature, and then calls the abstract protocol specific internalConnect method in a threadsafe and exception-safe context.
When operating in asynchronous mode instead, this method schedules a connect operation for asynchronous execution and returns immediately. Please note that possible exceptions which occur during the eventually executed connect are not thrown directly but reported with the error event.- Overrides:
connectin classProtocol- Throws:
ProtocolException- If connecting to the destination fails. Can only occur when operating in normal blocking mode. In asynchronous mode, the error event is used for reporting exceptions instead
-
disconnect
public void disconnect() throws ProtocolExceptionDescription copied from class:ProtocolDisconnects from the protocol destination.In normal blocking mode (see isValidOption), this method checks if this protocol has a working connection and then calls the protocol specific internalDisconnect method in a threadsafe and exception-safe context.
When operating in asynchronous mode instead, this method schedules a disconnect operation for asynchronous execution and then blocks until the internal protocol thread is done. Please note that possible exceptions which occur during the eventually executed disconnect are not thrown directly but reported with the ProtocolListener.onError, error event.
- Overrides:
disconnectin classProtocol- Throws:
ProtocolException- Disconnecting from the destination failed. Can only occur when operating in normal blocking mode. In asynchronous mode, the error event is used for reporting exceptions instead
-
internalValidateWritePacketAnswer
protected void internalValidateWritePacketAnswer(int bytesRead, byte[] answerBytes) throws Exception- Overrides:
internalValidateWritePacketAnswerin classTcpProtocol- Throws:
Exception
-
internalInitializeSocket
protected Socket internalInitializeSocket() throws Exception
- Overrides:
internalInitializeSocketin classTcpProtocol- Throws:
Exception
-
internalWritePacket
protected void internalWritePacket(Packet packet) throws Exception
Description copied from class:TcpProtocolOverridden. Sends a packet to the Console.This method sends the supplied packet to the SmartInspect Console and waits for a valid response.
- Overrides:
internalWritePacketin classTcpProtocol- Parameters:
packet- The packet to write- Throws:
Exception- If sending the packet to the Console failed
-
internalReconnect
protected boolean internalReconnect() throws ExceptionDescription copied from class:ProtocolReconnects to the protocol specific destination.This method initiates a protocol specific reconnect attempt. The behavior of real method implementations can often be changed by setting protocol options with initialize. This method is always called in a threadsafe and exception-safe context.
The default implementation simply calls the protocol specific internalConnect method. Derived classes can change this behavior by overriding this method.
- Overrides:
internalReconnectin classProtocol- Returns:
- True if the reconnect attempt has been successful and false otherwise
- Throws:
Exception- if reconnecting to the destination failed
-
-