xmlBlaster 2.2.0 API

org.xmlBlaster.util.dispatch.plugins.prio
Class PriorizedDispatchPlugin

java.lang.Object
  extended by org.xmlBlaster.util.dispatch.plugins.prio.PriorizedDispatchPlugin
All Implemented Interfaces:
I_ConnectionStatusListener, I_MsgDispatchInterceptor, I_Notify, I_Plugin, I_PropertyChangeListener

public final class PriorizedDispatchPlugin
extends java.lang.Object
implements I_MsgDispatchInterceptor, I_Plugin, I_PropertyChangeListener, I_Notify

This dispatcher plugin allows to control how messages are sent to the remote side.

We subscribe to a status message which describes the current connection to the remote side. Depending on a status message we pick messages with specific priorities and send only these.

This allows for example to send all messages if a 2MBit connection is up, and send only high priority messages when the line drops to 64kBit.

The class ConfigurationParser Javadoc has an xml example of the configuration

This plugin class has only one instance per typeVersion for each Global scope. The xmlBlaster client used to subscribe to the status messages is a singleton (in Global.instance() scope).

Note that two status sources exist:

  1. The state of the connection of the dispatcher framework, it may for example be POLLING for a remote connection or have an ALIVE state or even be in DEAD state. If a configuration is found for this state it has highest precedence.
  2. The status of a status message from outside. This is freely configurable and is for example 2M or BACKUP. This status message has lower precedence.

Author:
xmlBlaster@marcelruff.info
See Also:
ConfigurationParser, TestPriorizedDispatchPlugin, the dispatch.control.plugin requirement

Field Summary
static java.lang.String CONFIG_PROPERTY_KEY
           
private  java.lang.String currMsgStatus
           
private  StatusConfiguration currMsgStatusConfiguration
          This is the configuration for the current status of the last received status message:
private  java.util.Map dispatchManagerEntryMap
           
private  Global glob
           
private  boolean hasDefaultActionOnly
           
private  boolean hasSpecificConf
           
private  boolean isShutdown
           
private static java.util.logging.Logger log
           
private  java.lang.String ME
           
private  ConfigurationParser parser
           
 DispatchAction QUEUE_ACTION
           
private  java.lang.String specificConfigPropertyKey
           
private  XmlBlasterNativeClient xmlBlasterClient
           
 
Constructor Summary
PriorizedDispatchPlugin()
           
 
Method Summary
 void addDispatchManager(I_DispatchManager dispatchManager)
          This is called once for each dispatch manager using this plugin.
private  DispatchManagerEntry changeManagerState(I_DispatchManager dispatchManager, ConnectionStateEnum newState, boolean flush)
           
 boolean doActivate(I_DispatchManager dispatchManager)
          Called when new messages are available.
private  void flushHoldbackQueue(DispatchManagerEntry managerEntry)
          All entries from our holdback queue are flushed to the official queues of the DispatchManager
private  DispatchAction getDispatchAction(DispatchManagerEntry managerEntry, MsgQueueEntry entry)
          Lookup the corresponding DispatchAction object this message priority.
private  DispatchManagerEntry getDispatchManagerEntry(I_DispatchManager dispatchManager)
           
private  DispatchManagerEntry[] getDispatchManagerEntryArr()
           
 java.lang.String getType()
          Enforced by I_Plugin
 java.lang.String getVersion()
          Enforced by I_Plugin
 java.util.List<I_Entry> handleNextMessages(I_DispatchManager dispatchManager, java.util.List<I_Entry> entries)
          Enforced by I_MsgDispatchInterceptor.
 void init(Global glob, PluginInfo pluginInfo)
          Enforced by I_Plugin
 void initialize(Global glob, java.lang.String typeVersion)
          Is called by DispatchPluginManager after the instance is created.
 boolean isShutdown()
           
 void onDispatchWorkerException(I_DispatchManager dispatchManager, java.lang.Throwable ex)
          Not doing anything in this method since no Exception handling is done.
 void postHandleNextMessages(I_DispatchManager dispatchManager, MsgUnit[] processedEntries)
          Not doing anything in this method since no cleanup needed.
 void propertyChanged(PropertyChangeEvent ev)
          Invoked when the configuration PriorizedDispatchPlugin/config has changed.
private  void putToHoldbackQueue(DispatchManagerEntry managerEntry, MsgQueueEntry entry)
           
 void shutdown()
          Shutdown the implementation, sync with data store
 void shutdown(I_DispatchManager dispatchManager)
          Deregister a dispatch manager.
 void statusChanged(java.lang.String status)
          Changing the status of the dispatch strategy.
