public class CloudProtocol extends TcpProtocol
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
SmartInspect| Modifier and Type | Field and Description |
|---|---|
static Logger |
logger |
fFormatter, fHostName, fIstream, fOstream, fPort, fTimeoutfConnected| Constructor and Description |
|---|
CloudProtocol() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
buildOptions(ConnectionsBuilder builder)
Overridden.
|
static String |
composeCustomLabelsString(Map<String,String> customLabels) |
protected LogHeader |
composeLogHeaderPacket()
Overrides TCP header packet composition, adds cloud-specific fields,
such as write key, virtual file id, custom labels.
|
void |
connect()
Connects to the protocol destination.
|
void |
disconnect()
Disconnects from the protocol destination.
|
protected void |
doHandShake()
Overrides TCP protocol handshake by reversing the order,
for compatibility with TLS.
|
protected boolean |
getAsyncEnabledDefaultValue()
Defines the default value for `async.enabled` option as `true`.
|
protected int |
getAsyncQueueDefaultValue()
Defines the default value for `async.queue` option as 20 megabytes.
|
protected String |
getName()
Overridden.
|
protected boolean |
getReconnectDefaultValue()
Defines the default value for `reconnect` option as `true`.
|
protected Socket |
internalInitializeSocket() |
protected boolean |
internalReconnect()
Reconnects to the protocol specific destination.
|
protected void |
internalValidateWritePacketAnswer(int bytesRead,
byte[] answerBytes) |
boolean |
isReconnectAllowed() |
protected boolean |
isValidOption(String name)
Overridden.
|
protected void |
loadOptions()
Overridden.
|
void |
writePacket(Packet packet)
Writes a packet to the protocol specific destination.
|
internalConnect, internalDisconnect, internalWritePacket, readServerBanner, sendClientBanneraddListener, 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, setHostNamepublic static final Logger logger
public boolean isReconnectAllowed()
protected String getName()
getName in class TcpProtocolprotected boolean isValidOption(String name)
The following table lists all valid options, their default values and descriptions for the TCP protocol.
| 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()
);
isValidOption in class TcpProtocolname - The option name to validate.protected void loadOptions()
This method loads all relevant options and ensures their correctness. See IsValidOption for a list of options which are recognized by the TCP protocol.
loadOptions in class TcpProtocolprotected boolean getReconnectDefaultValue()
getReconnectDefaultValue in class Protocolprotected boolean getAsyncEnabledDefaultValue()
getAsyncEnabledDefaultValue in class Protocolprotected int getAsyncQueueDefaultValue()
getAsyncQueueDefaultValue in class Protocolprotected void buildOptions(ConnectionsBuilder builder)
buildOptions in class TcpProtocolbuilder - ConnectionsBuilder object to fill with the current options of this protocol.protected LogHeader composeLogHeaderPacket()
composeLogHeaderPacket in class Protocolpublic static String composeCustomLabelsString(Map<String,String> customLabels)
protected void doHandShake()
throws IOException,
SmartInspectException
doHandShake in class TcpProtocolIOException - io exceptionSmartInspectException - failed to read bannerpublic void writePacket(Packet packet) throws ProtocolException
ProtocolThis 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.
writePacket in class Protocolpacket - The packet to writeProtocolException - 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 insteadpublic void connect()
throws ProtocolException
Protocol
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.
connect in class ProtocolProtocolException - 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 insteadpublic void disconnect()
throws ProtocolException
ProtocolIn 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.
disconnect in class ProtocolProtocolException - 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 insteadprotected void internalValidateWritePacketAnswer(int bytesRead,
byte[] answerBytes)
throws Exception
internalValidateWritePacketAnswer in class TcpProtocolExceptionprotected Socket internalInitializeSocket() throws Exception
internalInitializeSocket in class TcpProtocolExceptionprotected boolean internalReconnect()
throws Exception
ProtocolThis 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.
internalReconnect in class ProtocolException - if reconnecting to the destination failedCopyright © 2023. All rights reserved.