xmlBlaster 2.2.0 client API

org.xmlBlaster.util.queuemsg
Class MsgQueueEntry

java.lang.Object
  extended by org.xmlBlaster.util.queuemsg.MsgQueueEntry
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, I_Entry, I_QueueEntry
Direct Known Subclasses:
DummyEntry, MsgQueueConnectEntry, MsgQueueDisconnectEntry, MsgQueueEraseEntry, MsgQueueGetEntry, MsgQueuePublishEntry, MsgQueueSubscribeEntry, MsgQueueUnSubscribeEntry

public abstract class MsgQueueEntry
extends java.lang.Object
implements I_QueueEntry, java.lang.Cloneable

Base class to enter xmlBlaster method invocations (messages) into an ordered queue.

Author:
xmlBlaster@marcelruff.info, michele@laghi.eu
See Also:
Serialized Form

Field Summary
protected  java.lang.String entryType
          Which method we invoke, e.g.
protected  Global glob
           
protected  boolean persistent
          the flag telling if a message is persistent (opposite to transient)
protected  PriorityEnum priority
          The message priority, see Constants.java
protected  int redeliverCounter
          How often the entry was tried to send but failed
protected  MsgQueueEntry refToCloneOrigin
           
protected  java.lang.Object returnObj
           
protected  StorageId storageId
          The queue to which this entry belongs (set in the constructors)
protected  java.lang.String uniqueIdString
          The queue to which this entry belongs (set in the constructors)
protected  Timestamp uniqueIdTimestamp
          The unique creation timestamp (unique in a Global of a virtual machine)
protected  boolean wantReturnObj
           
 
Constructor Summary
MsgQueueEntry(Global glob, MethodName methodName, PriorityEnum priority, StorageId storageId, boolean persistent)
           
MsgQueueEntry(Global glob, java.lang.String entryType, PriorityEnum priority, StorageId storageId, boolean persistent)
          Creates a new queue entry object.
MsgQueueEntry(Global glob, java.lang.String entryType, PriorityEnum priority, Timestamp timestamp, StorageId storageId, boolean persistent)
          This constructor is for internal creation from persistence only.
 
Method Summary
 void added(StorageId storageId)
          Notification if this entry is added to queue
 java.lang.Object clone()
          Returns a shallow clone.
 int compare(I_QueueEntry m2)
          Needed for sorting the queue.
 boolean equals(I_QueueEntry m2)
          Needed for sorting in queue
 void finalize()
           
 java.lang.String getEmbeddedType()
          Gets the type of the object embedded in this entry, how the object is serialized.
abstract  java.lang.String getKeyOid()
           
 java.lang.String getLogId()
          Return a human readable identifier for logging output.
 XBMeat getMeat()
          For the new queues
 MethodName getMethodName()
           
abstract  MsgUnit getMsgUnit()
           
 int getPriority()
          Enforced by I_QueueEntry
 PriorityEnum getPriorityEnum()
           
abstract  SessionName getReceiver()
           
 int getRedeliverCounter()
          How often we tried to redeliver the message.
 XBRef getRef()
          For the new queues
 java.lang.Object getReturnObj()
           
abstract  SessionName getSender()
           
 long getSizeInBytes()
          Try to find out the approximate memory consumption of this message in RAM.
 StorageId getStorageId()
          To which queue do i belong
 long getUniqueId()
          The unique creation timestamp (unique in a Global of a virtual machine) Enforced by I_QueueEntry
 java.lang.Long getUniqueIdLong()
          The unique creation timestamp (unique in a Global of a virtual machine)
 void incrRedeliverCounter()
          Increment the counter if message delivery fails (exception during sending) We don't know if other side has processed it completely or not
abstract  boolean isDestroyed()
          Flag which marks the entry as destroyed, you should take it from queue and ignore/discard it
abstract  boolean isExpired()
          Flag which marks the entry as outdated