private  void subscribeStatusMessages()
          Subscribe to messages according to the current configuration.
 void toAlive(I_DispatchManager dispatchManager, ConnectionStateEnum oldState)
          Call by DispatchConnectionsHandler on state transition.
 void toAliveSync(I_DispatchManager dispatchManager, ConnectionStateEnum oldState)
           
 void toDead(I_DispatchManager dispatchManager, ConnectionStateEnum oldState, XmlBlasterException xmlBlasterException)
          Call by DispatchConnectionsHandler on state transition

Enforced by interface I_ConnectionStatusListener

 void toPolling(I_DispatchManager dispatchManager, ConnectionStateEnum oldState)
          Call by DispatchConnectionsHandler on state transition

Enforced by interface I_ConnectionStatusListener

 java.lang.String toXml(java.lang.String extraOffset)
           
 java.lang.String usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

glob

private Global glob

log

private static java.util.logging.Logger log

parser

private ConfigurationParser parser

CONFIG_PROPERTY_KEY

public static final java.lang.String CONFIG_PROPERTY_KEY
See Also:
Constant Field Values

specificConfigPropertyKey

private java.lang.String specificConfigPropertyKey

hasSpecificConf

private boolean hasSpecificConf

currMsgStatusConfiguration

private StatusConfiguration currMsgStatusConfiguration
This is the configuration for the current status of the last received status message:


currMsgStatus

private java.lang.String currMsgStatus

hasDefaultActionOnly

private boolean hasDefaultActionOnly

xmlBlasterClient

private XmlBlasterNativeClient xmlBlasterClient

dispatchManagerEntryMap

private java.util.Map dispatchManagerEntryMap

isShutdown

private boolean isShutdown

QUEUE_ACTION

public DispatchAction QUEUE_ACTION
Constructor Detail

PriorizedDispatchPlugin

public PriorizedDispatchPlugin()
Method Detail

initialize

public void initialize(Global glob,
                       java.lang.String typeVersion)
                throws XmlBlasterException
Is called by DispatchPluginManager after the instance is created.

Specified by:
initialize in interface I_MsgDispatchInterceptor
Throws:
XmlBlasterException
See Also:
I_MsgDispatchInterceptor.initialize(Global, String)

addDispatchManager

public void addDispatchManager(I_DispatchManager dispatchManager)
This is called once for each dispatch manager using this plugin.

Specified by:
addDispatchManager in interface I_MsgDispatchInterceptor

propertyChanged

public void propertyChanged(PropertyChangeEvent ev)
Invoked when the configuration PriorizedDispatchPlugin/config has changed. Supports changing configuration in hot operation.

Specified by:
propertyChanged in interface I_PropertyChangeListener

subscribeStatusMessages

private void subscribeStatusMessages()
                              throws XmlBlasterException
Subscribe to messages according to the current configuration.

Throws:
XmlBlasterException

init

public void init(Global glob,
                 PluginInfo pluginInfo)
Enforced by I_Plugin

Specified by:
init in interface I_Plugin
See Also:
I_Plugin.init(org.xmlBlaster.util.Global, PluginInfo)

getType

public java.lang.String getType()
Enforced by I_Plugin

Specified by:
getType in interface I_Plugin
Returns:
"Priority"

getVersion

public final java.lang.String getVersion()
Enforced by I_Plugin

Specified by:
getVersion in interface I_Plugin
Returns:
"1.0"

statusChanged

public final void statusChanged(java.lang.String status)
Changing the status of the dispatch strategy.

Enforced by I_Notify

On initialize: addPropertyChangeListener(this.CONFIG_PROPERTY_KEY, "startup", this); an initial event is fired an calls this method to initialize all attributes here

Specified by:
statusChanged in interface I_Notify

getDispatchAction

private final DispatchAction getDispatchAction(DispatchManagerEntry managerEntry,
                                               MsgQueueEntry entry)
Lookup the corresponding DispatchAction object this message priority.


doActivate

public final boolean doActivate(I_DispatchManager dispatchManager)
Called when new messages are available.

Specified by:
doActivate in interface I_MsgDispatchInterceptor
Returns:
true: create a worker thread to process messages from queue (it will call our getNextMessages() method where we can decide which messages it will process
false: abort, don't start worker thread
See Also:
I_MsgDispatchInterceptor#doActivate(DispatchManager)

handleNextMessages

public final java.util.List<I_Entry> handleNextMessages(I_DispatchManager dispatchManager,
                                                        java.util.List<I_Entry> entries)
                                                 throws XmlBlasterException
Enforced by I_MsgDispatchInterceptor.

NOTE: When copying entries from one queue to another one we have to take care that the reference counter in msgUnitStore is not temporary zero (and is garbage collected). This is avoided by a peek() and later remove() - which is necessary for persistent messages anyhow to ensure 100% crash safety.

Specified by:
handleNextMessages in interface I_MsgDispatchInterceptor
entries - null: Take messages yourself from queue (async mode)
not null: Use messages pushed (sync mode) or messages from ErrorCode.COMMUNICATION*
Returns:
An ArrayList containing the I_QueueEntry to send.
If list.size() == 0 the worker thread stops and does nothing
If list.size() > 0 the given messages are sent. In case of pushEntries>0 and ErrorCode.COMMUNICATION* if you return them they are send to error handler.
Throws:
XmlBlasterException
See Also:
I_MsgDispatchInterceptor#handleNextMessages(DispatchManager, ArrayList)

getDispatchManagerEntry

private DispatchManagerEntry getDispatchManagerEntry(I_DispatchManager dispatchManager)

putToHoldbackQueue

private void putToHoldbackQueue(DispatchManagerEntry managerEntry,
                                MsgQueueEntry entry)
                         throws XmlBlasterException
Throws:
XmlBlasterException

flushHoldbackQueue

private void flushHoldbackQueue(DispatchManagerEntry managerEntry)
All entries from our holdback queue are flushed to the official queues of the DispatchManager


toAlive

public final void toAlive(I_DispatchManager dispatchManager,
                          ConnectionStateEnum oldState)
Call by DispatchConnectionsHandler on state transition.

Enforced by interface I_ConnectionStatusListener

Specified by:
toAlive in interface I_ConnectionStatusListener

toAliveSync

public void toAliveSync(I_DispatchManager dispatchManager,
                        ConnectionStateEnum oldState)
Specified by:
toAliveSync in interface I_ConnectionStatusListener

toPolling

public final void toPolling(I_DispatchManager dispatchManager,
                            ConnectionStateEnum oldState)
Call by DispatchConnectionsHandler on state transition

Enforced by interface I_ConnectionStatusListener

Specified by:
toPolling in interface I_ConnectionStatusListener

toDead

public final void toDead(I_DispatchManager dispatchManager,
                         ConnectionStateEnum oldState,
                         XmlBlasterException xmlBlasterException)
Call by DispatchConnectionsHandler on state transition

Enforced by interface I_ConnectionStatusListener

Specified by:
toDead in interface I_ConnectionStatusListener
xmlBlasterException - Can be null

changeManagerState

private DispatchManagerEntry changeManagerState(I_DispatchManager dispatchManager,
                                                ConnectionStateEnum newState,
                                                boolean flush)

getDispatchManagerEntryArr

private DispatchManagerEntry[] getDispatchManagerEntryArr()
Returns:
A current snapshot (thread save etc)

shutdown

public void shutdown(I_DispatchManager dispatchManager)
              throws XmlBlasterException
Deregister a dispatch manager.

Specified by:
shutdown in interface I_MsgDispatchInterceptor
Throws:
XmlBlasterException
See Also:
I_MsgDispatchInterceptor#shutdown(DispatchManager)

shutdown

public void shutdown()
              throws XmlBlasterException
Description copied from interface: I_MsgDispatchInterceptor
Shutdown the implementation, sync with data store

Specified by:
shutdown in interface I_MsgDispatchInterceptor
Specified by:
shutdown in interface I_Plugin
Throws:
XmlBlasterException - if an exception occurs. The exception is handled by the RunLevelManager depending on how the plugin has been configured with the action:

<action do='STOP' onShutdownRunlevel='2' sequence='5' onFail='resource.configuration.pluginFailed'> If onFail is defined to something, the RunLevelManager will stop.


isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface I_MsgDispatchInterceptor
Returns:
true if shutdown

usage

public java.lang.String usage()
Specified by:
usage in interface I_MsgDispatchInterceptor
Returns:
a human readable usage help string

toXml

public java.lang.String toXml(java.lang.String extraOffset)
Specified by:
toXml in interface I_MsgDispatchInterceptor
Parameters:
extraOffset - Indent the dump with given ASCII blanks
Returns:
An xml encoded dump
See Also:
I_MsgDispatchInterceptor.toXml(String)

postHandleNextMessages

public void postHandleNextMessages(I_DispatchManager dispatchManager,
                                   MsgUnit[] processedEntries)
                            throws XmlBlasterException
Not doing anything in this method since no cleanup needed.

Specified by:
postHandleNextMessages in interface I_MsgDispatchInterceptor
Parameters:
dispatchManager - The used dispatch manager.
processedEntries - The entries which have been previously processed.
Throws:
XmlBlasterException

onDispatchWorkerException

public void onDispatchWorkerException(I_DispatchManager dispatchManager,
                                      java.lang.Throwable ex)
Not doing anything in this method since no Exception handling is done.

Specified by:
onDispatchWorkerException in interface I_MsgDispatchInterceptor

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.