xmlBlaster 2.2.0 API

org.xmlBlaster.engine.mime.demo
Class PublishDelayer

java.lang.Object
  extended by org.xmlBlaster.engine.mime.demo.PublishDelayer
All Implemented Interfaces:
PublishDelayerMBean, I_PublishFilter, I_Plugin

public class PublishDelayer
extends java.lang.Object
implements I_Plugin, I_PublishFilter, PublishDelayerMBean

This demo plugin delays incoming (published) messages. You can also provide for example an exceptionErrorCode=internal.publish and each message will throw such an exception (usually for testing).

Please register this plugin in xmlBlaster.properties

 MimePublishPlugin[TestDelayer][1.0]=org.xmlBlaster.engine.mime.demo.PublishDelayer,delayMillis=200,exceptionErrorCode=,filterKeyOid=
 
Plugins must implement the I_Plugin interface to be loadable by the PluginManager and must implement the I_PublishFilter interface to be usable as a filter.

Author:
xmlBlaster@marcelruff.info

Field Summary
private  ContextNode contextNode
           
private  long delayMillis
          How long to delay an incoming publish message
private  java.lang.String exceptionErrorCode
           
private  java.lang.String filterKeyOid
           
private  Global glob
           
private static java.util.logging.Logger log
           
private  java.lang.Object mbeanHandle
          My JMX registration
private  java.lang.String ME
           
private  PluginInfo pluginConfig
           
 
Constructor Summary
PublishDelayer()
           
 
Method Summary
 long getDelayMillis()
           
 java.lang.String getExceptionErrorCode()
           
 java.lang.String getFilterKeyOid()
           
 java.lang.String[] getMimeExtended()
          Get the content MIME version number for which this plugin applies
 java.lang.String[] getMimeTypes()
          Get the content MIME type for which this plugin applies
 java.lang.String getName()
          Get a human readable name of this filter implementation
 java.lang.String getType()
           
 java.lang.String getVersion()
           
 void init(Global glob, PluginInfo pluginInfo)
          This method is called by the PluginManager (enforced by I_Plugin).
 void initialize(ServerScope serverScope)
          This is called after instantiation of the plugin
 java.lang.String intercept(SubjectInfo publisher, MsgUnit msgUnit)
          Delay the message for the configured amount of time.
 void setDelayMillis(long delayMillis)
           
 void setExceptionErrorCode(java.lang.String exceptionErrorCode)
          By setting an errorCode String != "" the published message is rejected with the given exception type.
 void setFilterKeyOid(java.lang.String filterKeyOid)
          By setting a topicId != "" the plugin is only applied for the given messages oid.
 void shutdown()
          Cleans up the resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private final java.lang.String ME
See Also:
Constant Field Values

glob

private Global glob

mbeanHandle

private java.lang.Object mbeanHandle
My JMX registration


contextNode

private ContextNode contextNode

pluginConfig

private PluginInfo pluginConfig

log

private static java.util.logging.Logger log

delayMillis

private long delayMillis
How long to delay an incoming publish message


exceptionErrorCode

private java.lang.String exceptionErrorCode

filterKeyOid

private java.lang.String filterKeyOid
Constructor Detail

PublishDelayer

public PublishDelayer()
Method Detail

initialize

public void initialize(ServerScope serverScope)
This is called after instantiation of the plugin

Specified by:
initialize in interface I_PublishFilter
Parameters:
glob - The global handle of this xmlBlaster server instance.

init

public void init(Global glob,
                 PluginInfo pluginInfo)
          throws XmlBlasterException
This method is called by the PluginManager (enforced by I_Plugin).

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

getType

public java.lang.String getType()
Specified by:
getType in interface I_Plugin
See Also:
I_Plugin.getType()

getVersion

public java.lang.String getVersion()
Specified by:
getVersion in interface I_Plugin
See Also:
I_Plugin.getVersion()

getName

public java.lang.String getName()
Get a human readable name of this filter implementation

Specified by:
getName in interface I_PublishFilter
Returns:
"PublishDelayer"

getMimeTypes

public java.lang.String[] getMimeTypes()
Get the content MIME type for which this plugin applies

Specified by:
getMimeTypes in interface I_PublishFilter
Returns:
"*" This plugin handles all mime types

getMimeExtended

public java.lang.String[] getMimeExtended()
Get the content MIME version number for which this plugin applies

Specified by:
getMimeExtended in interface I_PublishFilter
Returns:
"1.0" (this is the default version number)

intercept

public java.lang.String intercept(SubjectInfo publisher,
                                  MsgUnit msgUnit)
                           throws XmlBlasterException
Delay the message for the configured amount of time. Please read the I_PublisheFilter.intercept() Javadoc.

Specified by:
intercept in interface I_PublishFilter
Parameters:
publisher - The subject object describing the publisher
msgUnit - The message to check
Returns:
"" or "OK": The message is accepted
Throws:
XmlBlasterException - Is thrown on problems, for example if the MIME type does not fit to message content.
Take care throwing an exception, as the exception is routed back to the publisher. If the publish() had many messages (a MsgUnit[]), all other messages are lost as well. Probably it is best to return 'ERROR' instead and log the situation.
See Also:
I_PublisheFilter#intercept(SubjectInfo, MsgUnit)

shutdown

public void shutdown()
Description copied from interface: I_Plugin
Cleans up the resource.

Specified by:
shutdown in interface I_PublishFilter
Specified by:
shutdown in interface I_Plugin

getDelayMillis

public long getDelayMillis()
Specified by:
getDelayMillis in interface PublishDelayerMBean

setDelayMillis

public void setDelayMillis(long delayMillis)
Specified by:
setDelayMillis in interface PublishDelayerMBean

getExceptionErrorCode

public java.lang.String getExceptionErrorCode()
Specified by:
getExceptionErrorCode in interface PublishDelayerMBean

setExceptionErrorCode

public void setExceptionErrorCode(java.lang.String exceptionErrorCode)
By setting an errorCode String != "" the published message is rejected with the given exception type. Typically used for testing.

Specified by:
setExceptionErrorCode in interface PublishDelayerMBean
Parameters:
exceptionErrorCode - e.g. "internal.publish" to be thrown
See Also:
ErrorCode

getFilterKeyOid

public java.lang.String getFilterKeyOid()
Specified by:
getFilterKeyOid in interface PublishDelayerMBean

setFilterKeyOid

public void setFilterKeyOid(java.lang.String filterKeyOid)
By setting a topicId != "" the plugin is only applied for the given messages oid. If set to "" all messages are checked.

Specified by:
setFilterKeyOid in interface PublishDelayerMBean
Parameters:
filterKeyOid - e.g. "Hello" to only slow down "Hello" messages, others are ignored
See Also:
ErrorCode

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.