abstract  boolean isInternal()
           
 boolean isPersistent()
          Returns true if the entry is persistent (persistent on HD), false otherwise.
 boolean isStored()
           
 void removed(StorageId storageId)
          Notification if this entry is removed from queue
 void setGlobal(Global global)
           
 void setPersistent(boolean persistent)
          Note: Setting here is probably buggy as on reload from DB it seems to be handled as transient if embedded MsgUnit is not persistent.
 void setReturnObj(java.lang.Object returnObj)
          Set the object to be carried as return value.
 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 setWantReturnObject(boolean wantReturnObj)
          sets the 'wantReturnObj' flag to what you specify (overwrites the default for the implementing class).
 java.lang.String toString()
          Nice for logging
 java.lang.String toXml()
          Dump state of this object into XML.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into XML.
 boolean wantReturnObj()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xmlBlaster.util.queue.I_Entry
embeddedObjectToXml, getEmbeddedObject
 

Field Detail

glob

protected transient Global glob

wantReturnObj

protected transient boolean wantReturnObj

returnObj

protected transient java.lang.Object returnObj

refToCloneOrigin

protected transient MsgQueueEntry refToCloneOrigin

storageId

protected StorageId storageId
The queue to which this entry belongs (set in the constructors)


redeliverCounter

protected int redeliverCounter
How often the entry was tried to send but failed


uniqueIdTimestamp

protected final Timestamp uniqueIdTimestamp
The unique creation timestamp (unique in a Global of a virtual machine)


priority

protected final PriorityEnum priority
The message priority, see Constants.java


persistent

protected boolean persistent
the flag telling if a message is persistent (opposite to transient)


entryType

protected final java.lang.String entryType
Which method we invoke, e.g. "update" or "publish"


uniqueIdString

protected final java.lang.String uniqueIdString
The queue to which this entry belongs (set in the constructors)

Constructor Detail

MsgQueueEntry

public MsgQueueEntry(Global glob,
                     MethodName methodName,
                     PriorityEnum priority,
                     StorageId storageId,
                     boolean persistent)
Parameters:
methodName - use methodName as entryType

MsgQueueEntry

public MsgQueueEntry(Global glob,
                     java.lang.String entryType,
                     PriorityEnum priority,
                     StorageId storageId,
                     boolean persistent)
Creates a new queue entry object.

Parameters:
priority - The message priority
storageId - The queue i belong to
See Also:
Timestamp

MsgQueueEntry

public MsgQueueEntry(Global glob,
                     java.lang.String entryType,
                     PriorityEnum priority,
                     Timestamp timestamp,
                     StorageId storageId,
                     boolean persistent)
This constructor is for internal creation from persistence only.

Parameters:
entryType - MethodName.SUBSCRIBE etc
timestamp - The unique nano timestamp as from org.xmlBlaster.util.Timestamp or null to create one now
Method Detail

setGlobal

public final void setGlobal(Global global)

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

getPriority

public int getPriority()
Enforced by I_QueueEntry

Specified by:
getPriority in interface I_Entry
Returns:
The priority of this message as int (see PriorityEnum.java)

getPriorityEnum

public final PriorityEnum getPriorityEnum()
Returns:
The priority of this message

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
Returns:
The persistent flag of this message

setPersistent

public void setPersistent(boolean persistent)
Note: Setting here is probably buggy as on reload from DB it seems to be handled as transient if embedded MsgUnit is not persistent. Workaround: Always set this flag on MsgUnit directly until a test case is implemented 2010-11-16 Marcel, Michele

Parameters:
persistent -

getUniqueId

public long getUniqueId()
The unique creation timestamp (unique in a Global of a virtual machine) Enforced by I_QueueEntry

Specified by:
getUniqueId in interface I_Entry
Parameters:
nano - seconds
Returns:
The unique Id of this entry.

getUniqueIdLong

public java.lang.Long getUniqueIdLong()
The unique creation timestamp (unique in a Global of a virtual machine)

Parameters:
nano - seconds

isExpired

