xmlBlaster 2.2.0 contributions API

org.xmlBlaster.contrib.replication.impl
Class ReplManagerPlugin

java.lang.Object
  extended by org.xmlBlaster.contrib.GlobalInfo
      extended by org.xmlBlaster.contrib.replication.impl.ReplManagerPlugin
All Implemented Interfaces:
java.util.EventListener, org.xmlBlaster.authentication.I_ClientListener, org.xmlBlaster.client.I_Callback, ContribConstants, I_Info, ReplManagerPluginMBean, ReplicationConstants, org.xmlBlaster.engine.I_SubscriptionListener, org.xmlBlaster.engine.mime.I_PublishFilter, org.xmlBlaster.util.dispatch.I_ConnectionStatusListener, org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor, org.xmlBlaster.util.I_Timeout, org.xmlBlaster.util.plugin.I_Plugin

public class ReplManagerPlugin
extends GlobalInfo
implements ReplManagerPluginMBean, org.xmlBlaster.client.I_Callback, org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor, org.xmlBlaster.authentication.I_ClientListener, org.xmlBlaster.engine.I_SubscriptionListener, org.xmlBlaster.util.I_Timeout, ReplicationConstants, org.xmlBlaster.util.plugin.I_Plugin, org.xmlBlaster.engine.mime.I_PublishFilter

ReplManagerPlugin is a plugin wrapper if you want to run DbWatcher inside xmlBlaster.

DbWatcher checks a database for changes and publishes these to the MoM

This plugin needs to be registered in xmlBlasterPlugins.xml to be available on xmlBlaster server startup.

This plugin uses java.util.logging and redirects the logging to xmlBlasters default logging framework. You can switch this off by setting the attribute xmlBlaster/jdk14loggingCapture to false.

Author:
Michele Laghi

Field Summary
static java.lang.String SESSION_ID
           
 
Fields inherited from class org.xmlBlaster.contrib.GlobalInfo
global, LOWER_CASE, ORIGINAL_ENGINE_GLOBAL, pluginInfo, UNTOUCHED, UPPER_CASE
 
Fields inherited from interface org.xmlBlaster.engine.I_SubscriptionListener
PRIO_01, PRIO_05, PRIO_10
 
Fields inherited from interface org.xmlBlaster.contrib.replication.ReplicationConstants
ABSOLUTE_COUNT, ACTION_ATTR, ALREADY_PROCESSED_ATTR, ALTER_ACTION, CATALOG_ATTR, CONTRIB_PERSISTENT_MAP, CREATE_ACTION, DB_ID_ATTR, DELETE_ACTION, DROP_ACTION, DUMP_ACTION, DUMP_CONTENT_ATTR, DUMP_FILENAME, DUMP_POSTFIX, END_OF_TRANSITION, EXCEPTION_ATTR, EXTRA_REPL_KEY_ATTR, GUID_ATTR, INITIAL_DATA_END, INITIAL_DATA_END_TO_REMOTE, INITIAL_DATA_ID, INITIAL_DUMP_AS_XML, INITIAL_FILES_LOCATION, INITIAL_UPDATE_COLLECT, INITIAL_UPDATE_ONLY_REGISTER, INITIAL_UPDATE_START_BATCH, INITIAL_XML_CMD, INSERT_ACTION, KEEP_TRANSACTION_OPEN, MASTER_ATTR, MAX_ENTRIES_ATTR, MESSAGE_SEQ, NUM_OF_TRANSACTIONS, OLD_CONTENT_ATTR, PURPOSE_REPLICATION, REPL_KEY_ATTR, REPL_MANAGER_SESSION, REPL_MANAGER_TOPIC, REPL_PREFIX_DEFAULT, REPL_PREFIX_GROUP_KEY, REPL_PREFIX_KEY, REPL_REQUEST_CANCEL_UPDATE, REPL_REQUEST_RECREATE_TRIGGERS, REPL_REQUEST_UPDATE, REPL_VERSION, REPLICATION_CMD, REPLICATION_FORCE_SENDING, REPLICATION_MAX_ENTRIES_DEFAULT, REPLICATION_MAX_ENTRIES_KEY, REPLICATION_SEND_UNCHANGED_UPDATES, REPLICATION_VERSION, REQUEST_BROADCAST_SQL_TOPIC, REQUEST_CANCEL_UPDATE_TOPIC, REQUEST_INITIAL_DATA_TOPIC, REQUEST_RECREATE_TRIGGERS, RESPONSE_INITIAL_DATA_TOPIC, SCHEMA_ATTR, SIMPLE_MESSAGE, SLAVE_NAME, SQL_TOPIC_ATTR, STATEMENT_ACTION, STATEMENT_ATTR, STATEMENT_ID_ATTR, STATEMENT_PRIO_ATTR, SUPPORTED_VERSIONS, TABLE_NAME_ATTR, TRANSACTION_ATTR, TRANSACTION_SEQ, UPDATE_ACTION, VERSION_ATTR, VERSION_TOKEN
 
