xmlBlaster 2.2.0 API

org.xmlBlaster.engine
Class MsgUnitWrapper

java.lang.Object
  extended by org.xmlBlaster.engine.MsgUnitWrapper
All Implemented Interfaces:
java.io.Serializable, I_ChangeCallback, I_MapEntry, I_Timeout, I_Entry

public final class MsgUnitWrapper
extends java.lang.Object
implements I_MapEntry, I_Timeout, I_ChangeCallback

Wraps a publish() message into an entry for a persistence cache.

There are two options to make this object persistent (measure on a 2GHz Intel Linux laptop with Postgres):

1. QoS and Key are stored as XML ASCII strings, the content as byte[]
This variant takes about 50 microsec to serialize (toXml()) and 380 microsec to create the object again (SAX parse). The size for an empty content is approx. 80 bytes for a medium sized key and QoS.

2. The whole object is java.io.Serialized
This variant takes about 160 microsec to serialize and 750 microsec to deserialize.

So we have chosen the XML variant as it is faster, has no versioning problems and has smaller size

Author:
xmlBlaster@marcelruff.info
See Also:
ServerEntryFactory.main(String[]), Serialized Form

Field Summary
private static int ALIVE
           
private static int DESTROYED
           
private  Timeout destroyTimer
          This topic is destroyed after given timeout The timer is activated on state change to UNREFERENCED and removed on change to ALIVE
private  java.lang.String embeddedType
           
private static int EXPIRED
           
private  ServerScope glob
           
private  int historyReferenceCounter
           
private  long immutableSizeInBytes
           
private static java.util.logging.Logger log
           
private  MsgUnit msgUnit
           
private  I_Map ownerCache
           
private static int PRE_EXPIRED
           
private  int referenceCounter
           
private  java.lang.Object returnObj
           
private static long serialVersionUID
           
private  Timestamp sortTimestamp
           
private  int state
           
private  StorageId storageId
           
private  boolean stored
           
private  boolean swapped
           
private  Timestamp timerKey
           
private  long uniqueId
           
private  java.lang.String uniqueIdStr
           
private  boolean wantReturnObj
          used to tell to the MsgQueueEntry if a return value is desidered
 
Constructor Summary
MsgUnitWrapper(ServerScope glob, MsgUnit msgUnit, I_Map ownerCache, int referenceCounter, int historyReferenceCounter, long sizeInBytes)
          Used when message is created from TopicHandler.publish
MsgUnitWrapper(ServerScope glob, MsgUnit msgUnit, I_Map ownerCache, StorageId storageId, int referenceCounter, int historyReferenceCounter, java.lang.String embeddedType, long sizeInBytes)
          Used when message comes from persistence, the owning I_Map is unknown
MsgUnitWrapper(ServerScope glob, MsgUnit msgUnit, StorageId storageId)
          Testsuite
MsgUnitWrapper(ServerScope glob, MsgUnit msgUnit, StorageId storageId, int referenceCounter, int historyReferenceCounter, long sizeInBytes)
          Used when message comes from persistence, the owning I_Map is unknown
 
Method Summary
 void added(StorageId storageId)
          Notification if this entry is added to storage
 I_MapEntry changeEntry(I_MapEntry entry)
          Callback invoked by I_Map.change inside the synchronization point.
 java.lang.Object clone()
          Returns a shallow clone
 void embeddedObjectToXml(java.io.OutputStream out, java.util.Properties props)
          Dump content to xml representation
 void finalize()
          Cleanup timer, it is a weak reference on us therefor it is a 'nice to have'.
 java.lang.String getContentMime()
           
 java.lang.String getContentMimeExtended()
           
 java.lang.String getDomain()
           
 java.lang.Object getEmbeddedObject()
          The embedded object.
 java.lang.String getEmbeddedType()
          Gets the type of the object embedded in this entry, how the object is serialized.
 int getHistoryReferenceCounter()
           
 java.lang.String getKeyOid()
           
 java.lang.String getLogId()
          Return a human readable identifier for logging output.
 XBMeat getMeat()
          For the new queues
 MsgKeyData getMsgKeyData()
           
 MsgQosData getMsgQosData()
           
 MsgUnit getMsgUnit()
           
 int getPriority()
          Returns a dummy only as sorting is not important in this context.
 XBRef getRef()
          For the new queues
 int getReferenceCounter()
           
 java.lang.Object getReturnObj()
           
 ServerScope getServerScope()
           
 long getSizeInBytes()
          returns the size in bytes of this entry.
 Timestamp getSortTimestamp()
          Can be used by cache implementation to implement LRU
 java.lang.String getStateStr()
           
 StorageId getStorageId()
          Must be filled if retrieved from database.
 long getUniqueId()
          The unique ID for this entry = getMsgQosData().getRcvTimestamp().getTimestamp()
 java.lang.String getUniqueIdStr()
           
 boolean getWantReturnObj()
           
 boolean hasRemainingLife()
          The state may still be alive.
 void incrementReferenceCounter(int count, StorageId storageId)
          Invoked by ReferenceEntry.java and TopicHandler.java to support reference counting
