xmlBlaster 2.2.0 API

org.xmlBlaster.util
Class MsgUnit

java.lang.Object
  extended by org.xmlBlaster.util.MsgUnit
All Implemented Interfaces:
java.io.Serializable

public final class MsgUnit
extends java.lang.Object
implements java.io.Serializable

Encapsulates the parsed xmlKey and QoS, and the raw content.

The constructor arguments are checked to be not null and corrected to "" or 'new byte[0]' if they are null

See Also:
Serialized Form

Field Summary
private  byte[] content
           
private static byte[] EMPTY_BYTEARR
           
private  Global glob
           
private  KeyData keyData
           
private  QosData qosData
           
private static long serialVersionUID
           
 
Constructor Summary
MsgUnit(Global glob, MsgUnitRaw msgUnitRaw, MethodName methodName)
           
MsgUnit(Global glob, java.lang.String key, byte[] content, java.lang.String qos)
          Assumes a PUBLISH.
MsgUnit(Global glob, java.lang.String key, byte[] content, java.lang.String qos, MethodName methodName)
          The normal constructor.
MsgUnit(Global glob, java.lang.String key, java.lang.String contentAsString, java.lang.String qos)
          Assumes a PUBLISH.
MsgUnit(KeyData key, byte[] content, QosData qos)
          Create a MsgUnit with pre-parsed parameters.
MsgUnit(MsgUnit old, KeyData key, byte[] content, QosData qos)
          Clone this message unit (but not the content).
MsgUnit(PublishKey key, byte[] content, PublishQos qos)
          This is a constructor suitable for clients.
MsgUnit(PublishKey key, java.lang.String contentAsString, PublishQos qos)
          This is a constructor suitable for clients.
MsgUnit(java.lang.String key, byte[] content, java.lang.String qos)
          Uses the default global and assumes a PUBLISH.
MsgUnit(java.lang.String key, java.lang.String contentAsString, java.lang.String qos)
          Uses the default global and assumes a PUBLISH.
 
Method Summary
 MsgUnit getClone()
          Deep clone this message unit.
 byte[] getContent()
          Get the raw content.
 java.lang.String getContentMime()
           
 java.lang.String getContentMimeExtended()
           
 java.lang.String getContentStr()
          Convenience method to get the raw content as a string, the encoding is UTF-8 if not specified by clientProperty Constants.CLIENTPROPERTY_CONTENT_CHARSET,
 java.lang.String getContentStrNoEx()
           
 java.lang.String getDomain()
           
 Global getGlobal()
           
 java.lang.String getKey()
          The raw XML string for PUBLISH/UPDATE never null, otherwise it may be null
 KeyData getKeyData()
          The parsed key.
 java.lang.String getKeyOid()
          The key oid, can be null if not a PUBLISH or UPDATE
 java.lang.String getLogId()
           
 MethodName getMethodName()
           
 MsgUnitRaw getMsgUnitRaw()
           
 java.lang.String getQos()
          The QoS XML string.
 byte[] getQosBytes()
           
 QosData getQosData()
          The parsed QoS.
 boolean hasDomain()
           
 boolean sameContent(byte[] newContent)
          Compares bytes if the given content is identical to the internal content
 void setContent(byte[] content)
          Used internally and my be used by publish mime plugin
 void setGlobal(Global glob)
           
 long size()
          The number of bytes of qos+key+content
 java.lang.String toString()
           
 java.lang.String toXml()
          Dump state of this object into a XML ASCII string.
 void toXml(java.io.OutputStream out, java.util.Properties props)
           
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into a XML ASCII string.
 java.lang.String toXml(java.lang.String extraOffset, boolean forceReadable)
          Overwrite QosData.toXml()
 java.lang.String toXml(java.lang.String extraOffset, int maxContentLen, boolean forceReadable)
          Dump state of this object into a XML ASCII string.
private  void toXml(java.lang.String extraOffset, java.io.OutputStream out, java.util.Properties props)
          Dump status as XML to outstream.
 java.lang.String toXml(java.lang.String extraOffset, java.util.Properties props)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

EMPTY_BYTEARR

private static final transient byte[] EMPTY_BYTEARR

glob

private transient Global glob

qosData

private QosData qosData

content

private byte[] content

keyData

private KeyData keyData
Constructor Detail

MsgUnit

public MsgUnit(java.lang.String key,
               byte[] content,
               java.lang.String qos)
        throws XmlBlasterException
Uses the default global and assumes a PUBLISH.

Throws:
XmlBlasterException
See Also:
MsgUnit(Global, String, byte[], String, MethodName)

MsgUnit

public MsgUnit(Global glob,
               java.lang.String key,
               byte[] content,
               java.lang.String qos)
        throws XmlBlasterException
Assumes a PUBLISH.

Throws:
XmlBlasterException
See Also:
MsgUnit(Global, String, byte[], String, MethodName)

MsgUnit

public MsgUnit(Global glob,
               MsgUnitRaw msgUnitRaw,
               MethodName methodName)
        throws XmlBlasterException
Throws:
XmlBlasterException
See Also:
MsgUnit(Global, String, byte[], String, MethodName)

MsgUnit

public MsgUnit(Global glob,
               java.lang.String key,
               byte[] content,
               java.lang.String qos,
               MethodName methodName)
        throws XmlBlasterException
The normal constructor.

Parameters:
glob - The specific Global handle
key - The XML key
qos - The XML qos
methodName - The method you want to invoked (like PUBLISH or SUBSCRIBE)
Throws:
XmlBlasterException

MsgUnit

