From jbosscache-commits at lists.jboss.org Tue Nov 25 06:08:03 2008 Content-Type: multipart/mixed; boundary="===============5870218622869644790==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r7194 - core/trunk/src/main/java/org/jboss/cache/interceptors. Date: Tue, 25 Nov 2008 06:08:03 -0500 Message-ID: --===============5870218622869644790== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2008-11-25 06:08:02 -0500 (Tue, 25 Nov 2008) New Revision: 7194 Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationIntercep= tor.java core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationIn= terceptor.java Log: Passivation efficiency improvements Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationI= nterceptor.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterce= ptor.java 2008-11-24 22:07:40 UTC (rev 7193) +++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterce= ptor.java 2008-11-25 11:08:02 UTC (rev 7194) @@ -32,13 +32,7 @@ import org.jboss.cache.commands.read.GetNodeCommand; import org.jboss.cache.commands.tx.OptimisticPrepareCommand; import org.jboss.cache.commands.tx.PrepareCommand; -import org.jboss.cache.commands.write.ClearDataCommand; -import org.jboss.cache.commands.write.MoveCommand; -import org.jboss.cache.commands.write.PutDataMapCommand; -import org.jboss.cache.commands.write.PutForExternalReadCommand; -import org.jboss.cache.commands.write.PutKeyValueCommand; -import org.jboss.cache.commands.write.RemoveKeyCommand; -import org.jboss.cache.commands.write.RemoveNodeCommand; +import org.jboss.cache.commands.write.*; import org.jboss.cache.factories.annotations.Inject; import org.jboss.cache.factories.annotations.Start; import org.jboss.cache.jmx.annotations.ManagedAttribute; @@ -48,11 +42,7 @@ = import javax.transaction.SystemException; import javax.transaction.TransactionManager; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; = /** @@ -63,366 +53,308 @@ * @author {Hany Mesha} * @version $Id$ */ -public class ActivationInterceptor extends CacheLoaderInterceptor -{ +public class ActivationInterceptor extends CacheLoaderInterceptor { = - protected TransactionManager txMgr =3D null; - private long activations =3D 0; - ActivationModificationsBuilder builder; + protected TransactionManager txMgr =3D null; + private long activations =3D 0; + ActivationModificationsBuilder builder; = - /** - * List that we have registered for - */ - protected ConcurrentHashMap transactions =3D new ConcurrentHashMap(16); - protected static final Object NULL =3D new Object(); + /** + * List that we have registered for + */ + protected ConcurrentHashMap transactions =3D new ConcurrentHashMap(16); + protected static final Object NULL =3D new Object(); = - public ActivationInterceptor() - { - isActivation =3D true; - useCacheStore =3D false; - } + public ActivationInterceptor() { + isActivation =3D true; + useCacheStore =3D false; + } = - @Inject - public void injectTransactionManager(TransactionManager txMgr) - { - this.txMgr =3D txMgr; - } + @Inject + public void injectTransactionManager(TransactionManager txMgr) { + this.txMgr =3D txMgr; + } = - @Start - public void createModificationsBuilder() - { - builder =3D new ActivationModificationsBuilder(); - } + @Start + public void createModificationsBuilder() { + builder =3D new ActivationModificationsBuilder(); + } = - @Override - public Object visitClearDataCommand(InvocationContext ctx, ClearDataCom= mand command) throws Throwable - { - Object returnValue =3D super.visitClearDataCommand(ctx, command); - if (trace) - log.trace("This is a remove data operation; removing the data fro= m the loader, no activation processing needed."); - loader.removeData(command.getFqn()); - return returnValue; - } + @Override + public Object visitClearDataCommand(InvocationContext ctx, ClearDataCo= mmand command) throws Throwable { + Object returnValue =3D super.visitClearDataCommand(ctx, command); + if (trace) + log.trace("This is a remove data operation; removing the data = from the loader, no activation processing needed."); + loader.removeData(command.getFqn()); + return returnValue; + } = - @Override - public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeC= ommand command) throws Throwable - { - Object returnValue =3D super.visitRemoveNodeCommand(ctx, command); - if (trace) - log.trace("This is a remove operation; removing the node from the= loader, no activation processing needed."); - loader.remove(command.getFqn()); - return returnValue; - } + @Override + public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNode= Command command) throws Throwable { + Object returnValue =3D super.visitRemoveNodeCommand(ctx, command); + if (trace) + log.trace("This is a remove operation; removing the node from = the loader, no activation processing needed."); + loader.remove(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetCh= ildrenNamesCommand command) throws Throwable - { - Object returnValue =3D super.visitGetChildrenNamesCommand(ctx, comma= nd); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetC= hildrenNamesCommand command) throws Throwable { + Object returnValue =3D super.visitGetChildrenNamesCommand(ctx, com= mand); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand= command) throws Throwable - { - Object returnValue =3D super.visitGetKeysCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetKeysCommand(InvocationContext ctx, GetKeysComman= d command) throws Throwable { + Object returnValue =3D super.visitGetKeysCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand= command) throws Throwable - { - Object returnValue =3D super.visitGetNodeCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetNodeCommand(InvocationContext ctx, GetNodeComman= d command) throws Throwable { + Object returnValue =3D super.visitGetNodeCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValu= eCommand command) throws Throwable - { - Object returnValue =3D super.visitGetKeyValueCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyVal= ueCommand command) throws Throwable { + Object returnValue =3D super.visitGetKeyValueCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitPutForExternalReadCommand(InvocationContext ctx, Put= ForExternalReadCommand command) throws Throwable - { - return visitPutKeyValueCommand(ctx, command); - } + @Override + public Object visitPutForExternalReadCommand(InvocationContext ctx, Pu= tForExternalReadCommand command) throws Throwable { + return visitPutKeyValueCommand(ctx, command); + } = - @Override - public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValu= eCommand command) throws Throwable - { - Object returnValue =3D super.visitPutKeyValueCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyVal= ueCommand command) throws Throwable { + Object returnValue =3D super.visitPutKeyValueCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapC= ommand command) throws Throwable - { - Object returnValue =3D super.visitPutDataMapCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMap= Command command) throws Throwable { + Object returnValue =3D super.visitPutDataMapCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCom= mand command) throws Throwable - { - Object returnValue =3D super.visitRemoveKeyCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCo= mmand command) throws Throwable { + Object returnValue =3D super.visitRemoveKeyCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitMoveCommand(InvocationContext ctx, MoveCommand comma= nd) throws Throwable - { - Object returnValue =3D super.visitMoveCommand(ctx, command); - if (trace) - log.trace("This is a move operation; removing the FROM node from = the loader, no activation processing needed."); - loader.remove(command.getFqn()); - removeNodeFromCacheLoader(command.getFqn().getParent()); - removeNodeFromCacheLoader(command.getTo()); - return returnValue; - } + @Override + public Object visitMoveCommand(InvocationContext ctx, MoveCommand comm= and) throws Throwable { + Object returnValue =3D super.visitMoveCommand(ctx, command); + if (trace) + log.trace("This is a move operation; removing the FROM node fr= om the loader, no activation processing needed."); + loader.remove(command.getFqn()); + removeNodeFromCacheLoader(command.getFqn().getParent()); + removeNodeFromCacheLoader(command.getTo()); + return returnValue; + } = = - /** - * Remove the node from the cache loader if it exists in memory, - * its attributes have been initialized, its children have been loaded, - * AND it was found in the cache loader (nodeLoaded =3D true). - * Then notify the listeners that the node has been activated. - */ - private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable - { - if (fqn =3D=3D null) return; - InternalNode n; - if (((n =3D dataContainer.peekInternalNode(fqn, true)) !=3D null) &&= n.isDataLoaded() && loader.exists(fqn)) - { - // node not null and attributes have been loaded? - if (n.hasChildren()) - { - boolean result =3D childrenLoaded(n); - if (result) - { - log.debug("children all initialized"); - remove(fqn); + /** + * Remove the node from the cache loader if it exists in memory, + * its attributes have been initialized, its children have been loaded, + * AND it was found in the cache loader (nodeLoaded =3D true). + */ + private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable { + if (fqn =3D=3D null) return; + InternalNode n; + if (((n =3D dataContainer.peekInternalNode(fqn, true)) !=3D null) = && n.isDataLoaded()) { + // node not null and attributes have been loaded? + if (n.hasChildren()) { + boolean result =3D childrenLoaded(n); + if (result) { + log.debug("children all initialized"); + remove(fqn); + } + } else if (loaderNoChildren(fqn)) { + if (log.isDebugEnabled()) log.debug("no children " + n); + remove(fqn); } - } - else if (loaderNoChildren(fqn)) - { - if (log.isDebugEnabled()) log.debug("no children " + n); - remove(fqn); - } - } - } + } + } = - private boolean childrenLoaded(InternalNode node) - { - if (!node.isChildrenLoaded()) - { - return false; - } - for (InternalNode child : node.getChildren()) - { - if (!child.isDataLoaded()) - { + private boolean childrenLoaded(InternalNode node) { + if (!node.isChildrenLoaded()) { return false; - } + } + for (InternalNode child : node.getChildren()) { + if (!child.isDataLoaded()) { + return false; + } = - if (child.hasChildren()) - { - if (!childrenLoaded(child)) - return false; - } - else if (!loaderNoChildren(child.getFqn())) - { - return false; - } - } - return true; + if (child.hasChildren()) { + if (!childrenLoaded(child)) + return false; + } else if (!loaderNoChildren(child.getFqn())) { + return false; + } + } + return true; = - } + } = - @Override - public Object visitOptimisticPrepareCommand(InvocationContext ctx, Opti= misticPrepareCommand command) throws Throwable - { - Object retval =3D invokeNextInterceptor(ctx, command); - if (inTransaction()) - { - prepareCacheLoader(ctx); - } - return retval; - } + @Override + public Object visitOptimisticPrepareCommand(InvocationContext ctx, Opt= imisticPrepareCommand command) throws Throwable { + Object retval =3D invokeNextInterceptor(ctx, command); + if (inTransaction()) { + prepareCacheLoader(ctx); + } + return retval; + } = - private boolean inTransaction() throws SystemException - { - return txMgr !=3D null && txMgr.getTransaction() !=3D null; - } + private boolean inTransaction() throws SystemException { + return txMgr !=3D null && txMgr.getTransaction() !=3D null; + } = - @Override - public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand= command) throws Throwable - { - Object retval =3D invokeNextInterceptor(ctx, command); - if (inTransaction()) - { - prepareCacheLoader(ctx); - } - return retval; - } + @Override + public Object visitPrepareCommand(InvocationContext ctx, PrepareComman= d command) throws Throwable { + Object retval =3D invokeNextInterceptor(ctx, command); + if (inTransaction()) { + prepareCacheLoader(ctx); + } + return retval; + } = - private void remove(Fqn fqn) throws Exception - { - loader.remove(fqn); - if (getStatisticsEnabled()) activations++; - } + private void remove(Fqn fqn) throws Exception { + loader.remove(fqn); + if (getStatisticsEnabled()) activations++; + } = - /** - * Returns true if the loader indicates no children for this node. - * Return false on error. - */ - private boolean loaderNoChildren(Fqn fqn) - { - try - { - Set childrenNames =3D loader.getChildrenNames(fqn); - return (childrenNames =3D=3D null); - } - catch (Exception e) - { - log.error("failed getting the children names for " + fqn + " from= the cache loader", e); - return false; - } - } + /** + * Returns true if the loader indicates no children for this node. + * Return false on error. + */ + private boolean loaderNoChildren(Fqn fqn) { + try { + Set childrenNames =3D loader.getChildrenNames(fqn); + return (childrenNames =3D=3D null); + } + catch (Exception e) { + log.error("failed getting the children names for " + fqn + " f= rom the cache loader", e); + return false; + } + } = - private void prepareCacheLoader(InvocationContext ctx) throws Throwable - { - GlobalTransaction gtx =3D ctx.getGlobalTransaction(); - TransactionContext tCtx =3D ctx.getTransactionContext(); - if (tCtx =3D=3D null) - { - throw new Exception("tCtx for transaction " + gtx + " not found i= n transaction table"); - } - List cacheLoaderModifications =3D new ArrayList(); + private void prepareCacheLoader(InvocationContext ctx) throws Throwabl= e { + GlobalTransaction gtx =3D ctx.getGlobalTransaction(); + TransactionContext tCtx =3D ctx.getTransactionContext(); + if (tCtx =3D=3D null) { + throw new Exception("tCtx for transaction " + gtx + " not foun= d in transaction table"); + } + List cacheLoaderModifications =3D new ArrayList(); = - builder.visitCollection(ctx, tCtx.getModifications()); - if (cacheLoaderModifications.size() > 0) - { - loader.prepare(gtx, cacheLoaderModifications, false); - } - } + builder.visitCollection(ctx, tCtx.getModifications()); + if (cacheLoaderModifications.size() > 0) { + loader.prepare(gtx, cacheLoaderModifications, false); + } + } = - public class ActivationModificationsBuilder extends AbstractVisitor - { + public class ActivationModificationsBuilder extends AbstractVisitor { = - private List cacheLoaderModifications =3D new ArrayLis= t(); + private List cacheLoaderModifications =3D new ArrayL= ist(); = - private int txActs =3D 0; + private int txActs =3D 0; = - @Override - public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNo= deCommand removeNodeCommand) throws Throwable - { - Modification mod =3D new Modification(Modification.ModificationTy= pe.REMOVE_NODE, removeNodeCommand.getFqn()); - cacheLoaderModifications.add(mod); - return null; - } + @Override + public Object visitRemoveNodeCommand(InvocationContext ctx, Remove= NodeCommand removeNodeCommand) throws Throwable { + Modification mod =3D new Modification(Modification.Modificatio= nType.REMOVE_NODE, removeNodeCommand.getFqn()); + cacheLoaderModifications.add(mod); + return null; + } = - @Override - public Object visitPutDataMapCommand(InvocationContext ctx, PutDataM= apCommand command) throws Throwable - { - Fqn fqn =3D command.getFqn(); - handlePutCommand(ctx, fqn); - return null; - } + @Override + public Object visitPutDataMapCommand(InvocationContext ctx, PutDat= aMapCommand command) throws Throwable { + Fqn fqn =3D command.getFqn(); + handlePutCommand(ctx, fqn); + return null; + } = - @Override - public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyV= alueCommand command) throws Throwable - { - Fqn fqn =3D command.getFqn(); - handlePutCommand(ctx, fqn); - return null; - } + @Override + public Object visitPutKeyValueCommand(InvocationContext ctx, PutKe= yValueCommand command) throws Throwable { + Fqn fqn =3D command.getFqn(); + handlePutCommand(ctx, fqn); + return null; + } = - // On the way out, remove the node from the cache loader. - // Only remove the node if it exists in memory, its attributes have - // been initialized, its children have been loaded - // AND it was found in the cache loader (nodeLoaded =3D true). - // Then notify the listeners that the node has been activated. - private void handlePutCommand(InvocationContext ctx, Fqn fqn) - throws Exception - { - if (fqn !=3D null && dataContainer.exists(fqn) && loader.exists(f= qn)) - { - InternalNode n =3D dataContainer.peekInternalNode(fqn, true);/= / don't load - // node not null and attributes have been loaded? - if (n !=3D null && n.isDataLoaded()) - { - // has children? - boolean result =3D childrenLoaded(n); - if (n.hasChildren() && result) - { - // children have been loaded, remove the node - addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getDa= ta()); - txActs++; - } - // doesn't have children, check the cache loader - else if (loaderNoChildren(fqn)) - { - addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getDa= ta()); - txActs++; - } + // On the way out, remove the node from the cache loader. + // Only remove the node if it exists in memory, its attributes have + // been initialized, its children have been loaded + // AND it was found in the cache loader (nodeLoaded =3D true). + // Then notify the listeners that the node has been activated. + private void handlePutCommand(InvocationContext ctx, Fqn fqn) + throws Exception { + if (fqn !=3D null && dataContainer.exists(fqn) && loader.exist= s(fqn)) { + InternalNode n =3D dataContainer.peekInternalNode(fqn, tru= e);// don't load + // node not null and attributes have been loaded? + if (n !=3D null && n.isDataLoaded()) { + // has children? + boolean result =3D childrenLoaded(n); + if (n.hasChildren() && result) { + // children have been loaded, remove the node + addRemoveMod(ctx, cacheLoaderModifications, fqn, n= .getData()); + txActs++; + } + // doesn't have children, check the cache loader + else if (loaderNoChildren(fqn)) { + addRemoveMod(ctx, cacheLoaderModifications, fqn, n= .getData()); + txActs++; + } + } } - } - } + } = - private boolean loaderNoChildren(Fqn fqn) throws Exception - { - return loader.getChildrenNames(fqn) !=3D null; - } + private boolean loaderNoChildren(Fqn fqn) throws Exception { + return loader.getChildrenNames(fqn) !=3D null; + } = - private void addRemoveMod(InvocationContext ctx, List = l, Fqn fqn, Map data) - { - Modification mod =3D new Modification(Modification.ModificationTy= pe.REMOVE_NODE, fqn); - l.add(mod); - notifier.notifyNodeActivated(fqn, false, data, ctx); - } + private void addRemoveMod(InvocationContext ctx, List l, Fqn fqn, Map data) { + Modification mod =3D new Modification(Modification.Modificatio= nType.REMOVE_NODE, fqn); + l.add(mod); + notifier.notifyNodeActivated(fqn, false, data, ctx); + } = - public List getCacheLoaderModifications() - { - return cacheLoaderModifications; - } + public List getCacheLoaderModifications() { + return cacheLoaderModifications; + } = - public int getTxActs() - { - return txActs; - } + public int getTxActs() { + return txActs; + } = - } + } = - @ManagedAttribute(description =3D "number of cache node activations") - public long getActivations() - { - return activations; - } + @ManagedAttribute(description =3D "number of cache node activations") + public long getActivations() { + return activations; + } = - @ManagedOperation - public void resetStatistics() - { - super.resetStatistics(); - activations =3D 0; - } + @ManagedOperation + public void resetStatistics() { + super.resetStatistics(); + activations =3D 0; + } = - @ManagedOperation - public Map dumpStatistics() - { - Map retval =3D super.dumpStatistics(); - if (retval =3D=3D null) - { - retval =3D new HashMap(); - } - retval.put("Activations", activations); - return retval; - } + @ManagedOperation + public Map dumpStatistics() { + Map retval =3D super.dumpStatistics(); + if (retval =3D=3D null) { + retval =3D new HashMap(); + } + retval.put("Activations", activations); + return retval; + } } Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActiv= ationInterceptor.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationI= nterceptor.java 2008-11-24 22:07:40 UTC (rev 7193) +++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationI= nterceptor.java 2008-11-25 11:08:02 UTC (rev 7194) @@ -32,13 +32,7 @@ import org.jboss.cache.commands.read.GetNodeCommand; import org.jboss.cache.commands.tx.OptimisticPrepareCommand; import org.jboss.cache.commands.tx.PrepareCommand; -import org.jboss.cache.commands.write.ClearDataCommand; -import org.jboss.cache.commands.write.MoveCommand; -import org.jboss.cache.commands.write.PutDataMapCommand; -import org.jboss.cache.commands.write.PutForExternalReadCommand; -import org.jboss.cache.commands.write.PutKeyValueCommand; -import org.jboss.cache.commands.write.RemoveKeyCommand; -import org.jboss.cache.commands.write.RemoveNodeCommand; +import org.jboss.cache.commands.write.*; import org.jboss.cache.factories.annotations.Inject; import org.jboss.cache.factories.annotations.Start; import org.jboss.cache.jmx.annotations.ManagedOperation; @@ -47,11 +41,7 @@ = import javax.transaction.SystemException; import javax.transaction.TransactionManager; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; = /** @@ -64,364 +54,306 @@ * @deprecated will be removed along with optimistic and pessimistic locki= ng. */ @Deprecated -public class LegacyActivationInterceptor extends LegacyCacheLoaderIntercep= tor -{ +public class LegacyActivationInterceptor extends LegacyCacheLoaderIntercep= tor { = - protected TransactionManager txMgr =3D null; - private long activations =3D 0; - ActivationModificationsBuilder builder; + protected TransactionManager txMgr =3D null; + private long activations =3D 0; + ActivationModificationsBuilder builder; = - /** - * List that we have registered for - */ - protected ConcurrentHashMap transactions =3D new ConcurrentHashMap(16); - protected static final Object NULL =3D new Object(); + /** + * List that we have registered for + */ + protected ConcurrentHashMap transactions =3D new ConcurrentHashMap(16); + protected static final Object NULL =3D new Object(); = - public LegacyActivationInterceptor() - { - isActivation =3D true; - useCacheStore =3D false; - } + public LegacyActivationInterceptor() { + isActivation =3D true; + useCacheStore =3D false; + } = - @Inject - public void injectTransactionManager(TransactionManager txMgr) - { - this.txMgr =3D txMgr; - } + @Inject + public void injectTransactionManager(TransactionManager txMgr) { + this.txMgr =3D txMgr; + } = - @Start - public void createModificationsBuilder() - { - builder =3D new ActivationModificationsBuilder(); - } + @Start + public void createModificationsBuilder() { + builder =3D new ActivationModificationsBuilder(); + } = - @Override - public Object visitClearDataCommand(InvocationContext ctx, ClearDataCom= mand command) throws Throwable - { - Object returnValue =3D super.visitClearDataCommand(ctx, command); - if (trace) - log.trace("This is a remove data operation; removing the data fro= m the loader, no activation processing needed."); - loader.removeData(command.getFqn()); - return returnValue; - } + @Override + public Object visitClearDataCommand(InvocationContext ctx, ClearDataCo= mmand command) throws Throwable { + Object returnValue =3D super.visitClearDataCommand(ctx, command); + if (trace) + log.trace("This is a remove data operation; removing the data = from the loader, no activation processing needed."); + loader.removeData(command.getFqn()); + return returnValue; + } = - @Override - public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeC= ommand command) throws Throwable - { - Object returnValue =3D super.visitRemoveNodeCommand(ctx, command); - if (trace) - log.trace("This is a remove operation; removing the node from the= loader, no activation processing needed."); - loader.remove(command.getFqn()); - return returnValue; - } + @Override + public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNode= Command command) throws Throwable { + Object returnValue =3D super.visitRemoveNodeCommand(ctx, command); + if (trace) + log.trace("This is a remove operation; removing the node from = the loader, no activation processing needed."); + loader.remove(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetCh= ildrenNamesCommand command) throws Throwable - { - Object returnValue =3D super.visitGetChildrenNamesCommand(ctx, comma= nd); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetC= hildrenNamesCommand command) throws Throwable { + Object returnValue =3D super.visitGetChildrenNamesCommand(ctx, com= mand); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand= command) throws Throwable - { - Object returnValue =3D super.visitGetKeysCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetKeysCommand(InvocationContext ctx, GetKeysComman= d command) throws Throwable { + Object returnValue =3D super.visitGetKeysCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand= command) throws Throwable - { - Object returnValue =3D super.visitGetNodeCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetNodeCommand(InvocationContext ctx, GetNodeComman= d command) throws Throwable { + Object returnValue =3D super.visitGetNodeCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValu= eCommand command) throws Throwable - { - Object returnValue =3D super.visitGetKeyValueCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyVal= ueCommand command) throws Throwable { + Object returnValue =3D super.visitGetKeyValueCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitPutForExternalReadCommand(InvocationContext ctx, Put= ForExternalReadCommand command) throws Throwable - { - return visitPutKeyValueCommand(ctx, command); - } + @Override + public Object visitPutForExternalReadCommand(InvocationContext ctx, Pu= tForExternalReadCommand command) throws Throwable { + return visitPutKeyValueCommand(ctx, command); + } = - @Override - public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValu= eCommand command) throws Throwable - { - Object returnValue =3D super.visitPutKeyValueCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyVal= ueCommand command) throws Throwable { + Object returnValue =3D super.visitPutKeyValueCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapC= ommand command) throws Throwable - { - Object returnValue =3D super.visitPutDataMapCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMap= Command command) throws Throwable { + Object returnValue =3D super.visitPutDataMapCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCom= mand command) throws Throwable - { - Object returnValue =3D super.visitRemoveKeyCommand(ctx, command); - removeNodeFromCacheLoader(command.getFqn()); - return returnValue; - } + @Override + public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCo= mmand command) throws Throwable { + Object returnValue =3D super.visitRemoveKeyCommand(ctx, command); + removeNodeFromCacheLoader(command.getFqn()); + return returnValue; + } = - @Override - public Object visitMoveCommand(InvocationContext ctx, MoveCommand comma= nd) throws Throwable - { - Object returnValue =3D super.visitMoveCommand(ctx, command); - if (trace) - log.trace("This is a move operation; removing the FROM node from = the loader, no activation processing needed."); - loader.remove(command.getFqn()); - removeNodeFromCacheLoader(command.getFqn().getParent()); - removeNodeFromCacheLoader(command.getTo()); - return returnValue; - } + @Override + public Object visitMoveCommand(InvocationContext ctx, MoveCommand comm= and) throws Throwable { + Object returnValue =3D super.visitMoveCommand(ctx, command); + if (trace) + log.trace("This is a move operation; removing the FROM node fr= om the loader, no activation processing needed."); + loader.remove(command.getFqn()); + removeNodeFromCacheLoader(command.getFqn().getParent()); + removeNodeFromCacheLoader(command.getTo()); + return returnValue; + } = = - /** - * Remove the node from the cache loader if it exists in memory, - * its attributes have been initialized, its children have been loaded, - * AND it was found in the cache loader (nodeLoaded =3D true). - * Then notify the listeners that the node has been activated. - */ - private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable - { - NodeSPI n; - if (((n =3D dataContainer.peek(fqn, true, false)) !=3D null) && n.is= DataLoaded() && loader.exists(fqn)) - { - // node not null and attributes have been loaded? - if (!n.getChildrenDirect().isEmpty()) - { - boolean result =3D childrenLoaded(n); - if (result) - { - log.debug("children all initialized"); - remove(fqn); + /** + * Remove the node from the cache loader if it exists in memory, + * its attributes have been initialized, its children have been loaded, + * AND it was found in the cache loader (nodeLoaded =3D true). + */ + private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable { + NodeSPI n; + if (((n =3D dataContainer.peek(fqn, true, false)) !=3D null) && n.= isDataLoaded()) { + // node not null and attributes have been loaded? + if (!n.getChildrenDirect().isEmpty()) { + boolean result =3D childrenLoaded(n); + if (result) { + log.debug("children all initialized"); + remove(fqn); + } + } else if (loaderNoChildren(fqn)) { + if (log.isDebugEnabled()) log.debug("no children " + n); + remove(fqn); } - } - else if (loaderNoChildren(fqn)) - { - if (log.isDebugEnabled()) log.debug("no children " + n); - remove(fqn); - } - } - } + } + } = - private boolean childrenLoaded(NodeSPI node) - { - if (!node.isChildrenLoaded()) - { - return false; - } - for (NodeSPI child : node.getChildrenDirect()) - { - if (!child.isDataLoaded()) - { + private boolean childrenLoaded(NodeSPI node) { + if (!node.isChildrenLoaded()) { return false; - } + } + for (NodeSPI child : node.getChildrenDirect()) { + if (!child.isDataLoaded()) { + return false; + } = - if (child.getChildrenDirect().size() > 0) - { - if (!childrenLoaded(child)) - return false; - } - else if (!loaderNoChildren(child.getFqn())) - { - return false; - } - } - return true; + if (child.getChildrenDirect().size() > 0) { + if (!childrenLoaded(child)) + return false; + } else if (!loaderNoChildren(child.getFqn())) { + return false; + } + } + return true; = - } + } = - @Override - public Object visitOptimisticPrepareCommand(InvocationContext ctx, Opti= misticPrepareCommand command) throws Throwable - { - Object retval =3D invokeNextInterceptor(ctx, command); - if (inTransaction()) - { - prepareCacheLoader(ctx); - } - return retval; - } + @Override + public Object visitOptimisticPrepareCommand(InvocationContext ctx, Opt= imisticPrepareCommand command) throws Throwable { + Object retval =3D invokeNextInterceptor(ctx, command); + if (inTransaction()) { + prepareCacheLoader(ctx); + } + return retval; + } = - private boolean inTransaction() throws SystemException - { - return txMgr !=3D null && txMgr.getTransaction() !=3D null; - } + private boolean inTransaction() throws SystemException { + return txMgr !=3D null && txMgr.getTransaction() !=3D null; + } = - @Override - public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand= command) throws Throwable - { - Object retval =3D invokeNextInterceptor(ctx, command); - if (inTransaction()) - { - prepareCacheLoader(ctx); - } - return retval; - } + @Override + public Object visitPrepareCommand(InvocationContext ctx, PrepareComman= d command) throws Throwable { + Object retval =3D invokeNextInterceptor(ctx, command); + if (inTransaction()) { + prepareCacheLoader(ctx); + } + return retval; + } = - private void remove(Fqn fqn) throws Exception - { - loader.remove(fqn); - if (getStatisticsEnabled()) activations++; - } + private void remove(Fqn fqn) throws Exception { + loader.remove(fqn); + if (getStatisticsEnabled()) activations++; + } = - /** - * Returns true if the loader indicates no children for this node. - * Return false on error. - */ - private boolean loaderNoChildren(Fqn fqn) - { - try - { - Set childrenNames =3D loader.getChildrenNames(fqn); - return (childrenNames =3D=3D null); - } - catch (Exception e) - { - log.error("failed getting the children names for " + fqn + " from= the cache loader", e); - return false; - } - } + /** + * Returns true if the loader indicates no children for this node. + * Return false on error. + */ + private boolean loaderNoChildren(Fqn fqn) { + try { + Set childrenNames =3D loader.getChildrenNames(fqn); + return (childrenNames =3D=3D null); + } + catch (Exception e) { + log.error("failed getting the children names for " + fqn + " f= rom the cache loader", e); + return false; + } + } = - public long getActivations() - { - return activations; - } + public long getActivations() { + return activations; + } = - private void prepareCacheLoader(InvocationContext ctx) throws Throwable - { - GlobalTransaction gtx =3D ctx.getGlobalTransaction(); - TransactionContext tCtx =3D ctx.getTransactionContext(); - if (tCtx =3D=3D null) - { - throw new Exception("tCtx for transaction " + gtx + " not found i= n transaction table"); - } - List cacheLoaderModifications =3D new ArrayList(); + private void prepareCacheLoader(InvocationContext ctx) throws Throwabl= e { + GlobalTransaction gtx =3D ctx.getGlobalTransaction(); + TransactionContext tCtx =3D ctx.getTransactionContext(); + if (tCtx =3D=3D null) { + throw new Exception("tCtx for transaction " + gtx + " not foun= d in transaction table"); + } + List cacheLoaderModifications =3D new ArrayList(); = - builder.visitCollection(ctx, tCtx.getModifications()); - if (cacheLoaderModifications.size() > 0) - { - loader.prepare(gtx, cacheLoaderModifications, false); - } - } + builder.visitCollection(ctx, tCtx.getModifications()); + if (cacheLoaderModifications.size() > 0) { + loader.prepare(gtx, cacheLoaderModifications, false); + } + } = - public class ActivationModificationsBuilder extends AbstractVisitor - { + public class ActivationModificationsBuilder extends AbstractVisitor { = - private List cacheLoaderModifications =3D new ArrayLis= t(); + private List cacheLoaderModifications =3D new ArrayL= ist(); = - private int txActs =3D 0; + private int txActs =3D 0; = - @Override - public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNo= deCommand removeNodeCommand) throws Throwable - { - Modification mod =3D new Modification(Modification.ModificationTy= pe.REMOVE_NODE, removeNodeCommand.getFqn()); - cacheLoaderModifications.add(mod); - return null; - } + @Override + public Object visitRemoveNodeCommand(InvocationContext ctx, Remove= NodeCommand removeNodeCommand) throws Throwable { + Modification mod =3D new Modification(Modification.Modificatio= nType.REMOVE_NODE, removeNodeCommand.getFqn()); + cacheLoaderModifications.add(mod); + return null; + } = - @Override - public Object visitPutDataMapCommand(InvocationContext ctx, PutDataM= apCommand command) throws Throwable - { - Fqn fqn =3D command.getFqn(); - handlePutCommand(ctx, fqn); - return null; - } + @Override + public Object visitPutDataMapCommand(InvocationContext ctx, PutDat= aMapCommand command) throws Throwable { + Fqn fqn =3D command.getFqn(); + handlePutCommand(ctx, fqn); + return null; + } = - @Override - public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyV= alueCommand command) throws Throwable - { - Fqn fqn =3D command.getFqn(); - handlePutCommand(ctx, fqn); - return null; - } + @Override + public Object visitPutKeyValueCommand(InvocationContext ctx, PutKe= yValueCommand command) throws Throwable { + Fqn fqn =3D command.getFqn(); + handlePutCommand(ctx, fqn); + return null; + } = - // On the way out, remove the node from the cache loader. - // Only remove the node if it exists in memory, its attributes have - // been initialized, its children have been loaded - // AND it was found in the cache loader (nodeLoaded =3D true). - // Then notify the listeners that the node has been activated. - private void handlePutCommand(InvocationContext ctx, Fqn fqn) - throws Exception - { - if (fqn !=3D null && dataContainer.peek(fqn, false, false) !=3D n= ull && loader.exists(fqn)) - { - NodeSPI n =3D dataContainer.peek(fqn, true, false);// don't lo= ad - // node not null and attributes have been loaded? - if (n !=3D null && n.isDataLoaded()) - { - // has children? - boolean result =3D childrenLoaded(n); - if (!n.getChildrenDirect().isEmpty() && result) - { - // children have been loaded, remove the node - addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getDa= taDirect()); - txActs++; - } - // doesn't have children, check the cache loader - else if (loaderNoChildren(fqn)) - { - addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getDa= taDirect()); - txActs++; - } + // On the way out, remove the node from the cache loader. + // Only remove the node if it exists in memory, its attributes have + // been initialized, its children have been loaded + // AND it was found in the cache loader (nodeLoaded =3D true). + // Then notify the listeners that the node has been activated. + private void handlePutCommand(InvocationContext ctx, Fqn fqn) + throws Exception { + if (fqn !=3D null && dataContainer.peek(fqn, false, false) != =3D null && loader.exists(fqn)) { + NodeSPI n =3D dataContainer.peek(fqn, true, false);// don'= t load + // node not null and attributes have been loaded? + if (n !=3D null && n.isDataLoaded()) { + // has children? + boolean result =3D childrenLoaded(n); + if (!n.getChildrenDirect().isEmpty() && result) { + // children have been loaded, remove the node + addRemoveMod(ctx, cacheLoaderModifications, fqn, n= .getDataDirect()); + txActs++; + } + // doesn't have children, check the cache loader + else if (loaderNoChildren(fqn)) { + addRemoveMod(ctx, cacheLoaderModifications, fqn, n= .getDataDirect()); + txActs++; + } + } } - } - } + } = - private boolean loaderNoChildren(Fqn fqn) throws Exception - { - return loader.getChildrenNames(fqn) !=3D null; - } + private boolean loaderNoChildren(Fqn fqn) throws Exception { + return loader.getChildrenNames(fqn) !=3D null; + } = - private void addRemoveMod(InvocationContext ctx, List = l, Fqn fqn, Map data) - { - Modification mod =3D new Modification(Modification.ModificationTy= pe.REMOVE_NODE, fqn); - l.add(mod); - notifier.notifyNodeActivated(fqn, false, data, ctx); - } + private void addRemoveMod(InvocationContext ctx, List l, Fqn fqn, Map data) { + Modification mod =3D new Modification(Modification.Modificatio= nType.REMOVE_NODE, fqn); + l.add(mod); + notifier.notifyNodeActivated(fqn, false, data, ctx); + } = - public List getCacheLoaderModifications() - { - return cacheLoaderModifications; - } + public List getCacheLoaderModifications() { + return cacheLoaderModifications; + } = - public int getTxActs() - { - return txActs; - } + public int getTxActs() { + return txActs; + } = - } + } = - @ManagedOperation - public void resetStatistics() - { - super.resetStatistics(); - activations =3D 0; - } + @ManagedOperation + public void resetStatistics() { + super.resetStatistics(); + activations =3D 0; + } = - @ManagedOperation - public Map dumpStatistics() - { - Map retval =3D super.dumpStatistics(); - if (retval =3D=3D null) - { - retval =3D new HashMap(); - } - retval.put("Activations", activations); - return retval; - } + @ManagedOperation + public Map dumpStatistics() { + Map retval =3D super.dumpStatistics(); + if (retval =3D=3D null) { + retval =3D new HashMap(); + } + retval.put("Activations", activations); + return retval; + } } \ No newline at end of file --===============5870218622869644790==--