IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

com.ibm.websphere.objectgrid.plugins.builtins
Class JMSObjectGridEventListener

java.lang.Object
  extended by com.ibm.websphere.objectgrid.plugins.builtins.JMSObjectGridEventListener
All Implemented Interfaces:
EventListener, LogSequenceFilter, ObjectGridEventListener, Runnable, ExceptionListener

public class JMSObjectGridEventListener
extends Object
implements ObjectGridEventListener, LogSequenceFilter, Runnable, ExceptionListener

This class is a JMS-based implementation of ObjectGridEventListener. It is designed to support client side near cache invalidation and peer-to-peer replication mechanism.

The client invalidation mechanism can be used in distributed ObjectGrid environment to ensure client near cache data to be synchronized with servers or other clients. Without this function, client near cache could hold stale data. However, even with this JMS-based client invalidation mechanism, you have to realize the timing window for updating client near cache. There will be a delay for the ObjectGrid runtime to publish updates.

The peer-to-peer replication mechanism can be used in both distributed and local ObjectGrid environment. It is an ObjectGrid core to core replication process and allows data updates flow among local ObjectGrids and distributed ObjectGrids. For example, with this mechanism you can move data updates from an ObjectGrid cluster to a local ObjectGrid, or from an ObjectGrid cluster to another ObjectGrid cluster in different system domain.

This class requires user to configure JMS and JNDI information in order to obtain required JMS resources. Additionally, replication related properties must be set correctly. In J2EE environment, the JNDI should be available in both web and EJB containers. In this case, the JNDI property is optional unless you want to obtained external JMS resources.

This JMS-based implementation of ObjectGridEventListener has some properties you can configure via xml or programmatic approaches. They could be only for client invalidation mechanism, only for peer-to-peer replication, or common for both. Most properties are optional for customizing the behavior to achieve desired function. Within the value of property, the semicolon ( ; ) can be used as delimiter to separate elements.

Client invalidation mechanism related properties:

Peer-to-peer replication related properties:

Required common properties to both client invalidation and Peer-to-peer replication mechanism:

Optional common properties to both client invalidation and Peer-to-peer replication mechanism:

There are two models available for client invalidation mechanism in distributed ObjectGrid environment:

The following is an xml configuration example to enable client invalidation mechanism with client-server model on an ObjectGrid configuration.

     <bean id="ObjectGridEventListener" className="com.ibm.ws.objectgrid.plugins.JMSObjectGridEventListener">
         <property name="invalidationModel" type="java.lang.String" value="CLIENT_SERVER_MODEL" description="" />
         <property name="invalidationStrategy" type="java.lang.String" value="PUSH" description="" />
         <property name="jms_topicConnectionFactoryJndiName" type="java.lang.String" value="defaultTCF" description="" />
         <property name="jms_topicJndiName" type="java.lang.String" value="defaultTopic" description="" />
         <property name="jms_topicName" type="java.lang.String" value="defaultTopic" description="" />
     </bean>
 
The following is an xml configuration example to enable client invalidation mechanism with client as dual roles model on an ObjectGrid configuration.
     <bean id="ObjectGridEventListener" className="com.ibm.ws.objectgrid.plugins.JMSObjectGridEventListener">
         <property name="invalidationModel" type="java.lang.String" value="CLIENT_AS_DUAL_ROLES_MODEL" description="" />
         <property name="invalidationStrategy" type="java.lang.String" value="PUSH" description="" />
         <property name="jms_topicConnectionFactoryJndiName" type="java.lang.String" value="defaultTCF" description="" />
         <property name="jms_topicJndiName" type="java.lang.String" value="defaultTopic" description="" />
         <property name="jms_topicName" type="java.lang.String" value="defaultTopic" description="" />
     </bean>
 

