xmlBlaster 2.2.0 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, I_ClientListener, I_Callback, ContribConstants, I_Info, ReplManagerPluginMBean, ReplicationConstants, I_SubscriptionListener, I_PublishFilter, I_ConnectionStatusListener, I_MsgDispatchInterceptor, I_Timeout, I_Plugin

public class ReplManagerPlugin
extends GlobalInfo
implements ReplManagerPluginMBean, I_Callback, I_MsgDispatchInterceptor, I_ClientListener, I_SubscriptionListener, I_Timeout, ReplicationConstants, I_Plugin, 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

Nested Class Summary
private  class ReplManagerPlugin.Counter
           
 
Field Summary
private  java.lang.String cachedListOfReplications
           
private  java.util.Map counterMap
           
private  java.util.Set initialDataTopicSet
           
private  java.lang.String initialFilesLocation
           
private  boolean initialized
           
private  java.lang.String instanceName
           
private static java.util.logging.Logger log
           
private  int maxNumOfEntries
           
private  long maxResponseEntries
           
private  long maxSize
           
private  java.lang.Object mbeanHandle
           
private static java.lang.String ME
           
private  long numRefresh
           
private  java.lang.String password
           
private  I_Info persistentInfo
           
private  I_DbPool pool
           
private  java.util.Map replications
           
private  java.util.Map replSlaveMap
           
private static java.lang.String SENDER_SESSION
           
static java.lang.String SESSION_ID
           
private  boolean shutdown
           
private  java.util.Map sqlStatementMap
          Keys are requestId Strings, and values are SqlStatement objects
private  java.lang.String sqlTopic
           
private static long STATUS_POLLER_INTERVAL_DEFAULT
           
private  long statusPollerInterval
           
private  long statusProcessingTime
           
private  Timeout timeout
           
private  Timestamp timeoutHandle
           
private  java.util.Map topicToPrefixMap
           
private  VersionTransformerCache transformerCache
           
private  java.lang.String user
           
 
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(I_DispatchManager dispatchManager)
          This method is invoked always so see sessionAdded javadoc.
private  void addIfNotSet(java.lang.String key, java.lang.String defValue)
           
 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(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(Global global, PluginInfo pluginInfo)
           
private  I_ReplSlave[] getAllSlaves()
           
static byte[] getContent(java.io.InputStream is)
           
 long[] getCurrentTransactionCount(java.lang.String replPrefix)
           
private  ServerScope getEngineGlobal(Global glob)
           
 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()
           
 I_AdminSession getMasterSession(java.lang.String replicationPrefix)
           
 int getMaxNumOfEntries()
           
private  int getMaxNumOfEntries(I_ReplSlave slave)
          TODO implement this
 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.
 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<I_Entry> handleNextMessages(I_DispatchManager dispatchManager, java.util.List<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()).
private  boolean hasUsAsDispatchPlugin(ConnectQosServer connQos)
          Convenience method to determine if a connect Qos is for us, i.e.
 void initialize(Global glob, java.lang.String typeVersion)
          Is called once only after the instance is created.
 void initialize(ServerScope glob)
          This is called after instantiation of the plugin
private  I_DbPool initializePersistentInfo()
          Creates a I_DbPool object using the defaults out of the JDBC,1.0 Queue Properties and initializes the pool.
 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(SubjectInfo publisher, 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)
           
private static void mainUsage()
           
 void onDispatchWorkerException(I_DispatchManager dispatchManager, java.lang.Throwable ex)
          Invoked when the dispatching failed due to an exception.
private static long parseLong(java.lang.String val, long def)
           
 void postHandleNextMessages(I_DispatchManager dispatchManager, MsgUnit[] processedEntries)
          Does cleanup, particularly it sets the status and counters.
private  java.lang.String processDeadLetter(UpdateQos qos)
           
private  java.lang.String publishSimpleMessage(java.lang.String replicationPrefix, java.lang.String msgTxt)
           
static long[] readOldReplData(I_Info persistentInfo, java.lang.String propName)
           
private static long[] readOldReplDataOldStyle(I_Info persistentInfo, java.lang.String propName)
          Deprecated.  
 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.
private  void registerSqlStatement(java.lang.String replPrefix, java.lang.String reqId, java.lang.String statement)
           
 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)
           
