xmlBlaster 2.2.0 API

org.xmlBlaster.engine
Class TopicAccessor

java.lang.Object
  extended by org.xmlBlaster.engine.TopicAccessor

public final class TopicAccessor
extends java.lang.Object

Singleton in ServerScope to access a TopicHandler instance.

Used to guarantee single threaded access to a TopicHandler instance. Only well defined methods allow dirty reads from other threads simultaneously, further we have a pattern to dispatch the topicHandler access to a worker thread.

Author:
Marcel Ruff
See Also:
The engine.message.lifecylce requirement, TestTopicLifeCycle

Nested Class Summary
private  class TopicAccessor.Consumer
          Called by msgUnitWrapper.toDestroyed(): this.glob.getTopicAccessor().entryDestroyed_scheduleForExecution(this); Is currently switched off (not used)
private  class TopicAccessor.TopicContainer
          Helper class to hold the TopicHandler and some additonal locking information.
 
Field Summary
private  java.util.concurrent.BlockingQueue blockingQueue
           
private static java.util.logging.Logger log
           
private  ServerScope serverScope
           
private  java.util.Map topicHandlerMap
          Map for TopicContainer.
private  java.util.Set topicListenerSet
          For listeners who want to be informed about topic creation / deletion events.
 
Constructor Summary
TopicAccessor(ServerScope serverScope)
           
 
Method Summary
 TopicHandler access(java.lang.String oid)
          Access a topicHandler by its unique oid.
 TopicHandler accessDirtyRead(java.lang.String oid)
          The topicHandler is not locked, use for read only access only and when you know what you are doing.
private  TopicAccessor.TopicContainer accessTopicContainer(java.lang.String oid)
           
 void addTopicListener(I_TopicListener l)
          Adds the specified Topic listener to receive creation/destruction events of Topics.
 void changeDirtyRead(MsgUnitWrapper msgUnitWrapper)
           
 void entryDestroyed_scheduleForExecution(MsgUnitWrapper msgUnitWrapper)
          Queue request for later execution, to be outside of sync-locks
 void erase(java.lang.String oid)
          Remove the given topic
 TopicHandler findOrCreate(SessionInfo sessionInfo, java.lang.String oid)
          Access a topicHandler by its unique oid or create it if not known.
private  void fireTopicEvent(TopicHandler topicHandler)
          Is fired on topic creation or destruction.
 int getNumTopics()
          Access the number of known topics.
 I_TopicListener[] getRemotePropertiesListenerArr()
          Access a current snapshot of all listeners.
 SubscriptionInfo[] getSubscriptionInfoArrDirtyRead(java.lang.String topicId)
           
private  TopicHandler[] getTopicHandlerArr()
          Treat as read only! For class internal use only.
private  TopicHandler getTopicHandlerDirtyRead(java.lang.String topicId)
           
 java.lang.String[] getTopics()
          Access oid array
 boolean hasMsgDistributorPluginDirtyRead(java.lang.String topicId)
           
 MsgUnitWrapper lookupDirtyRead(java.lang.String topicId, long msgUnitWrapperUniqueId)
          Access the message meat without a lock.
 MsgUnitWrapper lookupNewest(java.lang.String topicId)
          Access the newest entry.
 void release(TopicHandler topicHandler)
          Return the topicHandler which you previously got with access(String oid).
 void removeTopicListener(I_TopicListener l)
          Removes the specified listener.
 void spanTopicDestroyTimeout()
          Called from SessionPersistencePlugin after all sessions / subscriptions are alive after a server startup.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump all TopicHandler to xml.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverScope

private final ServerScope serverScope

log

private static java.util.logging.Logger log

topicHandlerMap

private final java.util.Map topicHandlerMap
Map for TopicContainer.

key = oid value from (== topicHandler.getUniqueKey()) value = TopicContainer instance


topicListenerSet

private final java.util.Set topicListenerSet
For listeners who want to be informed about topic creation / deletion events.


blockingQueue

private java.util.concurrent.BlockingQueue blockingQueue
Constructor Detail

TopicAccessor

public TopicAccessor(ServerScope serverScope)
Method Detail

access

public TopicHandler access(java.lang.String oid)
Access a topicHandler by its unique oid.

You need to call release(topicHandler) after usage!

Parameters:
oid - topicHandler.getUniqueKey()
Returns:
The topicHandler instance or null, in case of null you don't need to release anything

