xmlBlaster 2.2.0 API

org.xmlBlaster.engine.queuemsg
Class TopicEntry

java.lang.Object
  extended by org.xmlBlaster.engine.queuemsg.TopicEntry
All Implemented Interfaces:
java.io.Serializable, I_MapEntry, I_Entry

public final class TopicEntry
extends java.lang.Object
implements I_MapEntry

Wraps an 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  java.lang.String embeddedType
           
private  long immutableSizeInBytes
           
private static java.util.logging.Logger log
           
private  java.lang.String ME
           
private  MsgUnit msgUnit
           
private static long serialVersionUID
           
private  Timestamp sortTimestamp
           
private  StorageId storageId
           
private  boolean stored
           
private  boolean swapped
           
private  long uniqueId
           
private  java.lang.String uniqueIdStr
           
 
Constructor Summary
TopicEntry(ServerScope glob, MsgUnit msgUnit, StorageId storageId)
          Use this constructor if a new message object is fed by method publish().
TopicEntry(ServerScope glob, MsgUnit msgUnit, StorageId storageId, java.lang.String embeddedType, 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
 java.lang.Object clone()
          Returns a shallow clone
 void embeddedObjectToXml(java.io.OutputStream out, java.util.Properties props)
          Dump content to xml representation
 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.
 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
 long getSizeInBytes()
          returns the size in bytes of this entry.
 Timestamp getSortTimestamp()
          Can be used by cache implementation to implement LRU
 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 isExpired()
           
 boolean isInternal()
           
 boolean isPersistent()
          Returns true if the entry is persistent (persistent on HD), false otherwise.
 boolean isStored()
           
 boolean isSwapped()
          Enforced by I_Map
 void isSwapped(boolean swapped)
          Enforced by I_Map
static void main(java.lang.String[] args)
          Measure size for XML-ASCII versus java.io.Serializable persistence.
 void removed(StorageId storageId)
          Notification if this entry is removed from storage
 void setMsgUnit(MsgUnit msg)
           
 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.
 java.lang.String toXml()
           
 java.lang.String toXml(java.lang.String extraOffset)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

ME

private final transient java.lang.String ME

uniqueId

private final transient long uniqueId

uniqueIdStr

private final transient java.lang.String uniqueIdStr

embeddedType

private final transient java.lang.String embeddedType

msgUnit

private MsgUnit msgUnit

immutableSizeInBytes

private final long immutableSizeInBytes

stored

private transient boolean stored

swapped

private transient boolean swapped

sortTimestamp

private transient Timestamp sortTimestamp

storageId

private transient StorageId storageId
Constructor Detail

TopicEntry

public TopicEntry(ServerScope glob,
                  MsgUnit msgUnit,
                  StorageId storageId)
           throws XmlBlasterException
Use this constructor if a new message object is fed by method publish().

Parameters:
msgUnit - The raw data
storageId - TODO
Throws:
XmlBlasterException

TopicEntry

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

Parameters:
storageId - TODO
embeddedType - Allows you to control how to make this object persistent:
ServerEntryFactory.ENTRY_TYPE_TOPIC_XML Dump strings as XML ASCII (which is smaller, faster, portable -> and therefor default)
ServerEntryFactory.ENTRY_TYPE_TOPIC_SERIAL Dump object with java.io.Serializable
sizeInByte - The estimated size of the entry in RAM (can be totally different on HD). If -1L it is estimated for you
Throws:
XmlBlasterException
Method Detail

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 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 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_TOPIC_XML or ServerEntryFactory.ENTRY_TYPE_TOPIC_SERIAL

getEmbeddedObject

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

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

toXml

public java.lang.String toXml(java.lang.String extraOffset)

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)

isExpired

public boolean isExpired()

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

isSwapped

public boolean isSwapped()
Enforced by I_Map

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

isSwapped

public void isSwapped(boolean swapped)
Enforced by I_Map

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

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

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

main

public static void main(java.lang.String[] args)
Measure size for XML-ASCII versus java.io.Serializable persistence.
 
 java org.xmlBlaster.engine.TopicEntry
 
Result:

java.io.Serialized file 'TopicEntry.ser' size=1407 bytes versus XML dump=123 bytes


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.