xmlBlaster 2.2.0 client API

org.xmlBlaster.util.xbformat
Class MsgInfo

java.lang.Object
  extended by org.xmlBlaster.util.xbformat.MsgInfo

public class MsgInfo
extends java.lang.Object

Holds MsgUnits from socket or email protocol drivers with additional tranport attributes.
This class creates and parses raw byte[] messages which can be used to transfer over a socket connection or as email attachment.
MsgInfo instances may be reused, but are NOT reentrant (there are many 'global' variables)

Author:
xmlBlaster@marcelruff.info
See Also:
The protocol.socket requirement

Field Summary
static byte EXCEPTION_BYTE
           
static byte INVOKE_BYTE
           
protected  boolean requestIdGuessed
          Remember if we got an explicit requestId or if we extracted it from the email-sentDate
static byte RESPONSE_BYTE
           
 
Constructor Summary
MsgInfo(Global glob)
          The same instance object may be reused.
MsgInfo(Global glob, byte type, MethodName methodName, java.lang.String sessionId)
          Create a raw message.
MsgInfo(Global glob, byte type, MethodName methodName, java.lang.String sessionId, I_ProgressListener progressListener)
           
MsgInfo(Global glob, byte type, MethodName methodName, java.lang.String sessionId, I_ProgressListener progressListener, java.lang.String msgInfoParserClassName)
           
MsgInfo(Global glob, byte type, java.lang.String requestId, MethodName methodName, java.lang.String sessionId, I_ProgressListener progressListener)
           
MsgInfo(Global glob, I_ProgressListener progressListener)
          Ctor to parse messages with msgInfo.parse(iStream);
 
Method Summary
 void addException(XmlBlasterException e)
          Use for exception message