public MsgUnit(java.lang.String key,
               java.lang.String contentAsString,
               java.lang.String qos)
        throws XmlBlasterException
Uses the default global and assumes a PUBLISH.

Throws:
XmlBlasterException
See Also:
MsgUnit(Global, String, byte[], String, MethodName)

MsgUnit

public MsgUnit(Global glob,
               java.lang.String key,
               java.lang.String contentAsString,
               java.lang.String qos)
        throws XmlBlasterException
Assumes a PUBLISH.

Throws:
XmlBlasterException
See Also:
MsgUnit(Global, String, byte[], String, MethodName)

MsgUnit

public MsgUnit(PublishKey key,
               java.lang.String contentAsString,
               PublishQos qos)
This is a constructor suitable for clients.


MsgUnit

public MsgUnit(PublishKey key,
               byte[] content,
               PublishQos qos)
This is a constructor suitable for clients.


MsgUnit

public MsgUnit(KeyData key,
               byte[] content,
               QosData qos)
Create a MsgUnit with pre-parsed parameters.

Parameters:
key - can be null
content - can be null
qos - Never null!

MsgUnit

public MsgUnit(MsgUnit old,
               KeyData key,
               byte[] content,
               QosData qos)
Clone this message unit (but not the content).

In order to keep up with performance we don't encapsulate the content in an immutable object. Keep in mind however that you should never (ever) change the content of a MsgUnit since such a change would affect the messages to all other reference of this message (e.g. subscribers) and therefore it might lead to unpredictable (and undesired) results.

Example:

 
 byte[] content = msgUnit.getContent();
 content[6] = (byte)'A';  // NOT ALLOWED !
 

Parameters:
old - The MsgUnit to clone
key - The new key to use, if you pass 'null' the old is shallow cloned
content - If you pass null note that the byte[] is a reference to the original and you should not manipulate it
qos - The new qos to use, if you pass 'null' the old is shallow cloned
Method Detail

getGlobal

public Global getGlobal()

setGlobal

public void setGlobal(Global glob)

getMethodName

public MethodName getMethodName()

setContent

public void setContent(byte[] content)
Used internally and my be used by publish mime plugin


getKeyOid

public java.lang.String getKeyOid()
The key oid, can be null if not a PUBLISH or UPDATE


getKey

public java.lang.String getKey()
The raw XML string for PUBLISH/UPDATE never null, otherwise it may be null


getContent

public byte[] getContent()
Get the raw content.

For performance reasons you get a reference to the internal byte[] buffer and no copy. Note that you are not allowed to manipulate the returned byte[].

Returns:
never null

getContentStr

public java.lang.String getContentStr()
                               throws XmlBlasterException
Convenience method to get the raw content as a string, the encoding is UTF-8 if not specified by clientProperty Constants.CLIENTPROPERTY_CONTENT_CHARSET,

Returns:
never null
Throws:
XmlBlasterException

getContentStrNoEx

public java.lang.String getContentStrNoEx()

getQos

public java.lang.String getQos()
The QoS XML string.

Returns:
never null

getQosBytes

public byte[] getQosBytes()

getKeyData

public KeyData getKeyData()
The parsed key.

Returns:
for PUBLISH/UPDATE never null, otherwise it may be null

getQosData

public QosData getQosData()
The parsed QoS. Is of type QueryQosData, MsgQosData depending on the MethodName

Returns:
never null

getLogId

public java.lang.String getLogId()

getContentMime

public java.lang.String getContentMime()
Returns:
null if not known

getContentMimeExtended

public java.lang.String getContentMimeExtended()
Returns:
null if not known

hasDomain

public boolean hasDomain()

getDomain

public java.lang.String getDomain()
Returns:
null if not known

getClone

public MsgUnit getClone()
Deep clone this message unit.

The content byte[] is new allocated (a copy), the key an qos objects are shallow cloned (the String, int etc are clones there)


getMsgUnitRaw

public MsgUnitRaw getMsgUnitRaw()

sameContent

public boolean sameContent(byte[] newContent)
Compares bytes if the given content is identical to the internal content

Returns:
true content is identical

size

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


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toXml

public java.lang.String toXml()
Dump state of this object into a XML ASCII string.

Returns:
The data of this MsgUnit as a XML ASCII string

toXml

public java.lang.String toXml(java.lang.String extraOffset)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output
Returns:
The data of this MsgUnit as a XML ASCII string

toXml

public java.lang.String toXml(java.lang.String extraOffset,
                              boolean forceReadable)
Overwrite QosData.toXml()

Parameters:
extraOffset -
forceReadable -
Returns:

toXml

public java.lang.String toXml(java.lang.String extraOffset,
                              int maxContentLen,
                              boolean forceReadable)
Dump state of this object into a XML ASCII string.
Needs to be portable for XmlScripting

Parameters:
extraOffset - indenting of tags for nice output
maxContentLen - For huge content length you can choose to display only the given size of the content (from the beginning), the rest is not dumped.
-1 dumps the complete content
0 dumps no content
Returns:
The data of this MsgUnit as a XML ASCII string

toXml

public java.lang.String toXml(java.lang.String extraOffset,
                              java.util.Properties props)

toXml

public final void toXml(java.io.OutputStream out,
                        java.util.Properties props)
                 throws java.io.IOException
Throws:
java.io.IOException

toXml

private final void toXml(java.lang.String extraOffset,
                         java.io.OutputStream out,
                         java.util.Properties props)
                  throws java.io.IOException
Dump status as XML to outstream.

Parameters:
extraOffset - Indenting, can be null
out - Destination
props - Configuration settings
Throws:
java.io.IOException

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.