Doug,
good for you, now I will have to change the training
(btw this was a feature required by CarPhone Warehouse in the UK, thanks to
them).
The idea is that option A/B/C in the spec are *brain dead* it either always
refreshes or never refreshes... here we offer a simple way to specify a
refresh time.
How about making the time configurable? in the jboss.xml?
marc
|-----Original Message-----
|From: [EMAIL PROTECTED]
|[mailto:[EMAIL PROTECTED]]On Behalf Of
|[EMAIL PROTECTED]
|Sent: Thursday, May 31, 2001 7:51 PM
|To: [EMAIL PROTECTED]
|Subject: [JBoss-dev] CVS update: jboss/src/main/org/jboss/ejb/plugins
|EntitySynchronizationInterceptor.java
|
|
| User: thedug
| Date: 01/05/31 16:50:47
|
| Modified: src/main/org/jboss/ejb/plugins
| EntitySynchronizationInterceptor.java
| Log:
| Added commit option D.
| Lazy synchronization. Only every 30 seconds
|
| Revision Changes Path
| 1.32 +63 -6
|jboss/src/main/org/jboss/ejb/plugins/EntitySynchronizationInterceptor.java
|
| Index: EntitySynchronizationInterceptor.java
| ===================================================================
| RCS file:
|/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/EntitySynchroni
|zationInterceptor.java,v
| retrieving revision 1.31
| retrieving revision 1.32
| diff -u -r1.31 -r1.32
| --- EntitySynchronizationInterceptor.java 2001/03/11 17:04:17 1.31
| +++ EntitySynchronizationInterceptor.java 2001/05/31 23:50:47 1.32
| @@ -12,6 +12,7 @@
| import java.util.Map;
| import java.util.HashMap;
| import java.util.ArrayList;
| +import java.util.HashSet;
|
| import javax.ejb.EJBObject;
| import javax.ejb.CreateException;
| @@ -48,7 +49,7 @@
| * @see <related>
| * @author Rickard �berg ([EMAIL PROTECTED])
| * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
| -* @version $Revision: 1.31 $
| +* @version $Revision: 1.32 $
| */
| public class EntitySynchronizationInterceptor
| extends AbstractInterceptor
| @@ -72,6 +73,11 @@
| */
| protected Method isModified;
|
| + /**
| + * For commit option D this is the cache of valid entities
| + */
| + protected HashSet validContexts;
| +
| // Static --------------------------------------------------------
|
| // Constructors --------------------------------------------------
| @@ -85,16 +91,25 @@
| public void init()
| throws Exception
| {
| +
| + try{
| +
| + validContexts = new HashSet();
| commitOption =
|container.getBeanMetaData().getContainerConfiguration().getCommitOption();
| - // Check for isModified method
| - try
| - {
| +
| + //start up the validContexts thread if commit option D
| + if(commitOption == ConfigurationMetaData.D_COMMIT_OPTION){
| + ValidContextsRefresher vcr = new
|ValidContextsRefresher(validContexts);
| + new Thread(vcr).start();
| + }
| +
| +
| isModified =
|container.getBeanClass().getMethod("isModified", new Class[0]);
| if (!isModified.getReturnType().equals(Boolean.TYPE))
| isModified = null; // Has to have "boolean" as return type!
| } catch (Exception e)
| {
| - // Ignore
| + System.out.println(e.getMessage());
| }
| }
|
| @@ -182,6 +197,13 @@
| // The Tx coming as part of the Method Invocation
| Transaction tx = mi.getTransaction();
|
| + //Commit Option D....
| + if(!validContexts.contains(ctx.getId())){
| + //bean isn't in cache
| + //so set valid to false so that we load...
| + ctx.setValid(false);
| + }
| +
| //Logger.debug("CTX in: isValid():"+ctx.isValid()+"
|isInvoked():"+ctx.isInvoked());
| //Logger.debug("newTx: "+ tx);
|
| @@ -416,7 +438,6 @@
| // Invalidate state (there might be other
|points of entry)
| ctx.setValid(false);
| break;
| -
| // Invalidate everything AND Passivate instance
| case ConfigurationMetaData.C_COMMIT_OPTION:
| try {
| @@ -425,6 +446,12 @@
| Logger.debug(e);
| }
| break;
| + case ConfigurationMetaData.D_COMMIT_OPTION:
| + //add to cache....
| + //if the cache doesn't time out valid remains true
| + //if the cache is emptied then valid is set
|to false(see invoke() )
| + validContexts.add(ctx.getId());
| + break;
| }
|
| // finish the transaction association
| @@ -439,5 +466,35 @@
| }
| }
| }
| +
| +class ValidContextsRefresher implements Runnable{
| + private HashSet validContexts;
| + private long refreshRate;
| + private final int THIRTY_SECS = 30000;
| +
| + public ValidContextsRefresher(HashSet validContexts,long
|refreshRate){
| + this.validContexts = validContexts;
| + this.refreshRate = refreshRate;
| + }
| +
| + public ValidContextsRefresher(HashSet validContexts){
| + this(validContexts, THIRTY_SECS);
| +
| + }
| +
| + public void run(){
| + while(true){
| + validContexts.clear();
| + // debug System.out.println("Flushing the
|valid contexts");
| + try{
| + Thread.sleep(refreshRate);
| + }catch(Exception e){
| + System.out.println(e.getMessage());
| + }
| + }
| + }
| +
| +}
| +
| }
|
|
|
|
|
|_______________________________________________
|Jboss-development mailing list
|[EMAIL PROTECTED]
|http://lists.sourceforge.net/lists/listinfo/jboss-development
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development