accessDirtyRead

public TopicHandler accessDirtyRead(java.lang.String oid)
The topicHandler is not locked, use for read only access only and when you know what you are doing.

Parameters:
oid - topicHandler.getUniqueKey()
Returns:
The topicHandler instance or null, you don't need to release anything

accessTopicContainer

private TopicAccessor.TopicContainer accessTopicContainer(java.lang.String oid)

release

public void release(TopicHandler topicHandler)
Return the topicHandler which you previously got with access(String oid).

Parameters:
topicHandler - Currently logs severe if null

findOrCreate

public TopicHandler findOrCreate(SessionInfo sessionInfo,
                                 java.lang.String oid)
                          throws XmlBlasterException
Access a topicHandler by its unique oid or create it if not known.

You need to call release(topicHandler) after usage.

Parameters:
sessionInfo - Can be null if called by a subscription
oid - topicHandler.getUniqueKey()
Returns:
The topicHandler instance but never null
Throws:
XmlBlasterException

erase

public void erase(java.lang.String oid)
           throws XmlBlasterException
Remove the given topic

Parameters:
topicHandler -
Throws:
XmlBlasterException

getTopicHandlerArr

private TopicHandler[] getTopicHandlerArr()
Treat as read only! For class internal use only.

Returns:
A current snapshot of all topics (never null)

getTopics

public java.lang.String[] getTopics()
Access oid array

Returns:
A string array of all topicHandler.getUniqueKey()

getNumTopics

public int getNumTopics()
Access the number of known topics.

Returns:
Number of registered topics

spanTopicDestroyTimeout

public void spanTopicDestroyTimeout()
Called from SessionPersistencePlugin after all sessions / subscriptions are alive after a server startup.

The topic destroy timers where inhibited and can now be activated


lookupDirtyRead

public MsgUnitWrapper lookupDirtyRead(java.lang.String topicId,
                                      long msgUnitWrapperUniqueId)
                               throws XmlBlasterException
Access the message meat without a lock.

Parameters:
topicId - The topic oid
msgUnitWrapperUniqueId - The message instance id
Returns:
null if not found
Throws:
XmlBlasterException

lookupNewest

public MsgUnitWrapper lookupNewest(java.lang.String topicId)
                            throws XmlBlasterException
Access the newest entry.

Parameters:
topicId -
Returns:
null if not found
Throws:
XmlBlasterException

changeDirtyRead

public void changeDirtyRead(MsgUnitWrapper msgUnitWrapper)
                     throws XmlBlasterException
Throws:
XmlBlasterException

getTopicHandlerDirtyRead

private TopicHandler getTopicHandlerDirtyRead(java.lang.String topicId)

hasMsgDistributorPluginDirtyRead

public boolean hasMsgDistributorPluginDirtyRead(java.lang.String topicId)

getSubscriptionInfoArrDirtyRead

public final SubscriptionInfo[] getSubscriptionInfoArrDirtyRead(java.lang.String topicId)
Parameters:
topicId - key oid
Returns:
Never null

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
                             throws XmlBlasterException
Dump all TopicHandler to xml. This is implemented as dirty read to gain performance

Parameters:
extraOffset -
Returns:
The markup of all TopicHandlers
Throws:
XmlBlasterException

entryDestroyed_scheduleForExecution

public void entryDestroyed_scheduleForExecution(MsgUnitWrapper msgUnitWrapper)
Queue request for later execution, to be outside of sync-locks

Parameters:
msgUnitWrapper -

addTopicListener

public void addTopicListener(I_TopicListener l)
Adds the specified Topic listener to receive creation/destruction events of Topics.

Note that the fired event holds a locked topicHandler, you shouldn't spend too much time with it to allow other threads to do their work as well

Parameters:
l - Your listener implementation

removeTopicListener

public void removeTopicListener(I_TopicListener l)
Removes the specified listener.

Parameters:
l - Your listener implementation

getRemotePropertiesListenerArr

public I_TopicListener[] getRemotePropertiesListenerArr()
Access a current snapshot of all listeners.

Returns:
The array of registered listeners

fireTopicEvent

private void fireTopicEvent(TopicHandler topicHandler)
Is fired on topic creation or destruction.

Does never throw any exception

Parameters:
topicHandler - The locked! handler

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.