Fields inherited from interface org.xmlBlaster.contrib.ContribConstants
FILE_DATE, FILENAME_ATTR, FILENAME_ATTR_OLD_FASHION, SUBDIR_ATTR, TIMESTAMP_ATTR, TOPIC_NAME
 
Fields inherited from interface org.xmlBlaster.contrib.I_Info
ID, JMX_PREFIX
 
Constructor Summary
ReplManagerPlugin()
          Default constructor, you need to call init() thereafter.
 
Method Summary
 java.lang.String activateSlaveDispatchers(java.lang.String replPrefix)
           
 void addDispatchManager(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager)
          This method is invoked always so see sessionAdded javadoc.
 void broadcastSql(java.lang.String repl, java.lang.String sql)
          Executes either a query or an update.
static java.io.File checkExistance(java.lang.String pathName)
           
 void clearVersionCache()
           
 java.lang.String collectInitialUpdates(java.lang.String replicationPrefix)
          Sends a message to the initial updates to collect all requests of initial updates for this replPrefix.
 boolean doActivate(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager)
          If there are new messages available in the queue, you get invoked here and are asked if you want to start a worker thread (from the thread pool) to start taking messages from the queue and send them over the remote connection.
 void doExecuteSchedulerJob(boolean open, java.lang.String prefix, java.lang.String dest)
           
protected  void doInit(org.xmlBlaster.util.Global global, org.xmlBlaster.util.plugin.PluginInfo pluginInfo)
           
static byte[] getContent(java.io.InputStream is)
           
 long[] getCurrentTransactionCount(java.lang.String replPrefix)
           
 java.lang.String getInitialFilesLocation()
          Returns the (default) initialFileLocation which is the directory where the initial data is stored in case you want to transfer it per file.
 java.lang.String getInstanceName()
           
 org.xmlBlaster.engine.admin.I_AdminSession getMasterSession(java.lang.String replicationPrefix)
           
 int getMaxNumOfEntries()
           
 java.lang.String[] getMimeExtended()
          Get the content MIME version number for which this plugin applies.
 java.lang.String[] getMimeTypes()
          Get the content MIME types for which this plugin applies, "*" is for all mime types
 java.lang.String getName()
          Get a human readable name of this filter implementation
 long getNumOfRefreshes()
          Returns the number of refreshes occured (to get the status of the slaves).
 I_Info getPersistentInfo()
           
static java.lang.String getPluginName()
           
 java.lang.Integer getPriority()
          The priority by which it will be invoked.
 I_Info getReplicationInfo(java.lang.String replicationPrefix)
          Gets the properties associated to this replication.
 java.lang.String getReplications()
          Never returns null.
 org.xmlBlaster.engine.admin.I_AdminSession getSession(java.lang.String sessionId)
           
 I_ReplSlave getSlave(java.lang.String name)
           
 java.lang.String getSlaves()
          Never returns null.
 long getStatusPollerInterval()
          This method returns the polling interval for retrieval of the status data of the slaves which has to be retrieved asynchronously in order not to block the monitor.
 long getStatusProcessingTime()
          Returns the time in milliseconds it took to retrieve all the status information for all the slaves.
 java.lang.String getType()
          The plugin name as configured im xmlBlasterPlugins.xml
 java.lang.String getVersion()
          The plugin version as configured in xmlBlasterPlugins.xml
 java.util.List<org.xmlBlaster.util.queue.I_Entry> handleNextMessages(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager, java.util.List<org.xmlBlaster.util.queue.I_Entry> pushEntries)
          If you returned true from doActivate() the worker thread will ask us to retrieve the next messages from the queue (dispatchManager.getQueue()).
 void initialize(org.xmlBlaster.util.Global glob, java.lang.String typeVersion)
          Is called once only after the instance is created.
 void initialize(org.xmlBlaster.engine.ServerScope glob)
          This is called after instantiation of the plugin
 java.lang.String initiateReplication(java.lang.String slaveSessionName, java.lang.String prefixWithVersion, java.lang.String cascadeSlaveSessionName, java.lang.String cascadeReplicationPrefix, java.lang.String realInitialFilesLocation)
          Intiates the replication for the given slave.
 java.lang.String initiateReplicationNonMBean(java.lang.String slaveSessionName, java.lang.String prefixWithVersion, java.lang.String cascadeSlaveSessionName, java.lang.String cascadeReplicationPrefix, java.lang.String realInitialFilesLocation)
          Intiates the replication for the given slave.
 java.lang.String intercept(org.xmlBlaster.authentication.SubjectInfo publisher, org.xmlBlaster.util.MsgUnit msgUnit)
          Is only invoked when it is configured as a MimePlugin (to count messages containing several transactions).
 boolean isShutdown()
           
static void main(java.lang.String[] args)
           
 void onDispatchWorkerException(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager, java.lang.Throwable ex)
          Invoked when the dispatching failed due to an exception.
 void postHandleNextMessages(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager, org.xmlBlaster.util.MsgUnit[] processedEntries)
          Does cleanup, particularly it sets the status and counters.
static long[] readOldReplData(I_Info persistentInfo, java.lang.String propName)
           
 java.lang.String recreateTriggers(java.lang.String replPrefix)
          Recreates the triggers for the given replication source.
 void register(java.lang.String senderSession, java.lang.String replicationPrefix, I_Info info)
          Used to register a dbWatcher.
 java.lang.String reInitiate(java.lang.String replPrefix)
          This will start an initial update for all slaves replicating from the specified replPrefix.
 void removeSqlStatement(java.lang.String statementId)
           
 void sessionAdded(org.xmlBlaster.authentication.ClientEvent e)
          The part of this code inherent to the slave could be moved to the addDispatchManager since that method would always invoked too.
 void sessionPreRemoved(org.xmlBlaster.authentication.ClientEvent e)
          Invoked before a client does a logout
 void sessionRemoved(org.xmlBlaster.authentication.ClientEvent e)
          Invoked when client does a logout
 void sessionUpdated(org.xmlBlaster.authentication.ClientEvent e)
          Invoked on successful client re-login (interface I_ClientListener)
 void setMaxNumOfEntries(int maxNumOfEntries)
           
 void setStatusPollerInterval(long statusPollerInterval)
          This method sets the polling interval for retrieval of the status data of the slaves which has to be retrieved asynchronously in order not to block the monitor.
 void shutdown()
          Cleans up the resource.
 void shutdown(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager)
          Deregister the given dispatchManager
 java.lang.String startBatchUpdate(java.lang.String replicationPrefix)
          Sends a message to the initial updater for the replPrefix that it can start the initial update for all collected (registered) slaves.
 java.lang.String stopSlaveDispatchers(java.lang.String replPrefix)
           
static void storeReplData(I_Info persistentInfo, java.lang.String propName, long[] values)
           
 void subjectAdded(org.xmlBlaster.authentication.ClientEvent e)
          Invoked on first successful client login, when SubjectInfo is created
 void subjectRemoved(org.xmlBlaster.authentication.ClientEvent e)
          Invoked when client does its last logout
 void subscriptionAdd(org.xmlBlaster.engine.SubscriptionEvent e)
          To make it simpler one could think to put this method together with sessionAdded.
 void subscriptionRemove(org.xmlBlaster.engine.SubscriptionEvent e)
          Invoked when subscription does a logout
 void timeout(java.lang.Object userData)
          You will be notified about the timeout through this method.
 void toAlive(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState)
           
 void toAliveSync(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState)
           
 void toDead(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState, org.xmlBlaster.util.XmlBlasterException xmlBlasterException)
           
 void toPolling(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState)
           
 java.lang.String toXml(java.lang.String extraOffset)
           
 byte[] transformVersion(java.lang.String replPrefix, java.lang.String destVersion, java.lang.String destination, byte[] content)
           
 java.lang.String transformVersion(java.lang.String replPrefix, java.lang.String destVersion, java.lang.String destination, java.lang.String is)
          Performs a version transformation from one version to the other.
 byte[] transformVersion(java.lang.String replPrefix, java.lang.String srcVersion, java.lang.String destVersion, java.lang.String destination, byte[] srcData)
           
 void unregister(java.lang.String senderSession, java.lang.String replicationPrefix)
           
 java.lang.String update(java.lang.String cbSessionId, org.xmlBlaster.client.key.UpdateKey updateKey, byte[] content, org.xmlBlaster.client.qos.UpdateQos updateQos)
          It receives events from all ReplicationConverter instances which want to register themselves for administration of initial updates.
 java.lang.String usage()
           
 
Methods inherited from class org.xmlBlaster.contrib.GlobalInfo
dump, get, getBoolean, getGlobal, getInt, getKeys, getLong, getObject, getObjectKeys, getOriginalGlobal, getRaw, getStrippedString, init, loadPlugin, put, putObject, putRaw, replaceAllEntries, setStrippedHostname
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xmlBlaster.util.plugin.I_Plugin
init
 

Field Detail

SESSION_ID

public static final java.lang.String SESSION_ID
See Also:
Constant Field Values
Constructor Detail

ReplManagerPlugin

public ReplManagerPlugin()
Default constructor, you need to call init() thereafter.

Method Detail

transformVersion

public byte[] transformVersion(java.lang.String replPrefix,
                               java.lang.String srcVersion,
                               java.lang.String destVersion,
                               java.lang.String destination,
                               byte[] srcData)
                        throws java.lang.Exception
Throws:
java.lang.Exception

transformVersion

public byte[] transformVersion(java.lang.String replPrefix,
                               java.lang.String destVersion,
                               java.lang.String destination,
                               byte[] content)
                        throws java.lang.Exception
