|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.websphere.objectgrid.plugins.builtins.JMSObjectGridEventListener
public class JMSObjectGridEventListener
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:
DistributionMode.INVALIDATE
DistributionMode.INVALIDATE_CONDITIONAL
DistributionMode.PUSH
)DistributionMode.PUSH_CONDITIONAL
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:
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 |
---|
public static final String INVALIDATE_STRING
public static final String INVALIDATE_CONDITIONAL_STRING
public static final String PUSH_STRING
public static final String PUSH_CONDITIONAL_STRING
public static final String PUSH_INCLUDED_STRING
public static final String PUSH_INCLUDED_CONDITIONAL_STRING
public static final String NONE_INVALIDATION_MODEL_STRING
public static final String CLIENT_SERVER_MODEL_STRING
public static final String CLIENT_AS_DUAL_ROLES_MODEL_STRING
public static final String NONE_ROLE_STRING
public static final String DUAL_ROLES_STRING
public static final String PUBLISHER_ROLE_STRING
public static final String SUBSCRIBER_ROLE_STRING
Constructor Detail |
---|
public JMSObjectGridEventListener()
Method Detail |
---|
public void initialize(Session session)
initialize
in interface ObjectGridEventListener
session
- a Session instance that this listener is associated with.ObjectGridEventListener.initialize(com.ibm.websphere.objectgrid.Session)
public void transactionBegin(String txid, boolean isWriteThroughEnabled)
ObjectGridEventListener
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.
transactionBegin
in interface ObjectGridEventListener
txid
- Stringified version of the TxIDisWriteThroughEnabled
- boolean flag indicating whether the Session
transaction was started using the
Session.beginNoWriteThrough()
.
method. false
is passed if
beginNoWriteThrough()
was used.Session.begin()
,
Session.beginNoWriteThrough()
public void transactionEnd(String txid, boolean isWriteThroughEnabled, boolean committed, Collection changes)
transactionEnd
in interface ObjectGridEventListener
txid
- string version of the TxIDisWriteThroughEnabled
- 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.LogSequence.isRollback()
,
Session.begin()
,
Session.beginNoWriteThrough()
,
Session.commit()
,
Session.rollback()
public boolean accept(LogElement logElement)
accept
in interface LogSequenceFilter
logElement
- the LogElement to be filtered
LogSequenceFilter.accept(com.ibm.websphere.objectgrid.plugins.LogElement)
public void run()
run
in interface Runnable
Runnable.run()
public Topic getTopic()
public void setTopic(Topic topic)
topic
- The JMS topic to set.public TopicConnectionFactory getTopicConnectionFactory()
public void setTopicConnectionFactory(TopicConnectionFactory topicConnectionFactory)
topicConnectionFactory
- The topicConnectionFactory to set.public String getInvalidationModelString(int invalidationModelInt)
public void setCredentials(String userid, String pass)
userid
- The userid to set.public void setMapsToPublish(List mapNames)
mapNames
- public void onException(JMSException arg0)
onException
in interface ExceptionListener
public void destroy()
destroy
in interface ObjectGridEventListener
ObjectGridEventListener.destroy()
public void release()
public void setJms_topicConnectionFactoryJndiName(String s)
public void setJms_topicJndiName(String s)
public void setJms_topicName(String s)
public void setJms_userid(String s)
public void setJms_password(String s)
public void setJndi_properties(String s)
public void setInvalidationModel(String s)
public void setInvalidationStrategy(String s)
public void setReplicationStrategy(String s)
public void setReplicationRole(String s)
public void setMapsToPublish(String s)
public void setEnableOnClientObjectGrid(boolean s)
public void setEnableOnServerObjectGrid(boolean s)
protected void onMessage(Collection logSequences)
logSequences
- the LogSequence collection embedded in received JMS message.
|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |