anonymous wrote : To lock object O:
  | 1. val = cache.put( '/locks', O, 'lock' )
  | 2a. If val == null, we have the lock (no previous 'put')
  | 2b. Else (val != null ) somebody else locked it first. Use a cache listener 
to wait for removed nodes
  | 3a. Lock owner in (2a) proceeds. When finished, call cache.remove( 
'/locks', O )
  | 3b. Contenders from (2b) get notified and return to (1)
You have to use tx in order to keep the lock from step1 to step 3. Otherwise 
the lock will be released when cache.put returns. Here is a way for doing this:

//1 use the tx manager that comes with cache;line bellow can also be specified 
through configuration, in transaction element, transactionManagerLookupClass 
attribute
  | 
configuration.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
  | 
  | //2. obtain the TransactionManager
  | TransactionManager tm = 
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
  | 
  | //3. start a transaction
  |       tm.begin();
  | 
  | //4. make sure that the node will be locked even if you only read it. After 
this call you are ensured to be the only one having access to the node
  | cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
  | Object o = cache.get(fqn, "k");
  | 
  | //5. do whatever you need, the locks are still held here
  | ....
  | 
  | //locks are released here, other trying to read same fqn will be allowed to
  | 6.tm.release();



View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4238745#4238745

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4238745
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to