The peer-to-peer replication mechanism allows ObjectGrid cores to send transactional changes among each other. This mechanism can be configured on both local and distributed ObjectGrid. The following is an xml configuration example to enable peer-to-peer replication mechanism on an ObjectGrid configuration.

     <bean id="ObjectGridEventListener" className="com.ibm.ws.objectgrid.plugins.JMSObjectGridEventListener">
         <property name="replicationRole" type="java.lang.String" value="DUAL_ROLES" description="" />
         <property name="replicationStrategy" type="java.lang.String" value="PUSH" description="" />
         <property name="jms_topicConnectionFactoryJndiName" type="java.lang.String" value="defaultTCF" description="" />
         <property name="jms_topicJndiName" type="java.lang.String" value="defaultTopic" description="" />
         <property name="jms_topicName" type="java.lang.String" value="defaultTopic" description="" />
         <property name="jms_userid" type="java.lang.String" value="" description="" />
         <property name="jms_password" type="java.lang.String" value="" description="" />
         <property name="jndi_properties" type="java.lang.String" value="java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory;java.naming.provider.url=tcp://localhost:61616;connectionFactoryNames=defaultTCF;topic.defaultTopic=defaultTopic" description="jndi properties" />
     </bean>
 
The mapsToPublish property in both client invalidation mechanism and peer-to-peer replication mechanism is optional. It allows specifying maps that should publish and receive transactional chnages. If this property is not specified, All maps defined in the ObjectGrid will publish and receive transactional changes.

The jndi_properties property is only required when JMS resource is not available locally. For example, a Java program uses a local ObjectGrid that has this JMS-based ObjectGridEventListener configured to enable peer-to-peer replication mechanism. The JMS server is another Java process, so that the jndi_properties property is required for the Java program to perform JNDI lookup on remote JMS server. Usually, in WebSphere Application Server environment, the application that uses ObjectGrid should not need to set this jndi_properties property, because usually the JMS resources will be configured to be available for applications installed on the WebSphere servers.

In distributed ObjectGrid environment, both client invalidation mechanism and peer-to-peer replication mechanism can specify whether this JMS-based ObjectGridEventListener should run on either server or client process. This can be achieved by the setting of the following two properties:

     <property name="enableOnClientObjectGrid" type="boolean" value="false" description="" />
     <property name="enableOnServerObjectGrid" type="boolean" value="false" description="" />
 
Both enableOnClientObjectGrid and enableOnServerObjectGrid properties are default to true that means by default the configured JMS-based ObjectGridEventListener will run on both server and client process. If set to false, the configured JMS-based ObjectGridEventListener will be disable on the specified process. For example, if a distributed ObjectGrid has these two properties set to false as above, that means this configured JMS-based ObjectGridEventListener is virtually disabled.

If you would like to set thess properties programmatically, you can follow Java Bean pattern. For example, the setInvalidationModel(String) method is for setting invalidationModel property. The following is a programming example:

      JMSObjectGridEventListener jmsObjectGridEventListener = new JMSObjectGridEventListener();
      jmsObjectGridEventListener.setInvalidationModel(JMSObjectGridEventListener.CLIENT_SERVER_MODEL_STRING);
 
Note: Use constants provided by this class in property setters to avoid typo, e.g. the value of JMSObjectGridEventListener.CLIENT_SERVER_MODEL_STRING is "CLIENT_SERVER_MODEL".

The JMSObjectGridEventListener provides an extension point, the onMessage method, for application that wants to be notified when receiving JMS message.

A normal usage scenario of this extension point is when configuring client invalidation mechanism with CLIENT_SERVER_MODEL invalidationModel and application wants to know evictions occur in server ObjectGrid from client ObjectGrid. In this usage scenario, application can provide a class that extends JMSObjectGridEventListener and put handling logic in overridden onMessage method, and configure this extended JMSObjectGridEventListener the same way as JMSObjectGridEventListener.

The extended JMSObjectGridEventListener is child class of JMSObjectGridEventListener and can only override two methods: initialize and onMessage method. Overriding initialize method is optional. If the child class of JMSObjectGridEventListener needs to use any ObjectGrid artifacts, such as ObjectGrid, Session, and so on, in onMessage method, it can get these ObjectGrid artifacts in initialize method and cache them as instance variables. Within onMessage method, cached ObjectGrid artifacts can be used to process passed collection of LogSequences.

