Class MemoryProtocol
- java.lang.Object
-
- com.gurock.smartinspect.protocols.Protocol
-
- com.gurock.smartinspect.protocols.MemoryProtocol
-
public class MemoryProtocol extends Protocol
Used for writing log data to memory and saving it to a stream or protocol object on request.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.
-
-
Field Summary
-
Fields inherited from class com.gurock.smartinspect.protocols.Protocol
fConnected
-
-
Constructor Summary
Constructors Constructor Description MemoryProtocol()Creates and initializes a new MemoryProtocol instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildOptions(ConnectionsBuilder builder)Overridden.protected StringgetName()Overridden.protected voidinternalConnect()Overridden.protected voidinternalDisconnect()Overridden.protected voidinternalDispatch(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 voidinternalWritePacket(Packet packet)Overridden.protected booleanisValidOption(String name)Overridden.protected voidloadOptions()Overridden.-
Methods inherited from class com.gurock.smartinspect.protocols.Protocol
addListener, composeLogHeaderPacket, connect, disconnect, dispatch, dispose, doError, failed, getAppName, getAsyncEnabledDefaultValue, getAsyncQueueDefaultValue, getAsyncThrottleDefaultValue, 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, writePacket
-
-
-
-
Method Detail
-
internalConnect
protected void internalConnect() throws ExceptionOverridden. Creates and initializes the packet queue.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.
- Specified by:
internalConnectin classProtocol- Throws:
Exception- If connecting to the destination failed.
-
internalDisconnect
protected void internalDisconnect() throws ExceptionOverridden. Clears the internal queue of packets. This method does nothing more than to clear the internal queue of packets. After this method has been called, the internalDispatch method writes an empty log unless new packets are queued in the meantime.- Specified by:
internalDisconnectin classProtocol- Throws:
Exception- If disconnecting from the destination failed
-
internalWritePacket
protected void internalWritePacket(Packet packet) throws Exception
Overridden. Writes a packet to the packet queue. This method writes the supplied packet to the internal queue of packets. If the size of the queue exceeds the maximum size as specified with the setOptions method, the queue is automatically resized and older packets are discarded.- Specified by:
internalWritePacketin classProtocol- Parameters:
packet- The packet to write.- Throws:
Exception- if writing the packet to the destination failed
-
internalDispatch
protected void internalDispatch(ProtocolCommand command) throws Exception
Overrides and implements a custom action for saving the current queue of packets of this memory protocol to a stream or protocol object.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.
- Overrides:
internalDispatchin classProtocol- Parameters:
command- The protocol command which is expected to provide the stream or protocol object- Throws:
Exception- if writing the internal queue of packets to the supplied stream or protocol object fails- See Also:
Protocol.dispatch(com.gurock.smartinspect.protocols.ProtocolCommand),SmartInspect.dispatch(java.lang.String, int, java.lang.Object)
-
getName
protected String getName()
Overridden. Returns "mem".
-
buildOptions
protected void buildOptions(ConnectionsBuilder builder)
Overridden. Fills a ConnectionsBuilder instance with the options currently used by this memory protocol.- Overrides:
buildOptionsin classProtocol- Parameters:
builder- The ConnectionsBuilder object to fill with the current options of this protocol
-
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 this memory protocol. For a list of options common to all protocols, please have a look at the method of the parent class.Memory protocol options 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)")- Overrides:
isValidOptionin classProtocol- 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 memory specific options.This method loads all relevant options and ensures their correctness. See isValidOption for a list of options which are recognized by the memory protocol.
- Overrides:
loadOptionsin classProtocol
-
-