NOTE: Exceptions don't return
 void addKeyAndQos(java.lang.String key, java.lang.String qos)
          Use for methods get, subscribe, unSubscribe, erase
 void addMessage(MsgUnitRaw msg)
          Use for methods update, publish.
 void addMessage(MsgUnitRaw[] arr)
          Use for methods update, publish.
 void addMessage(java.lang.String qos)
          Add a QoS value, use for methods connect, disconnect, ping.
 void addMessage(java.lang.String[] qos)
          Add a QoS array value.
 void addQos(java.lang.String[] qos)
           
 byte[] createRawMsg()
          Access the serialized message, ready to send over the wire.
 byte[] createRawMsg(java.lang.String className)
          Access the serialized message, ready to send over the wire.
 java.lang.String createRequestId(java.lang.String prefix)
          Use this when sending a message.
 MsgInfo createReturner(byte type)
          Creates a new instance with the meta info from source.
 java.lang.String dump()
           
 AttachmentHolder[] getBounceAttachments()
           
 java.lang.Object getBounceObject(java.lang.String key)
           
 java.util.Map getBounceObjects()
           
 XmlBlasterException getException()
          On errors.
 MsgUnitRaw[] getMessageArr()
          Returns all messages as an array.
 java.util.Vector getMessages()
          Returns all messages in a Vector
 MethodName getMethodName()
          For example MethodName.PUBLISH
 java.lang.String getMethodNameStr()
          Access the method name as a string
 I_MsgInfoParser getMsgInfoParser(java.lang.String className, I_PluginConfig pluginConfig)
          Note this method gets (returns) the associated I_MsgInfoParser if it was not initialized before.
 int getNumMessages()
           
 I_PluginConfig getPluginConfig()
           
 I_ProgressListener getProgressListener()
           
 java.lang.String getQos()
          Response is usually only a QoS
 java.lang.String[] getQosArr()
          Response is usually only a QoS
 java.lang.String getRequestId()
          Use this when receiving a message.
 long getRequestSequence()
          The monoton increasing sequence number (extracted from the requestId which could in fact contain other things than just the long.
 java.lang.String getSecretSessionId()
          The authentication sessionId
 byte getType()
           
static char getTypeChar(byte type)
          Access the char representation to send over the wire.
 java.lang.String getTypeStr()
          Similar to getType() but returns a nice human readable string for logging output
static java.lang.String getTypeStr(byte type)
          Similar to getType() but returns a nice human readable string for logging output
 int getVersion()
           
 void initialize()
          This method allows to reuse a MsgInfo instance.
 boolean isChecksum()
           
 boolean isCompressed()
           
static boolean isCompressed(java.lang.String fileName, java.lang.String mimeType)
          Guessing if attachment is compressed.
 boolean isException()
           
 boolean isInvoke()
           
 boolean isRequestIdGuessed()
          Check if we got an explicit requestId or if we extracted it for example from the email-sentDate.
 boolean isResponse()
           
static void main(java.lang.String[] args)
          java org.xmlBlaster.util.xbformat.MsgInfo java org.xmlBlaster.util.xbformat.MsgInfo org.xmlBlaster.util.xbformat.XmlScriptParser TODO: Put into test suite with xmlunit
static MsgInfo[] parse(Global glob, I_ProgressListener progressListener, byte[] rawMsg, java.lang.String className, I_PluginConfig pluginConfig)
          Convenience method.
static MsgInfo[] parse(Global glob, I_ProgressListener progressListener, java.io.InputStream in, java.lang.String className, I_PluginConfig pluginConfig)
          Convenience method.
 void removeMessage(MsgUnitRaw msg)
           
 java.lang.Object setBounceObject(java.lang.String key, java.lang.Object value)
          You can use this as a generic store to convej stuff in MsgInfo.
 void setBounceObjects(java.util.Map bounceObjects)
          Sets the given map.
 void setByte4(byte byte4)
           
 void setByte5(byte byte5)
           
 void setChecksum(boolean checksum)
          Enable checksum?
 void setCompressed(boolean compressed)
          Compress message? NOTE: This compressed flag is set if the SOCKET header is plain text and the MsgUnit[] is compressed.
 void setMethodName(MethodName methodName)
          For example MethodName.PUBLISH
 void setMsgInfoParser(I_MsgInfoParser msgInfoParser)
           
 void setMsgInfoParser(java.lang.String className)
           
 void setPluginConfig(I_PluginConfig pluginConfig)
           
 void setRequestId(java.lang.String requestId)
          Set a unique ID (unique for this client), it will be bounced back with the return value or with an exception occurred during this request.
 void setRequestIdGuessed(boolean requestIdGuessed)
           
 void setSecretSessionId(java.lang.String sessionId)
          The authentication sessionId
 void setType(byte type)
           
 void setVersion(int version)
           
 long size()
          The number of bytes of qos+key+content
 java.lang.String toLiteral()
          Get the raw messages as a string, for tests and for dumping only
static java.lang.String toLiteral(byte[] rawMsg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVOKE_BYTE

public static final byte INVOKE_BYTE
See Also:
Constant Field Values

RESPONSE_BYTE

public static final byte RESPONSE_BYTE
See Also:
Constant Field Values

EXCEPTION_BYTE

public static final byte EXCEPTION_BYTE
See Also:
Constant Field Values

requestIdGuessed

protected boolean requestIdGuessed
Remember if we got an explicit requestId or if we extracted it from the email-sentDate

Constructor Detail

MsgInfo

public MsgInfo(Global glob)
The same instance object may be reused. Ctor to parse messages using I_MsgInfoParser implementations.


MsgInfo

public MsgInfo(Global glob,
               I_ProgressListener progressListener)
Ctor to parse messages with msgInfo.parse(iStream);


MsgInfo

public MsgInfo(Global glob,
               byte type,
               MethodName methodName,
               java.lang.String sessionId)
Create a raw message. msgInfo = new MsgInfo(glob, MsgInfo.INVOKE_BYTE, MethodName.UPDATE, cbSessionId, progressListener); msgInfo.addMessage(msgArr); byte[] rawMsg = msgInfo.createRawMsg();

Parameters:
glob -
type -
methodName -
sessionId -

MsgInfo

public MsgInfo(Global glob,
               byte type,
               MethodName methodName,
               java.lang.String sessionId,
               I_ProgressListener progressListener,
               java.lang.String msgInfoParserClassName)
        throws XmlBlasterException
Throws:
XmlBlasterException

MsgInfo

public MsgInfo(Global glob,
               byte type,
               MethodName methodName,
               java.lang.String sessionId,
               I_ProgressListener progressListener)

MsgInfo

public MsgInfo(Global glob,
               byte type,
               java.lang.String requestId,
               MethodName methodName,
               java.lang.String sessionId,
               I_ProgressListener progressListener)
Method Detail

createReturner

public MsgInfo createReturner(byte type)
Creates a new instance with the meta info from source.

Parameters:
type - Please choose RESPONSE_BYTE or EXCEPTION_BYTE
Returns:
The type is set to RESPONSE_BYTE, the content is empty

initialize

public void initialize()
This method allows to reuse a MsgInfo instance.


isCompressed

public static boolean isCompressed(java.lang.String fileName,
                                   java.lang.String mimeType)
Guessing if attachment is compressed. TODO: Ask formatting plugins

Parameters:
fileName -
mimeType -
Returns:
true if one of parameters ends with 'z'

getNumMessages

public int getNumMessages()

setType

public final void setType(byte type)
Parameters:
type - The method type, e.g. MsgInfo.INVOKE_BYTE

getType

public final byte getType()
Returns:
The method type, e.g. MsgInfo.INVOKE_BYTE

getTypeChar

public static char getTypeChar(byte type)
Access the char representation to send over the wire.

Parameters:
type -
Returns:
'I', 'R' or 'E'

getTypeStr

public final java.lang.String getTypeStr()
Similar to getType() but returns a nice human readable string for logging output


getTypeStr

public static final java.lang.String getTypeStr(byte type)
Similar to getType() but returns a nice human readable string for logging output


isInvoke

public final boolean isInvoke()

isResponse

public final boolean isResponse()

isException

public final boolean isException()

setRequestId

public final void setRequestId(java.lang.String requestId)
Set a unique ID (unique for this client), it will be bounced back with the return value or with an exception occurred during this request.
Note that you usually shouldn't set this value, this class generates a unique requestId which you can access with getRequestId()


createRequestId

public final java.lang.String createRequestId(java.lang.String prefix)
Use this when sending a message.

Get a unique ID (unique for this client), it will be bounced back with the return value or with an exception occurred during this request

Parameters:
prefix - If desired you can specify a prefix for the request ID, e.g. "joe:"
Returns:
An ID (unique in this JVM scope), e.g. "joe:3400" or "3400" if prefix is null

getRequestId

public final java.lang.String getRequestId()
Use this when receiving a message.

Returns:
The received request ID, is never null

getRequestSequence

public final long getRequestSequence()
The monoton increasing sequence number (extracted from the requestId which could in fact contain other things than just the long.

Returns:
the long number.

setMethodName

public final void setMethodName(MethodName methodName)
For example MethodName.PUBLISH


getMethodName

public final MethodName getMethodName()
For example MethodName.PUBLISH

Returns:
Can be null

getMethodNameStr

public final java.lang.String getMethodNameStr()
Access the method name as a string

Returns:
Never null, for example "update"

setSecretSessionId

public final void setSecretSessionId(java.lang.String sessionId)
The authentication sessionId


getSecretSessionId

public final java.lang.String getSecretSessionId()
The authentication sessionId

Returns:
never null

setChecksum

public final void setChecksum(boolean checksum)
Enable checksum?


setCompressed

public final void setCompressed(boolean compressed)
Compress message? NOTE: This compressed flag is set if the SOCKET header is plain text and the MsgUnit[] is compressed. This mode is not implemented, as we have "zlib:stream" compression which compresses the whole socket input/output stream (there is no need to set this flag as it is compressed as well).


addKeyAndQos

public final void addKeyAndQos(java.lang.String key,
                               java.lang.String qos)
                        throws XmlBlasterException
Use for methods get, subscribe, unSubscribe, erase

Throws:
java.lang.IllegalArgumentException - if invoked multiple times
XmlBlasterException

addException

public final void addException(XmlBlasterException e)
                        throws XmlBlasterException
Use for exception message
NOTE: Exceptions don't return

Throws:
java.lang.IllegalArgumentException - if invoked multiple times
XmlBlasterException

addMessage

public final void addMessage(MsgUnitRaw msg)
Use for methods update, publish.
Use for return value of method get.
Multiple adds are OK


removeMessage

public final void removeMessage(MsgUnitRaw msg)

addMessage

public final void addMessage(MsgUnitRaw[] arr)
Use for methods update, publish.
Use for return value of method get.
Multiple adds are OK


addMessage

public final void addMessage(java.lang.String qos)
                      throws XmlBlasterException
Add a QoS value, use for methods connect, disconnect, ping.
Use for return value of methods connect, disconnect, ping, update, publish, subscribe, unSubscribe and erase

Throws:
java.lang.IllegalArgumentException - if invoked multiple times
XmlBlasterException

addMessage

public final void addMessage(java.lang.String[] qos)
                      throws XmlBlasterException
Add a QoS array value.
Use for return value of methods publishArr and erase

Throws:
java.lang.IllegalArgumentException - if invoked multiple times
XmlBlasterException

addQos

public final void addQos(java.lang.String[] qos)
                  throws XmlBlasterException
Throws:
XmlBlasterException
See Also:
addMessage(String[] qos)

getMessages

public final java.util.Vector getMessages()
Returns all messages in a Vector


getMessageArr

public final MsgUnitRaw[] getMessageArr()
Returns all messages as an array.

Returns:
Never null

getQos

public final java.lang.String getQos()
Response is usually only a QoS

Throws:
java.lang.IllegalArgumentException - if there is no QoS to get

getQosArr

public final java.lang.String[] getQosArr()
Response is usually only a QoS

Throws:
java.lang.IllegalArgumentException - if there is no QoS to get

getException

public final XmlBlasterException getException()
On errors.

Throws:
java.lang.IllegalArgumentException - if there is no exception to get

size

public long size()
The number of bytes of qos+key+content


setByte4

public void setByte4(byte byte4)
Parameters:
byte4 - The byte4 to set.

setByte5

public void setByte5(byte byte5)
Parameters:
byte5 - The byte5 to set.

getVersion

public int getVersion()
Returns:
Returns the version.

setVersion

public void setVersion(int version)
Parameters:
version - The version to set.

isChecksum

public final boolean isChecksum()
Returns:
Returns the checksum.

isCompressed

public final boolean isCompressed()
Returns:
Returns the compressed.

getMsgInfoParser

public I_MsgInfoParser getMsgInfoParser(java.lang.String className,
                                        I_PluginConfig pluginConfig)
                                 throws XmlBlasterException
Note this method gets (returns) the associated I_MsgInfoParser if it was not initialized before.

Parameters:
className - Can be null
pluginConfig - Can be null
Returns:
Returns the msgInfoParser.
Throws:
XmlBlasterException

setMsgInfoParser

public void setMsgInfoParser(I_MsgInfoParser msgInfoParser)
Parameters:
msgInfoParser - The msgInfoParser to set.

setMsgInfoParser

public void setMsgInfoParser(java.lang.String className)
                      throws XmlBlasterException
Parameters:
msgInfoParser - The msgInfoParser to set.
Throws:
XmlBlasterException

dump

public final java.lang.String dump()

toLiteral

public final java.lang.String toLiteral()
                                 throws XmlBlasterException
Get the raw messages as a string, for tests and for dumping only

Returns:
The stringified message, null bytes are replaced by '*'
Throws:
XmlBlasterException

toLiteral

public static java.lang.String toLiteral(byte[] rawMsg)
                                  throws XmlBlasterException
Throws:
XmlBlasterException

createRawMsg

public final byte[] createRawMsg()
                          throws XmlBlasterException
Access the serialized message, ready to send over the wire.

Returns:
Throws:
XmlBlasterException

createRawMsg

public final byte[] createRawMsg(java.lang.String className)
                          throws XmlBlasterException
Access the serialized message, ready to send over the wire.

Parameters:
className - The parser/serializer to use
Returns:
Throws:
XmlBlasterException

parse

public static MsgInfo[] parse(Global glob,
                              I_ProgressListener progressListener,
                              java.io.InputStream in,
                              java.lang.String className,
                              I_PluginConfig pluginConfig)
                       throws java.io.IOException,
                              XmlBlasterException
Convenience method.

Parameters:
in -
className - Class implementing I_MsgInfoParser Can be null to choose the default parser
Returns:
Never null, usually of length==1
Throws:
java.io.IOException
XmlBlasterException

parse

public static MsgInfo[] parse(Global glob,
                              I_ProgressListener progressListener,
                              byte[] rawMsg,
                              java.lang.String className,
                              I_PluginConfig pluginConfig)
                       throws java.io.IOException,
                              XmlBlasterException
Convenience method.

Parameters:
className - Class implementing I_MsgInfoParser Can be null to choose the default parser
pluginConfig - The configuration of the plugin, can be null
Returns:
Never null, usually of length==1
Throws:
java.io.IOException
XmlBlasterException

getBounceObjects

public java.util.Map getBounceObjects()
Returns:
Returns the bounceObjects, is null if none is available

getBounceAttachments

public AttachmentHolder[] getBounceAttachments()
Returns:
Returns the bounceObjects of type AttachmentHolder, is never null

getBounceObject

public java.lang.Object getBounceObject(java.lang.String key)
Returns:
Returns the value, is null if none is found

setBounceObjects

public void setBounceObjects(java.util.Map bounceObjects)
Sets the given map.


setBounceObject

public java.lang.Object setBounceObject(java.lang.String key,
                                        java.lang.Object value)
You can use this as a generic store to convej stuff in MsgInfo.

Parameters:
key - The identifier of the object.
value - The bounceObjects to set, if null nothing happens.

getProgressListener

public I_ProgressListener getProgressListener()
Returns:
Returns the progressListener.

main

public static void main(java.lang.String[] args)
java org.xmlBlaster.util.xbformat.MsgInfo java org.xmlBlaster.util.xbformat.MsgInfo org.xmlBlaster.util.xbformat.XmlScriptParser TODO: Put into test suite with xmlunit


isRequestIdGuessed

public boolean isRequestIdGuessed()
Check if we got an explicit requestId or if we extracted it for example from the email-sentDate.

Returns:
Returns the requestIdGuessed.

setRequestIdGuessed

public void setRequestIdGuessed(boolean requestIdGuessed)
Parameters:
requestIdGuessed - The requestIdGuessed to set.

getPluginConfig

public I_PluginConfig getPluginConfig()

setPluginConfig

public void setPluginConfig(I_PluginConfig pluginConfig)

xmlBlaster 2.2.0 client API

Copyright © 1999-2014 The xmlBlaster.org contributers.