Throws:
java.lang.Exception

transformVersion

public java.lang.String transformVersion(java.lang.String replPrefix,
                                         java.lang.String destVersion,
                                         java.lang.String destination,
                                         java.lang.String is)
                                  throws java.lang.Exception
Description copied from interface: ReplManagerPluginMBean
Performs a version transformation from one version to the other.

Specified by:
transformVersion in interface ReplManagerPluginMBean
Parameters:
replPrefix - The replication prefix of the source to be used.
destVersion - The desidered version on the destination
destination - The session name of the destination.
is - The content of the data to be transformed
Returns:
the transformed string.
Throws:
java.lang.Exception

clearVersionCache

public void clearVersionCache()
Specified by:
clearVersionCache in interface ReplManagerPluginMBean

getSlave

public I_ReplSlave getSlave(java.lang.String name)
Parameters:
name - the slave associated with this name or null if none found.
Returns:

reInitiate

public java.lang.String reInitiate(java.lang.String replPrefix)
Description copied from interface: ReplManagerPluginMBean
This will start an initial update for all slaves replicating from the specified replPrefix. Note that this operation only can be used if the slaves have already been initiated before. The registration for initial updates will be done automatically but you still have to manually start the batch update for all these slaves manually with the startBatchUpdate command to the same replPrefix.

Specified by:
reInitiate in interface ReplManagerPluginMBean
Returns:

getSlaves

public java.lang.String getSlaves()
Never returns null. It returns a list of keys identifying the slaves using the replication manager.

Specified by:
getSlaves in interface ReplManagerPluginMBean
Returns:

getReplications

public java.lang.String getReplications()
Never returns null. It returns a list of keys identifying the ongoing replications.

Specified by:
getReplications in interface ReplManagerPluginMBean
Returns:

getPluginName

public static java.lang.String getPluginName()

getType

public java.lang.String getType()
Description copied from class: GlobalInfo
The plugin name as configured im xmlBlasterPlugins.xml

Specified by:
getType in interface org.xmlBlaster.util.plugin.I_Plugin
Overrides:
getType in class GlobalInfo
See Also:
I_Plugin.getType()

getVersion

public java.lang.String getVersion()
Description copied from class: GlobalInfo
The plugin version as configured in xmlBlasterPlugins.xml

Specified by:
getVersion in interface org.xmlBlaster.util.plugin.I_Plugin
Overrides:
getVersion in class GlobalInfo
See Also:
I_Plugin.getVersion()

initiateReplication

public java.lang.String initiateReplication(java.lang.String slaveSessionName,
                                            java.lang.String prefixWithVersion,
                                            java.lang.String cascadeSlaveSessionName,
                                            java.lang.String cascadeReplicationPrefix,
                                            java.lang.String realInitialFilesLocation)
Intiates the replication for the given slave. TODO Specify that the replicationKey (dbmasterid) must be short and DB conform. Usually called by Humans via JMX Console. The cascaded replication is the replication which will be automatically started once the initial update of the first replication is finished. This is used to concatenate replications. A typical usecase is in two way replication, then the initial update of the back replication can be automatically triggered once the initial update of the main replication is finished.

Specified by:
initiateReplication in interface ReplManagerPluginMBean
Parameters:
slaveSessionName -
replicationKey - This is the dbWatcher replication.prefix attribute.
cascadeSlaveSessionName - The Name of the session of the dbWriter to be used for the cascaded replication. Can be null.
cascadedReplicationPrefix - the prefix identifing the DbWatcher for the cascaded replication. Can be null.
realInitialFilesLocation - the file location where the initial dump is stored. If null or an empty String, then it is assumed to be transfered the "normal" way, that is over the choosen communication protocol.

initiateReplicationNonMBean

public java.lang.String initiateReplicationNonMBean(java.lang.String slaveSessionName,
                                                    java.lang.String prefixWithVersion,
                                                    java.lang.String cascadeSlaveSessionName,
                                                    java.lang.String cascadeReplicationPrefix,
                                                    java.lang.String realInitialFilesLocation)
                                             throws java.lang.Exception
Intiates the replication for the given slave. TODO Specify that the replicationKey (dbmasterid) must be short and DB conform. The cascaded replication is the replication which will be automatically started once the initial update of the first replication is finished. This is used to concatenate replications. A typical usecase is in two way replication, then the initial update of the back replication can be automatically triggered once the initial update of the main replication is finished.

Parameters:
slaveSessionName -
replicationKey - This is the dbWatcher replication.prefix attribute.
cascadeSlaveSessionName - The Name of the session of the dbWriter to be used for the cascaded replication. Can be null.
cascadedReplicationPrefix - the prefix identifing the DbWatcher for the cascaded replication. Can be null.
realInitialFilesLocation - the file location where the initial dump is stored. If null or an empty String, then it is assumed to be transfered the "normal" way, that is over the choosen communication protocol.
Throws:
java.lang.Exception

