xmlBlaster 2.2.0 contributions API

org.xmlBlaster.contrib.dbwatcher.mom
Class XmlBlasterPublisher

java.lang.Object
  extended by org.xmlBlaster.contrib.dbwatcher.mom.XmlBlasterPublisher
All Implemented Interfaces:
java.util.EventListener, org.xmlBlaster.client.I_Callback, org.xmlBlaster.client.I_ConnectionStateListener, DbWatcherConstants, I_AlertProducer, XmlBlasterPublisherMBean, I_ChangePublisher, I_ContribPlugin

public class XmlBlasterPublisher
extends java.lang.Object
implements I_ChangePublisher, I_AlertProducer, org.xmlBlaster.client.I_Callback, org.xmlBlaster.client.I_ConnectionStateListener, DbWatcherConstants, XmlBlasterPublisherMBean

Implementation to send change events to xmlBlaster.

This plugin plays two roles, first it is the gateway to xmlBlaster and second if can be configured to listen on a alert topic and use incoming messages as alerts to check the database again.

Supported configuration:

Author:
Marcel Ruff

Field Summary
protected  java.lang.String alertSubscribeKey
           
protected  java.lang.String alertSubscribeQos
           
protected  java.lang.String alertSubscriptionId
           
protected  I_ChangeDetector changeDetector
           
protected  org.xmlBlaster.client.I_XmlBlasterAccess con
           
protected  org.xmlBlaster.client.qos.ConnectQos connectQos
           
protected  boolean eraseOnDelete
           
protected  boolean eraseOnDrop
           
protected  org.xmlBlaster.util.Global glob
           
protected  java.lang.String loginName
           
protected  java.lang.String password
           
protected  java.lang.String publishKey
           
protected  java.lang.String publishQos
           
protected  java.lang.String topicNameTemplate
           
 
Fields inherited from interface org.xmlBlaster.contrib.dbwatcher.DbWatcherConstants
_COMPRESSION_TYPE, _UNCOMPRESSED_SIZE, COMPRESSION_TYPE_GZIP, COMPRESSION_TYPE_ZIP, MOM_ALERT_SUBSCRIBE_KEY, MOM_ALERT_SUBSCRIBE_QOS, MOM_COMPRESS_SIZE, MOM_CONNECT_QOS, MOM_ERASE_ON_DELETE, MOM_ERASE_ON_DROP, MOM_LOGIN_NAME, MOM_MAX_SESSIONS, MOM_PASSWORD, MOM_PROPS_TO_ADD_TO_CONNECT, MOM_PUBLISH_KEY, MOM_PUBLISH_QOS, MOM_STATUS_TOPIC_NAME, MOM_TOPIC_NAME
 
Constructor Summary
XmlBlasterPublisher()
          Default constructor.
 
Method Summary
protected  java.util.Map clientPropertiesToMap(java.util.Map clp)
          Copy a map to a map.
 java.lang.String getAdminKey()
           
 java.lang.String getAlertSubscribeKey()
           
 java.lang.String getAlertSubscribeQos()
           
 java.lang.String getAlertSubscriptionId()
           
 int getCompressSize()
           
 java.lang.String getConnectQos()
           
 org.xmlBlaster.jms.XBSession getJmsSession()
          Only used in replication, can return null if not used.
 long getLastPublishTime()
          Returns the time in ms it took for the last real publish.
 java.lang.String getLoginName()
           
 java.lang.String getPublishKey()
           
 java.lang.String getPublishQos()
           
 java.lang.String getTopicNameTemplate()
           
 java.util.Set getUsedPropertyKeys()
          Gets all property keys which may be used by this object.
 void init(I_Info info)
          If a global is passed with info.getObject("org.xmlBlaster.engine.Global") we take a clone and reuse it.
 void init(I_Info info, I_ChangeDetector changeDetector)
          If called we shall subcribe to xmlBlaster for alert messages which notifies us that there may be new changes available, we call I_ChangeDetector.checkAgain(java.util.Map) in such a case.
 void initWithExistingGlob(org.xmlBlaster.util.Global global, java.lang.String pubKey, java.lang.String pubQos, int compressionSize)
           
 boolean isEraseOnDelete()
           
 boolean isEraseOnDrop()
           
 boolean isThrowAwayMessages()
           
 java.lang.String publish(java.lang.String changeKey, byte[] out, java.util.Map attrMap)
          The send message is configured with mom.publishKey and mom.publishQos.
 void reachedAlive(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState, org.xmlBlaster.client.I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess notifying the client that a connection has been established and that its status is now ALIVE.
 void reachedAliveSync(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState, org.xmlBlaster.client.I_XmlBlasterAccess connection)
          Invoked when the dispatcher goes to synch again after having delivered entries which where in the queue when the state changed to ALIVE.
 void reachedDead(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState, org.xmlBlaster.client.I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess informing the client that the connection was lost (i.e.
 void reachedPolling(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState, org.xmlBlaster.client.I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess informing the client that the connection state has changed to POLLING.
 boolean registerAlertListener(I_Update momCb, java.util.Map attrs)
          Subscribes on the alert topic as configured with mom.alertSubscribeKey.
 void setAdminKey(java.lang.String adminKey)
           
 void setAlertSubscribeKey(java.lang.String alertSubscribeKey)
           
 void setAlertSubscribeQos(java.lang.String alertSubscribeQos)
           
 void setAlertSubscriptionId(java.lang.String alertSubscriptionId)
           
 void setCompressSize(int compressSize)
           
 void setEraseOnDelete(boolean eraseOnDelete)
           
 void setEraseOnDrop(boolean eraseOnDrop)
           
 void setPublishKey(java.lang.String publishKey)
           
 void setPublishQos(java.lang.String publishQos)
           
 void setThrowAwayMessages(boolean throwAwayMessages)
           
 void setTopicNameTemplate(java.lang.String topicNameTemplate)
           
 void shutdown()
          Stop producing alerts and cleanup resources.
 void startProducing()
          Subscribes on the alert topic as configured with mom.alertSubscribeKey.
 void stopProducing()
          Unsubscribes from the alert topic.
 java.lang.String subscribe(java.lang.String topic, I_Update momCb)
          Not available via interface, used by test suite only.
 java.lang.String update(java.lang.String s, org.xmlBlaster.client.key.UpdateKey k, byte[] content, org.xmlBlaster.client.qos.UpdateQos q)
          Dummy implementation, PtP messages could arrive here which are ignored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

changeDetector

protected I_ChangeDetector changeDetector

glob

protected org.xmlBlaster.util.Global glob

con

protected org.xmlBlaster.client.I_XmlBlasterAccess con

topicNameTemplate

protected java.lang.String topicNameTemplate

loginName

protected java.lang.String loginName

password

protected java.lang.String password

publishKey

protected java.lang.String publishKey

publishQos

protected java.lang.String publishQos

alertSubscribeKey

protected java.lang.String alertSubscribeKey

alertSubscribeQos

protected java.lang.String alertSubscribeQos

alertSubscriptionId

protected java.lang.String alertSubscriptionId

connectQos

protected org.xmlBlaster.client.qos.ConnectQos connectQos

eraseOnDrop

protected boolean eraseOnDrop

eraseOnDelete

protected boolean eraseOnDelete
Constructor Detail

XmlBlasterPublisher

public XmlBlasterPublisher()
Default constructor. You need to call init(I_Info) thereafter.

Method Detail

init

public void init(I_Info info,
                 I_ChangeDetector changeDetector)
          throws java.lang.Exception
If called we shall subcribe to xmlBlaster for alert messages which notifies us that there may be new changes available, we call I_ChangeDetector.checkAgain(java.util.Map) in such a case.

Specified by:
init in interface I_AlertProducer
Parameters:
info - The configuration environment
Throws:
java.lang.Exception - Can be any plugin specific exception
See Also:
I_AlertProducer.init(I_Info,I_ChangeDetector)

startProducing

public void startProducing()
                    throws java.lang.Exception
Subscribes on the alert topic as configured with mom.alertSubscribeKey.

Specified by:
startProducing in interface I_AlertProducer
Throws:
java.lang.Exception - of any type
See Also:
I_AlertProducer.startProducing()

stopProducing

public void stopProducing()
                   throws java.lang.Exception
Unsubscribes from the alert topic.

Specified by:
stopProducing in interface I_AlertProducer
Throws:
java.lang.Exception - of any type
See Also:
I_AlertProducer.stopProducing()

getUsedPropertyKeys

public java.util.Set getUsedPropertyKeys()
Description copied from interface: I_ContribPlugin
Gets all property keys which may be used by this object.

Specified by:
getUsedPropertyKeys in interface I_ContribPlugin
Returns:
See Also:
I_ContribPlugin.getUsedPropertyKeys()

initWithExistingGlob

public void initWithExistingGlob(org.xmlBlaster.util.Global global,
                                 java.lang.String pubKey,
                                 java.lang.String pubQos,
                                 int compressionSize)

init

public void init(I_Info info)
          throws java.lang.Exception
If a global is passed with info.getObject("org.xmlBlaster.engine.Global") we take a clone and reuse it.

Specified by:
init in interface I_ChangePublisher
Specified by:
init in interface I_ContribPlugin
Parameters:
info - The configuration environment
Throws:
java.lang.Exception - MoM specific
See Also:
org.xmlBlaster.contrib.dbwatcher.mom.I_ChangePublisher#init(I_Info)

shutdown

public void shutdown()
Description copied from interface: I_AlertProducer
Stop producing alerts and cleanup resources.

Specified by:
shutdown in interface I_AlertProducer
Specified by:
shutdown in interface I_ChangePublisher
Specified by:
shutdown in interface I_ContribPlugin
See Also:
org.xmlBlaster.contrib.dbwatcher.mom.I_ChangePublisher#shutdown

publish

public java.lang.String publish(java.lang.String changeKey,
                                byte[] out,
                                java.util.Map attrMap)
                         throws java.lang.Exception
The send message is configured with mom.publishKey and mom.publishQos. A DROP command erases the topic.

Specified by:
publish in interface I_ChangePublisher
Parameters:
changeKey - Can be used to create the topic name
out - The message content to send
attrMap - An optional map with attributes or null
Returns:
A unique identifier of the sent message
Throws:
java.lang.Exception - On sending problems
See Also:
org.xmlBlaster.contrib.dbwatcher.mom.I_ChangePublisher#publish(String, String, Map)

registerAlertListener

public boolean registerAlertListener(I_Update momCb,
                                     java.util.Map attrs)
                              throws java.lang.Exception
Subscribes on the alert topic as configured with mom.alertSubscribeKey.

Specified by:
registerAlertListener in interface I_ChangePublisher
Parameters:
attrs - it currently accepts a null (old behaviour) or if it is not null, then the attribute ptp must be set (does not matter to what).
momCb - The callback interface to receive the notification
Returns:
true if a notification is available (is configured)
Throws:
java.lang.Exception - Typically a XmlBlasterException
See Also:
org.xmlBlaster.contrib.dbwatcher.mom.I_ChangePublisher#registerAlertListener(I_Update)

subscribe

public java.lang.String subscribe(java.lang.String topic,
                                  I_Update momCb)
                           throws java.lang.Exception
Not available via interface, used by test suite only.

Parameters:
topic - If the topic starts with "XPATH:" the prefix will be stripped and an Xpath subscription is done.
momCb - Incoming messages are forwarded to this interface
Returns:
A unique identifier of the subscription
Throws:
java.lang.Exception - Typically a XmlBlasterException

update

public java.lang.String update(java.lang.String s,
                               org.xmlBlaster.client.key.UpdateKey k,
                               byte[] content,
                               org.xmlBlaster.client.qos.UpdateQos q)
                        throws org.xmlBlaster.util.XmlBlasterException
Dummy implementation, PtP messages could arrive here which are ignored.

Specified by:
update in interface org.xmlBlaster.client.I_Callback
Parameters:
s - The sessionId
k - The xml key
c - The message content
q - The message QoS
Returns:
The UpdateReturnQos
Throws:
org.xmlBlaster.util.XmlBlasterException
See Also:
I_Callback.update(java.lang.String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)

clientPropertiesToMap

protected java.util.Map clientPropertiesToMap(java.util.Map clp)
Copy a map to a map.

Parameters:
clp - The xmlBlaster ClientProperties
Returns:
The simple string map

getJmsSession

public org.xmlBlaster.jms.XBSession getJmsSession()
Description copied from interface: I_ChangePublisher
Only used in replication, can return null if not used.

Specified by:
getJmsSession in interface I_ChangePublisher
Returns:
See Also:
I_ChangePublisher.getJmsSession()

reachedAlive

public void reachedAlive(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState,
                         org.xmlBlaster.client.I_XmlBlasterAccess connection)
Description copied from interface: org.xmlBlaster.client.I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess notifying the client that a connection has been established and that its status is now ALIVE.

Note that this method is invoked also when the connection has been established the first time. In this case the connection is fully operational but your connect() call has not yet returned. You can access the returned connect QoS in this case with connect.getConnectReturnQos().

You can erase all entries of the queue manually or add others before you return and in this way control the behavior. During you have control in reachedAlive() the client side queue is blocked and does not accept publish or request messages from other threads. So you can do peacefully your work (your thread is allowed to modify the queue exclusively).

If you send messages during this method invocation they are queued only and are sent as soon as this method returns.

This method is invoked by the login polling thread from I_XmlBlasterAccess in which case it is a physical Alive, and by the connect method on successful login in which case it is a logical Alive.

Specified by:
reachedAlive in interface org.xmlBlaster.client.I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.
See Also:
I_ConnectionStateListener.reachedAlive(org.xmlBlaster.util.dispatch.ConnectionStateEnum, org.xmlBlaster.client.I_XmlBlasterAccess)

reachedAliveSync

public void reachedAliveSync(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState,
                             org.xmlBlaster.client.I_XmlBlasterAccess connection)
Description copied from interface: org.xmlBlaster.client.I_ConnectionStateListener
Invoked when the dispatcher goes to synch again after having delivered entries which where in the queue when the state changed to ALIVE. Note that this could take some time or in the worst case it could never been invoked if the queue is never completely processed.

Specified by:
reachedAliveSync in interface org.xmlBlaster.client.I_ConnectionStateListener
Parameters:
oldState - is always ALIVE.

reachedDead

public void reachedDead(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState,
                        org.xmlBlaster.client.I_XmlBlasterAccess connection)
Description copied from interface: org.xmlBlaster.client.I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess informing the client that the connection was lost (i.e. when the state of the connection has gone to DEAD).

Specified by:
reachedDead in interface org.xmlBlaster.client.I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.
See Also:
I_ConnectionStateListener.reachedDead(org.xmlBlaster.util.dispatch.ConnectionStateEnum, org.xmlBlaster.client.I_XmlBlasterAccess)

reachedPolling

public void reachedPolling(org.xmlBlaster.util.dispatch.ConnectionStateEnum oldState,
                           org.xmlBlaster.client.I_XmlBlasterAccess connection)
Description copied from interface: org.xmlBlaster.client.I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess informing the client that the connection state has changed to POLLING.

Specified by:
reachedPolling in interface org.xmlBlaster.client.I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.
See Also:
I_ConnectionStateListener.reachedPolling(org.xmlBlaster.util.dispatch.ConnectionStateEnum, org.xmlBlaster.client.I_XmlBlasterAccess)

getAdminKey

public java.lang.String getAdminKey()
Specified by:
getAdminKey in interface XmlBlasterPublisherMBean

setAdminKey

public void setAdminKey(java.lang.String adminKey)
Specified by:
setAdminKey in interface XmlBlasterPublisherMBean

getAlertSubscribeKey

public java.lang.String getAlertSubscribeKey()
Specified by:
getAlertSubscribeKey in interface XmlBlasterPublisherMBean

setAlertSubscribeKey

public void setAlertSubscribeKey(java.lang.String alertSubscribeKey)
Specified by:
setAlertSubscribeKey in interface XmlBlasterPublisherMBean

getAlertSubscribeQos

public java.lang.String getAlertSubscribeQos()
Specified by:
getAlertSubscribeQos in interface XmlBlasterPublisherMBean

setAlertSubscribeQos

public void setAlertSubscribeQos(java.lang.String alertSubscribeQos)
Specified by:
setAlertSubscribeQos in interface XmlBlasterPublisherMBean

getAlertSubscriptionId

public java.lang.String getAlertSubscriptionId()
Specified by:
getAlertSubscriptionId in interface XmlBlasterPublisherMBean

setAlertSubscriptionId

public void setAlertSubscriptionId(java.lang.String alertSubscriptionId)
Specified by:
setAlertSubscriptionId in interface XmlBlasterPublisherMBean

getCompressSize

public int getCompressSize()
Specified by:
getCompressSize in interface XmlBlasterPublisherMBean

setCompressSize

public void setCompressSize(int compressSize)
Specified by:
setCompressSize in interface XmlBlasterPublisherMBean

getConnectQos

public java.lang.String getConnectQos()
Specified by:
getConnectQos in interface XmlBlasterPublisherMBean

isEraseOnDelete

public boolean isEraseOnDelete()
Specified by:
isEraseOnDelete in interface XmlBlasterPublisherMBean

setEraseOnDelete

public void setEraseOnDelete(boolean eraseOnDelete)
Specified by:
setEraseOnDelete in interface XmlBlasterPublisherMBean

isEraseOnDrop

public boolean isEraseOnDrop()
Specified by:
isEraseOnDrop in interface XmlBlasterPublisherMBean

setEraseOnDrop

public void setEraseOnDrop(boolean eraseOnDrop)
Specified by:
setEraseOnDrop in interface XmlBlasterPublisherMBean

getPublishKey

public java.lang.String getPublishKey()
Specified by:
getPublishKey in interface XmlBlasterPublisherMBean

setPublishKey

public void setPublishKey(java.lang.String publishKey)
Specified by:
setPublishKey in interface XmlBlasterPublisherMBean

getPublishQos

public java.lang.String getPublishQos()
Specified by:
getPublishQos in interface XmlBlasterPublisherMBean

setPublishQos

public void setPublishQos(java.lang.String publishQos)
Specified by:
setPublishQos in interface XmlBlasterPublisherMBean

isThrowAwayMessages

public boolean isThrowAwayMessages()
Specified by:
isThrowAwayMessages in interface XmlBlasterPublisherMBean

setThrowAwayMessages

public void setThrowAwayMessages(boolean throwAwayMessages)
Specified by:
setThrowAwayMessages in interface XmlBlasterPublisherMBean

getTopicNameTemplate

public java.lang.String getTopicNameTemplate()
Specified by:
getTopicNameTemplate in interface XmlBlasterPublisherMBean

setTopicNameTemplate

public void setTopicNameTemplate(java.lang.String topicNameTemplate)
Specified by:
setTopicNameTemplate in interface XmlBlasterPublisherMBean

getLoginName

public java.lang.String getLoginName()
Specified by:
getLoginName in interface XmlBlasterPublisherMBean

getLastPublishTime

public long getLastPublishTime()
Returns the time in ms it took for the last real publish. Real publish is meant the last publish of messages which are not drop or delete

Specified by:
getLastPublishTime in interface XmlBlasterPublisherMBean

xmlBlaster 2.2.0 contributions API

Copyright © 1999-2014 The xmlBlaster.org contributers.