Note: the overridden initialize method has to invoke super.initialize method in order to initialize parent JMSObjectGridEventListener appropriately

The onMessage method will be invoked when the JMSObjectGridEventListener instance is in JMS receiver role and receives JMS messages that wrap a collection of LogSequences. The collection of LogSequences will be passed to the onMessgae method and the application can process the LogSequence collection within the onMessage method. A LogSequence represents a series of map operations, such as INSERT, DELETE, EVICT, and so on. With the collection of LogSequences passed to OnMessage method, application can know all server side ObjectGrid activities from client ObjectGrid.

In summary, to use the onMessage extension point, application has to do the following steps:

Since:
WAS XD 6.1
See Also:
ObjectGridEventListener, LogSequenceFilter

Field Summary
static String CLIENT_AS_DUAL_ROLES_MODEL_STRING
          The constant string that can be used in setInvalidationModel(String) method for setting invalidationModel as CLIENT_AS_DUAL_ROLES_MODEL.
static String CLIENT_SERVER_MODEL_STRING
          The constant string that can be used in setInvalidationModel(String) method for setting invalidationModel as CLIENT_SERVER_MODEL.
static String DUAL_ROLES_STRING
          The constant string that can be used in setReplicationRole(String) method for setting replicationRole as DUAL_ROLES.
static String INVALIDATE_CONDITIONAL_STRING
          The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as INVALIDATE_CONDITIONAL.
static String INVALIDATE_STRING
          The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as INVALIDATE.
static String NONE_INVALIDATION_MODEL_STRING
          The constant string that can be used in setInvalidationModel(String) method for setting invalidationModel as NONE_INVALIDATION_MODEL that implies disabling client invalidation mechanism.
static String NONE_ROLE_STRING
          The constant string that can be used in setReplicationRole(String) method for setting replicationRole as NONE_ROLE.
static String PUBLISHER_ROLE_STRING
          The constant string that can be used in setReplicationRole(String) method for setting replicationRole as PUBLISHER_ROLE.
static String PUSH_CONDITIONAL_STRING
          The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH_CONDITIONAL.
static String PUSH_INCLUDED_CONDITIONAL_STRING
          The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH_INCLUDED_CONDITIONAL.
static String PUSH_INCLUDED_STRING
          The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH_INCLUDED.
static String PUSH_STRING
          The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH.
static String SUBSCRIBER_ROLE_STRING
          The constant string that can be used in setReplicationRole(String) method for setting replicationRole as SUBSCRIBER_ROLE.
 
Constructor Summary
JMSObjectGridEventListener()
          This constructs the object and initializes any variables.
 
Method Summary
 boolean accept(LogElement logElement)
          This is used to filter the LogElements written to each message.
 void destroy()
          This is called when the application tells the ObjectGrid to stop.
 String getInvalidationModelString(int invalidationModelInt)
           
 Topic getTopic()
           
 TopicConnectionFactory getTopicConnectionFactory()
           
 void initialize(Session session)
          This is called when the ObjectGrid is initialized.
 void onException(JMSException arg0)
           
