public class MemoryProtocol extends Protocol
This class is used for writing log data to memory. On request, this
data can be saved to a stream or protocol object. To initiate such
a request, use the internalDispatch method.
This class is used when the 'mem' protocol is specified in the
connections string of the SmartInspect.setConnections(java.lang.String). Please see
the isValidOption method for a list of available options for this
protocol.
The public members of this class are threadsafe.
fConnected| Constructor and Description |
|---|
MemoryProtocol()
Creates and initializes a new MemoryProtocol instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
buildOptions(ConnectionsBuilder builder)
Overridden.
|
protected String |
getName()
Overridden.
|
protected void |
internalConnect()
Overridden.
|
protected void |
internalDisconnect()
Overridden.
|
protected void |
internalDispatch(ProtocolCommand command)
Overrides and implements a custom action for saving the current
queue of packets of this memory protocol to a stream or
protocol object.
|
protected void |
internalWritePacket(Packet packet)
Overridden.
|
protected boolean |
isValidOption(String name)
Overridden.
|
protected void |
loadOptions()
Overridden.
|
addListener, composeLogHeaderPacket, connect, disconnect, dispatch, dispose, doError, failed, getAppName, getAsyncEnabledDefaultValue, getAsyncQueueDefaultValue, getBooleanOption, getBytesOption, getCaption, getHostName, getIntegerOption, getLevelOption, getReconnectDefaultValue, getRotateOption, getSizeOption, getStringOption, getTimespanOption, handleException, implConnect, implDisconnect, implDispatch, implWritePacket, initialize, internalReconnect, internalWriteLogHeader, isAsynchronous, removeListener, reset, scheduleWritePacket, setAppName, setHostName, writePacketpublic MemoryProtocol()
protected void internalConnect()
throws Exception
This method creates and initializes a new packet queue with a maximum size as specified with the initialize method. For other valid options which might affect the behavior of this method and protocol, please see the isValidOption method.
internalConnect in class ProtocolException - If connecting to the destination failed.protected void internalDisconnect()
throws Exception
internalDisconnect in class ProtocolException - If disconnecting from the destination failedprotected void internalWritePacket(Packet packet) throws Exception
internalWritePacket in class Protocolpacket - The packet to write.Exception - if writing the packet to the destination failedprotected void internalDispatch(ProtocolCommand command) throws Exception
Depending on the supplied command argument, this method does the following. If the supplied state object of the protocol command is of type OutputStream, then this method uses this stream to write the entire content of the internal queue of packets. The necessary header is written first and then the actual packets are appended. The header and packet output format can be influenced with the "astext" protocol option (see isValidOption). If the "astext" option is true, the header is a UTF8 Byte Order Mark and the packets are written in plain text format. If the "astext" option is false, the header is the standard header for SmartInspect log files and the packets are written in the default binary mode. In the latter case, the resulting log files can be loaded by the SmartInspect Console.
The getAction method of the command argument should currently always return 0. If the state object is not a stream or protocol object or if the command argument is null, then this method does nothing.
internalDispatch in class Protocolcommand - The protocol command which is expected to provide the stream or protocol objectException - if writing the internal queue of packets to the supplied stream or protocol object failsProtocol.dispatch(com.gurock.smartinspect.protocols.ProtocolCommand),
SmartInspect.dispatch(java.lang.String, int, java.lang.Object)protected String getName()
protected void buildOptions(ConnectionsBuilder builder)
buildOptions in class Protocolbuilder - The ConnectionsBuilder object to fill with the current options
of this protocolprotected boolean isValidOption(String name)
| Valid Options | Default Value | Description |
|---|---|---|
| astext | false | Specifies if logging data should be written as text instead of binary. |
| indent | false | Indicates if the logging output should automatically be indented like in the Console if 'astext' is set to true. |
| maxsize | 2048 | Specifies the maxi size of the packet queue of this protocol in kilobytes. Specify size units like this: "1 MB". Supported units are "KB", "MB" and "GB". |
| pattern | "[%timestamp%] %level%: %title%" | Specifies the pattern used to create a text representation of a packet. |
If the "astext" option is used for creating a textual output instead of the default binary, the "pattern" string specifies the textual representation of a log packet. For detailed information of how a pattern string can look like, please have a look at the documentation of the PatternParser class, especially the PatternParser.setPattern method.
Example Usage:
SiAuto.si.setConnections("mem()")
SiAuto.si.setConnections("mem(maxsize=\"8MB\")")
SiAuto.si.setConnections("mem(astext=true)")
isValidOption in class Protocolname - The option name to validateprotected void loadOptions()
This method loads all relevant options and ensures their correctness. See isValidOption for a list of options which are recognized by the memory protocol.
loadOptions in class ProtocolCopyright © 2023. All rights reserved.