Class Packet

  • Direct Known Subclasses:
    Chunk, ControlCommand, LogEntry, LogHeader, ProcessFlow, Watch

    public abstract class Packet
    extends Object
    This is the abstract base class for all packets in the SmartInspect Java library.

    This class is the base class for all packets in the SmartInspect Java library. The following table lists the available packets together with a short description:
    - ControlCommand: Responsible for administrative tasks like clearing the Console.
    - LogEntry: Represents the most important packet in the entire SmartInspect concept. It is used for the majority of logging methods in the Session class.
    - LogHeader: Responsible for storing and transferring log metadata. Used by the PipeProtocol and TcpProtocol classes to support the filter and trigger functionality of the SmartInspect Router service application.
    - ProcessFlow: Responsible for managing thread and process information about your application.
    - Watch: Responsible for handling variable watches.

    This class and sub-classes are not guaranteed to be thread-safe. To ensure thread-safety, use setThreadSafe as well as the lock and unlock methods.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int PACKET_HEADER  
    • Constructor Summary

      Constructors 
      Constructor Description
      Packet()
      Creates and initializes a Packet instance with a default log level of Level.Message.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      int getBytes()
      Returns the amount of bytes needed for storing this packet in the standard SmartInspect binary log file format as represented by BinaryFormatter.
      Level getLevel()
      Returns the log level of this packet.
      abstract PacketType getPacketType()
      Intended to return the type of the packet.
      abstract int getSize()
      This method returns the total occupied memory size of this packet.
      protected int getStringSize​(String s)
      Returns the memory size occupied by a string.
      protected int getThreadId()
      Returns the ID of the current thread.
      boolean isThreadSafe()
      Indicates if this packet is used in a multi-threaded SmartInspect environment.
      void lock()
      This method locks this packet for safe multi-threaded packet processing if this packet is operating in thread-safe mode.
      void setBytes​(int bytes)
      Sets the amount of bytes needed for storing this packet in the standard SmartInspect binary log file format as represented by BinaryFormatter.
      void setLevel​(Level level)
      Sets the log level of this packet.
      void setThreadSafe​(boolean threadSafe)
      Specifies if this packet is used in a multi-threaded SmartInspect environment.
      void unlock()
      Unlocks a previously locked packet.
    • Constructor Detail

      • Packet

        public Packet()
        Creates and initializes a Packet instance with a default log level of Level.Message.
    • Method Detail

      • getBytes

        public int getBytes()
        Returns the amount of bytes needed for storing this packet in the standard SmartInspect binary log file format as represented by BinaryFormatter.

        Please note that this method is only intended to be used by a possible Java implementation of the SmartInspect SDK. The SmartInspect SDK is a small library for reading SmartInspect binary log files and is available for download on the Gurock Software website.

        Returns:
        The amount of bytes needed for storing this packet in the standard SmartInspect binary log file format
      • setBytes

        public void setBytes​(int bytes)
        Sets the amount of bytes needed for storing this packet in the standard SmartInspect binary log file format as represented by BinaryFormatter.

        Please note that this method is only intended to be used by a possible Java implementation of the SmartInspect SDK. The SmartInspect SDK is a small library for reading SmartInspect binary log files and is available for download on the Gurock Software website.

        Parameters:
        bytes - The amount of bytes needed for storing this packet in the standard SmartInspect binary log file format
      • getThreadId

        protected int getThreadId()
        Returns the ID of the current thread.

        This method is intended to be used by derived packet classes which make use of a thread ID.

        Returns:
        The ID the current thread
      • getStringSize

        protected int getStringSize​(String s)
        Returns the memory size occupied by a string.

        This method calculates and returns the total memory size occupied by the supplied string. If the supplied argument is null, 0 is returned.

        Parameters:
        s - The string whose memory size to return. Can be null
        Returns:
        The memory size occupied by the supplied string or 0 if the supplied argument is null
      • getLevel

        public Level getLevel()
        Returns the log level of this packet.

        Every packet can have a certain log level value. Log levels describe the severity of a packet. Please see the Level enum for more information about log levels and their usage.

        Returns:
        The log level of this packet
      • setLevel

        public void setLevel​(Level level)
        Sets the log level of this packet.

        Every packet can have a certain log level value. Log levels describe the severity of a packet. Please see the Level enum for more information about log levels and their usage.

        If the level argument is a null reference a NullPointerException will be thrown.

        Parameters:
        level - The new log level of this packet. Not allowed to be null
        Throws:
        NullPointerException - If the level argument is null
      • getSize

        public abstract int getSize()
        This method returns the total occupied memory size of this packet. This functionality is used by the backlog protocol feature to calculate the total backlog queue size.
        Returns:
        The total memory size occupied by this packet
      • getPacketType

        public abstract PacketType getPacketType()
        Intended to return the type of the packet.
        Returns:
        The type of this packet. Please see the PacketType type for a list of available packet types
      • lock

        public void lock()
        This method locks this packet for safe multi-threaded packet processing if this packet is operating in thread-safe mode.

        You need to call this method before reading or changing properties of a packet when using this packet from multiple threads at the same time. This is needed, for example, when one or more SmartInspect.setConnections(java.lang.String) connections of a SmartInspect object are told to operate in Protocol.isValidOption() asynchronous protocol mode. Each lock call must be matched by a call to unlock.

        Before using lock and unlock in a multi-threaded environment you must indicate that this packet should operate in thread-safe mode by setting the setThreadSafe(boolean) method to true. Otherwise, the lock and unlock methods do nothing. Note that setting the setThreadSafe(boolean) method is done automatically if this packet has been created by the Session class and is processed by a related SmartInspect object which has one or more connections which operate in asynchronous protocol mode.

      • unlock

        public void unlock()
        Unlocks a previously locked packet.

        You need to call this method after reading or changing properties of a packet when using this packet from multiple threads at the same time. This is needed, for example, when one or more connections of a SmartInspect object are told to operate in asynchronous protocol mode. Each unlock call must be matched by a previous call to lock.

        Before using lock and unlock in a multi-threaded environment you must indicate that this packet should operate in thread-safe mode by setting the setThreadSafe method to true. Otherwise, the lock and unlock methods do nothing. Note that setting the setThreadSafe method is done automatically if this packet has been created by the Session class and is processed by a related SmartInspect object which has one or more connections which operate in asynchronous protocol mode.

      • isThreadSafe

        public boolean isThreadSafe()
        Indicates if this packet is used in a multi-threaded SmartInspect environment. If this method returns true, the lock and unlock methods lock this packet for safe multi-threaded access. Otherwise, the lock and unlock methods do nothing. Please see the corresponding setThreadSafe method for more information.
        Returns:
        True if this packet is used in a multi-threaded SmartInspect environment and false otherwise.
      • setThreadSafe

        public void setThreadSafe​(boolean threadSafe)
        Specifies if this packet is used in a multi-threaded SmartInspect environment.

        Set this method to true before calling lock and unlock in a multi-threaded environment. Otherwise, the lock and unlock methods do nothing. Note that setting this method is done automatically if this packet has been created by the Session class and is processed by a related SmartInspect object which has one or more connections which operate in asynchronous protocol mode.

        Setting this method must be done before using this packet from multiple threads simultaneously.

        Parameters:
        threadSafe - True if this packet is used in a multi-threaded SmartInspect environment and false otherwise