xmlBlaster 2.2.0 client API

org.xmlBlaster.client.dispatch
Class ClientDispatchManager

java.lang.Object
  extended by org.xmlBlaster.client.dispatch.ClientDispatchManager
All Implemented Interfaces:
java.util.EventListener, I_DispatchManager, I_Timeout, I_QueuePutListener

public final class ClientDispatchManager
extends java.lang.Object
implements I_DispatchManager

Manages the sending of messages and commands and does error recovery further we communicate with the dispatcher plugin if one is configured.

There is one instance of this class per queue and remote connection.

Author:
xmlBlaster@marcelruff.info

Field Summary
 java.lang.String ME
           
 
Constructor Summary
ClientDispatchManager(Global glob, I_MsgErrorHandler failureListener, org.xmlBlaster.authentication.plugins.I_MsgSecurityInterceptor securityInterceptor, I_Queue msgQueue, I_ConnectionStatusListener connectionStatusListener, AddressBase[] addrArr, SessionName sessionName)
           
 
Method Summary
 boolean addConnectionStatusListener(I_ConnectionStatusListener connectionStatusListener)
           
 boolean addConnectionStatusListener(I_ConnectionStatusListener connectionStatusListener, boolean fireInitial)
           
 java.util.ArrayList filterDistributorEntries(java.util.ArrayList entries, java.lang.Throwable ex)
           
 void finalize()
           
 long getAliveSinceTime()
          Get timestamp when we went to ALIVE state.
 long getBurstModeMaxBytes()
          How many bytes maximum shall the callback thread take in one bulk out of the callback queue and deliver in one bulk.
 int getBurstModeMaxEntries()
          How many messages maximum shall the callback thread take in one bulk out of the callback queue and deliver in one bulk.
 I_ConnectionStatusListener[] getConnectionStatusListeners()
           
 DispatchConnectionsHandler getDispatchConnectionsHandler()
           
 DispatchStatistic getDispatchStatistic()
           
 java.lang.String getId()
          For logging
 I_MsgDispatchInterceptor getMsgDispatchInterceptor()
           
 I_MsgErrorHandler getMsgErrorHandler()
           
 org.xmlBlaster.authentication.plugins.I_MsgSecurityInterceptor getMsgSecurityInterceptor()
           
 int getNotifyCounter()
          Counts how often a new entry was added since the current worker thread was started.
 long getPollingSinceTime()
          Get timestamp when we went to POLLING state.
 I_Queue getQueue()
           
 SessionName getSessionName()
           
 java.lang.String getTypeVersion()
          The name in the configuration file for the plugin
 void handleSyncWorkerException(java.util.List<I_Entry> entryList, java.lang.Throwable throwable)
          Called by DispatchWorker if an Exception occured in sync mode Only on client side
 void handleWorkerException(java.util.List<I_Entry> entryList, java.lang.Throwable throwable)
          Called by DispatchWorker if an Exception occurred in async mode.
 void internalError(java.lang.Throwable throwable)
          Called locally and from TopicHandler when internal error (Throwable) occurred to avoid infinite looping
 boolean isAlive()
           
 boolean isDead()
           
 boolean isDispatcherActive()
           
 boolean isPolling()
           
 boolean isShutdown()
           
 boolean isSyncMode()
           
 void lostClientConnection()
          Can be called when client connection is lost (NOT the callback connection).
 void notifyAboutNewEntry()
          When somebody puts a new entry into the queue, we want to be notified about this after the entry is fed.
 boolean pingCallbackServer(boolean sync, boolean connectionIsDown)
           
 void postSendNotification(MsgQueueEntry entry)
           
 void postSendNotification(MsgQueueEntry[] entries)
           
 java.util.ArrayList prepareMsgsFromQueue(java.util.List<I_Entry> entryList)
          Here we prepare messages which are coming directly from the queue.