private  boolean isAlive()
           
 boolean isDestroyed()
           
 boolean isExpired()
           
 boolean isInternal()
           
 boolean isPersistent()
          Returns true if the entry is persistent (persistent on HD), false otherwise.
 boolean isStored()
           
 boolean isSwapped()
          The cache sets it to true when the entry is swapped away.
 void isSwapped(boolean swapped)
          Used by the cache implementation to mark entries which will be swapped to the persistent store.
 void removed(StorageId storageId)
          Notification if this entry is removed from storage
 void setMsgUnit(MsgUnit msg)
           
(package private)  void setReferenceCounter(int count)
          Internal use for TopicHandler
 void setReturnObj(java.lang.Object returnObj)
          Set the object to be carried as return value.
 void setSortTimestamp(Timestamp timestamp)
          Can be used by cache implementation to implement LRU
 void setStored(boolean stored)
          Is invoked by the storage implementation with 'true' when the entry is put in a storage and with 'false' when the entry is removed from the storage.
 void setWantReturnObj(boolean wantReturnObj)
          Sets this flag to true/false.
 void startExpiryTimer()
           
 void timeout(java.lang.Object userData)
          This timeout occurs after a configured expiration delay
 void toDestroyed()
          Called by TopicHandler.java or ReferenceEntry.java
private  void toExpired()
           
 java.lang.String toXml()
           
 java.lang.String toXml(java.lang.String extraOffset, boolean forceReadable)
          Dumps the message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

glob

private final transient ServerScope glob

log

private static java.util.logging.Logger log

historyReferenceCounter

private transient int historyReferenceCounter

referenceCounter

private transient int referenceCounter

uniqueId

private final transient long uniqueId

uniqueIdStr

private final transient java.lang.String uniqueIdStr

ownerCache

private transient I_Map ownerCache

embeddedType

private final transient java.lang.String embeddedType

wantReturnObj

private transient boolean wantReturnObj
used to tell to the MsgQueueEntry if a return value is desidered


returnObj

private transient java.lang.Object returnObj

destroyTimer

private transient Timeout destroyTimer
This topic is destroyed after given timeout The timer is activated on state change to UNREFERENCED and removed on change to ALIVE


timerKey

private transient Timestamp timerKey

ALIVE

private static final int ALIVE
See Also:
Constant Field Values

PRE_EXPIRED

private static final int PRE_EXPIRED
See Also:
Constant Field Values

EXPIRED

private static final int EXPIRED
See Also:
Constant Field Values

DESTROYED

private static final int DESTROYED
See Also:
Constant Field Values

state

private transient int state

msgUnit

private MsgUnit msgUnit

immutableSizeInBytes

private final long immutableSizeInBytes

stored

private boolean stored

swapped

private transient boolean swapped

sortTimestamp

private transient Timestamp sortTimestamp

storageId

private transient StorageId storageId
Constructor Detail

MsgUnitWrapper

public MsgUnitWrapper(ServerScope glob,
                      MsgUnit msgUnit,
                      StorageId storageId)
               throws XmlBlasterException
Testsuite

Throws:
XmlBlasterException

MsgUnitWrapper

public MsgUnitWrapper(ServerScope glob,
                      MsgUnit msgUnit,
                      I_Map ownerCache,
                      int referenceCounter,
                      int historyReferenceCounter,
                      long sizeInBytes)
               throws XmlBlasterException
Used when message is created from TopicHandler.publish

Throws:
XmlBlasterException

MsgUnitWrapper

public MsgUnitWrapper(ServerScope glob,
                      MsgUnit msgUnit,
                      StorageId storageId,
                      int referenceCounter,
                      int historyReferenceCounter,
                      long sizeInBytes)
               throws XmlBlasterException
Used when message comes from persistence, the owning I_Map is unknown

Throws:
XmlBlasterException

MsgUnitWrapper

public MsgUnitWrapper(ServerScope glob,
                      MsgUnit msgUnit,
                      I_Map ownerCache,
                      StorageId storageId,
                      int referenceCounter,
                      int historyReferenceCounter,
                      java.lang.String embeddedType,
                      long sizeInBytes)
               throws XmlBlasterException