doInit

protected void doInit(org.xmlBlaster.util.Global global,
                      org.xmlBlaster.util.plugin.PluginInfo pluginInfo)
               throws org.xmlBlaster.util.XmlBlasterException
Specified by:
doInit in class GlobalInfo
Parameters:
global - The global passed by the RunLevelManager, this is not the object owned by the plugin. It is the original global.
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_Plugin.init(org.xmlBlaster.util.Global, org.xmlBlaster.util.plugin.PluginInfo)

shutdown

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

Specified by:
shutdown in interface org.xmlBlaster.engine.mime.I_PublishFilter
Specified by:
shutdown in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Specified by:
shutdown in interface org.xmlBlaster.util.plugin.I_Plugin
Overrides:
shutdown in class GlobalInfo
See Also:
I_Plugin.shutdown()

getReplicationInfo

public I_Info getReplicationInfo(java.lang.String replicationPrefix)
Gets the properties associated to this replication. Note that the info is this of the last registration. This method can return null if no object is found or if the replicationPrefix was null.

Parameters:
replicationPrefix -
Returns:

register

public void register(java.lang.String senderSession,
                     java.lang.String replicationPrefix,
                     I_Info info)
Used to register a dbWatcher. This is a request coming directly from the DbWatcher which registeres himself to this plugin. Note that if you are using the same id for the replication on several DbWatcher (several writers) only the first dbWatcher will pass the configuration. You are responsible of ensuring that the relevant configuration parameters are the same for all such DbWatcher instances.

Parameters:
senderSession - The session requesting this registration. This is needed to reply to the right requestor.
replId -
info - These are the Configuration of the DbWatcher, for example Table Names and so forth.

unregister

public void unregister(java.lang.String senderSession,
                       java.lang.String replicationPrefix)

getContent

public static byte[] getContent(java.io.InputStream is)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

update

public java.lang.String update(java.lang.String cbSessionId,
                               org.xmlBlaster.client.key.UpdateKey updateKey,
                               byte[] content,
                               org.xmlBlaster.client.qos.UpdateQos updateQos)
                        throws org.xmlBlaster.util.XmlBlasterException
It receives events from all ReplicationConverter instances which want to register themselves for administration of initial updates.

Specified by:
update in interface org.xmlBlaster.client.I_Callback
Parameters:
cbSessionId - The session ID specified by the client which registered the callback. You can specify a cbSessionId during connection (with ConnectQos) and this is bounced back here so you can authenticate the message.
updateKey - The arrived key containing the topic name
content - The arrived message content. This is your payload.
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_Callback.update(java.lang.String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)

addDispatchManager

public void addDispatchManager(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager)
This method is invoked always so see sessionAdded javadoc.

Specified by:
addDispatchManager in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
See Also:
org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor#addDispatchManager(org.xmlBlaster.util.dispatch.DispatchManager)

getInstanceName

public java.lang.String getInstanceName()

doActivate

public boolean doActivate(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager)
Description copied from interface: org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
If there are new messages available in the queue, you get invoked here and are asked if you want to start a worker thread (from the thread pool) to start taking messages from the queue and send them over the remote connection.

Note: If the session cb is in polling and the callback queue contains entries and you return true, the dispatchWorker thread will loop! In such a case check with

 if (dispatchManager.getDispatchConnectionsHandler().isPolling()) {
     return false;
  }
 

Specified by:
doActivate in interface org.xmlBlaster.util.dispatch.plugins.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:
org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor#doActivate(org.xmlBlaster.util.dispatch.DispatchManager)

handleNextMessages

public java.util.List<org.xmlBlaster.util.queue.I_Entry> handleNextMessages(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager,
                                                                            java.util.List<org.xmlBlaster.util.queue.I_Entry> pushEntries)
                                                                     throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
If you returned true from doActivate() the worker thread will ask us to retrieve the next messages from the queue (dispatchManager.getQueue()).

This is where this plugin comes in action. The plugin may filter the queue entries and for example only return high priority messages

Usually you take the message out of the queue and then invoke prepareMsgsFromQueue() to filter expired messages away and do a shallow copy of the messages to avoid that changes in the messages have impact on the original messages. See the following example:

  // take messages from queue (none blocking)
  // we take all messages with same priority as a bulk ...
  ArrayList entryList = dispatchManager.getQueue().peekSamePriority(-1);

  // filter expired entries etc. ...
  // you should always call this method after taking messages from queue
  entryList = dispatchManager.prepareMsgsFromQueue(entryList);

  // ... do plugin specific work ...

  return entryList;
 

Specified by:
handleNextMessages in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
pushEntries - 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:
org.xmlBlaster.util.XmlBlasterException
See Also:
org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor#handleNextMessages(org.xmlBlaster.util.dispatch.DispatchManager, java.util.ArrayList)

