public abstract class Packet extends Object
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.
| Modifier and Type | Field and Description |
|---|---|
static int |
PACKET_HEADER |
| Constructor and Description |
|---|
Packet()
Creates and initializes a Packet instance with a default log
level of Level.Message.
|
| Modifier and Type | Method and 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.
|
public static final int PACKET_HEADER
public Packet()
public int getBytes()
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.
public void setBytes(int bytes)
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.
bytes - The amount of bytes needed for storing this packet in the
standard SmartInspect binary log file formatprotected int getThreadId()
This method is intended to be used by derived packet classes which make use of a thread ID.
protected int getStringSize(String s)
This method calculates and returns the total memory size occupied by the supplied string. If the supplied argument is null, 0 is returned.
s - The string whose memory size to return. Can be nullpublic Level getLevel()
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.
public void setLevel(Level level)
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.
level - The new log level of this packet. Not allowed to be nullNullPointerException - If the level argument is nullpublic abstract int getSize()
public abstract PacketType getPacketType()
public void lock()
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.
public void unlock()
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.
public boolean isThreadSafe()
public void setThreadSafe(boolean threadSafe)
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.
threadSafe - True if this packet is used in a multi-threaded SmartInspect
environment and false otherwiseCopyright © 2023. All rights reserved.