Class 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 Detail

      • logger

        public static final Logger logger
    • Constructor Detail

      • CloudProtocol

        public CloudProtocol()
    • Method Detail

      • isReconnectAllowed

        public boolean isReconnectAllowed()
      • getName

        protected String getName()
        Overridden. Returns 'cloud'.
        Overrides:
        getName in class TcpProtocol
        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.

        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.
        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.

        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:
        isValidOption in class TcpProtocol
        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:
        loadOptions in class TcpProtocol
      • getReconnectDefaultValue

        protected boolean getReconnectDefaultValue()
        Defines the default value for `reconnect` option as `true`.
        Overrides:
        getReconnectDefaultValue in class Protocol
        Returns:
        true
      • getAsyncEnabledDefaultValue

        protected boolean getAsyncEnabledDefaultValue()
        Defines the default value for `async.enabled` option as `true`.
        Overrides:
        getAsyncEnabledDefaultValue in class Protocol
        Returns:
        true
      • getAsyncThrottleDefaultValue

        protected boolean getAsyncThrottleDefaultValue()
        Defines the default value for `async.throttle` option as `false`.
        Overrides:
        getAsyncThrottleDefaultValue in class Protocol
        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:
        getAsyncQueueDefaultValue in class Protocol
        Returns:
        20480 KB
      • buildOptions

        protected void buildOptions​(ConnectionsBuilder builder)
        Overridden. Fills a TSiConnectionsBuilder instance with the options currently used by this Cloud protocol.
        Overrides:
        buildOptions in class TcpProtocol
        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:
        composeLogHeaderPacket in class Protocol
        Returns:
        log header packet
      • composeCustomLabelsString

        public static String composeCustomLabelsString​(Map<String,​String> customLabels)
      • writePacket

        public void writePacket​(Packet packet)
                         throws ProtocolException
        Description copied from class: Protocol
        Writes 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:
        writePacket in class Protocol
        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 ProtocolException
        Description copied from class: Protocol
        Connects 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:
        connect in class Protocol
        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 ProtocolException
        Description copied from class: Protocol
        Disconnects 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:
        disconnect in class Protocol
        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
      • internalWritePacket

        protected void internalWritePacket​(Packet packet)
                                    throws Exception
        Description copied from class: TcpProtocol
        Overridden. Sends a packet to the Console.

        This method sends the supplied packet to the SmartInspect Console and waits for a valid response.

        Overrides:
        internalWritePacket in class TcpProtocol
        Parameters:
        packet - The packet to write
        Throws:
        Exception - If sending the packet to the Console failed
      • internalReconnect

        protected boolean internalReconnect()
                                     throws Exception
        Description copied from class: Protocol
        Reconnects 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:
        internalReconnect in class Protocol
        Returns:
        True if the reconnect attempt has been successful and false otherwise
        Throws:
        Exception - if reconnecting to the destination failed