initialize

public void initialize(org.xmlBlaster.util.Global glob,
                       java.lang.String typeVersion)
                throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Is called once only after the instance is created.

Specified by:
initialize in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_MsgDispatchInterceptor.initialize(org.xmlBlaster.util.Global, java.lang.String)

isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Returns:
true if shutdown
See Also:
I_MsgDispatchInterceptor.isShutdown()

shutdown

public void shutdown(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager)
              throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Deregister the given dispatchManager

Specified by:
shutdown in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor#shutdown(org.xmlBlaster.util.dispatch.DispatchManager)

toXml

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

usage

public java.lang.String usage()
Specified by:
usage in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Returns:
a human readable usage help string
See Also:
I_MsgDispatchInterceptor.usage()

toAlive

public void toAlive(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager,
                    org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState)
Specified by:
toAlive in interface org.xmlBlaster.util.dispatch.I_ConnectionStatusListener
See Also:
org.xmlBlaster.util.dispatch.I_ConnectionStatusListener#toAlive(org.xmlBlaster.util.dispatch.DispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum)

toAliveSync

public void toAliveSync(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager,
                        org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState)
Specified by:
toAliveSync in interface org.xmlBlaster.util.dispatch.I_ConnectionStatusListener

toDead

public void toDead(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager,
                   org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState,
                   org.xmlBlaster.util.XmlBlasterException xmlBlasterException)
Specified by:
toDead in interface org.xmlBlaster.util.dispatch.I_ConnectionStatusListener
xmlBlasterException - Can be null
See Also:
org.xmlBlaster.util.dispatch.I_ConnectionStatusListener#toDead(org.xmlBlaster.util.dispatch.DispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum, XmlBlasterException)

toPolling

public void toPolling(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager,
                      org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState)
Specified by:
toPolling in interface org.xmlBlaster.util.dispatch.I_ConnectionStatusListener
See Also:
org.xmlBlaster.util.dispatch.I_ConnectionStatusListener#toPolling(org.xmlBlaster.util.dispatch.DispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum)

removeSqlStatement

public void removeSqlStatement(java.lang.String statementId)
Specified by:
removeSqlStatement in interface ReplManagerPluginMBean

broadcastSql

public void broadcastSql(java.lang.String repl,
                         java.lang.String sql)
                  throws java.lang.Exception
Description copied from interface: ReplManagerPluginMBean
Executes either a query or an update. Responses will come back asynchronously.

Specified by:
broadcastSql in interface ReplManagerPluginMBean
Parameters:
repl - The replication to which to send the request.
sql - The sql statement to perform (can either be a query or an update).
Throws:
java.lang.Exception - if either the repl or sql was null.
See Also:
ReplManagerPluginMBean.broadcastSql(java.lang.String, java.lang.String)

sessionAdded

public void sessionAdded(org.xmlBlaster.authentication.ClientEvent e)
                  throws org.xmlBlaster.util.XmlBlasterException
The part of this code inherent to the slave could be moved to the addDispatchManager since that method would always invoked too. This method is only invoked on the first connect, which is when the client connects the very first time, or when recovering sessions from persistence.

Specified by:
sessionAdded in interface org.xmlBlaster.authentication.I_ClientListener
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_ClientListener.sessionAdded(org.xmlBlaster.authentication.ClientEvent)

sessionUpdated

public void sessionUpdated(org.xmlBlaster.authentication.ClientEvent e)
                    throws org.xmlBlaster.util.XmlBlasterException
Invoked on successful client re-login (interface I_ClientListener)

Specified by:
sessionUpdated in interface org.xmlBlaster.authentication.I_ClientListener
Throws:
org.xmlBlaster.util.XmlBlasterException

sessionPreRemoved

public void sessionPreRemoved(org.xmlBlaster.authentication.ClientEvent e)
                       throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.authentication.I_ClientListener
Invoked before a client does a logout

Specified by:
sessionPreRemoved in interface org.xmlBlaster.authentication.I_ClientListener
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_ClientListener.sessionPreRemoved(org.xmlBlaster.authentication.ClientEvent)

sessionRemoved

public void sessionRemoved(org.xmlBlaster.authentication.ClientEvent e)
                    throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.authentication.I_ClientListener
Invoked when client does a logout

Specified by:
sessionRemoved in interface org.xmlBlaster.authentication.I_ClientListener
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_ClientListener.sessionRemoved(org.xmlBlaster.authentication.ClientEvent)

subjectAdded

public void subjectAdded(org.xmlBlaster.authentication.ClientEvent e)
                  throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.authentication.I_ClientListener
Invoked on first successful client login, when SubjectInfo is created

Specified by:
subjectAdded in interface org.xmlBlaster.authentication.I_ClientListener
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_ClientListener.subjectAdded(org.xmlBlaster.authentication.ClientEvent)

subjectRemoved