protected  void onMessage(Collection logSequences)
          This method is default to do nothing, but it allows child classes want to process LogSequence collection embedded on received JMS message by overriding this method.
 void release()
           
 void run()
          This is the thread which receives messages on a topic and then applies them to the local grid.
 void setCredentials(String userid, String pass)
           
 void setEnableOnClientObjectGrid(boolean s)
          Setter for the enableOnClientObjectGrid property
 void setEnableOnServerObjectGrid(boolean s)
          Setter for the enableOnServerObjectGrid property
 void setInvalidationModel(String s)
          Setter for the invalidationModel property
 void setInvalidationStrategy(String s)
          Setter for the invalidationStrategy property
 void setJms_password(String s)
          Setter for the jms_password property
 void setJms_topicConnectionFactoryJndiName(String s)
          Setter for the jms_topicConnectionFactoryJndiName property
 void setJms_topicJndiName(String s)
          Setter for the jms_topicJndiName property
 void setJms_topicName(String s)
          Setter for the topicName property
 void setJms_userid(String s)
          Setter for the jms_userid property
 void setJndi_properties(String s)
          Setter for the jndiProperties property
 void setMapsToPublish(List mapNames)
          If this is specified then only the maps in the list will be published.
 void setMapsToPublish(String s)
          Setter for the mapsToPublish property
 void setReplicationRole(String s)
          Setter for the replicationRole property
 void setReplicationStrategy(String s)
          Setter for the replicationStrategy property
 void setTopic(Topic topic)
           
 void setTopicConnectionFactory(TopicConnectionFactory topicConnectionFactory)
           
 void transactionBegin(String txid, boolean isWriteThroughEnabled)
          Signals the beginning of a Session transaction.
 void transactionEnd(String txid, boolean isWriteThroughEnabled, boolean committed, Collection changes)
          This is called whenever a transaction commits for the grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALIDATE_STRING

public static final String INVALIDATE_STRING
The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as INVALIDATE. The INVALIDATE invalidation or replication strategy is same as DistributionMode#INVALIDATE

See Also:
Constant Field Values

INVALIDATE_CONDITIONAL_STRING

public static final String INVALIDATE_CONDITIONAL_STRING
The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as INVALIDATE_CONDITIONAL. The INVALIDATE_CONDITIONAL invalidation or replication strategy is same as DistributionMode#INVALIDATE_CONDITIONAL

See Also:
Constant Field Values

PUSH_STRING

public static final String PUSH_STRING
The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH. The PUSH invalidation or replication strategy is same as DistributionMode#PUSH

See Also:
Constant Field Values

PUSH_CONDITIONAL_STRING

public static final String PUSH_CONDITIONAL_STRING
The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH_CONDITIONAL. The PUSH_CONDITIONAL invalidation or replication strategy is same as DistributionMode#PUSH_CONDITIONAL

See Also:
Constant Field Values

PUSH_INCLUDED_STRING

public static final String PUSH_INCLUDED_STRING
The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH_INCLUDED. This is an extension to PUSH strategy. With PUSH strategy, all updates including INSERT type will be published and received. Becasue it also includes INSERT type update, the receivers will insert data into its maps locally that might not be desired. Besides, the receivers might be overwhelmed by inserting too many unnecessary data. The PUSH_INCLUDED strategy is like PUSH strategy, but it does not include INSERT type update. The suffix INCLUDED means the changes only include existing data, and exclude new data that is the result of INSERT operation.

See Also:
Constant Field Values

PUSH_INCLUDED_CONDITIONAL_STRING

public static final String PUSH_INCLUDED_CONDITIONAL_STRING
The constant string that can be used in setInvalidationStrategy(String) or setReplicationStrategy(String) method for setting invalidationStrategy or replicationStrategy as PUSH_INCLUDED_CONDITIONAL. This is an extension to PUSH_CONDITIONAL strategy. Similar to the PUSH_INCLUDED, the PUSH_INCLUDED_CONDITIONAL is like PUSH_CONDITIONAL, but it does not include INSERT type update.

See Also:
Constant Field Values

NONE_INVALIDATION_MODEL_STRING

public static final String NONE_INVALIDATION_MODEL_STRING
The constant string that can be used in setInvalidationModel(String) method for setting invalidationModel as NONE_INVALIDATION_MODEL that implies disabling client invalidation mechanism.

See Also:
Constant Field Values

CLIENT_SERVER_MODEL_STRING

public static final String CLIENT_SERVER_MODEL_STRING
The constant string that can be used in setInvalidationModel(String) method for setting invalidationModel as CLIENT_SERVER_MODEL. In this model, all server processes will be in publisher role that will publish all transaction changes to designated JMS destination. All client processes will be in receiver roles and will receive all transactional changes from designated JMS destination.