Used when message comes from persistence, the owning I_Map is unknown

Parameters:
embeddedType - Allows you to control how to make this object persistent:
ServerEntryFactory.ENTRY_TYPE_MSG_XML Dump strings as XML ASCII (which is smaller, faster, portable -> and therefor default)
ServerEntryFactory.ENTRY_TYPE_MSG_SERIAL Dump object with java.io.Serializable
sizeInBytes - The estimated size of this entry in RAM, if -1 we estimate it for you
Throws:
XmlBlasterException
Method Detail

getServerScope

public final ServerScope getServerScope()

finalize

public void finalize()
Cleanup timer, it is a weak reference on us therefor it is a 'nice to have'.

Overrides:
finalize in class java.lang.Object

isSwapped

public boolean isSwapped()
The cache sets it to true when the entry is swapped away. You should not write on a swapped away entry as those changes are lost. Enforced by I_Map

Specified by:
isSwapped in interface I_MapEntry
See Also:
I_Map#isSwapped()

isSwapped

public void isSwapped(boolean swapped)
Used by the cache implementation to mark entries which will be swapped to the persistent store. Enforced by I_Map

Specified by:
isSwapped in interface I_MapEntry

incrementReferenceCounter

public void incrementReferenceCounter(int count,
                                      StorageId storageId)
                               throws XmlBlasterException
Invoked by ReferenceEntry.java and TopicHandler.java to support reference counting

Parameters:
count - The number of ref-counts to add/subtract
storageId -
Throws:
XmlBlasterException

setReferenceCounter

void setReferenceCounter(int count)
Internal use for TopicHandler


changeEntry

public I_MapEntry changeEntry(I_MapEntry entry)
                       throws XmlBlasterException
Callback invoked by I_Map.change inside the synchronization point. Enforced by I_ChangeCallback

Specified by:
changeEntry in interface I_ChangeCallback
Parameters:
entry - the entry to modify.
Returns:
I_MapEntry the modified entry.
Throws:
XmlBlasterException - if something has gone wrong and the change must be rolled back.

getReferenceCounter

public int getReferenceCounter()
Returns:
The number or references on myself (history, callback queue and plugin queues)

getHistoryReferenceCounter

public int getHistoryReferenceCounter()
Returns:
1: Is referenced one time from history queue, else 0

getPriority

public int getPriority()
Returns a dummy only as sorting is not important in this context.

Specified by:
getPriority in interface I_Entry
Returns:
The priority

getMsgQosData

public MsgQosData getMsgQosData()

isPersistent

public boolean isPersistent()
Description copied from interface: I_Entry
Returns true if the entry is persistent (persistent on HD), false otherwise.

Specified by:
isPersistent in interface I_Entry

getMsgKeyData

public MsgKeyData getMsgKeyData()

getMsgUnit

public MsgUnit getMsgUnit()

getKeyOid

public final java.lang.String getKeyOid()

getContentMime

public java.lang.String getContentMime()

getContentMimeExtended

public java.lang.String getContentMimeExtended()

getDomain

public java.lang.String getDomain()

setMsgUnit

public void setMsgUnit(MsgUnit msg)

getSizeInBytes

public long getSizeInBytes()
Description copied from interface: I_Entry
returns the size in bytes of this entry.

Specified by:
getSizeInBytes in interface I_Entry

getUniqueId

public long getUniqueId()
The unique ID for this entry = getMsgQosData().getRcvTimestamp().getTimestamp()

Specified by:
getUniqueId in interface I_Entry
Returns:
The unique Id of this entry.

getUniqueIdStr

public java.lang.String getUniqueIdStr()
Specified by:
getUniqueIdStr in interface I_MapEntry
Returns:
The unique ID as a string (cached for performance)

getLogId

public final java.lang.String getLogId()
Description copied from interface: I_Entry
Return a human readable identifier for logging output.

See the derived class for a syntax description.

Specified by:
getLogId in interface I_Entry

isInternal

public final boolean isInternal()

getEmbeddedType

public java.lang.String getEmbeddedType()
Description copied from interface: I_Entry
Gets the type of the object embedded in this entry, how the object is serialized.

Specified by:
getEmbeddedType in interface I_Entry
Returns:
ServerEntryFactory.ENTRY_TYPE_MSG_XML or ServerEntryFactory.ENTRY_TYPE_MSG_SERIAL

getEmbeddedObject