public void subjectRemoved(org.xmlBlaster.authentication.ClientEvent e)
                    throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.authentication.I_ClientListener
Invoked when client does its last logout

Specified by:
subjectRemoved in interface org.xmlBlaster.authentication.I_ClientListener
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_ClientListener.subjectRemoved(org.xmlBlaster.authentication.ClientEvent)

getPriority

public java.lang.Integer getPriority()
Description copied from interface: org.xmlBlaster.engine.I_SubscriptionListener
The priority by which it will be invoked. Lower numbers are invoked first on subscribe and last on unsubscribe.

Specified by:
getPriority in interface org.xmlBlaster.engine.I_SubscriptionListener
Returns:
See Also:
I_SubscriptionListener.getPriority()

subscriptionAdd

public void subscriptionAdd(org.xmlBlaster.engine.SubscriptionEvent e)
                     throws org.xmlBlaster.util.XmlBlasterException
To make it simpler one could think to put this method together with sessionAdded. This is however not possible since at the time the initiateReplication is invoked, the subcription is done for the first time. However if sessionAdded was not invoked previously, there would no be any chance to know that this is wanting to subscribe. It checks if the event is for one of our guys and dispatches the call to them

Specified by:
subscriptionAdd in interface org.xmlBlaster.engine.I_SubscriptionListener
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_SubscriptionListener.subscriptionAdd(org.xmlBlaster.engine.SubscriptionEvent)

subscriptionRemove

public void subscriptionRemove(org.xmlBlaster.engine.SubscriptionEvent e)
                        throws org.xmlBlaster.util.XmlBlasterException
Description copied from interface: org.xmlBlaster.engine.I_SubscriptionListener
Invoked when subscription does a logout

Specified by:
subscriptionRemove in interface org.xmlBlaster.engine.I_SubscriptionListener
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_SubscriptionListener.subscriptionRemove(org.xmlBlaster.engine.SubscriptionEvent)

recreateTriggers

public final java.lang.String recreateTriggers(java.lang.String replPrefix)
                                        throws java.lang.Exception
Description copied from interface: ReplManagerPluginMBean
Recreates the triggers for the given replication source.

Specified by:
recreateTriggers in interface ReplManagerPluginMBean
Parameters:
replPrefix - this is the same as specified in the configuration as 'replication.prefix' and it identifies a replication source.
Throws:
java.lang.Exception

getInitialFilesLocation

public java.lang.String getInitialFilesLocation()
Description copied from interface: ReplManagerPluginMBean
Returns the (default) initialFileLocation which is the directory where the initial data is stored in case you want to transfer it per file.

Specified by:
getInitialFilesLocation in interface ReplManagerPluginMBean
Returns:

checkExistance

public static java.io.File checkExistance(java.lang.String pathName)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)

timeout

public void timeout(java.lang.Object userData)
Description copied from interface: org.xmlBlaster.util.I_Timeout
You will be notified about the timeout through this method.

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

getStatusPollerInterval

public long getStatusPollerInterval()
Description copied from interface: ReplManagerPluginMBean
This method returns the polling interval for retrieval of the status data of the slaves which has to be retrieved asynchronously in order not to block the monitor.

Specified by:
getStatusPollerInterval in interface ReplManagerPluginMBean
Returns:

getNumOfRefreshes

public long getNumOfRefreshes()
Description copied from interface: ReplManagerPluginMBean
Returns the number of refreshes occured (to get the status of the slaves).

Specified by:
getNumOfRefreshes in interface ReplManagerPluginMBean
Returns:

setStatusPollerInterval

public void setStatusPollerInterval(long statusPollerInterval)
Description copied from interface: ReplManagerPluginMBean
This method sets the polling interval for retrieval of the status data of the slaves which has to be retrieved asynchronously in order not to block the monitor. If you set it to zero or a negative value it will not refresh.

Specified by:
setStatusPollerInterval in interface ReplManagerPluginMBean

getStatusProcessingTime

public long getStatusProcessingTime()
Description copied from interface: ReplManagerPluginMBean
Returns the time in milliseconds it took to retrieve all the status information for all the slaves.

Specified by:
getStatusProcessingTime in interface ReplManagerPluginMBean
Returns:

postHandleNextMessages

public void postHandleNextMessages(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager,
                                   org.xmlBlaster.util.MsgUnit[] processedEntries)
                            throws org.xmlBlaster.util.XmlBlasterException
Does cleanup, particularly it sets the status and counters.

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

onDispatchWorkerException

public void onDispatchWorkerException(org.xmlBlaster.util.dispatch.I_DispatchManager dispatchManager,
                                      java.lang.Throwable ex)
Description copied from interface: org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor
Invoked when the dispatching failed due to an exception. This way the implementation of the plugin gets a notification that an exception occurred.

Specified by:
onDispatchWorkerException in interface org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor

startBatchUpdate