See Also:
Constant Field Values

CLIENT_AS_DUAL_ROLES_MODEL_STRING

public static final String CLIENT_AS_DUAL_ROLES_MODEL_STRING
The constant string that can be used in setInvalidationModel(String) method for setting invalidationModel as CLIENT_AS_DUAL_ROLES_MODEL. In this model, all server processes have nothing to do with JMS destination. All client processes will be both JMS publisher and receiver roles. Transactional changes occur on client will be published to JMS destination and all clients will receive these transactional changes.

See Also:
Constant Field Values

NONE_ROLE_STRING

public static final String NONE_ROLE_STRING
The constant string that can be used in setReplicationRole(String) method for setting replicationRole as NONE_ROLE. The NONE_ROLE replication role indicates the current ObjectGrid has nothing to do with JMS. This virtually disable this plugin on the current ObjectGrid instance.

See Also:
Constant Field Values

DUAL_ROLES_STRING

public static final String DUAL_ROLES_STRING
The constant string that can be used in setReplicationRole(String) method for setting replicationRole as DUAL_ROLES. The DUAL_ROLES replication role indicates the current ObjectGrid will act as both JMS publisher and subscriber role.

See Also:
Constant Field Values

PUBLISHER_ROLE_STRING

public static final String PUBLISHER_ROLE_STRING
The constant string that can be used in setReplicationRole(String) method for setting replicationRole as PUBLISHER_ROLE. The PUBLISHER_ROLE replication role indicates the current ObjectGrid will only act as JMS publisher role.

See Also:
Constant Field Values

SUBSCRIBER_ROLE_STRING

public static final String SUBSCRIBER_ROLE_STRING
The constant string that can be used in setReplicationRole(String) method for setting replicationRole as SUBSCRIBER_ROLE. The SUBSCRIBER_ROLE replication role indicates the current ObjectGrid will only act as JMS subscriber role.

See Also:
Constant Field Values
Constructor Detail

JMSObjectGridEventListener

public JMSObjectGridEventListener()
This constructs the object and initializes any variables.

Method Detail

initialize

public void initialize(Session session)
This is called when the ObjectGrid is initialized. This method obtains JMS connections and starts them. It then creates a TopicSession to publish all changes in the local ObjectGrid. It creates a thread to listen for messages from peer ObjectGrids.

Specified by:
initialize in interface ObjectGridEventListener
Parameters:
session - a Session instance that this listener is associated with.
See Also:
ObjectGridEventListener.initialize(com.ibm.websphere.objectgrid.Session)

transactionBegin

public void transactionBegin(String txid,
                             boolean isWriteThroughEnabled)
Description copied from interface: ObjectGridEventListener
Signals the beginning of a Session transaction.

A stringified version of the TxID is provided for correlating with the end of the transaction, if so desired. The type of transaction is also provided by the isWriteThroughEnabled boolean parameter.

Specified by:
transactionBegin in interface ObjectGridEventListener
Parameters:
txid - Stringified version of the TxID
isWriteThroughEnabled - boolean flag indicating whether the Session transaction was started using the Session.beginNoWriteThrough(). method. false is passed if beginNoWriteThrough() was used.
See Also:
Session.begin(), Session.beginNoWriteThrough()

transactionEnd

public void transactionEnd(String txid,
                           boolean isWriteThroughEnabled,
                           boolean committed,
                           Collection changes)
This is called whenever a transaction commits for the grid. If its a write through transaction then we will publish a message with the changes. This is synchronised to make sure only one thread uses the session plus it enforces an order on the messages transmitted.

Specified by:
transactionEnd in interface ObjectGridEventListener
Parameters:
txid - string version of the TxID
isWriteThroughEnabled - boolean flag indicating whether the Session transaction was started using the Session.beginNoWriteThrough(). method. false is passed if beginNoWriteThrough() was used.
committed - a boolean flag indicating whether the transaction was committed (true) or rolled back (false)
changes - a Collection of LogSequences representing the changes that were committed or rolled back.
See Also:
LogSequence.isRollback(), Session.begin(), Session.beginNoWriteThrough(), Session.commit(), Session.rollback()