private  void sendBroadcastRequest(java.lang.String replicationPrefix, java.lang.String sql, boolean isHighPrio, java.lang.String requestId)
           
 void sessionAdded(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(ClientEvent e)
          Invoked before a client does a logout
 void sessionRemoved(ClientEvent e)
          Invoked when client does a logout
 void sessionUpdated(ClientEvent e)
          Invoked on successful client re-login (interface I_ClientListener)
private  java.lang.String setDispatcher(boolean alive, java.lang.String replPrefix)
           
(package private)  void setEngineGlobalProperty(java.lang.String key, java.lang.String val)
           
 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(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(ClientEvent e)
          Invoked on first successful client login, when SubjectInfo is created
 void subjectRemoved(ClientEvent e)
          Invoked when client does its last logout
 void subscriptionAdd(SubscriptionEvent e)
          To make it simpler one could think to put this method together with sessionAdded.
 void subscriptionRemove(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(I_DispatchManager dispatchManager, ConnectionStateEnum oldState)
           
 void toAliveSync(I_DispatchManager dispatchManager, ConnectionStateEnum oldState)
           
 void toDead(I_DispatchManager dispatchManager, ConnectionStateEnum oldState, XmlBlasterException xmlBlasterException)
           
 void toPolling(I_DispatchManager dispatchManager, 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)
           
private  void unregisterSqlStatement(java.lang.String reqId)
           
 java.lang.String update(java.lang.String cbSessionId, UpdateKey updateKey, byte[] content, 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

SENDER_SESSION

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

ME

private static final java.lang.String ME

log

private static java.util.logging.Logger log

mbeanHandle

private java.lang.Object mbeanHandle

user

private java.lang.String user

password

private java.lang.String password

replications

private java.util.Map replications

replSlaveMap

private java.util.Map replSlaveMap

sqlStatementMap

private java.util.Map sqlStatementMap
Keys are requestId Strings, and values are SqlStatement objects


shutdown

private boolean shutdown

initialized

private volatile boolean initialized

instanceName

private java.lang.String instanceName

maxSize

private long maxSize

sqlTopic

private java.lang.String sqlTopic

maxResponseEntries

private long maxResponseEntries

pool

private I_DbPool pool

transformerCache

private VersionTransformerCache transformerCache

cachedListOfReplications

private java.lang.String cachedListOfReplications

initialFilesLocation

private java.lang.String initialFilesLocation

timeoutHandle

private Timestamp timeoutHandle

timeout

private Timeout timeout

STATUS_POLLER_INTERVAL_DEFAULT

private static final long STATUS_POLLER_INTERVAL_DEFAULT
See Also:
Constant Field Values

statusPollerInterval

private long statusPollerInterval

statusProcessingTime

private long statusProcessingTime

numRefresh

private long numRefresh

maxNumOfEntries

private int maxNumOfEntries

persistentInfo

private I_Info persistentInfo

topicToPrefixMap

private java.util.Map topicToPrefixMap

counterMap

private java.util.Map counterMap

initialDataTopicSet

private java.util.Set initialDataTopicSet
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 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 I_Plugin
Overrides:
getVersion in class GlobalInfo
See Also:
I_Plugin.getVersion()

addIfNotSet

private void addIfNotSet(java.lang.String key,
                         java.lang.String defValue)

initializePersistentInfo

private I_DbPool initializePersistentInfo()
                                   throws java.lang.Exception
Creates a I_DbPool object using the defaults out of the JDBC,1.0 Queue Properties and initializes the pool.

Returns:
Throws:
java.lang.Exception

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(Global global,
                      PluginInfo pluginInfo)
               throws 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:
XmlBlasterException
See Also:
I_Plugin.init(org.xmlBlaster.util.Global, org.xmlBlaster.util.plugin.PluginInfo)

getEngineGlobal

private ServerScope getEngineGlobal(Global glob)

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_MsgDispatchInterceptor
Specified by:
shutdown in interface 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

processDeadLetter

private java.lang.String processDeadLetter(UpdateQos qos)

update

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

Specified by:
update in interface 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:
XmlBlasterException
See Also:
I_Callback.update(java.lang.String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)

addDispatchManager

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

Specified by:
addDispatchManager in interface 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(I_DispatchManager dispatchManager)
Description copied from interface: 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 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)

getMaxNumOfEntries

private final int getMaxNumOfEntries(I_ReplSlave slave)
TODO implement this

Parameters:
slave -

handleNextMessages

public java.util.List<I_Entry> handleNextMessages(I_DispatchManager dispatchManager,
                                                  java.util.List<I_Entry> pushEntries)
                                           throws XmlBlasterException
Description copied from interface: 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 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:
XmlBlasterException
See Also:
org.xmlBlaster.util.dispatch.plugins.I_MsgDispatchInterceptor#handleNextMessages(org.xmlBlaster.util.dispatch.DispatchManager, java.util.ArrayList)

initialize

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

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

isShutdown

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

shutdown

public void shutdown(I_DispatchManager dispatchManager)
              throws XmlBlasterException
Description copied from interface: I_MsgDispatchInterceptor
Deregister the given dispatchManager

Specified by:
shutdown in interface I_MsgDispatchInterceptor
Throws:
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 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 I_MsgDispatchInterceptor
Returns:
a human readable usage help string
See Also:
I_MsgDispatchInterceptor.usage()

toAlive

public void toAlive(I_DispatchManager dispatchManager,
                    ConnectionStateEnum oldState)
Specified by:
toAlive in interface 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(I_DispatchManager dispatchManager,
                        ConnectionStateEnum oldState)
Specified by:
toAliveSync in interface I_ConnectionStatusListener

toDead

public void toDead(I_DispatchManager dispatchManager,
                   ConnectionStateEnum oldState,
                   XmlBlasterException xmlBlasterException)
Specified by:
toDead in interface 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(I_DispatchManager dispatchManager,
                      ConnectionStateEnum oldState)
Specified by:
toPolling in interface I_ConnectionStatusListener
See Also:
org.xmlBlaster.util.dispatch.I_ConnectionStatusListener#toPolling(org.xmlBlaster.util.dispatch.DispatchManager, org.xmlBlaster.util.dispatch.ConnectionStateEnum)

registerSqlStatement

private void registerSqlStatement(java.lang.String replPrefix,
                                  java.lang.String reqId,
                                  java.lang.String statement)
                           throws java.lang.Exception
Throws:
java.lang.Exception

unregisterSqlStatement

private void unregisterSqlStatement(java.lang.String reqId)

removeSqlStatement

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

sendBroadcastRequest

private void sendBroadcastRequest(java.lang.String replicationPrefix,
                                  java.lang.String sql,
                                  boolean isHighPrio,
                                  java.lang.String requestId)
                           throws java.lang.Exception
Throws:
java.lang.Exception

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)

hasUsAsDispatchPlugin

private final boolean hasUsAsDispatchPlugin(ConnectQosServer connQos)
Convenience method to determine if a connect Qos is for us, i.e. if they have defined us as the DispatchPlugin in their connect qos.

Parameters:
connQos -
Returns:

sessionAdded

public void sessionAdded(ClientEvent e)
                  throws 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 I_ClientListener
Throws:
XmlBlasterException
See Also:
I_ClientListener.sessionAdded(org.xmlBlaster.authentication.ClientEvent)

sessionUpdated

public void sessionUpdated(ClientEvent e)
                    throws XmlBlasterException
Invoked on successful client re-login (interface I_ClientListener)

Specified by:
sessionUpdated in interface I_ClientListener
Throws:
XmlBlasterException

sessionPreRemoved

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

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

sessionRemoved

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

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

subjectAdded

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

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

subjectRemoved

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

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

getPriority

public java.lang.Integer getPriority()
Description copied from interface: 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 I_SubscriptionListener
Returns:
See Also:
I_SubscriptionListener.getPriority()

subscriptionAdd

public void subscriptionAdd(SubscriptionEvent e)
                     throws 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 I_SubscriptionListener
Throws:
XmlBlasterException
See Also:
I_SubscriptionListener.subscriptionAdd(org.xmlBlaster.engine.SubscriptionEvent)

subscriptionRemove

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

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

setEngineGlobalProperty

void setEngineGlobalProperty(java.lang.String key,
                             java.lang.String val)

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

mainUsage

private static void mainUsage()

main

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

timeout

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

Specified by:
timeout in interface 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(I_DispatchManager dispatchManager,
                                   MsgUnit[] processedEntries)
                            throws XmlBlasterException
Does cleanup, particularly it sets the status and counters.

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)
Description copied from interface: 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 I_MsgDispatchInterceptor

publishSimpleMessage

private java.lang.String publishSimpleMessage(java.lang.String replicationPrefix,
                                              java.lang.String msgTxt)

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:

getAllSlaves

private final I_ReplSlave[] getAllSlaves()

setDispatcher

private java.lang.String setDispatcher(boolean alive,
                                       java.lang.String replPrefix)

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: 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 I_PublishFilter
Returns:
E.g. a string array like { "1.0", "1.3", "stable" }

getMimeTypes

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

Specified by:
getMimeTypes in interface 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: I_PublishFilter
Get a human readable name of this filter implementation

Specified by:
getName in interface I_PublishFilter

initialize

public void initialize(ServerScope glob)
Description copied from interface: I_PublishFilter
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.

intercept

public java.lang.String intercept(SubjectInfo publisher,
                                  MsgUnit msgUnit)
                           throws 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 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:
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)

parseLong

private static long parseLong(java.lang.String val,
                              long def)

readOldReplData

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

readOldReplDataOldStyle

private static long[] readOldReplDataOldStyle(I_Info persistentInfo,
                                              java.lang.String propName)
Deprecated. 

Parameters:
persistentInfo -
propName -
Returns:

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 I_AdminSession getSession(java.lang.String sessionId)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getMasterSession

public 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 API

Copyright © 1999-2014 The xmlBlaster.org contributers.