static java.util.ArrayList prepareMsgsFromQueue(java.lang.String logId, java.util.logging.Logger log, I_Queue queue, java.util.List<I_Entry> entryList)
           
 void putPost(I_QueueEntry queueEntry)
          Called by I_Queue implementation before leaving put() and somebody has registered for such events.
 void putPost(I_QueueEntry[] queueEntries)
          Called by I_Queue implementation before leaving put() and somebody has registered for such events.
 boolean putPre(I_QueueEntry queueEntry)
          Called by I_Queue implementation when a put() is invoked and somebody has registered for such events
 boolean putPre(I_QueueEntry[] queueEntries)
          Called by I_Queue implementation when a put() is invoked and somebody has registered for such events
 void reachedAliveSync(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
           
 boolean removeConnectionStatusListener(I_ConnectionStatusListener connectionStatusListener)
          Remove the given listener
 void removeFromQueue(MsgQueueEntry[] entries, boolean postSendNotify)
          Messages are successfully sent, remove them now from queue (sort of a commit()): We remove filtered/destroyed messages as well (which doen't show up in entryListChecked)
 boolean sendingFailedNotification(MsgQueueEntry[] entries, XmlBlasterException ex)
          Notify I_PostSendListener about problem.
 void setAddresses(AddressBase[] addr)
          Set new callback addresses, typically after a session login/logout
 void setDispatcherActive(boolean dispatcherActive)
          Inhibits/activates the delivery of asynchronous dispatches of messages.
 void setDispatchWorkerIsActive(boolean val)
          The worker notifies us that it is finished, if messages are available it is triggered again.
 void shutdown()
          Stop all callback drivers of this client.
 void shutdownFomAnyState(ConnectionStateEnum oldState, XmlBlasterException ex)
          Call by DispatchConnectionsHandler on state transition
 void switchToASyncMode()
          Switch back to asynchronous mode.
 void switchToSyncMode()
          We register a QueuePutListener and all put() into the queue are intercepted - our put() is called instead.
 void timeout(java.lang.Object userData)
          We are notified about the burst mode timeout through this method.
 void toAlive(ConnectionStateEnum oldState)
          Call by DispatchConnectionsHandler on state transition NOTE: toAlive is called initially when a protocol plugin is successfully loaded but we don't know yet if it ever is able to connect
 void toDead(XmlBlasterException ex)
           
 void toPolling(ConnectionStateEnum oldState)
          Call by DispatchConnectionsHandler on state transition
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into a XML ASCII string.
 void trySyncMode(boolean trySyncMode)
          Set behavior of dispatch framework.
 void updateProperty(CallbackAddress[] addressArr)
          Reconfigure dispatcher with given properties.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

public final java.lang.String ME
Constructor Detail

ClientDispatchManager

public ClientDispatchManager(Global glob,
                             I_MsgErrorHandler failureListener,
                             org.xmlBlaster.authentication.plugins.I_MsgSecurityInterceptor securityInterceptor,
                             I_Queue msgQueue,
                             I_ConnectionStatusListener connectionStatusListener,
                             AddressBase[] addrArr,
                             SessionName sessionName)
                      throws XmlBlasterException
Parameters:
msgQueue - The message queue which i use (!!! TODO: this changes, we should pass it on every method where needed)
connectionStatusListener - The implementation which listens on connectionState events (e.g. XmlBlasterAccess.java), or null
addrArr - The addresses i shall connect to
Throws:
XmlBlasterException
Method Detail

getSessionName

public SessionName getSessionName()
Specified by:
getSessionName in interface I_DispatchManager
Returns:
Never null

isSyncMode

public boolean isSyncMode()
Specified by:
isSyncMode in interface I_DispatchManager

trySyncMode

public void trySyncMode(boolean trySyncMode)
Set behavior of dispatch framework.

Specified by:
trySyncMode in interface I_DispatchManager
Parameters:
trySyncMode - true: client side queue embedding, false: server side callback queue defaults to false

updateProperty

public final void updateProperty(CallbackAddress[] addressArr)
                          throws XmlBlasterException
Reconfigure dispatcher with given properties. Note that only a limited re-configuration is supported

Specified by:
updateProperty in interface I_DispatchManager
Parameters:
addressArr - The new configuration
Throws:
XmlBlasterException

finalize

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

getQueue

public I_Queue getQueue()
Specified by:
getQueue in interface I_DispatchManager

addConnectionStatusListener

public boolean addConnectionStatusListener(I_ConnectionStatusListener connectionStatusListener)
Specified by:
addConnectionStatusListener in interface I_DispatchManager

addConnectionStatusListener

public boolean addConnectionStatusListener(I_ConnectionStatusListener connectionStatusListener,
                                           boolean fireInitial)
Specified by:
addConnectionStatusListener in interface I_DispatchManager

removeConnectionStatusListener

public boolean removeConnectionStatusListener(I_ConnectionStatusListener connectionStatusListener)
Remove the given listener

Specified by:
removeConnectionStatusListener in interface I_DispatchManager
Parameters:
connectionStatusListener -
Returns:
true if it was removed

getConnectionStatusListeners

public I_ConnectionStatusListener[] getConnectionStatusListeners()
Specified by:
getConnectionStatusListeners in interface I_DispatchManager

getTypeVersion

public java.lang.String getTypeVersion()
The name in the configuration file for the plugin

Specified by:
getTypeVersion in interface I_DispatchManager
Returns:
e.g. "Priority,1.0"

getMsgSecurityInterceptor

public org.xmlBlaster.authentication.plugins.I_MsgSecurityInterceptor getMsgSecurityInterceptor()
Specified by:
getMsgSecurityInterceptor in interface I_DispatchManager
Returns:
The import/export encrypt handle or null if created by a SubjectInfo (no session info available)

getDispatchConnectionsHandler

public final DispatchConnectionsHandler getDispatchConnectionsHandler()
Specified by:
getDispatchConnectionsHandler in interface I_DispatchManager
Returns:
The handler of all callback plugins, is never null

getBurstModeMaxEntries

public final int getBurstModeMaxEntries()
How many messages maximum shall the callback thread take in one bulk out of the callback queue and deliver in one bulk.

Specified by:
getBurstModeMaxEntries in interface I_DispatchManager

getBurstModeMaxBytes

public final long getBurstModeMaxBytes()
How many bytes maximum shall the callback thread take in one bulk out of the callback queue and deliver in one bulk.

Specified by:
getBurstModeMaxBytes in interface I_DispatchManager

getAliveSinceTime

public final long getAliveSinceTime()
Get timestamp when we went to ALIVE state.

Specified by:
getAliveSinceTime in interface I_DispatchManager
Returns:
millis timestamp

getPollingSinceTime

public final long getPollingSinceTime()
Get timestamp when we went to POLLING state.

Specified by:
getPollingSinceTime in interface I_DispatchManager
Returns:
millis timestamp

toAlive

public void toAlive(ConnectionStateEnum oldState)
Call by DispatchConnectionsHandler on state transition NOTE: toAlive is called initially when a protocol plugin is successfully loaded but we don't know yet if it ever is able to connect

Specified by:
toAlive in interface I_DispatchManager

reachedAliveSync

public void reachedAliveSync(ConnectionStateEnum oldState,
                             I_XmlBlasterAccess connection)
Specified by:
reachedAliveSync in interface I_DispatchManager

toPolling

public void toPolling(ConnectionStateEnum oldState)
Call by DispatchConnectionsHandler on state transition

Specified by:
toPolling in interface I_DispatchManager

toDead

public void toDead(XmlBlasterException ex)
Specified by:
toDead in interface I_DispatchManager
Parameters:
ex -

shutdownFomAnyState

public void shutdownFomAnyState(ConnectionStateEnum oldState,
                                XmlBlasterException ex)
Call by DispatchConnectionsHandler on state transition

Specified by:
shutdownFomAnyState in interface I_DispatchManager

postSendNotification

public void postSendNotification(MsgQueueEntry entry)
Specified by:
postSendNotification in interface I_DispatchManager

postSendNotification

public void postSendNotification(MsgQueueEntry[] entries)
Specified by:
postSendNotification in interface I_DispatchManager

sendingFailedNotification

public boolean sendingFailedNotification(MsgQueueEntry[] entries,
                                         XmlBlasterException ex)
Notify I_PostSendListener about problem.

Typically XmlBlasterAccess is notified when message came asynchronously from queue

Specified by:
sendingFailedNotification in interface I_DispatchManager
Parameters:
entryList -
ex -
Returns:
true if processed
See Also:
for explanation

handleSyncWorkerException

public void handleSyncWorkerException(java.util.List<I_Entry> entryList,
                                      java.lang.Throwable throwable)
                               throws XmlBlasterException
Called by DispatchWorker if an Exception occured in sync mode Only on client side

Specified by:
handleSyncWorkerException in interface I_DispatchManager
Throws:
XmlBlasterException

removeFromQueue

public void removeFromQueue(MsgQueueEntry[] entries,
                            boolean postSendNotify)
                     throws XmlBlasterException
Messages are successfully sent, remove them now from queue (sort of a commit()): We remove filtered/destroyed messages as well (which doen't show up in entryListChecked)

Specified by:
removeFromQueue in interface I_DispatchManager
Parameters:
postSendNotify - TODO
Throws:
XmlBlasterException

handleWorkerException

public void handleWorkerException(java.util.List<I_Entry> entryList,
                                  java.lang.Throwable throwable)
                           throws XmlBlasterException
Called by DispatchWorker if an Exception occurred in async mode.

Specified by:
handleWorkerException in interface I_DispatchManager
Throws:
XmlBlasterException - should never happen but is possible during removing entries from queue

getMsgErrorHandler

public I_MsgErrorHandler getMsgErrorHandler()
Specified by:
getMsgErrorHandler in interface I_DispatchManager

switchToSyncMode

public void switchToSyncMode()
We register a QueuePutListener and all put() into the queue are intercepted - our put() is called instead. We then deliver this QueueEntry directly to the remote connection and return synchronously the returned value or the Exception if one is thrown.

Specified by:
switchToSyncMode in interface I_DispatchManager

switchToASyncMode

public void switchToASyncMode()
Switch back to asynchronous mode. Our thread pool will take the messages out of the queue and deliver them in asynchronous mode.

Specified by:
switchToASyncMode in interface I_DispatchManager

putPre

public boolean putPre(I_QueueEntry queueEntry)
               throws XmlBlasterException
Description copied from interface: I_QueuePutListener
Called by I_Queue implementation when a put() is invoked and somebody has registered for such events

Specified by:
putPre in interface I_DispatchManager
Specified by:
putPre in interface I_QueuePutListener
Parameters:
queueEntry - Is guaranteed to never be null
Returns:
true: Continue to put message into queue, false: return without putting entry into queue
Throws:
XmlBlasterException
See Also:
I_QueuePutListener.putPre(I_QueueEntry)

putPre

public boolean putPre(I_QueueEntry[] queueEntries)
               throws XmlBlasterException
Description copied from interface: I_QueuePutListener
Called by I_Queue implementation when a put() is invoked and somebody has registered for such events

Specified by:
putPre in interface I_DispatchManager
Specified by:
putPre in interface I_QueuePutListener
Parameters:
queueEntries - Is guaranteed to never be null
Returns:
true: Continue to put message into queue, false: return without putting entry into queue
Throws:
XmlBlasterException
See Also:
putPre(I_QueueEntry), I_QueuePutListener.putPre(I_QueueEntry[])

putPost

public void putPost(I_QueueEntry queueEntry)
             throws XmlBlasterException
Description copied from interface: I_QueuePutListener
Called by I_Queue implementation before leaving put() and somebody has registered for such events. The message is already safely entered to the queue.

Specified by:
putPost in interface I_DispatchManager
Specified by:
putPost in interface I_QueuePutListener
Parameters:
queueEntry - Is guaranteed to never be null
Throws:
XmlBlasterException
See Also:
I_QueuePutListener.putPost(I_QueueEntry)

putPost

public void putPost(I_QueueEntry[] queueEntries)
             throws XmlBlasterException
Description copied from interface: I_QueuePutListener
Called by I_Queue implementation before leaving put() and somebody has registered for such events. The message is already safely entered to the queue.

Specified by:
putPost in interface I_DispatchManager
Specified by:
putPost in interface I_QueuePutListener
Parameters:
queueEntries - Is guaranteed to never be null
Throws:
XmlBlasterException
See Also:
putPost(I_QueueEntry), I_QueuePutListener.putPost(I_QueueEntry[])

prepareMsgsFromQueue

public java.util.ArrayList prepareMsgsFromQueue(java.util.List<I_Entry> entryList)
Here we prepare messages which are coming directly from the queue.
  1. We eliminate destroyed messages
  2. We make a shallow copy of the message. We need to do this, out messages are references directly into the queue. The delivery framework is later changing the QoS and plugins may change the content - and this should not modify the queue entries

Specified by:
prepareMsgsFromQueue in interface I_DispatchManager

prepareMsgsFromQueue

public static java.util.ArrayList prepareMsgsFromQueue(java.lang.String logId,
                                                       java.util.logging.Logger log,
                                                       I_Queue queue,
                                                       java.util.List<I_Entry> entryList)

notifyAboutNewEntry

public void notifyAboutNewEntry()
When somebody puts a new entry into the queue, we want to be notified about this after the entry is fed.

Called by I_Queue.putPost()

Specified by:
notifyAboutNewEntry in interface I_DispatchManager

getNotifyCounter

public int getNotifyCounter()
Counts how often a new entry was added since the current worker thread was started.

Specified by:
getNotifyCounter in interface I_DispatchManager

isDead

public boolean isDead()
Specified by:
isDead in interface I_DispatchManager

isPolling

public boolean isPolling()
Specified by:
isPolling in interface I_DispatchManager

isAlive

public boolean isAlive()
Specified by:
isAlive in interface I_DispatchManager

lostClientConnection

public void lostClientConnection()
Can be called when client connection is lost (NOT the callback connection). Currently only detected by the SOCKET protocol plugin. Others can only detect lost clients with their callback protocol pings

Specified by:
lostClientConnection in interface I_DispatchManager

pingCallbackServer

public boolean pingCallbackServer(boolean sync,
                                  boolean connectionIsDown)
Specified by:
pingCallbackServer in interface I_DispatchManager

timeout

public void timeout(java.lang.Object userData)
We are notified about the burst mode timeout through this method.

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

getMsgDispatchInterceptor

public I_MsgDispatchInterceptor getMsgDispatchInterceptor()
Specified by:
getMsgDispatchInterceptor in interface I_DispatchManager
Returns:
The interceptor plugin if available, otherwise null

setAddresses

public void setAddresses(AddressBase[] addr)
                  throws XmlBlasterException
Set new callback addresses, typically after a session login/logout

Specified by:
setAddresses in interface I_DispatchManager
Throws:
XmlBlasterException

setDispatchWorkerIsActive

public void setDispatchWorkerIsActive(boolean val)
The worker notifies us that it is finished, if messages are available it is triggered again.

Specified by:
setDispatchWorkerIsActive in interface I_DispatchManager

internalError

public void internalError(java.lang.Throwable throwable)
Called locally and from TopicHandler when internal error (Throwable) occurred to avoid infinite looping

Specified by:
internalError in interface I_DispatchManager

getDispatchStatistic

public DispatchStatistic getDispatchStatistic()
Specified by:
getDispatchStatistic in interface I_DispatchManager
Returns:
A container holding some statistical delivery information

isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface I_DispatchManager

shutdown

public void shutdown()
Stop all callback drivers of this client. Possibly invoked twice (givingUpDelivery() calls it indirectly as well) We don't shutdown the corresponding queue.

Specified by:
shutdown in interface I_DispatchManager

getId

public java.lang.String getId()
For logging

Specified by:
getId in interface I_DispatchManager

toXml

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

Specified by:
toXml in interface I_DispatchManager
Parameters:
extraOffset - indenting of tags for nice output
Returns:
internal state as a XML ASCII string

setDispatcherActive

public void setDispatcherActive(boolean dispatcherActive)
Inhibits/activates the delivery of asynchronous dispatches of messages.

Specified by:
setDispatcherActive in interface I_DispatchManager
Parameters:
dispatcherActive -

isDispatcherActive

public boolean isDispatcherActive()
Specified by:
isDispatcherActive in interface I_DispatchManager
Returns:
true if the dispacher is currently activated, i.e. if it is able to deliver asynchronousy messages from the callback queue.

filterDistributorEntries

public java.util.ArrayList filterDistributorEntries(java.util.ArrayList entries,
                                                    java.lang.Throwable ex)
Specified by:
filterDistributorEntries in interface I_DispatchManager

xmlBlaster 2.2.0 client API

Copyright © 1999-2014 The xmlBlaster.org contributers.