public abstract boolean isExpired()
Flag which marks the entry as outdated


isDestroyed

public abstract boolean isDestroyed()
Flag which marks the entry as destroyed, you should take it from queue and ignore/discard it


isInternal

public abstract boolean isInternal()
Returns:
If it is an internal message (oid starting with "_").

getSender

public abstract SessionName getSender()
Returns:
The name of the sender (data source) or null

getReceiver

public abstract SessionName getReceiver()
Returns:
The name of the receiver (data sink) or null

getKeyOid

public abstract java.lang.String getKeyOid()
Returns:
The message key oid or null

getStorageId

public final StorageId getStorageId()
To which queue do i belong


incrRedeliverCounter

public final void incrRedeliverCounter()
Increment the counter if message delivery fails (exception during sending) We don't know if other side has processed it completely or not


getRedeliverCounter

public final int getRedeliverCounter()
How often we tried to redeliver the message.

Note: Depending on the derived class implementation this information is lost on server crash (the redeliver counter is not persistent). Only MsgQueueUpdateEntry persists it.

Returns:
Number of failed tries

getSizeInBytes

public long getSizeInBytes()
Try to find out the approximate memory consumption of this message in RAM.

NOTE: The derived classes need to add their data amount to this value.

Specified by:
getSizeInBytes in interface I_Entry
Returns:
the approximate size in bytes of this object which contributes to a QueueEntry memory consumption

compare

public final int compare(I_QueueEntry m2)
Needed for sorting the queue. Comparing the longs directly is 20% faster than having a String compound key

Sorts the messages
  1. Priority
  2. Timestamp

The sorting order is priority,timestamp:

   ->    5,100 - 5,98 - 5,50 - 9,3000 - 9,2500   ->
 

As 9 is highest priority it is the first to be taken out.
As we need to maintain the timely sequence and id is a timestamp in (more or less) nano seconds elapsed since 1970) the id 2500 (it is older) has precedence to the id 3000

Specified by:
compare in interface I_QueueEntry

equals

public final boolean equals(I_QueueEntry m2)
Needed for sorting in queue

Specified by:
equals in interface I_QueueEntry

toXml

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

Returns:
XML state of MsgQueueEntry

toXml

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

Parameters:
extraOffset - indenting of tags
Returns:
XML state of MsgQueueEntry

toString

public java.lang.String toString()
Nice for logging

Overrides:
toString in class java.lang.Object
See Also:
getLogId()

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:
MethodName.xxx

added

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

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 queue

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

getMethodName

public MethodName getMethodName()
Returns:
e.g. MethodName.PUBLISH
See Also:
getEmbeddedType()

wantReturnObj

public boolean wantReturnObj()
Returns:
true if the dispatcher framework shall provide a return object

setWantReturnObject

public void setWantReturnObject(boolean wantReturnObj)
sets the 'wantReturnObj' flag to what you specify (overwrites the default for the implementing class).

Parameters:
wantReturnObj -

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.


clone

public java.lang.Object clone()
Returns a shallow clone. Is done by DispatchManager.prepareMsgsFromQueue() so that it can later encrypt the message without touching the original

Overrides:
clone in class java.lang.Object

getLogId

public final java.lang.String getLogId()
Return a human readable identifier for logging output.

Specified by:
getLogId in interface I_Entry
Returns:
e.g. "callback:/node/heron/client/joe/2/17/HIGH/23455969/TheMessageOid"

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()

getMsgUnit

public abstract MsgUnit getMsgUnit()
                            throws XmlBlasterException
Returns:
null (always)
Throws:
XmlBlasterException

getMeat

public XBMeat getMeat()
               throws XmlBlasterException
For the new queues

Specified by:
getMeat in interface I_Entry
Throws:
XmlBlasterException

getRef

public XBRef getRef()
For the new queues

Specified by:
getRef in interface I_Entry

xmlBlaster 2.2.0 client API

Copyright © 1999-2014 The xmlBlaster.org contributers.