accept

public boolean accept(LogElement logElement)
This is used to filter the LogElements written to each message. We use the mode to determine the filter.

Specified by:
accept in interface LogSequenceFilter
Parameters:
logElement - the LogElement to be filtered
Returns:
true if the given LogElement should be used in the operation; false otherwise.
See Also:
LogSequenceFilter.accept(com.ibm.websphere.objectgrid.plugins.LogElement)

run

public void run()
This is the thread which receives messages on a topic and then applies them to the local grid.

Specified by:
run in interface Runnable
See Also:
Runnable.run()

getTopic

public Topic getTopic()
Returns:
Returns the JMS topic.

setTopic

public void setTopic(Topic topic)
Parameters:
topic - The JMS topic to set.

getTopicConnectionFactory

public TopicConnectionFactory getTopicConnectionFactory()
Returns:
Returns the topicConnectionFactory.

setTopicConnectionFactory

public void setTopicConnectionFactory(TopicConnectionFactory topicConnectionFactory)
Parameters:
topicConnectionFactory - The topicConnectionFactory to set.

getInvalidationModelString

public String getInvalidationModelString(int invalidationModelInt)
Returns:
Returns the String representation of the invalidationStrategy.

setCredentials

public void setCredentials(String userid,
                           String pass)
Parameters:
userid - The userid to set.

setMapsToPublish

public void setMapsToPublish(List mapNames)
If this is specified then only the maps in the list will be published. This allows a subset of the maps in a transaction to be published.

Parameters:
mapNames -

onException

public void onException(JMSException arg0)
Specified by:
onException in interface ExceptionListener

destroy

public void destroy()
This is called when the application tells the ObjectGrid to stop. We will signal our listener thread to stop. The listener thread will also close the JMS connection.

Specified by:
destroy in interface ObjectGridEventListener
See Also:
ObjectGridEventListener.destroy()

release

public void release()

setJms_topicConnectionFactoryJndiName

public void setJms_topicConnectionFactoryJndiName(String s)
Setter for the jms_topicConnectionFactoryJndiName property


setJms_topicJndiName

public void setJms_topicJndiName(String s)
Setter for the jms_topicJndiName property


setJms_topicName

public void setJms_topicName(String s)
Setter for the topicName property


setJms_userid

public void setJms_userid(String s)
Setter for the jms_userid property


setJms_password

public void setJms_password(String s)
Setter for the jms_password property


setJndi_properties

public void setJndi_properties(String s)
Setter for the jndiProperties property


setInvalidationModel

public void setInvalidationModel(String s)
Setter for the invalidationModel property


setInvalidationStrategy

public void setInvalidationStrategy(String s)
Setter for the invalidationStrategy property


setReplicationStrategy

public void setReplicationStrategy(String s)
Setter for the replicationStrategy property


setReplicationRole

public void setReplicationRole(String s)
Setter for the replicationRole property


setMapsToPublish

public void setMapsToPublish(String s)
Setter for the mapsToPublish property


setEnableOnClientObjectGrid

public void setEnableOnClientObjectGrid(boolean s)
Setter for the enableOnClientObjectGrid property


setEnableOnServerObjectGrid

public void setEnableOnServerObjectGrid(boolean s)
Setter for the enableOnServerObjectGrid property


onMessage

protected void onMessage(Collection logSequences)
This method is default to do nothing, but it allows child classes want to process LogSequence collection embedded on received JMS message by overriding this method.

Parameters:
logSequences - the LogSequence collection embedded in received JMS message.
Since:
7.0.0.0 FIX1

IBM WebSphereTM eXtreme Scale, Release 8.6
API Specification

© Copyright International Business Machines Corp 2005,2012. All rights reserved.