public java.lang.String startBatchUpdate(java.lang.String replicationPrefix)
Description copied from interface: ReplManagerPluginMBean
Sends a message to the initial updater for the replPrefix that it can start the initial update for all collected (registered) slaves. It will only use one single source per version, so if you have 10 Slaves interested in version 1.0 and 5 interested in version 2.0 only two sources (two exports) will be done.

Specified by:
startBatchUpdate in interface ReplManagerPluginMBean
Returns:

collectInitialUpdates

public java.lang.String collectInitialUpdates(java.lang.String replicationPrefix)
Description copied from interface: ReplManagerPluginMBean
Sends a message to the initial updates to collect all requests of initial updates for this replPrefix.

Specified by:
collectInitialUpdates in interface ReplManagerPluginMBean
Returns:

activateSlaveDispatchers

public java.lang.String activateSlaveDispatchers(java.lang.String replPrefix)
Specified by:
activateSlaveDispatchers in interface ReplManagerPluginMBean

stopSlaveDispatchers

public java.lang.String stopSlaveDispatchers(java.lang.String replPrefix)
Specified by:
stopSlaveDispatchers in interface ReplManagerPluginMBean

getPersistentInfo

public I_Info getPersistentInfo()

getMimeExtended

public java.lang.String[] getMimeExtended()
Description copied from interface: org.xmlBlaster.engine.mime.I_PublishFilter
Get the content MIME version number for which this plugin applies. The returned String array length must be the same as this of getMimeTypes(), the index corresponds to the index of getMimeTypes().
For example "stable" is the extended mime type of "application/mytext" (see getMimeTypes()).

Specified by:
getMimeExtended in interface org.xmlBlaster.engine.mime.I_PublishFilter
Returns:
E.g. a string array like { "1.0", "1.3", "stable" }

getMimeTypes

public java.lang.String[] getMimeTypes()
Description copied from interface: org.xmlBlaster.engine.mime.I_PublishFilter
Get the content MIME types for which this plugin applies, "*" is for all mime types

Specified by:
getMimeTypes in interface org.xmlBlaster.engine.mime.I_PublishFilter
Returns:
The supported mime types, for example return { "text/plain", "text/xml", "application/mytext" };

getName

public java.lang.String getName()
Description copied from interface: org.xmlBlaster.engine.mime.I_PublishFilter
Get a human readable name of this filter implementation

Specified by:
getName in interface org.xmlBlaster.engine.mime.I_PublishFilter

initialize

public void initialize(org.xmlBlaster.engine.ServerScope glob)
Description copied from interface: org.xmlBlaster.engine.mime.I_PublishFilter
This is called after instantiation of the plugin

Specified by:
initialize in interface org.xmlBlaster.engine.mime.I_PublishFilter
Parameters:
glob - The Global handle of this xmlBlaster server instance.

intercept

public java.lang.String intercept(org.xmlBlaster.authentication.SubjectInfo publisher,
                                  org.xmlBlaster.util.MsgUnit msgUnit)
                           throws org.xmlBlaster.util.XmlBlasterException
Is only invoked when it is configured as a MimePlugin (to count messages containing several transactions). MimePublishPlugin[ReplManagerPlugin][1.0]=\ org.xmlBlaster.contrib.replication.impl.ReplManagerPlugin

Specified by:
intercept in interface org.xmlBlaster.engine.mime.I_PublishFilter
Parameters:
publisher - The subject object describing the publisher
msgUnit - The message to check
Returns:
"" or "OK": The message is accepted
Any other string: The message is rejected and your string is passed back to the publisher.
Throws:
org.xmlBlaster.util.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.

getCurrentTransactionCount

public long[] getCurrentTransactionCount(java.lang.String replPrefix)

readOldReplData

public static long[] readOldReplData(I_Info persistentInfo,
                                     java.lang.String propName)

storeReplData

public static void storeReplData(I_Info persistentInfo,
                                 java.lang.String propName,
                                 long[] values)

setMaxNumOfEntries

public void setMaxNumOfEntries(int maxNumOfEntries)
Specified by:
setMaxNumOfEntries in interface ReplManagerPluginMBean

getMaxNumOfEntries

public int getMaxNumOfEntries()
Specified by:
getMaxNumOfEntries in interface ReplManagerPluginMBean

getSession

public org.xmlBlaster.engine.admin.I_AdminSession getSession(java.lang.String sessionId)
                                                      throws java.lang.Exception
Throws:
java.lang.Exception

getMasterSession

public org.xmlBlaster.engine.admin.I_AdminSession getMasterSession(java.lang.String replicationPrefix)
                                                            throws java.lang.Exception
Throws:
java.lang.Exception

doExecuteSchedulerJob

public void doExecuteSchedulerJob(boolean open,
                                  java.lang.String prefix,
                                  java.lang.String dest)

xmlBlaster 2.2.0 contributions API

Copyright © 1999-2014 The xmlBlaster.org contributers.