public java.lang.Object getEmbeddedObject()
The embedded object. Object[] = { this.msgUnit, new Integer(this.referenceCounter) } or
qos.toXml, key.toXml, contentBytes

IMPORTANT NOTE: If you change the data here you need to change MsgQueueUpdateEntry#getEmbeddedObject() as well! Check ServerEntryFactory as well.

Specified by:
getEmbeddedObject in interface I_Entry

clone

public java.lang.Object clone()
Returns a shallow clone

Overrides:
clone in class java.lang.Object

toXml

public final java.lang.String toXml()

embeddedObjectToXml

public final void embeddedObjectToXml(java.io.OutputStream out,
                                      java.util.Properties props)
                               throws java.io.IOException
Description copied from interface: I_Entry
Dump content to xml representation

Specified by:
embeddedObjectToXml in interface I_Entry
Parameters:
out - The stream to dump to
props - Control porperties
Throws:
java.io.IOException

toXml

public java.lang.String toXml(java.lang.String extraOffset,
                              boolean forceReadable)
Dumps the message. NOTE: max 80 bytes of the content are displayed


added

public void added(StorageId storageId)
Notification if this entry is added to storage

Specified by:
added in interface I_Entry
See Also:
I_Entry.added(StorageId)

removed

public void removed(StorageId storageId)
Notification if this entry is removed from storage

Specified by:
removed in interface I_Entry
Parameters:
storageId - The storage id
See Also:
I_Entry.removed(StorageId)

isAlive

private boolean isAlive()

hasRemainingLife

public boolean hasRemainingLife()
The state may still be alive.

Returns:
true is the configured life span is elapsed

startExpiryTimer

public void startExpiryTimer()

isExpired

public boolean isExpired()

toExpired

private void toExpired()
                throws XmlBlasterException
Throws:
XmlBlasterException

isDestroyed

public boolean isDestroyed()

toDestroyed

public void toDestroyed()
Called by TopicHandler.java or ReferenceEntry.java


timeout

public final void timeout(java.lang.Object userData)
This timeout occurs after a configured expiration delay

Specified by:
timeout in interface I_Timeout
Parameters:
userData - You get bounced back your userData which you passed with Timeout.addTimeoutListener()

getStateStr

public java.lang.String getStateStr()

setStored

public final void setStored(boolean stored)
Description copied from interface: I_Entry
Is invoked by the storage implementation with 'true' when the entry is put in a storage and with 'false' when the entry is removed from the storage. The storage is for example a 'cache', a 'ram' or a 'jdbc' implementation.

Note that this callback is guaranteed to be called from within the queue specific synchronized block

Todo: Remove this in favour of added()/removed() (isStored() is currently only used by CacheQueueInterceptorPlugin.java) I'm not sure if this usage relies on being inside sync

This method may never throw any exception

Specified by:
setStored in interface I_Entry
Parameters:
stored - 'true' if the entry will be put into the storage, 'false' if it is removed.
See Also:
I_Entry.setStored(boolean)

isStored

public final boolean isStored()
Specified by:
isStored in interface I_Entry
Returns:
boolean 'true' if the entry is still in the storage, 'false' if the entry has been removed or if it has not been put in the storage yet.
See Also:
I_Entry.isStored()

setWantReturnObj

public void setWantReturnObj(boolean wantReturnObj)
Sets this flag to true/false. This flag can be passed to the MsgQueueEntry

Parameters:
wantReturnObj -

getWantReturnObj

public boolean getWantReturnObj()
Returns:

getReturnObj

public java.lang.Object getReturnObj()
Returns:
returnObj The carried object used as return QoS in sync or async I_Queue.put() mode, can be null.

setReturnObj

public void setReturnObj(java.lang.Object returnObj)
Set the object to be carried as return value. NOTE: This can be used only once as the first call to this method destroys the reference to the clone original instance.


getSortTimestamp

public final Timestamp getSortTimestamp()
Can be used by cache implementation to implement LRU

Specified by:
getSortTimestamp in interface I_MapEntry
Returns:
null if not previously set by setSortTimestamp()

setSortTimestamp

public final void setSortTimestamp(Timestamp timestamp)
Can be used by cache implementation to implement LRU

Specified by:
setSortTimestamp in interface I_MapEntry

getMeat

public XBMeat getMeat()
For the new queues

Specified by:
getMeat in interface I_Entry

getRef

public XBRef getRef()
For the new queues

Specified by:
getRef in interface I_Entry

getStorageId

public StorageId getStorageId()
Description copied from interface: I_MapEntry
Must be filled if retrieved from database.

Specified by:
getStorageId in interface I_MapEntry
Returns:
can be null

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.