JBoss Cache SVN: r4851 - in core/trunk/src: main/java/org/jboss/cache/buddyreplication and 12 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-13 17:36:59 -0500 (Thu, 13 Dec 2007)
New Revision: 4851
Modified:
core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java
core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java
core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java
Log:
reduced failure count, improved logging and comments
Modified: core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -36,7 +36,7 @@
{
for (Node<?, ?> child : children.values())
{
- ((AbstractNode) child).markAsDeleted(marker, true);
+ ((NodeSPI) child).markAsDeleted(marker, true);
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -13,13 +13,14 @@
import org.jboss.cache.buddyreplication.BuddyNotInitException;
import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.config.Option;
import org.jboss.cache.config.RuntimeConfig;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.InterceptorChainFactory;
+import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
@@ -218,10 +219,14 @@
return componentRegistry;
}
+ // NOTE: The RemoteCacheInvocationDelegate is a bit tricky since it is a subclass for CacheInvocationDelegate and hence
+ // also an implementation of CacheSPI. Components requesting a CacheSPI may inadvertently get a RemoteCacheInvocationDelegate
+ // To work around this, I'm explicitly naming the RCID as a "remoteDelegate". Perhaps all components should be named.
+
@Inject
- private void injectDependencies(Notifier notifier, RegionManager regionManager, TransactionManager transactionManager,
+ private void injectDependencies(Notifier notifier, RegionManager regionManager, TransactionManager transactionManager, Marshaller marshaller,
TransactionTable transactionTable, StateTransferManager stateTransferManager, NodeFactory nodeFactory,
- CacheSPI spi, CacheMessageListener messageListener, RemoteCacheInvocationDelegate remoteDelegate)
+ CacheSPI spi, CacheMessageListener messageListener, @ComponentName("remoteDelegate")RemoteCacheInvocationDelegate remoteDelegate)
{
this.notifier = notifier;
this.regionManager = regionManager;
@@ -232,6 +237,7 @@
this.spi = spi;
this.messageListener = messageListener;
this.remoteDelegate = remoteDelegate;
+ this.marshaller = marshaller;
}
public Configuration getConfiguration()
@@ -549,12 +555,7 @@
// if (notifier == null)
// notifier = new Notifier(this);
- // create a new root temporarily.
- NodeSPI tempRoot = nodeFactory.createRootDataNode();
- // if we don't already have a root or the new (temp) root is of a different class (optimistic vs pessimistic) to
- // the current root, then we use the new one. Helps preserve data between cache restarts.
- if (root == null || !root.getClass().equals(tempRoot.getClass()))
- root = tempRoot;
+ correctRootNodeType();
// if (configuration.getCacheLoaderConfig() != null && cacheLoaderManager == null)
// {
@@ -582,57 +583,12 @@
//createEvictionPolicy();
- regionManager.setDefaultInactive(configuration.isInactiveOnStartup());
+ // now done inside the regionManager
+ //regionManager.setDefaultInactive(configuration.isInactiveOnStartup());
cacheStatus = CacheStatus.CREATED;
}
- private void createTransactionManager()
- {
- // See if we had a TransactionManager injected into our config
- this.transactionManager = configuration.getRuntimeConfig().getTransactionManager();
- if (transactionManager == null)
- {
- // Nope. See if we can look it up from JNDI
- if (this.tm_lookup == null && configuration.getTransactionManagerLookupClass() != null)
- {
- try
- {
- Class clazz = Thread.currentThread().getContextClassLoader().loadClass(configuration.getTransactionManagerLookupClass());
- this.tm_lookup = (TransactionManagerLookup) clazz.newInstance();
- }
- catch (Exception e)
- {
- throw new CacheException("Problems creating the cache", e);
- }
- }
-
- try
- {
- if (tm_lookup != null)
- {
- transactionManager = tm_lookup.getTransactionManager();
- configuration.getRuntimeConfig().setTransactionManager(transactionManager);
- }
- else
- {
- if (configuration.getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC)
- {
- log.fatal("No transaction manager lookup class has been defined. Transactions cannot be used and thus OPTIMISTIC locking cannot be used");
- }
- else
- {
- log.info("No transaction manager lookup class has been defined. Transactions cannot be used");
- }
- }
- }
- catch (Exception e)
- {
- log.debug("failed looking up TransactionManager, will not use transactions", e);
- }
- }
- }
-
protected boolean shouldFetchStateOnStartup()
{
boolean loaderFetch = cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState();
@@ -640,6 +596,22 @@
}
/**
+ * Creates a new root node if one does not exist, or if the existing one does not match the type according to the configuration.
+ */
+ private void correctRootNodeType()
+ {
+ // create a new root temporarily.
+ NodeSPI tempRoot = nodeFactory.createRootDataNode();
+ // if we don't already have a root or the new (temp) root is of a different class (optimistic vs pessimistic) to
+ // the current root, then we use the new one.
+
+ Class currentRootType = root == null ? null : ((NodeInvocationDelegate) root).getDelegationTarget().getClass();
+ Class tempRootType = ((NodeInvocationDelegate) tempRoot).getDelegationTarget().getClass();
+
+ if (!tempRootType.equals(currentRootType)) root = tempRoot;
+ }
+
+ /**
* Lifecyle method.
*
* @throws CacheException
@@ -678,8 +650,10 @@
// re-wire all dependencies in case stuff has changed since the cache was created?
// TODO: Do we really need to nuke old deps? :/
CacheSPI spi = componentRegistry.getComponent(CacheSPI.class);
- componentRegistry.reset();
+ // remove the Interceptor.class component though, since it may pertain to an old config
+ componentRegistry.unregisterComponent(Interceptor.class);
+
componentRegistry.registerComponent(configuration);
componentRegistry.registerComponent(this);
componentRegistry.registerComponent(CacheSPI.class, spi);
@@ -693,22 +667,19 @@
// start all internal components
componentRegistry.startComponents();
- // create a new root temporarily.
- NodeSPI tempRoot = nodeFactory.createRootDataNode();
- // if we don't already have a root or the new (temp) root is of a different class (optimistic vs pessimistic) to
- // the current root, then we use the new one. Helps preserve data between cache restarts.
- if (root == null || !root.getClass().equals(tempRoot.getClass()))
- root = tempRoot;
+ correctRootNodeType();
// createTransactionManager();
// cache loaders should be initialised *before* any state transfers take place to prevent
// exceptions involving cache loaders not being started. - Manik
// create cache loader
- if (cacheLoaderManager != null)
- {
- cacheLoaderManager.startCacheLoader();
- }
+
+ // now done in the CLM
+// if (cacheLoaderManager != null)
+// {
+// cacheLoaderManager.startCacheLoader();
+// }
// now that we have a TM we can init the interceptor chain
// InterceptorChainFactory.getInstance().initialiseInterceptors(interceptor_chain, this);
@@ -939,12 +910,14 @@
{
cacheStatus = CacheStatus.STOPPING;
+ componentRegistry.stopComponents();
+
// before closing the channel stop the buddy manager
- if (buddyManager != null && buddyManager.isEnabled())
- {
- log.debug("stop(): stopping buddy manager");
- buddyManager.stop();
- }
+// if (buddyManager != null && buddyManager.isEnabled())
+// {
+// log.debug("stop(): stopping buddy manager");
+// buddyManager.stop();
+// }
if (channel != null)
{
@@ -975,13 +948,15 @@
repl_queue.stop();
}
- if (cacheLoaderManager != null)
- {
- log.debug("stop(): stopping cache loader manager");
- cacheLoaderManager.stopCacheLoader();
- }
+ // now done in the CLM
+// if (cacheLoaderManager != null)
+// {
+// log.debug("stop(): stopping cache loader manager");
+// cacheLoaderManager.stopCacheLoader();
+// }
- if (regionManager.isUsingEvictions()) regionManager.stopEvictionThread();
+ // now done in the region manager
+// if (regionManager.isUsingEvictions()) regionManager.stopEvictionThread();
if (notifier != null)
{
@@ -2659,7 +2634,7 @@
*/
public void invalidate(Fqn fqn, DataVersion versionToInvalidate)
{
- Node node = get(fqn); // force interceptor chain, load if necessary from cache loader.
+ Node node = spi.getNode(fqn); // force interceptor chain, load if necessary from cache loader.
if (node == null)
{
@@ -2684,7 +2659,7 @@
{
suspended = getTransactionManager().suspend();
}
- put(fqn, m);
+ spi.put(fqn, m);
if (suspended != null) getTransactionManager().resume(suspended);
ic.getOptionOverrides().setCacheModeLocal(origCacheModeLocal);
}
@@ -3757,6 +3732,8 @@
disp.setRequestMarshaller(marshaller);
disp.setResponseMarshaller(marshaller);
+
+ if (log.isTraceEnabled()) log.trace("Started with RpcDispatcher " + disp);
}
private JChannel getMultiplexerChannel() throws CacheException
Modified: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -92,6 +92,7 @@
un.setDataLoaded(false);
NodeInvocationDelegate<K, V> nid = new NodeInvocationDelegate(un);
componentRegistry.wireDependencies(nid);
+ componentRegistry.wireDependencies(un);
// back ref
un.setDelegate(nid);
return nid;
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -13,6 +13,7 @@
import org.jboss.cache.eviction.RegionNameConflictException;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.factories.annotations.Stop;
import org.jboss.cache.lock.NodeLock;
import org.jgroups.Address;
@@ -39,7 +40,7 @@
* eviction settings bound under this 'default' Fqn is appplied to {@link org.jboss.cache.Fqn#ROOT} internally so
* any region that is not explicitly defined comes under the settings defined for this default.
*/
- public static final Fqn DEFAULT_REGION = new Fqn("_default_");
+ public static final Fqn<?> DEFAULT_REGION = new Fqn<String>("_default_");
/**
* A registry of regions that have been defined.
@@ -64,6 +65,7 @@
Region r = new RegionImpl(Fqn.ROOT, this);
r.registerContextClassLoader(Thread.currentThread().getContextClassLoader() == null ? this.getClass().getClassLoader() : Thread.currentThread().getContextClassLoader());
r.setActive(true);
+ regionsRegistry.put(Fqn.ROOT, r);
}
@Inject
@@ -74,8 +76,9 @@
}
@Start
- protected void createEvictionPolicy()
+ protected void start()
{
+ log.trace("Starting region manager");
if (configuration.getEvictionConfig() != null
&& configuration.getEvictionConfig().isValidConfig())
{
@@ -87,10 +90,20 @@
setUsingEvictions(false);
log.debug("Not using an EvictionPolicy");
}
+
+ setDefaultInactive(configuration.isInactiveOnStartup());
+ if (log.isTraceEnabled())
+ log.trace("Finished region manager. Default region is " + regionsRegistry.get(Fqn.ROOT));
}
+ @Stop
+ protected void stop()
+ {
+ if (isUsingEvictions()) stopEvictionThread();
+ }
+
/**
- * Returns true if evictions are being processed.
+ * @return true if evictions are being processed.
*/
public boolean isUsingEvictions()
{
@@ -98,7 +111,7 @@
}
/**
- * Returns true if replication is by default inactive for new {@link Region}s.
+ * @return true if replication is by default inactive for new {@link Region}s.
*/
public boolean isDefaultInactive()
{
@@ -161,6 +174,7 @@
*/
public Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
{
+ if (log.isTraceEnabled()) log.trace("Contents of RegionsRegistry: " + regionsRegistry);
Fqn fqnToUse = fqn;
if (DEFAULT_REGION.equals(fqnToUse)) fqnToUse = Fqn.ROOT;
// first see if a region for this specific Fqn exists
@@ -201,6 +215,7 @@
if (regionsRegistry.containsKey(nextFqn))
{
Region r = regionsRegistry.get(nextFqn);
+ if (log.isTraceEnabled()) log.trace("Trying next region " + nextFqn + " and got " + r);
// this is a very poor way of telling whether a region is a marshalling one or an eviction one. :-(
// mandates that class loaders be registered for marshalling regions.
@@ -219,6 +234,8 @@
if ((nextBestThing == null || nextBestThing.getFqn().isRoot() && !regionsRegistry.containsKey(Fqn.ROOT))
&& type == EVICTION)
{
+ if (log.isTraceEnabled())
+ log.trace("Next best region is " + nextBestThing + ". RegionsRegistry contains a default? " + regionsRegistry.containsKey(Fqn.ROOT) + " Region type requested = " + type);
throw new RuntimeException("No default eviction region defined!");
}
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -30,7 +30,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.0.0
*/
-public class UnversionedNode<K, V> extends AbstractNode<K, V>// implements NodeSPI<K, V>
+public class UnversionedNode<K, V> extends AbstractNode<K, V>
{
/**
@@ -41,7 +41,7 @@
/**
* Debug log.
*/
- private static Log log = LogFactory.getLog(UnversionedNode.class);
+ protected static Log log = LogFactory.getLog(UnversionedNode.class);
/**
* True if all children have been loaded. This is set when CacheImpl.getChildrenNames() is called.
Modified: core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -6,6 +6,7 @@
*/
package org.jboss.cache;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.optimistic.DefaultDataVersion;
@@ -26,7 +27,7 @@
{
private static final String DATA_VERSION_INTERNAL_KEY = "_JBOSS_INTERNAL_OPTIMISTIC_DATA_VERSION";
private DataVersion version;
-
+
/**
* Although this object has a reference to the CacheImpl, the optimistic
* node is actually disconnected from the CacheImpl itself.
@@ -40,6 +41,8 @@
if (parent == null && !fqn.isRoot()) throw new NullPointerException("parent");
this.parent = parent;
if (this.version == null) this.version = DefaultDataVersion.ZERO;
+
+ log = LogFactory.getLog(VersionedNode.class);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -18,6 +18,7 @@
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Stop;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
@@ -215,24 +216,29 @@
/**
* Stops the buddy manager and the related async thread.
*/
+ @Stop
public void stop()
{
- // unregister the viewChangeListener
- if (cache != null) cache.removeCacheListener(viewChangeListener);
- try
+ if (config.isEnabled())
{
- queue.clear();
- queue.put(STOP_NOTIFIER);
+ log.debug("Stopping BuddyManager");
+ // unregister the viewChangeListener
+ if (cache != null) cache.removeCacheListener(viewChangeListener);
+ try
+ {
+ queue.clear();
+ queue.put(STOP_NOTIFIER);
+ }
+ catch (InterruptedException ie)
+ {
+ // do nothing - we're stopping anyway
+ }
}
- catch (InterruptedException ie)
- {
- // do nothing - we're stopping anyway
- }
}
public void init() throws CacheException
{
- log.debug("Starting buddy manager");
+ log.debug("Starting BuddyManager");
buddyGroup = new BuddyGroup();
buddyGroup.setDataOwner(cache.getLocalAddress());
buddyGroup.setGroupName(getGroupNameFromAddress(cache.getLocalAddress()));
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentFactory.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentFactory.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -35,18 +35,11 @@
/**
* Constructs a component.
*
- * @param componentName optional, if the ComponentName annotation is used with the parameter, it's value is passed in here for the implementing factory to use.
- * @param componentType type of component
- * @param configuration configuration to use
- * @param componentRegistry component registry to use
+ * @param componentName optional, if the ComponentName annotation is used with the parameter, it's value is passed in here for the implementing factory to use.
+ * @param componentType type of component
* @return a component
*/
protected abstract <T> T construct(String componentName, Class<T> componentType);
-// {
-// // not making this method abstract since it is valid that classes extend ComponentFactory for the wiring and injection
-// // but not for component creation.
-// throw new UnsupportedOperationException("Meant to be overridden!");
-// }
protected void assertTypeConstructable(Class requestedType, Class... ableToConstruct)
{
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -11,7 +11,6 @@
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.factories.annotations.Stop;
-import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.util.BeanUtils;
import java.lang.annotation.Annotation;
@@ -102,6 +101,7 @@
* @param c type to be able to assign component to.
* @return component, if found, or a null otherwise.
*/
+ @SuppressWarnings("unchecked")
public <T> T getComponent(Class<T> c)
{
if (c == null)
@@ -110,7 +110,7 @@
return null;
}
- if (log.isTraceEnabled()) log.trace("Scanning registry for an instance that can be assigned to class " + c);
+ //if (log.isTraceEnabled()) log.trace("Scanning registry for an instance that can be assigned to class " + c);
T component = (T) registry.get(c);
if (component == null)
@@ -136,9 +136,10 @@
* @param c type to be able to assign component to.
* @return component, if found, or a null otherwise.
*/
+ @SuppressWarnings("unchecked")
public <T> T getComponent(String name, Class<T> c)
{
- T component = (T) registry.get(c);
+ T component = (T) registry.get(name);
if (component == null) return null;
if (c.isAssignableFrom(component.getClass())) return component;
else
@@ -196,8 +197,7 @@
@SuppressWarnings("unchecked")
private <T> T getFromConfiguration(Class<T> componentClass)
{
- if (log.isDebugEnabled())
- log.debug("Looking in configuration for an instance of " + componentClass + " that may have been injected from an external source.");
+ //if (log.isDebugEnabled()) log.debug("Looking in configuration for an instance of " + componentClass + " that may have been injected from an external source.");
Method getter = BeanUtils.getterMethod(Configuration.class, componentClass);
T returnValue = null;
@@ -246,23 +246,9 @@
// make sure we work off a copy of the values set since wireDependencies may add components to the registry
// and this may otherwise end up in a CME.
- Set components = new HashSet(registry.values());
+ Set<Object> components = new HashSet<Object>(registry.values());
- for (Object component : components)
- {
- wireDependencies(component);
- if (component instanceof Interceptor)
- {
- // special behaviour - need to wire for all chained interceptors
- Interceptor i = (Interceptor) component;
- Interceptor next = i.getNext();
- if (next != null)
- {
- wireDependencies(next);
- next = next.getNext();
- }
- }
- }
+ for (Object component : components) wireDependencies(component);
}
/**
@@ -292,23 +278,21 @@
* as needed based on the Configuration passed in if these additional components don't exist in the
* {@link ComponentRegistry}.
*
- * @param target object to wire
- * @param configuration Configuration object with knowledge of what components to create and how to create them
+ * @param target object to wire
* @throws ConfigurationException if there is a problem wiring the instance
*/
public void wireDependencies(Object target) throws ConfigurationException
{
- if (log.isTraceEnabled()) log.trace("Inspecting class " + target.getClass());
+ //if (log.isTraceEnabled()) log.trace("Inspecting class " + target.getClass());
try
{
List<Method> methods = getAllMethods(target.getClass(), Inject.class);
- if (log.isTraceEnabled())
- log.trace("Found method set containing " + methods.size() + " methods that need injection: " + methods);
+ //if (log.isTraceEnabled()) log.trace("Found method set containing " + methods.size() + " methods that need injection: " + methods);
// search for anything we need to inject
for (Method method : methods)
{
- if (log.isTraceEnabled()) log.trace("Method " + method + " needs some other components injected!");
+ //if (log.isTraceEnabled()) log.trace("Method " + method + " needs some other components injected!");
performInjection(method, target);
}
}
@@ -322,9 +306,8 @@
* Looks through the parameter list of the given method, attempts to locate parameters that fit the types that may
* exist in the {@link ComponentRegistry}, and then calls the method on the target object with the necessary parameters.
*
- * @param method Method to call
- * @param target Instance on which to call the method
- * @param configuration contains details of how to create components if they do not already exist.
+ * @param method Method to call
+ * @param target Instance on which to call the method
* @throws IllegalAccessException if the method cannot be called
* @throws java.lang.reflect.InvocationTargetException
* if the method cannot be called
@@ -558,6 +541,7 @@
{
try
{
+ m.setAccessible(true);
m.invoke(component);
}
catch (Exception e)
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -70,9 +70,20 @@
private Interceptor createInterceptor(Class<? extends Interceptor> clazz) throws IllegalAccessException, InstantiationException
{
- Interceptor i = clazz.newInstance();
- componentRegistry.wireDependencies(i);
- i.setStatisticsEnabled(configuration.getExposeManagementStatistics());
+ Interceptor i = componentRegistry.getComponent(clazz.getName(), clazz);
+ if (i == null)
+ {
+ i = clazz.newInstance();
+ componentRegistry.wireDependencies(i);
+ // add this interceptor as a NAMED component into the registry
+ componentRegistry.registerComponent(clazz.getName(), i);
+ }
+ else
+ {
+ // wipe next/last chaining!!
+ i.setLast(null);
+ i.setNext(null);
+ }
return i;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -1,8 +1,15 @@
package org.jboss.cache.interceptors;
-import org.jboss.cache.*;
+import org.apache.commons.logging.Log;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.Configuration;
import static org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
@@ -10,7 +17,6 @@
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
-import org.apache.commons.logging.Log;
import java.util.Collections;
import java.util.HashMap;
@@ -32,6 +38,7 @@
private TransactionTable txTable = null;
protected boolean isActivation = false;
protected CacheLoader loader;
+ protected CacheLoaderManager clm;
protected boolean usingOptimisticInvalidation = false;
/**
@@ -46,15 +53,21 @@
return log;
}
- public void setCache(CacheSPI cache)
+ protected void injectDependencies(TransactionTable txTable, CacheLoaderManager clm, Configuration configuration)
{
- super.setCache(cache);
- txTable = cache.getTransactionTable();
- this.loader = cache.getCacheLoaderManager().getCacheLoader();
- CacheMode mode = cache.getConfiguration().getCacheMode();
- usingOptimisticInvalidation = cache.getConfiguration().isNodeLockingOptimistic() && mode.isInvalidation();
+ this.txTable = txTable;
+ this.clm = clm;
+ CacheMode mode = configuration.getCacheMode();
+ usingOptimisticInvalidation = configuration.isNodeLockingOptimistic() && mode.isInvalidation();
}
+ public Object invoke(InvocationContext ctx) throws Throwable
+ {
+ if (loader == null) loader = clm.getCacheLoader();
+ return super.invoke(ctx);
+ }
+
+
protected Object handlePutDataEraseMethod(InvocationContext ctx, GlobalTransaction gt, Fqn fqn, Map newData, boolean createUndoOps, boolean eraseContents) throws Throwable
{
if (fqn != null)
@@ -428,7 +441,7 @@
if (configuration.isNodeLockingOptimistic()) return;
MethodCall m = MethodCallFactory.create(MethodDeclarations.lockMethodLocal,
- fqn, lock_type, recursive);
+ fqn, lock_type, recursive);
// hacky
cache.getInterceptorChain().get(0).invoke(InvocationContext.fromMethodCall(m));
@@ -470,7 +483,7 @@
for (MethodCall m : entry.getCacheLoaderModifications())
{
if (m.getMethodId() == MethodDeclarations.removeNodeMethodLocal_id
- && fqn.isChildOrEquals((Fqn) m.getArgs()[1]))
+ && fqn.isChildOrEquals((Fqn) m.getArgs()[1]))
{
return true;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -45,6 +45,7 @@
@Inject
void setRegionManager(RegionManager regionManager)
{
+ log.trace("Having region manager " + regionManager + " injected.");
this.regionManager = regionManager;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -73,6 +73,7 @@
@Start
private void start()
{
+ setStatisticsEnabled(configuration.getExposeManagementStatistics());
// for backward compatibility, this must only be done when the cache starts.
setCache(cache);
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -24,7 +24,7 @@
* - the parameters of the hendler methods are passes in strongly typed, rather than as an array of Objects
* </pre>
* This interceptor acts as a switch that delegates method calls to handlers/methods.
- *
+ * <p/>
* Implementation notes:
* Current implementation checks to see the methods that are overwritten and does only perform calls to those methods.
* This is for avoiding the casts needed to build parameter list. If a non overwritten method is invoked,
@@ -47,7 +47,7 @@
processOverwritternMethods();
}
- /**
+ /**
* Acts like a 'switch case' that delegates the call to the appropriate method.
*/
public Object invoke(InvocationContext ctx) throws Throwable
@@ -63,12 +63,13 @@
MethodCall m = ctx.getMethodCall();
if (!overwrittenMethods.contains(m.getMethodId()))
{
+ log.trace("Not registered for any handlers, passing up the chain.");
return nextInterceptor(ctx);
}
Object[] args = m.getArgs();
Object result;
switch (m.getMethodId())
- {
+ {
case MethodDeclarations.putDataEraseMethodLocal_id:
result = handlePutDataEraseMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], (Map) args[2], (Boolean) args[3], (Boolean) args[4]);
break;
@@ -124,43 +125,43 @@
result = handleCommitMethod(ctx, (GlobalTransaction) args[0]);
break;
case MethodDeclarations.optimisticPrepareMethod_id:
- result = handleOptimisticPrepareMethod(ctx, (GlobalTransaction) args[0], (List)args[1],(Map)args[2], (Address)args[3], (Boolean)args[4]);
+ result = handleOptimisticPrepareMethod(ctx, (GlobalTransaction) args[0], (List) args[1], (Map) args[2], (Address) args[3], (Boolean) args[4]);
break;
case MethodDeclarations.prepareMethod_id:
- result = handlePrepareMethod(ctx, (GlobalTransaction) args[0], (List)args[1], (Address)args[2], (Boolean)args[3]);
+ result = handlePrepareMethod(ctx, (GlobalTransaction) args[0], (List) args[1], (Address) args[2], (Boolean) args[3]);
break;
case MethodDeclarations.evictNodeMethodLocal_id:
- result = handleEvictMethod(ctx, (Fqn)args[0]);
+ result = handleEvictMethod(ctx, (Fqn) args[0]);
break;
case MethodDeclarations.evictVersionedNodeMethodLocal_id:
- result = handleEvictVersionedNodeMethod(ctx, (Fqn)args[0], (DataVersion)args[1]);
+ result = handleEvictVersionedNodeMethod(ctx, (Fqn) args[0], (DataVersion) args[1]);
break;
case MethodDeclarations.existsMethod_id:
- result = handleExistsMethod(ctx, (Fqn)args[0]);
+ result = handleExistsMethod(ctx, (Fqn) args[0]);
break;
case MethodDeclarations.putDataEraseVersionedMethodLocal_id:
- result = handlePutDataEraseVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], (Map)args[2], (Boolean)args[3], (Boolean)args[4], (DataVersion)args[5]);
+ result = handlePutDataEraseVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], (Map) args[2], (Boolean) args[3], (Boolean) args[4], (DataVersion) args[5]);
break;
case MethodDeclarations.putDataVersionedMethodLocal_id:
- result = handlePutDataVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], (Map)args[2], (Boolean)args[3], (DataVersion)args[4]);
+ result = handlePutDataVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], (Map) args[2], (Boolean) args[3], (DataVersion) args[4]);
break;
case MethodDeclarations.putKeyValVersionedMethodLocal_id:
- result = handlePutKeyValueVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], args[2], args[3], (Boolean)args[4], (DataVersion)args[5]);
+ result = handlePutKeyValueVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], args[2], args[3], (Boolean) args[4], (DataVersion) args[5]);
break;
case MethodDeclarations.putForExternalReadVersionedMethodLocal_id:
- result = handlePutForExternalReadVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], args[2], args[3], (DataVersion)args[5]);
+ result = handlePutForExternalReadVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], args[2], args[3], (DataVersion) args[5]);
break;
case MethodDeclarations.dataGravitationCleanupMethod_id:
- result = handleDataGravitationCleanupMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], (Fqn)args[2]);
+ result = handleDataGravitationCleanupMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], (Fqn) args[2]);
break;
case MethodDeclarations.removeNodeVersionedMethodLocal_id:
- result = handleRemoveNodeVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], (Boolean)args[2], (DataVersion)args[3]);
+ result = handleRemoveNodeVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], (Boolean) args[2], (DataVersion) args[3]);
break;
case MethodDeclarations.removeKeyVersionedMethodLocal_id:
- result = handleRemoveKeyVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], args[2], (Boolean)args[3], (DataVersion)args[4]);
+ result = handleRemoveKeyVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], args[2], (Boolean) args[3], (DataVersion) args[4]);
break;
case MethodDeclarations.removeDataVersionedMethodLocal_id:
- result = handleRemoveDataVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn)args[1], (Boolean)args[2], (DataVersion)args[3]);
+ result = handleRemoveDataVersionedMethod(ctx, (GlobalTransaction) args[0], (Fqn) args[1], (Boolean) args[2], (DataVersion) args[3]);
break;
case MethodDeclarations.blockChannelMethodLocal_id:
result = handleBlockChannelMethod(ctx);
@@ -169,15 +170,15 @@
result = handleUnblockChannelMethod(ctx);
break;
case MethodDeclarations.lockMethodLocal_id:
- result = handleLockMethod(ctx, (Fqn)args[0], (NodeLock.LockType)args[1], (Boolean)args[2]);
+ result = handleLockMethod(ctx, (Fqn) args[0], (NodeLock.LockType) args[1], (Boolean) args[2]);
break;
default:
return nextInterceptor(ctx);
- }
+ }
return result;
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_lock(org.jboss.cache.Fqn, org.jboss.cache.lock.NodeLock.LockType, boolean)}
*/
protected Object handleLockMethod(InvocationContext ctx, Fqn fqn, NodeLock.LockType lockType, boolean recursive) throws Throwable
@@ -185,7 +186,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_unblock()}
*/
protected Object handleUnblockChannelMethod(InvocationContext ctx) throws Throwable
@@ -193,7 +194,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_block()}
*/
protected Object handleBlockChannelMethod(InvocationContext ctx) throws Throwable
@@ -201,7 +202,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_removeData(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, boolean, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handleRemoveDataVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, boolean createUndoOps, DataVersion dv) throws Throwable
@@ -209,7 +210,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_remove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, boolean, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handleRemoveKeyVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, boolean createUndoOps, DataVersion dv) throws Throwable
@@ -217,7 +218,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_remove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, boolean, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handleRemoveNodeVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, boolean createUndoOps, DataVersion dv) throws Throwable
@@ -225,7 +226,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_dataGravitationCleanup(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, org.jboss.cache.Fqn)}
*/
protected Object handleDataGravitationCleanupMethod(InvocationContext ctx, GlobalTransaction globalTransaction, Fqn primary, Fqn backup) throws Throwable
@@ -233,7 +234,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_putForExternalRead(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handlePutForExternalReadVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, Object value, DataVersion dv) throws Throwable
@@ -241,7 +242,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object, boolean, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handlePutKeyValueVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, Object value, boolean createUndoOps, DataVersion dv) throws Throwable
@@ -249,7 +250,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handlePutDataVersionedMethod(InvocationContext ctx, GlobalTransaction globalTransaction, Fqn fqn, Map map, Boolean createUndoOps, DataVersion dataVersion) throws Throwable
@@ -257,7 +258,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, boolean, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handlePutDataEraseVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Map data, boolean createUndoOps, boolean eraseContent, DataVersion dv) throws Throwable
@@ -265,7 +266,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#exists(String)}
*/
protected Object handleExistsMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -273,12 +274,12 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* used for logging various steps. if null is returned than nothing is logged.
*/
protected abstract Log getLog();
- /**
+ /**
* Each interceptor should extend this if it does not need any processing for current call.
* An sample usage would be: this interceptor is only interested if thre is one transaction going on. If so all
* handleXYZ would know that we have a transaction going and would not check its state.
@@ -288,7 +289,7 @@
return false;
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_evict(org.jboss.cache.Fqn, org.jboss.cache.optimistic.DataVersion)}
*/
protected Object handleEvictVersionedNodeMethod(InvocationContext ctx, Fqn fqn, DataVersion dataVersion) throws Throwable
@@ -296,7 +297,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#evict(org.jboss.cache.Fqn)}
*/
protected Object handleEvictMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -304,7 +305,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#prepare(org.jboss.cache.transaction.GlobalTransaction, java.util.List, org.jgroups.Address, boolean)}
*/
protected Object handlePrepareMethod(InvocationContext ctx, GlobalTransaction gtx, List modification, Address coordinator, boolean onePhaseCommit) throws Throwable
@@ -312,7 +313,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#optimisticPrepare(org.jboss.cache.transaction.GlobalTransaction, java.util.List, java.util.Map, org.jgroups.Address, boolean)}
*/
protected Object handleOptimisticPrepareMethod(InvocationContext ctx, GlobalTransaction gtx, List modifications, Map data, Address address, boolean onePhaseCommit) throws Throwable
@@ -320,7 +321,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#commit(org.jboss.cache.transaction.GlobalTransaction)}
*/
protected Object handleCommitMethod(InvocationContext ctx, GlobalTransaction globalTransaction) throws Throwable
@@ -328,7 +329,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_removeData(org.jboss.cache.transaction.GlobalTransaction, Fqn, boolean)}
*/
protected Object handleRemoveDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps) throws Throwable
@@ -336,7 +337,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_remove(org.jboss.cache.transaction.GlobalTransaction, String, Object, boolean)}
*/
protected Object handleRemoveKeyMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Object key, boolean createUndoOps) throws Throwable
@@ -344,7 +345,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_remove(org.jboss.cache.transaction.GlobalTransaction, String, boolean)}
*/
protected Object handleRemoveNodeMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps) throws Throwable
@@ -353,7 +354,7 @@
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#rollback(org.jboss.cache.transaction.GlobalTransaction)}
*/
protected Object handleRollbackMethod(InvocationContext ctx, GlobalTransaction globalTransaction) throws Throwable
@@ -361,7 +362,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_getData(org.jboss.cache.Fqn)}
*/
protected Object handleGetDataMapMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -369,7 +370,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#getKeys(Fqn)}
*/
protected Object handleGetKeysMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -377,7 +378,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_print(org.jboss.cache.Fqn)}
*/
protected Object handlePrintMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -385,7 +386,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_releaseAllLocks(org.jboss.cache.Fqn)}
*/
protected Object handleReleaseAllLocksMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -393,7 +394,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_getChildrenNames(org.jboss.cache.Fqn)}
*/
protected Object handleGetChildrenNamesMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -401,7 +402,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_get(org.jboss.cache.Fqn)}
*/
protected Object handleGetNodeMethod(InvocationContext ctx, Fqn fqn) throws Throwable
@@ -409,7 +410,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_get(org.jboss.cache.Fqn, Object, boolean)}
*/
protected Object handleGetKeyValueMethod(InvocationContext ctx, Fqn fqn, Object key, boolean sendNodeEvent) throws Throwable
@@ -417,7 +418,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_addChild(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, org.jboss.cache.Node, boolean)}
*/
protected Object handleAddChildMethod(InvocationContext ctx, GlobalTransaction tx, Fqn parentFqn, Object childName, Node cn, boolean createUndoOps) throws Throwable
@@ -426,7 +427,7 @@
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_move(org.jboss.cache.Fqn, org.jboss.cache.Fqn)}
*/
protected Object handleMoveMethod(InvocationContext ctx, Fqn from, Fqn to) throws Throwable
@@ -434,7 +435,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_put(org.jboss.cache.transaction.GlobalTransaction, String, Object, Object, boolean)}
*/
protected Object handlePutKeyValueMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, Object key, Object value, boolean createUndoOps) throws Throwable
@@ -442,7 +443,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_putForExternalRead(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, Object, Object)}
*/
protected Object handlePutForExternalReadMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Object key, Object value) throws Throwable
@@ -450,7 +451,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_put(org.jboss.cache.transaction.GlobalTransaction, String, java.util.Map, boolean)}
*/
protected Object handlePutDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Map data, boolean createUndoOps) throws Throwable
@@ -458,7 +459,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handles {@link org.jboss.cache.CacheImpl#_put(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.Fqn, java.util.Map, boolean, boolean)}
*/
protected Object handlePutDataEraseMethod(InvocationContext ctx, GlobalTransaction gt, Fqn fqn, Map newData, boolean createUndoOps, boolean eraseContents) throws Throwable
@@ -466,7 +467,7 @@
return defaultHandlersBehavior();
}
- /**
+ /**
* Handlers defined here should not be called directlly. There are two scenarios in which a handler might be called:
* 1 - DerivedInterceptor.super - pointless call
* 2 - if the logic that determines that an handler is overwritten fails. Throwing an exception by default is for
@@ -477,63 +478,64 @@
throw new IllegalStateException("this is either called from a derived class or nt overwritten and accidentally called. Either way, is not correct.");
}
- /**
- * Builds the list of methods that are overwiritten.
- */
- private void processOverwritternMethods()
- {
- checkIfOverwritten(MethodDeclarations.putDataEraseMethodLocal_id, "handlePutDataEraseMethod",InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, boolean.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.putDataMethodLocal_id, "handlePutDataMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.putForExternalReadMethodLocal_id, "handlePutForExternalReadMethod",InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class);
- checkIfOverwritten(MethodDeclarations.putKeyValMethodLocal_id, "handlePutKeyValueMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.moveMethodLocal_id, "handleMoveMethod",InvocationContext.class, Fqn.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.addChildMethodLocal_id, "handleAddChildMethod",InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Node.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.getKeyValueMethodLocal_id, "handleGetKeyValueMethod", InvocationContext.class, Fqn.class, Object.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.getNodeMethodLocal_id, "handleGetNodeMethod", InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.getChildrenNamesMethodLocal_id, "handleGetChildrenNamesMethod",InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.releaseAllLocksMethodLocal_id, "handleReleaseAllLocksMethod",InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.printMethodLocal_id, "handlePrintMethod",InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.getKeysMethodLocal_id, "handleGetKeysMethod", InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.getDataMapMethodLocal_id, "handleGetDataMapMethod", InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.rollbackMethod_id, "handleRollbackMethod", InvocationContext.class, GlobalTransaction.class);
- checkIfOverwritten(MethodDeclarations.removeNodeMethodLocal_id, "handleRemoveNodeMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.removeKeyMethodLocal_id, "handleRemoveKeyMethod",InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.removeDataMethodLocal_id, "handleRemoveDataMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.commitMethod_id, "handleCommitMethod",InvocationContext.class, GlobalTransaction.class);
- checkIfOverwritten(MethodDeclarations.optimisticPrepareMethod_id, "handleOptimisticPrepareMethod", InvocationContext.class, GlobalTransaction.class, List.class, Map.class, Address.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.prepareMethod_id, "handlePrepareMethod", InvocationContext.class, GlobalTransaction.class, List.class, Address.class, boolean.class);
- checkIfOverwritten(MethodDeclarations.evictNodeMethodLocal_id, "handleEvictMethod", InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.evictVersionedNodeMethodLocal_id, "handleEvictVersionedNodeMethod", InvocationContext.class, Fqn.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.existsMethod_id, "handleExistsMethod", InvocationContext.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.putDataEraseVersionedMethodLocal_id, "handlePutDataEraseVersionedMethod",InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, boolean.class, boolean.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.putDataVersionedMethodLocal_id, "handlePutDataVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, Boolean.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.putKeyValVersionedMethodLocal_id, "handlePutKeyValueVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class, boolean.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.putForExternalReadVersionedMethodLocal_id, "handlePutForExternalReadVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.dataGravitationCleanupMethod_id, "handleDataGravitationCleanupMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Fqn.class);
- checkIfOverwritten(MethodDeclarations.removeNodeVersionedMethodLocal_id, "handleRemoveNodeVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.removeKeyVersionedMethodLocal_id, "handleRemoveKeyVersionedMethod",InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, boolean.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.removeDataVersionedMethodLocal_id, "handleRemoveDataVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class, DataVersion.class);
- checkIfOverwritten(MethodDeclarations.blockChannelMethodLocal_id, "handleBlockChannelMethod",InvocationContext.class);
- checkIfOverwritten(MethodDeclarations.unblockChannelMethodLocal_id, "handleUnblockChannelMethod", InvocationContext.class);
- checkIfOverwritten(MethodDeclarations.lockMethodLocal_id, "handleLockMethod", InvocationContext.class, Fqn.class, NodeLock.LockType.class, boolean.class);
+ /**
+ * Builds the list of methods that are overwiritten.
+ */
+ private void processOverwritternMethods()
+ {
+ checkIfOverwritten(MethodDeclarations.putDataEraseMethodLocal_id, "handlePutDataEraseMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, boolean.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.putDataMethodLocal_id, "handlePutDataMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.putForExternalReadMethodLocal_id, "handlePutForExternalReadMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class);
+ checkIfOverwritten(MethodDeclarations.putKeyValMethodLocal_id, "handlePutKeyValueMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.moveMethodLocal_id, "handleMoveMethod", InvocationContext.class, Fqn.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.addChildMethodLocal_id, "handleAddChildMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Node.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.getKeyValueMethodLocal_id, "handleGetKeyValueMethod", InvocationContext.class, Fqn.class, Object.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.getNodeMethodLocal_id, "handleGetNodeMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.getChildrenNamesMethodLocal_id, "handleGetChildrenNamesMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.releaseAllLocksMethodLocal_id, "handleReleaseAllLocksMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.printMethodLocal_id, "handlePrintMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.getKeysMethodLocal_id, "handleGetKeysMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.getDataMapMethodLocal_id, "handleGetDataMapMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.rollbackMethod_id, "handleRollbackMethod", InvocationContext.class, GlobalTransaction.class);
+ checkIfOverwritten(MethodDeclarations.removeNodeMethodLocal_id, "handleRemoveNodeMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.removeKeyMethodLocal_id, "handleRemoveKeyMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.removeDataMethodLocal_id, "handleRemoveDataMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.commitMethod_id, "handleCommitMethod", InvocationContext.class, GlobalTransaction.class);
+ checkIfOverwritten(MethodDeclarations.optimisticPrepareMethod_id, "handleOptimisticPrepareMethod", InvocationContext.class, GlobalTransaction.class, List.class, Map.class, Address.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.prepareMethod_id, "handlePrepareMethod", InvocationContext.class, GlobalTransaction.class, List.class, Address.class, boolean.class);
+ checkIfOverwritten(MethodDeclarations.evictNodeMethodLocal_id, "handleEvictMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.evictVersionedNodeMethodLocal_id, "handleEvictVersionedNodeMethod", InvocationContext.class, Fqn.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.existsMethod_id, "handleExistsMethod", InvocationContext.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.putDataEraseVersionedMethodLocal_id, "handlePutDataEraseVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, boolean.class, boolean.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.putDataVersionedMethodLocal_id, "handlePutDataVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Map.class, Boolean.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.putKeyValVersionedMethodLocal_id, "handlePutKeyValueVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class, boolean.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.putForExternalReadVersionedMethodLocal_id, "handlePutForExternalReadVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, Object.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.dataGravitationCleanupMethod_id, "handleDataGravitationCleanupMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Fqn.class);
+ checkIfOverwritten(MethodDeclarations.removeNodeVersionedMethodLocal_id, "handleRemoveNodeVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.removeKeyVersionedMethodLocal_id, "handleRemoveKeyVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, Object.class, boolean.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.removeDataVersionedMethodLocal_id, "handleRemoveDataVersionedMethod", InvocationContext.class, GlobalTransaction.class, Fqn.class, boolean.class, DataVersion.class);
+ checkIfOverwritten(MethodDeclarations.blockChannelMethodLocal_id, "handleBlockChannelMethod", InvocationContext.class);
+ checkIfOverwritten(MethodDeclarations.unblockChannelMethodLocal_id, "handleUnblockChannelMethod", InvocationContext.class);
+ checkIfOverwritten(MethodDeclarations.lockMethodLocal_id, "handleLockMethod", InvocationContext.class, Fqn.class, NodeLock.LockType.class, boolean.class);
- }
+ }
- private void checkIfOverwritten(int putDataEraseMethodLocal_id, String methodName, Class... args)
- {
- Class currentClass = getClass();
- //if this is a > 1 inheritace deepth and the method was overwritten in the parent. We also have to look into parents
- while (currentClass != MethodDispacherInterceptor.class)
- {
- try
- {
- currentClass.getDeclaredMethod(methodName, args);
- this.overwrittenMethods.add(putDataEraseMethodLocal_id);
- } catch (NoSuchMethodException e)
- {
- //ignore
- }
- currentClass = (Class) currentClass.getGenericSuperclass();
- }
- }
+ private void checkIfOverwritten(int putDataEraseMethodLocal_id, String methodName, Class... args)
+ {
+ Class currentClass = getClass();
+ //if this is a > 1 inheritace deepth and the method was overwritten in the parent. We also have to look into parents
+ while (currentClass != MethodDispacherInterceptor.class)
+ {
+ try
+ {
+ currentClass.getDeclaredMethod(methodName, args);
+ this.overwrittenMethods.add(putDataEraseMethodLocal_id);
+ }
+ catch (NoSuchMethodException e)
+ {
+ //ignore
+ }
+ currentClass = (Class) currentClass.getGenericSuperclass();
+ }
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -7,13 +7,13 @@
package org.jboss.cache.interceptors;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.notifications.Notifier;
@@ -44,11 +44,11 @@
private NodeFactory nodeFactory;
private Notifier notifier;
- public void setCache(CacheSPI c)
+ @Inject
+ protected void injectDependencies(Notifier notifier, NodeFactory nodeFactory)
{
- super.setCache(c);
- nodeFactory = c.getConfiguration().getRuntimeConfig().getNodeFactory();
- notifier = cache.getNotifier();
+ this.notifier = notifier;
+ this.nodeFactory = nodeFactory;
}
public Object invoke(InvocationContext ctx) throws Throwable
@@ -234,7 +234,7 @@
WorkspaceNode oldParent = fetchWorkspaceNode(nodeFqn.getParent(), ws, false, true);
if (oldParent == null) throw new NodeNotExistsException("Node " + nodeFqn.getParent() + " does not exist!");
-
+
if (parentFqn.equals(oldParent.getFqn()))
{
log.warn("Attempting to move a node in same place. Not taking any action, treating this as a no-op.");
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -55,13 +55,13 @@
/**
* Map<Thread, List<NodeLock>>. Keys = threads, values = lists of locks held by that thread
*/
- private Map<Thread, List<NodeLock>> lock_table;
+ private Map<Thread, List<NodeLock>> lockTable;
private long lock_acquisition_timeout;
@Inject
public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
{
- this.lock_table = lockTable;
+ this.lockTable = lockTable;
lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
this.cacheImpl = cacheImpl;
this.tx_table = txTable;
@@ -90,9 +90,9 @@
private Object handlePutMethod(InvocationContext ctx, Fqn fqn)
throws Throwable
{
- log.trace("Suppressing locking");
if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().isSuppressLocking())
{
+ log.trace("Suppressing locking");
log.trace("Creating nodes if necessary");
int treeNodeSize = fqn.size();
NodeSPI n = cache.getRoot();
@@ -108,7 +108,7 @@
}
else
{
- acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, true, false, false, true);
+ acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.WRITE, true, false, false, true);
}
return nextInterceptor(ctx);
}
@@ -355,7 +355,7 @@
long expiryTime = System.currentTimeMillis() + timeout;
currentNode = cache.getRoot();
NodeSPI parent = null;
- String childName = null;
+ Object childName = null;
int currentIndex = -1;
do
{
@@ -422,7 +422,7 @@
parent = currentNode;
currentIndex = currentNode.getFqn().size();
currentNode = currentNode.getChildDirect(fqn.get(currentIndex));
- childName = (String) fqn.get(currentIndex);
+ childName = fqn.get(currentIndex);
}
} while (true);
return created;
@@ -502,7 +502,7 @@
if (!locks.contains(lock))
{
locks.add(lock);
- lock_table.put(currentThread, locks);
+ lockTable.put(currentThread, locks);
}
}
}
@@ -512,11 +512,11 @@
{
// This sort of looks like a get/put race condition, but
// since we key off the Thread, it's not
- List<NodeLock> locks = lock_table.get(currentThread);
+ List<NodeLock> locks = lockTable.get(currentThread);
if (locks == null)
{
locks = Collections.synchronizedList(new LinkedList<NodeLock>());
- lock_table.put(currentThread, locks);
+ lockTable.put(currentThread, locks);
}
return locks;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -1,14 +1,14 @@
package org.jboss.cache.interceptors;
+import org.apache.commons.logging.Log;
+import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Option;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.apache.commons.logging.Log;
import org.jgroups.Address;
import java.util.List;
@@ -58,7 +58,7 @@
{
return nextInterceptor(ctx);
}
- Object retVal = nextInterceptor(ctx);
+ Object retVal = nextInterceptor(ctx);
runPreparePhase(ctx.getMethodCall(), gtx, ctx);
return retVal;
}
@@ -84,7 +84,9 @@
Object returnValue = nextInterceptor(ctx);
cache.getTransactionTable().get(gtx).setForceAsyncReplication(true);
return returnValue;
- } else {
+ }
+ else
+ {
return handleCrudMethod(ctx);
}
}
@@ -195,16 +197,18 @@
* If the operation didn't originate locally we won't do any replication either.
*/
private Object handleCrudMethod(InvocationContext ctx)
- throws Throwable
+ throws Throwable
{
- if (ctx.getTransaction() == null && ctx.isOriginLocal() )
+ // FIRST pass this call up the chain. Only if it succeeds (no exceptions) locally do we attempt to replicate.
+ Object returnValue = nextInterceptor(ctx);
+ if (ctx.getTransaction() == null && ctx.isOriginLocal())
{
MethodCall m = ctx.getMethodCall();
if (log.isTraceEnabled())
{
log.trace("invoking method " + m + ", members=" + cache.getMembers() + ", mode=" +
- configuration.getCacheMode() + ", exclude_self=" + true + ", timeout=" +
- configuration.getSyncReplTimeout());
+ configuration.getCacheMode() + ", exclude_self=" + true + ", timeout=" +
+ configuration.getSyncReplTimeout());
}
if (!isSynchronous(ctx.getOptionOverrides()) || m.getMethodId() == MethodDeclarations.putForExternalReadMethodLocal_id)
{
@@ -218,7 +222,7 @@
replicateCall(m, true, ctx.getOptionOverrides());
}
}
- return nextInterceptor(ctx);
+ return returnValue;
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
@@ -22,21 +21,15 @@
public class UnlockInterceptor extends Interceptor
{
- Map<Thread, List<NodeLock>> lock_table = null;
+ Map<Thread, List<NodeLock>> lockTable = null;
boolean trace = log.isTraceEnabled();
@Inject
private void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable)
{
- this.lock_table = lockTable;
+ this.lockTable = lockTable;
}
- public void setCache(CacheSPI cache)
- {
- super.setCache(cache);
- lock_table = cache.getLockTable();
- }
-
public Object invoke(InvocationContext ctx) throws Throwable
{
try
@@ -59,13 +52,13 @@
else
{ // no TX
Thread currentThread = Thread.currentThread();
- List locks = (List) lock_table.get(currentThread);
- if (trace) log.trace("Attempting to release locks on current thread. Lock table is " + lock_table);
+ List locks = lockTable.get(currentThread);
+ if (trace) log.trace("Attempting to release locks on current thread. Lock table is " + lockTable);
if (locks != null && locks.size() > 0)
{
releaseLocks(locks, currentThread);
- lock_table.remove(currentThread);
+ lockTable.remove(currentThread);
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -1,5 +1,6 @@
package org.jboss.cache.invocation;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.*;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.buddyreplication.GravitateResult;
@@ -52,6 +53,11 @@
private Marshaller marshaller;
private Map<Thread, List<NodeLock>> lockTable;
+ public CacheInvocationDelegate()
+ {
+ log = LogFactory.getLog(CacheInvocationDelegate.class);
+ }
+
@Inject
private void injectDependencies(StateTransferManager stateTransferManager, CacheLoaderManager cacheLoaderManager, Notifier notifier,
TransactionManager transactionManager, BuddyManager buddyManager, TransactionTable transactionTable,
@@ -67,6 +73,7 @@
this.rpcManager = rpcManager;
this.regionManager = regionManager;
this.marshaller = marshaller;
+ this.lockTable = lockTable;
}
@Override
@@ -386,7 +393,7 @@
for (Object childName : peek(fqn, false, false).getChildrenNames())
{
ctx.setOptionOverrides(o);
- result = removeNode(new Fqn<Object>(fqn, childName)) && result;
+ result = removeNode(new Fqn<Object>((Fqn<Object>) fqn, childName)) && result;
}
return result;
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -34,7 +34,7 @@
this.node = node;
}
- public UnversionedNode getUnversionedNode()
+ public Object getDelegationTarget()
{
return node;
}
@@ -299,7 +299,7 @@
public V put(K key, V value)
{
assertValid();
- return (V) spi.put(getFqn(), key, value);
+ return spi.put(getFqn(), key, value);
}
public V putIfAbsent(K k, V v)
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -1,5 +1,6 @@
package org.jboss.cache.invocation;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
@@ -17,6 +18,7 @@
public RemoteCacheInvocationDelegate()
{
originLocal = false;
+ log = LogFactory.getLog(RemoteCacheInvocationDelegate.class);
}
public Object _replicate(MethodCall methodCall) throws Throwable
Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -15,6 +15,8 @@
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.factories.annotations.Stop;
import java.util.ArrayList;
import java.util.Iterator;
@@ -369,31 +371,37 @@
return fetchPersistentState;
}
+ @Stop
public void stopCacheLoader()
{
- if (loader == null) throw new RuntimeException("Problem with configured cache loader - it has been set to null!");
- // stop the cache loader
- loader.stop();
- // destroy the cache loader
- loader.destroy();
+ if (loader != null)
+ {
+ // stop the cache loader
+ loader.stop();
+ // destroy the cache loader
+ loader.destroy();
+ }
}
+ @Start
public void startCacheLoader() throws CacheException
{
- if (loader == null) throw new RuntimeException("Improperly configured cache loader - cache loader is null!");
- try
+ if (loader != null)
{
- // create the cache loader
- loader.create();
- // start the cache loader
- loader.start();
+ try
+ {
+ // create the cache loader
+ loader.create();
+ // start the cache loader
+ loader.start();
- purgeLoaders(false);
+ purgeLoaders(false);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to start cache loaders", e);
+ }
}
- catch (Exception e)
- {
- throw new CacheException("Unable to start cache loaders", e);
- }
}
public void purgeLoaders(boolean force) throws Exception
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -34,7 +34,7 @@
protected boolean useRegionBasedMarshalling;
protected RegionManager regionManager;
protected boolean defaultInactive;
- private static Log log = LogFactory.getLog(AbstractMarshaller.class);
+ protected Log log = LogFactory.getLog(AbstractMarshaller.class);
/**
* Map<GlobalTransaction, Fqn> for prepared tx that have not committed
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.marshall;
-import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
@@ -33,9 +32,6 @@
*/
public class CacheMarshaller200 extends AbstractMarshaller
{
- // logger
- private Log log = LogFactory.getLog(CacheMarshaller200.class);
-
// magic numbers
protected static final int MAGICNUMBER_METHODCALL = 1;
protected static final int MAGICNUMBER_FQN = 2;
@@ -69,10 +65,12 @@
public CacheMarshaller200()
{
+ log = LogFactory.getLog(CacheMarshaller200.class);
}
public CacheMarshaller200(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
{
+ log = LogFactory.getLog(CacheMarshaller200.class);
init(manager, defaultInactive, useRegionBasedMarshalling);
if (useRegionBasedMarshalling)
{
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -1,5 +1,6 @@
package org.jboss.cache.marshall;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.RegionManager;
import java.io.IOException;
@@ -20,11 +21,13 @@
{
public CacheMarshaller210()
{
+ log = LogFactory.getLog(CacheMarshaller210.class);
}
public CacheMarshaller210(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
{
super(manager, defaultInactive, useRegionBasedMarshalling);
+ log = LogFactory.getLog(CacheMarshaller210.class);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -81,4 +81,9 @@
return x;
}
}
+
+ public String toString()
+ {
+ return getClass().getSimpleName() + "[Outgoing marshaller: " + req_marshaller + "; incoming marshaller: " + rsp_marshaller + "]";
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -55,9 +55,9 @@
public WorkspaceNodeImpl(NodeSPI<K, V> node, TransactionWorkspace workspace)
{
NodeInvocationDelegate delegate = (NodeInvocationDelegate) node;
- if (!(delegate.getUnversionedNode() instanceof VersionedNode))
+ if (!(delegate.getDelegationTarget() instanceof VersionedNode))
{
- throw new IllegalArgumentException("node " + delegate.getUnversionedNode() + " not VersionedNode");
+ throw new IllegalArgumentException("node " + delegate.getDelegationTarget() + " not VersionedNode");
}
this.node = node;
this.workspace = workspace;
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -5,6 +5,9 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
+import org.jboss.cache.interceptors.PessimisticLockInterceptor;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import static org.testng.AssertJUnit.*;
@@ -74,8 +77,24 @@
}
}
+ private void assertOptimistic()
+ {
+ assert cache.getConfiguration().isNodeLockingOptimistic();
+ boolean interceptorChainOK = false;
+
+ for (Interceptor i : cache.getInterceptorChain())
+ {
+ if (i instanceof PessimisticLockInterceptor) assert false : "Not an optimistic locking chain!!";
+ if (i instanceof OptimisticNodeInterceptor) interceptorChainOK = true;
+ }
+
+ assert interceptorChainOK : "Not an optimistic locking chain!!";
+ }
+
public void testAddingData()
{
+ if (optimistic) assertOptimistic();
+
Node<Object, Object> nodeA = rootNode.addChild(A);
nodeA.put("key", "value");
@@ -215,7 +234,7 @@
else
{
TransactionWorkspace<Object, Object> w = getTransactionWorkspace();
- assert w.getNodes().size() == 4 : "Should be 4 nodes in the workspace.";
+ assert w.getNodes().size() == 4 : "Should be 4 nodes in the workspace, not " + w.getNodes().size();
// test deltas
List<Set<Fqn>> deltas = w.getNodes().get(Fqn.ROOT).getMergedChildren();
assert deltas.get(0).size() == 1 : "/ should have 1 child added";
Modified: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -78,6 +78,15 @@
assert cr.defaultFactories.get(Marshaller.class).equals(CacheMarshallerFactory.class);
}
+ public void testNamedComponents()
+ {
+ cr.registerComponent("blah", new Object());
+ Object namedComponent1 = cr.getOrCreateComponent("blah", Object.class);
+ Object namedComponent2 = cr.getOrCreateComponent("blah", Object.class);
+
+ assert namedComponent1 == namedComponent2;
+ }
+
/**
* Case 1:
* nothing injected, nothing specified in Configuration. Should use default factory.
Modified: core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -1,19 +1,24 @@
package org.jboss.cache.lock;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.interceptors.PessimisticLockInterceptor;
+import org.jboss.cache.interceptors.UnlockInterceptor;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
- /**
+
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
+/**
* basic locking test
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
@@ -41,10 +46,30 @@
cache.stop();
}
+ private void assertNoStaleLocks()
+ {
+ CacheSPI spi = (CacheSPI) cache;
+ PessimisticLockInterceptor pli = TestingUtil.findInterceptor(spi, PessimisticLockInterceptor.class);
+ UnlockInterceptor ui = TestingUtil.findInterceptor(spi, UnlockInterceptor.class);
+
+ Map lockTablePLI = (Map) TestingUtil.extractField(pli, "lockTable");
+ Map lockTableUI = (Map) TestingUtil.extractField(ui, "lockTable");
+
+ // they should be the SAME!!
+ assert lockTablePLI == lockTableUI : "PessimisticLockInterceptor and UnlockInterceptor should be referring to the same LockTable!!";
+
+ assert lockTablePLI.size() == 0 : "Lock table on pessimistic lock interceptor should be empty";
+ assert lockTableUI.size() == 0 : "Lock table on unlock interceptor should be empty";
+
+ assert spi.getNumberOfLocksHeld() == 0 : "Should have no stale locks!";
+ }
+
public void testPut() throws Exception
{
cache.put(fqn, "k", "v");
+ assertNoStaleLocks();
+
tm.begin();
cache.put(fqn, "k2", "v2");
NodeSPI<Object, Object> n = (NodeSPI<Object, Object>) cache.getRoot().getChild(fqn);
@@ -57,12 +82,16 @@
assertFalse(n.getParent().getParent().getLock().isWriteLocked());
tm.commit();
+
+ assertNoStaleLocks();
}
public void testGet() throws Exception
{
cache.put(fqn, "k", "v");
+ assertNoStaleLocks();
+
tm.begin();
cache.get(fqn, "k2");
NodeSPI<Object, Object> n = (NodeSPI<Object, Object>) cache.getRoot().getChild(fqn);
@@ -75,11 +104,16 @@
assertFalse(n.getParent().getParent().getLock().isWriteLocked());
tm.commit();
+
+ assertNoStaleLocks();
}
public void testRemove() throws Exception
{
cache.put(fqn, "k", "v");
+
+ assertNoStaleLocks();
+
tm.begin();
cache.remove(fqn, "k2");
NodeSPI<Object, Object> n = (NodeSPI<Object, Object>) cache.getRoot().getChild(fqn);
@@ -93,5 +127,7 @@
tm.commit();
+ assertNoStaleLocks();
+
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -44,17 +44,30 @@
*/
public static Object extractField(Object target, String fieldName)
{
+ return extractField(target.getClass(), target, fieldName);
+ }
+
+ private static Object extractField(Class type, Object target, String fieldName)
+ {
Field field;
try
{
- field = target.getClass().getDeclaredField(fieldName);
+ field = type.getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(target);
}
catch (Exception e)
{
- e.printStackTrace();
- return null;
+ if (type.equals(Object.class))
+ {
+ e.printStackTrace();
+ return null;
+ }
+ else
+ {
+ // try with superclass!!
+ return extractField(type.getSuperclass(), target, fieldName);
+ }
}
}
@@ -511,7 +524,7 @@
ComponentRegistry cr = extractComponentRegistry(cache);
// This will replace the previous interceptor chain in the component registry
- cr.registerComponent(interceptor);
+ cr.registerComponent(Interceptor.class, interceptor);
// update all component dependencies
cr.updateDependencies();
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -8,7 +8,10 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.VersionedNode;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
@@ -51,6 +54,12 @@
c = null;
}
+ public void testRoot()
+ {
+ NodeSPI node = c.getRoot();
+ assert ((NodeInvocationDelegate) node).getDelegationTarget() instanceof VersionedNode;
+ }
+
public void testExplicitTxFailure() throws Exception
{
// explicit.
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java 2007-12-13 17:30:43 UTC (rev 4850)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java 2007-12-13 22:36:59 UTC (rev 4851)
@@ -6,21 +6,19 @@
*/
package org.jboss.cache.replicated;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Option;
-import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.invocation.CacheInvocationDelegate;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -28,7 +26,7 @@
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test(groups = { "functional", "jgroups" })
+@Test(groups = {"functional", "jgroups"})
public class SyncReplTest
{
private Cache[] caches;
@@ -74,6 +72,9 @@
Node node = caches[0].getRoot().addChild(f);
+ assert ((NodeSPI) node).getCache() instanceof CacheInvocationDelegate;
+ assert !(((NodeSPI) node).getCache() instanceof RemoteCacheInvocationDelegate);
+
assertNotNull("Should not be null", node);
node.put(k, v);
@@ -114,7 +115,7 @@
assertFalse(caches[0].getRoot().hasChild(fqn));
assertFalse(caches[1].getRoot().hasChild(fqn));
assertEquals(false, caches[0].removeNode(fqn));
-
+
// Confirm it works as expected if the removed node has a child
Fqn<String> child = Fqn.fromString("/test/fqn/child");
caches[0].getRoot().addChild(child);
17 years, 3 months
JBoss Cache SVN: r4850 - in core/trunk/src: main/java/org/jboss/cache/factories and 5 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-13 12:30:43 -0500 (Thu, 13 Dec 2007)
New Revision: 4850
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
Log:
reduced failure count
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -580,7 +580,7 @@
setUseReplQueue(configuration.isUseReplQueue());
setIsolationLevel(configuration.getIsolationLevel());
- createEvictionPolicy();
+ //createEvictionPolicy();
regionManager.setDefaultInactive(configuration.isInactiveOnStartup());
@@ -693,6 +693,13 @@
// start all internal components
componentRegistry.startComponents();
+ // create a new root temporarily.
+ NodeSPI tempRoot = nodeFactory.createRootDataNode();
+ // if we don't already have a root or the new (temp) root is of a different class (optimistic vs pessimistic) to
+ // the current root, then we use the new one. Helps preserve data between cache restarts.
+ if (root == null || !root.getClass().equals(tempRoot.getClass()))
+ root = tempRoot;
+
// createTransactionManager();
// cache loaders should be initialised *before* any state transfers take place to prevent
@@ -1047,21 +1054,6 @@
/* ----------------------- End of buddy replication specific methods ------------*/
- protected void createEvictionPolicy()
- {
- if (configuration.getEvictionConfig() != null
- && configuration.getEvictionConfig().isValidConfig())
- {
- regionManager.setEvictionConfig(configuration.getEvictionConfig());
- regionManager.setUsingEvictions(true);
- }
- else
- {
- regionManager.setUsingEvictions(false);
- log.debug("Not using an EvictionPolicy");
- }
- }
-
/**
* Loads the indicated Fqn, plus all parents recursively from the
* CacheLoader. If no CacheLoader is present, this is a no-op
Modified: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -10,6 +10,7 @@
import org.jboss.cache.factories.ComponentFactory;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.optimistic.WorkspaceNode;
@@ -59,12 +60,12 @@
this.cache = cache;
this.configuration = configuration;
this.componentRegistry = componentRegistry;
- init();
}
/**
* Initialises the node factory with the configuration from the cache.
*/
+ @Start
public void init()
{
optimistic = configuration.isNodeLockingOptimistic();
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -5,12 +5,14 @@
import org.apache.commons.logging.LogFactory;
import static org.jboss.cache.Region.Type.*;
import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
import org.jboss.cache.eviction.RegionNameConflictException;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.lock.NodeLock;
import org.jgroups.Address;
@@ -51,6 +53,7 @@
private EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
protected final Set<Fqn> activationChangeNodes = Collections.synchronizedSet(new HashSet<Fqn>());
+ protected Configuration configuration;
/**
* Constructs a new instance not attached to a cache.
@@ -64,11 +67,28 @@
}
@Inject
- private void injectDependencies(CacheSPI cache)
+ private void injectDependencies(CacheSPI cache, Configuration configuration)
{
this.cache = cache;
+ this.configuration = configuration;
}
+ @Start
+ protected void createEvictionPolicy()
+ {
+ if (configuration.getEvictionConfig() != null
+ && configuration.getEvictionConfig().isValidConfig())
+ {
+ setEvictionConfig(configuration.getEvictionConfig());
+ setUsingEvictions(true);
+ }
+ else
+ {
+ setUsingEvictions(false);
+ log.debug("Not using an EvictionPolicy");
+ }
+ }
+
/**
* Returns true if evictions are being processed.
*/
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -12,7 +12,6 @@
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.jboss.cache.interceptors.*;
import org.jboss.cache.loader.CacheLoaderManager;
-import org.jboss.cache.util.Util;
import java.util.ArrayList;
import java.util.List;
@@ -69,14 +68,6 @@
return first;
}
-
- @SuppressWarnings("unchecked")
- private Interceptor createInterceptor(String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException
- {
- Class<Interceptor> clazz = Util.loadClass(classname);
- return createInterceptor(clazz);
- }
-
private Interceptor createInterceptor(Class<? extends Interceptor> clazz) throws IllegalAccessException, InstantiationException
{
Interceptor i = clazz.newInstance();
@@ -85,7 +76,6 @@
return i;
}
-
/**
* Adds an interceptor at the end of the chain
*/
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -7,11 +7,11 @@
package org.jboss.cache.interceptors;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.optimistic.DefaultDataVersion;
@@ -40,11 +40,10 @@
*/
private NodeFactory nodeFactory;
- public void setCache(CacheSPI cache)
+ @Inject
+ private void injectDependencies(NodeFactory nodeFactory)
{
- super.setCache(cache);
- // set a reference to the node factory
- nodeFactory = cache.getConfiguration().getRuntimeConfig().getNodeFactory();
+ this.nodeFactory = nodeFactory;
}
protected Object handlePutDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Map data, boolean createUndoOps) throws Throwable
@@ -143,135 +142,135 @@
synchronized (workspace)
{
*/
- DataVersion version = null;
- if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
- {
- version = ctx.getOptionOverrides().getDataVersion();
- workspace.setVersioningImplicit(false);
- }
+ DataVersion version = null;
+ if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
+ {
+ version = ctx.getOptionOverrides().getDataVersion();
+ workspace.setVersioningImplicit(false);
+ }
- // start with the ROOT node and then work our way down to the node necessary, creating nodes along the way.
- workspaceNode = workspace.getNode(Fqn.ROOT);
- if (debug) log.debug("GlobalTransaction: " + gtx + "; Root: " + workspaceNode);
+ // start with the ROOT node and then work our way down to the node necessary, creating nodes along the way.
+ workspaceNode = workspace.getNode(Fqn.ROOT);
+ if (debug) log.debug("GlobalTransaction: " + gtx + "; Root: " + workspaceNode);
- // we do not have the root in the workspace! Put it into thr workspace now.
- if (workspaceNode == null)
- {
- NodeSPI node = cache.getRoot();
- workspaceNode = nodeFactory.createWorkspaceNode(node, workspace);
- workspace.addNode(workspaceNode);
- log.debug("Created root node in workspace.");
- }
- else
- {
- log.debug("Found root node in workspace.");
- }
+ // we do not have the root in the workspace! Put it into thr workspace now.
+ if (workspaceNode == null)
+ {
+ NodeSPI node = cache.getRoot();
+ workspaceNode = nodeFactory.createWorkspaceNode(node, workspace);
+ workspace.addNode(workspaceNode);
+ log.debug("Created root node in workspace.");
+ }
+ else
+ {
+ log.debug("Found root node in workspace.");
+ }
- // iterate through the target Fqn's elements.
- int targetFqnSize = targetFqn.size(), currentDepth = 1;
- for (Object childName : targetFqn.peekElements())
- {
- boolean isTargetFqn = (currentDepth == targetFqnSize);
- currentDepth++;
+ // iterate through the target Fqn's elements.
+ int targetFqnSize = targetFqn.size(), currentDepth = 1;
+ for (Object childName : targetFqn.peekElements())
+ {
+ boolean isTargetFqn = (currentDepth == targetFqnSize);
+ currentDepth++;
- // current workspace node canot be null.
- // try and get the child of current node
+ // current workspace node canot be null.
+ // try and get the child of current node
- if (debug) log.debug("Attempting to get child " + childName);
- NodeSPI currentNode = workspaceNode.getNode().getChildDirect(childName);
+ if (debug) log.debug("Attempting to get child " + childName);
+ NodeSPI currentNode = workspaceNode.getNode().getChildDirect(childName);
- if (currentNode == null)
+ if (currentNode == null)
+ {
+ // first test that it exists in the workspace and has been created in thix tx!
+ WorkspaceNode peekInWorkspace = workspace.getNode(new Fqn(workspaceNode.getFqn(), childName));
+ if (peekInWorkspace != null && peekInWorkspace.isCreated())
{
- // first test that it exists in the workspace and has been created in thix tx!
- WorkspaceNode peekInWorkspace = workspace.getNode(new Fqn(workspaceNode.getFqn(), childName));
- if (peekInWorkspace != null && peekInWorkspace.isCreated())
+ // exists in workspace and has just been created.
+ currentNode = peekInWorkspace.getNode();
+ if (peekInWorkspace.isDeleted())
{
- // exists in workspace and has just been created.
- currentNode = peekInWorkspace.getNode();
- if (peekInWorkspace.isDeleted())
- {
- peekInWorkspace.markAsDeleted(false);
- // add in parent again
- workspaceNode.addChild(peekInWorkspace);
- }
+ peekInWorkspace.markAsDeleted(false);
+ // add in parent again
+ workspaceNode.addChild(peekInWorkspace);
}
}
+ }
- if (currentNode == null)
+ if (currentNode == null)
+ {
+ // no child exists with this name; create it in the underlying data structure and then add it to the workspace.
+ if (trace) log.trace("Creating new child, since it doesn't exist in the cache.");
+ // we put the parent node into the workspace as we are changing it's children.
+ // at this point "workspaceNode" refers to the parent of the current node. It should never be null if
+ // you got this far!
+ if (workspaceNode.isDeleted())
{
- // no child exists with this name; create it in the underlying data structure and then add it to the workspace.
- if (trace) log.trace("Creating new child, since it doesn't exist in the cache.");
- // we put the parent node into the workspace as we are changing it's children.
- // at this point "workspaceNode" refers to the parent of the current node. It should never be null if
- // you got this far!
- if (workspaceNode.isDeleted())
- {
- //add a new one or overwrite an existing one that has been deleted
- if (trace)
- log.trace("Parent node doesn't exist in workspace or has been deleted. Adding to workspace.");
- workspace.addNode(workspaceNode);
- if (!(workspaceNode.getVersion() instanceof DefaultDataVersion))
- workspaceNode.setVersioningImplicit(false);
- }
- else
- {
- if (trace) log.trace("Parent node exists: " + workspaceNode);
- }
-
- // get the version passed in, if we need to use explicit versioning.
- DataVersion versionToPassIn = null;
- if (isTargetFqn && !workspace.isVersioningImplicit()) versionToPassIn = version;
-
- NodeSPI newUnderlyingChildNode = workspaceNode.createChild(childName, workspaceNode.getNode(), cache, versionToPassIn);
-
- // now assign "workspaceNode" to the new child created.
- workspaceNode = nodeFactory.createWorkspaceNode(newUnderlyingChildNode, workspace);
- workspaceNode.setVersioningImplicit(versionToPassIn == null || !isTargetFqn);
+ //add a new one or overwrite an existing one that has been deleted
if (trace)
- log.trace("setting versioning of " + workspaceNode.getFqn() + " to be " + (workspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
-
- // now add the wrapped child node into the transaction space
+ log.trace("Parent node doesn't exist in workspace or has been deleted. Adding to workspace.");
workspace.addNode(workspaceNode);
- workspaceNode.markAsCreated();
- // save in list so we can broadcast our created nodes outside
- // the synch block
- nodesCreated.add(workspaceNode.getFqn());
+ if (!(workspaceNode.getVersion() instanceof DefaultDataVersion))
+ workspaceNode.setVersioningImplicit(false);
}
else
{
- // node does exist but might not be in the workspace
- workspaceNode = workspace.getNode(currentNode.getFqn());
- // wrap it up so we can put it in later if we need to
- if (workspaceNode == null || workspaceNode.isDeleted())
- {
- if (trace)
- log.trace("Child node " + currentNode.getFqn() + " doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
+ if (trace) log.trace("Parent node exists: " + workspaceNode);
+ }
- workspaceNode = nodeFactory.createWorkspaceNode(currentNode, workspace);
+ // get the version passed in, if we need to use explicit versioning.
+ DataVersion versionToPassIn = null;
+ if (isTargetFqn && !workspace.isVersioningImplicit()) versionToPassIn = version;
- // if the underlying node is a tombstone then mark the workspace node as newly created
- if (!currentNode.isValid()) workspaceNode.markAsCreated();
+ NodeSPI newUnderlyingChildNode = workspaceNode.createChild(childName, workspaceNode.getNode(), cache, versionToPassIn);
- if (isTargetFqn && !workspace.isVersioningImplicit())
- {
- workspaceNode.setVersion(version);
- workspaceNode.setVersioningImplicit(false);
- }
- else
- {
- workspaceNode.setVersioningImplicit(true);
- }
- if (trace)
- log.trace("setting versioning of " + workspaceNode.getFqn() + " to be " + (workspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
- workspace.addNode(workspaceNode);
+ // now assign "workspaceNode" to the new child created.
+ workspaceNode = nodeFactory.createWorkspaceNode(newUnderlyingChildNode, workspace);
+ workspaceNode.setVersioningImplicit(versionToPassIn == null || !isTargetFqn);
+ if (trace)
+ log.trace("setting versioning of " + workspaceNode.getFqn() + " to be " + (workspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
+
+ // now add the wrapped child node into the transaction space
+ workspace.addNode(workspaceNode);
+ workspaceNode.markAsCreated();
+ // save in list so we can broadcast our created nodes outside
+ // the synch block
+ nodesCreated.add(workspaceNode.getFqn());
+ }
+ else
+ {
+ // node does exist but might not be in the workspace
+ workspaceNode = workspace.getNode(currentNode.getFqn());
+ // wrap it up so we can put it in later if we need to
+ if (workspaceNode == null || workspaceNode.isDeleted())
+ {
+ if (trace)
+ log.trace("Child node " + currentNode.getFqn() + " doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
+
+ workspaceNode = nodeFactory.createWorkspaceNode(currentNode, workspace);
+
+ // if the underlying node is a tombstone then mark the workspace node as newly created
+ if (!currentNode.isValid()) workspaceNode.markAsCreated();
+
+ if (isTargetFqn && !workspace.isVersioningImplicit())
+ {
+ workspaceNode.setVersion(version);
+ workspaceNode.setVersioningImplicit(false);
}
else
{
- if (trace) log.trace("Found child node in the workspace: " + currentNode);
-
+ workspaceNode.setVersioningImplicit(true);
}
+ if (trace)
+ log.trace("setting versioning of " + workspaceNode.getFqn() + " to be " + (workspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
+ workspace.addNode(workspaceNode);
}
+ else
+ {
+ if (trace) log.trace("Found child node in the workspace: " + currentNode);
+
+ }
}
+ }
//}// end sync block
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -6,16 +6,16 @@
*/
package org.jboss.cache.interceptors;
+import org.apache.commons.logging.Log;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
-import org.apache.commons.logging.Log;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -32,17 +32,18 @@
protected TransactionTable txTable = null;
protected boolean trace;
- public void setCache(CacheSPI cache)
+ protected Log getLog()
{
- super.setCache(cache);
- txManager = cache.getTransactionManager();
- txTable = cache.getTransactionTable();
- trace = log != null && log.isTraceEnabled();
+ return null;
}
- protected Log getLog()
+ @Inject
+ private void injectDependencies(TransactionManager txManager, TransactionTable txTable)
{
- return null;
+ this.txManager = txManager;
+ this.txTable = txTable;
+ trace = log != null && log.isTraceEnabled();
+
}
protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws CacheException
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -8,7 +8,6 @@
import org.apache.commons.logging.Log;
import org.jboss.cache.CacheImpl;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
@@ -60,21 +59,14 @@
private long lock_acquisition_timeout;
@Inject
- public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl)
+ public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
{
this.lock_table = lockTable;
lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
this.cacheImpl = cacheImpl;
+ this.tx_table = txTable;
}
- public void setCache(CacheSPI cache)
- {
- super.setCache(cache);
- tx_table = cache.getTransactionTable();
- //lock_table = cache.getLockTable();
- //lock_acquisition_timeout = cache.getConfiguration().getLockAcquisitionTimeout();
- }
-
protected Log getLog()
{
return log;
@@ -172,12 +164,10 @@
else
{
Iterator removedNodes = entry.getRemovedNodes().iterator();
- CacheImpl cacheImpl = (CacheImpl) cache;
while (removedNodes.hasNext())
{
Fqn f = (Fqn) removedNodes.next();
cacheImpl.realRemove(f, false);
-
}
// 1. Revert the modifications by running the undo-op list in reverse. This *cannot* throw any exceptions !
entry.undoOperations(cache);
@@ -560,7 +550,6 @@
// first remove nodes that should be deleted.
Iterator removedNodes = entry.getRemovedNodes().iterator();
- CacheImpl cacheImpl = (CacheImpl) cache;
while (removedNodes.hasNext())
{
Fqn f = (Fqn) removedNodes.next();
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -564,4 +564,9 @@
{
return getChildrenNames(Fqn.fromString(fqn));
}
+
+ public CacheImpl getImpl()
+ {
+ return cache;
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -34,6 +34,11 @@
this.node = node;
}
+ public UnversionedNode getUnversionedNode()
+ {
+ return node;
+ }
+
@Inject
private void injectDependencies(CacheSPI spi)
{
@@ -236,7 +241,7 @@
public Set<Object> getChildrenNames()
{
assertValid();
- return cache.getChildrenNames(getFqn());
+ return spi.getChildrenNames(getFqn());
}
public Map<K, V> getData()
@@ -270,13 +275,13 @@
public boolean removeChild(Fqn<?> f)
{
assertValid();
- return cache.removeNode(new Fqn(getFqn(), f));
+ return spi.removeNode(new Fqn(getFqn(), f));
}
public boolean removeChild(Object childName)
{
assertValid();
- return cache.removeNode(new Fqn(getFqn(), childName));
+ return spi.removeNode(new Fqn(getFqn(), childName));
}
public Node<K, V> getChild(Fqn<?> f)
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -15,6 +15,7 @@
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.VersionedNode;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.transaction.GlobalTransaction;
import java.util.ArrayList;
@@ -53,9 +54,10 @@
*/
public WorkspaceNodeImpl(NodeSPI<K, V> node, TransactionWorkspace workspace)
{
- if (!(node instanceof VersionedNode))
+ NodeInvocationDelegate delegate = (NodeInvocationDelegate) node;
+ if (!(delegate.getUnversionedNode() instanceof VersionedNode))
{
- throw new IllegalArgumentException("node " + node + " not VersionedNode");
+ throw new IllegalArgumentException("node " + delegate.getUnversionedNode() + " not VersionedNode");
}
this.node = node;
this.workspace = workspace;
@@ -145,11 +147,11 @@
}
Set<Object> names = new HashSet<Object>(optimisticChildNodeMap.keySet());
-
+
// process deltas
for (Fqn child : childrenAdded) names.add(child.getLastElement());
for (Fqn child : childrenRemoved) names.remove(child.getLastElement());
-
+
return names;
}
@@ -194,11 +196,11 @@
// if not we need to create it
// if (child == null)
// {
- NodeFactory<K, V> factory = cache.getConfiguration().getRuntimeConfig().getNodeFactory();
- NodeSPI<K, V> child = (NodeSPI<K, V>) factory.createNodeOfType(parent, child_name, parent, null);
+ NodeFactory<K, V> factory = cache.getConfiguration().getRuntimeConfig().getNodeFactory();
+ NodeSPI<K, V> child = (NodeSPI<K, V>) factory.createNodeOfType(parent, child_name, parent, null);
// optimisticChildNodeMap.put(child_name, child);
- childrenAdded.add(child.getFqn());
- childrenRemoved.remove(child.getFqn());
+ childrenAdded.add(child.getFqn());
+ childrenRemoved.remove(child.getFqn());
// }
childrenModified = true;
return child;
@@ -294,22 +296,22 @@
else
{
// recursively create children
- Node<K,V> currentParent = this;
+ Node<K, V> currentParent = this;
for (Object o : f.peekElements())
{
if (currentParent instanceof WorkspaceNode)
{
- newNode = ((WorkspaceNode<K,V>) currentParent).getNode().getOrCreateChild(o, gtx);
+ newNode = ((WorkspaceNode<K, V>) currentParent).getNode().getOrCreateChild(o, gtx);
}
else
{
if (currentParent instanceof WorkspaceNode)
{
- newNode = ((WorkspaceNode<K,V>) currentParent).getNode().getOrCreateChild(o, gtx);
+ newNode = ((WorkspaceNode<K, V>) currentParent).getNode().getOrCreateChild(o, gtx);
}
else
{
- newNode = ((NodeSPI<K,V>) currentParent).getOrCreateChild(o, gtx);
+ newNode = ((NodeSPI<K, V>) currentParent).getOrCreateChild(o, gtx);
}
}
currentParent = newNode;
@@ -318,7 +320,7 @@
return newNode;
}
- public void addChild(WorkspaceNode<K,V> child)
+ public void addChild(WorkspaceNode<K, V> child)
{
// optimisticChildNodeMap.put(child.getFqn().getLastElement(), child.getNode());
childrenAdded.add(child.getFqn());
@@ -409,10 +411,10 @@
Fqn childFqn = new Fqn(getFqn(), childName);
/*if (n != null)
{*/
- childrenRemoved.add(childFqn);
- childrenAdded.remove(childFqn);
- childrenModified = true;
- return node.getChildDirect(childName) != null;
+ childrenRemoved.add(childFqn);
+ childrenAdded.remove(childFqn);
+ childrenModified = true;
+ return node.getChildDirect(childName) != null;
/*}
else
{
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -10,10 +10,12 @@
import net.jcip.annotations.ThreadSafe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.config.Option;
+import org.jboss.cache.invocation.CacheInvocationDelegate;
import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
@@ -338,14 +340,15 @@
{
l = new ArrayList<MethodCall>(undo_list);
}
+ CacheImpl ci = ((CacheInvocationDelegate) cache).getImpl();
for (ListIterator<MethodCall> i = l.listIterator(l.size()); i.hasPrevious();)
{
MethodCall undo_op = i.previous();
- undo(undo_op, cache);
+ undo(undo_op, ci);
}
}
- private void undo(MethodCall undo_op, CacheSPI cache)
+ private void undo(MethodCall undo_op, CacheImpl cache)
{
try
{
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2007-12-13 14:15:28 UTC (rev 4849)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2007-12-13 17:30:43 UTC (rev 4850)
@@ -7,7 +7,7 @@
package org.jboss.cache.marshall;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
@@ -31,7 +31,7 @@
public class ActiveInactiveTest
{
RegionManager rman;
- CacheImpl c;
+ CacheSPI c;
Fqn<String> A = Fqn.fromString("/a");
Fqn<String> I = Fqn.fromString("/i");
Fqn<String> A_B = new Fqn<String>(A, "b");
@@ -39,7 +39,7 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- c = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ c = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
c.getConfiguration().setUseRegionBasedMarshalling(true);
c.getConfiguration().setFetchInMemoryState(false);
c.start();
@@ -49,9 +49,12 @@
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- c.stop();
- c = null;
- rman = null;
+ if (c != null)
+ {
+ c.stop();
+ c = null;
+ rman = null;
+ }
}
public void testDefaultActive() throws Exception
17 years, 3 months
JBoss Cache SVN: r4848 - in core/branches/1.4.X: tests/functional/org/jboss/cache/lock/pessimistic and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-12-12 17:42:28 -0500 (Wed, 12 Dec 2007)
New Revision: 4848
Removed:
core/branches/1.4.X/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java
Modified:
core/branches/1.4.X/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
[JBCACHE-1235] Revert JBCACHE-1165 on 1.4.X branch
Modified: core/branches/1.4.X/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-12 21:52:59 UTC (rev 4847)
+++ core/branches/1.4.X/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-12 22:42:28 UTC (rev 4848)
@@ -118,7 +118,10 @@
fqn = (Fqn) args[1];
lock_type = DataNode.LOCK_TYPE_WRITE;
recursive = true; // remove node and *all* child nodes
- createIfNotExists = true;
+ // BES 2007/12/12 -- Revert JBCACHE-1165 fix as it causes endless loop
+ // in TransactionTest.testDoubleNodeRemoval, plus another failure
+ // in that test
+// createIfNotExists = true;
// JBCACHE-871 We need to store the node
storeLockedNode = true;
break;
@@ -308,20 +311,23 @@
// Try to acquire the lock; recording that we did if successful
acquireNodeLock(child_node, owner, gtx, currentLockType, lock_timeout);
+
+ // BES 2007/12/12 -- Revert JBCACHE-1165 fix as it causes endless loop
+ // in TransactionTest.testDoubleNodeRemoval, plus another failure
+ // in that test
+// // make sure the lock we acquired isn't on a deleted node/is an orphan!!
+// DataNode repeek = cache.peek(child_node.getFqn());
+// if (repeek != null && child_node != repeek)
+// {
+// log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore! Attempting lock acquisition again.");
+// // we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and potentially recreate the node).
+// child_node.getLock().release(owner);
+//
+// // do the loop again, but don't assign child_node to n so that child_node is processed again.
+// i--;
+// continue;
+// }
- // make sure the lock we acquired isn't on a deleted node/is an orphan!!
- DataNode repeek = cache.peek(child_node.getFqn());
- if (repeek != null && child_node != repeek)
- {
- log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore! Attempting lock acquisition again.");
- // we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and potentially recreate the node).
- child_node.getLock().release(owner);
-
- // do the loop again, but don't assign child_node to n so that child_node is processed again.
- i--;
- continue;
- }
-
if (recursive && isTargetNode(i, treeNodeSize))
{
{
Deleted: core/branches/1.4.X/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java
===================================================================
--- core/branches/1.4.X/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java 2007-12-12 21:52:59 UTC (rev 4847)
+++ core/branches/1.4.X/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java 2007-12-12 22:42:28 UTC (rev 4848)
@@ -1,104 +0,0 @@
-package org.jboss.cache.lock.pessimistic;
-
-import junit.framework.TestCase;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.DummyTransactionManagerLookup;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCache;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.misc.TestingUtil;
-
-import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public class ConcurrentPutRemoveTest extends TestCase
-{
- private TransactionManager tm;
-
- private TreeCache cache;
-
- private final Log log = LogFactory.getLog(ConcurrentPutRemoveTest.class);
- private List threads;
-
-
- public void setUp() throws Exception
- {
- cache = new TreeCache();
- cache.setIsolationLevel(IsolationLevel.READ_COMMITTED);
- cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- cache.setLockAcquisitionTimeout(1000);
- cache.start();
- tm = cache.getTransactionManager();
- threads = new ArrayList();
- }
-
- public void tearDown() throws Exception
- {
- TestingUtil.killCaches(new TreeCache[]{cache});
- }
-
- public void testLock() throws Exception
- {
- for (int x = 0; x < 2; x++)
- {
- SeparateThread t = new SeparateThread(x);
- threads.add(t);
- t.start();
- }
- for (Iterator i = threads.iterator(); i.hasNext();)
- {
- SeparateThread separateThread = (SeparateThread) i.next();
- separateThread.join();
- if (separateThread.getException() != null)
- {
- throw separateThread.getException();
- }
- }
- }
-
- private class SeparateThread extends Thread
- {
- Exception e = null;
-
- private int num = 0;
-
- public SeparateThread(int num)
- {
- this.num = num;
- }
-
- public Exception getException()
- {
- return e;
- }
-
- public void run()
- {
- Thread.currentThread().setName("Thread:" + num);
- try
- {
- for (int x = 0; x < 100; x++)
- {
- tm.begin();
- log.warn("Before Remove (" + x + ")");
- //inside transaction
- cache.remove(Fqn.fromString("/a"));
- log.warn("After Remove (" + x + ")");
- tm.commit();
- //outside transaction
- log.warn("Before Put (" + x + ")");
- cache.put(Fqn.fromString("/a/b/c/d"), "text" + x, "b");
- log.warn("After Put (" + x + ")");
- }
- }
- catch (Exception e)
- {
- this.e = e;
- }
- }
- }
-
-}
17 years, 3 months
JBoss Cache SVN: r4847 - core/tags/1.4.1.SP8/docs.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-12-12 16:52:59 -0500 (Wed, 12 Dec 2007)
New Revision: 4847
Modified:
core/tags/1.4.1.SP8/docs/Changelog.txt
Log:
[JBCACHE-1235] Revert JBCACHE-1165 on 1.4.X branch
Modified: core/tags/1.4.1.SP8/docs/Changelog.txt
===================================================================
--- core/tags/1.4.1.SP8/docs/Changelog.txt 2007-12-12 21:50:54 UTC (rev 4846)
+++ core/tags/1.4.1.SP8/docs/Changelog.txt 2007-12-12 21:52:59 UTC (rev 4847)
@@ -5,6 +5,7 @@
Patch release on 1.4.1.GA
** Bug
+ * [ JBCACHE-1165 ] Fix from SP7 reverted
* [ JBCACHE-1225 ] TreeCache._enqueueMethodCall doesn't handle buddy backup FQNs
* [ JBCACHE-1228 ] Optimistic lock interceptor always acquires write locks for nodes in workspace at commit time
* [ JBCACHE-1234 ] Region activation requests partial state transfer from wrong nodes
@@ -15,6 +16,7 @@
** Bug
* [ JBCACHE-1165 ] Endless loop in PessimisticLockInterceptor, sometimes seen as a NodeNotExistsException (when using READ_COMMITTED)
+ Note that this fix was reverted in SP8.
* [ JBCACHE-1166 ] UpgradeException on concurrent put/remove operation
* [ JBCACHE-1217 ] Exceptions in BuddyReplication group organisation methods not propagated to caller
* [ JBCACHE-1220 ] DataGravitatorInterceptor logs ERROR when alone in cluster
17 years, 3 months
JBoss Cache SVN: r4846 - core/tags/1.4.1.SP8/src/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-12-12 16:50:54 -0500 (Wed, 12 Dec 2007)
New Revision: 4846
Modified:
core/tags/1.4.1.SP8/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
[JBCACHE-1235] Revert JBCACHE-1165 on 1.4.X branch
Modified: core/tags/1.4.1.SP8/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/tags/1.4.1.SP8/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-12 21:28:20 UTC (rev 4845)
+++ core/tags/1.4.1.SP8/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-12 21:50:54 UTC (rev 4846)
@@ -118,7 +118,10 @@
fqn = (Fqn) args[1];
lock_type = DataNode.LOCK_TYPE_WRITE;
recursive = true; // remove node and *all* child nodes
- createIfNotExists = true;
+ // BES 2007/12/12 -- Revert JBCACHE-1165 fix as it causes endless loop
+ // in TransactionTest.testDoubleNodeRemoval, plus another failure
+ // in that test
+// createIfNotExists = true;
// JBCACHE-871 We need to store the node
storeLockedNode = true;
break;
@@ -309,19 +312,22 @@
// Try to acquire the lock; recording that we did if successful
acquireNodeLock(child_node, owner, gtx, currentLockType, lock_timeout);
- // make sure the lock we acquired isn't on a deleted node/is an orphan!!
- DataNode repeek = cache.peek(child_node.getFqn());
- if (repeek != null && child_node != repeek)
- {
- log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore! Attempting lock acquisition again.");
- // we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and potentially recreate the node).
- child_node.getLock().release(owner);
+ // BES 2007/12/12 -- Revert JBCACHE-1165 fix as it causes endless loop
+ // in TransactionTest.testDoubleNodeRemoval, plus another failure
+ // in that test
+// // make sure the lock we acquired isn't on a deleted node/is an orphan!!
+// DataNode repeek = cache.peek(child_node.getFqn());
+// if (repeek != null && child_node != repeek)
+// {
+// log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore! Attempting lock acquisition again.");
+// // we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and potentially recreate the node).
+// child_node.getLock().release(owner);
+//
+// // do the loop again, but don't assign child_node to n so that child_node is processed again.
+// i--;
+// continue;
+// }
- // do the loop again, but don't assign child_node to n so that child_node is processed again.
- i--;
- continue;
- }
-
if (recursive && isTargetNode(i, treeNodeSize))
{
{
17 years, 3 months
JBoss Cache SVN: r4845 - core/tags/1.4.1.SP8/tests/functional/org/jboss/cache/lock/pessimistic.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-12 16:28:20 -0500 (Wed, 12 Dec 2007)
New Revision: 4845
Removed:
core/tags/1.4.1.SP8/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java
Log:
Reverting
Deleted: core/tags/1.4.1.SP8/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java
===================================================================
--- core/tags/1.4.1.SP8/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java 2007-12-12 15:29:35 UTC (rev 4844)
+++ core/tags/1.4.1.SP8/tests/functional/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java 2007-12-12 21:28:20 UTC (rev 4845)
@@ -1,104 +0,0 @@
-package org.jboss.cache.lock.pessimistic;
-
-import junit.framework.TestCase;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.DummyTransactionManagerLookup;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCache;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.misc.TestingUtil;
-
-import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public class ConcurrentPutRemoveTest extends TestCase
-{
- private TransactionManager tm;
-
- private TreeCache cache;
-
- private final Log log = LogFactory.getLog(ConcurrentPutRemoveTest.class);
- private List threads;
-
-
- public void setUp() throws Exception
- {
- cache = new TreeCache();
- cache.setIsolationLevel(IsolationLevel.READ_COMMITTED);
- cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- cache.setLockAcquisitionTimeout(1000);
- cache.start();
- tm = cache.getTransactionManager();
- threads = new ArrayList();
- }
-
- public void tearDown() throws Exception
- {
- TestingUtil.killCaches(new TreeCache[]{cache});
- }
-
- public void testLock() throws Exception
- {
- for (int x = 0; x < 2; x++)
- {
- SeparateThread t = new SeparateThread(x);
- threads.add(t);
- t.start();
- }
- for (Iterator i = threads.iterator(); i.hasNext();)
- {
- SeparateThread separateThread = (SeparateThread) i.next();
- separateThread.join();
- if (separateThread.getException() != null)
- {
- throw separateThread.getException();
- }
- }
- }
-
- private class SeparateThread extends Thread
- {
- Exception e = null;
-
- private int num = 0;
-
- public SeparateThread(int num)
- {
- this.num = num;
- }
-
- public Exception getException()
- {
- return e;
- }
-
- public void run()
- {
- Thread.currentThread().setName("Thread:" + num);
- try
- {
- for (int x = 0; x < 100; x++)
- {
- tm.begin();
- log.warn("Before Remove (" + x + ")");
- //inside transaction
- cache.remove(Fqn.fromString("/a"));
- log.warn("After Remove (" + x + ")");
- tm.commit();
- //outside transaction
- log.warn("Before Put (" + x + ")");
- cache.put(Fqn.fromString("/a/b/c/d"), "text" + x, "b");
- log.warn("After Put (" + x + ")");
- }
- }
- catch (Exception e)
- {
- this.e = e;
- }
- }
- }
-
-}
17 years, 3 months
JBoss Cache SVN: r4844 - in core/trunk/src: main/java/org/jboss/cache/factories and 3 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-12 10:29:35 -0500 (Wed, 12 Dec 2007)
New Revision: 4844
Added:
core/trunk/src/main/java/org/jboss/cache/factories/annotations/Start.java
core/trunk/src/main/java/org/jboss/cache/factories/annotations/Stop.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
Log:
Use of a start and stop annotation for better backward compatibility with old Interceptor setCache() methods.
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-12 15:22:27 UTC (rev 4843)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-12 15:29:35 UTC (rev 4844)
@@ -690,6 +690,9 @@
cacheStatus = CacheStatus.STARTING;
+ // start all internal components
+ componentRegistry.startComponents();
+
// createTransactionManager();
// cache loaders should be initialised *before* any state transfers take place to prevent
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-12 15:22:27 UTC (rev 4843)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-12 15:29:35 UTC (rev 4844)
@@ -9,6 +9,8 @@
import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.factories.annotations.Stop;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.util.BeanUtils;
@@ -43,7 +45,7 @@
* Can contain either unnamed singletons (in which case the key is the class of the instance) or named singletons, keyed by a
* String representing the name of the instance.
*/
- private Map<Object, Object> registry = new HashMap<Object, Object>();
+ Map<Object, Object> registry = new HashMap<Object, Object>();
/**
* Contains class definitions of component factories that can be used to construct certain components
*/
@@ -299,7 +301,7 @@
if (log.isTraceEnabled()) log.trace("Inspecting class " + target.getClass());
try
{
- List<Method> methods = getAllMethods(target.getClass());
+ List<Method> methods = getAllMethods(target.getClass(), Inject.class);
if (log.isTraceEnabled())
log.trace("Found method set containing " + methods.size() + " methods that need injection: " + methods);
@@ -369,25 +371,26 @@
* Includes all methods annotated with &Inject as well as methods that are <i>not</i> annotated, but instead
* have parameters annotated accordingly.
*
- * @param c class to inspect
+ * @param c class to inspect
+ * @param annotationType the type of annotation to look for
* @return Set of Method objects that require injection.
*/
- private List<Method> getAllMethods(Class c)
+ private List<Method> getAllMethods(Class c, Class<? extends Annotation> annotationType)
{
List<Method> annotated = new LinkedList<Method>();
- inspectRecursively(c, annotated);
+ inspectRecursively(c, annotated, annotationType);
return annotated;
}
- private void inspectRecursively(Class c, List<Method> s)
+ private void inspectRecursively(Class c, List<Method> s, Class<? extends Annotation> annotationType)
{
// Superclass first
- if (!c.equals(Object.class)) inspectRecursively(c.getSuperclass(), s);
+ if (!c.equals(Object.class)) inspectRecursively(c.getSuperclass(), s, annotationType);
for (Method m : c.getDeclaredMethods())
{
// don't bother if this method has already been overridden by a subclass
- if (!alreadyFound(m, s) && m.isAnnotationPresent(Inject.class))
+ if (!alreadyFound(m, s) && m.isAnnotationPresent(annotationType))
{
s.add(m);
}
@@ -519,4 +522,50 @@
{
registry.clear();
}
+
+ /**
+ * Starts all components that contain the {@link Start} annotation.
+ */
+ public void startComponents()
+ {
+ for (Object component : registry.values())
+ {
+ List<Method> methods = getAllMethods(component.getClass(), Start.class);
+ for (Method m : methods)
+ {
+ try
+ {
+ m.setAccessible(true);
+ m.invoke(component);
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to invoke @Start annotated method " + m, e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Stops all components that contain the {@link Stop} annotation.
+ */
+ public void stopComponents()
+ {
+ for (Object component : registry.values())
+ {
+ List<Method> methods = getAllMethods(component.getClass(), Stop.class);
+ for (Method m : methods)
+ {
+ try
+ {
+ m.invoke(component);
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to invoke @Stop annotated method " + m, e);
+ }
+ }
+ }
+ }
+
}
Added: core/trunk/src/main/java/org/jboss/cache/factories/annotations/Start.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/annotations/Start.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/factories/annotations/Start.java 2007-12-12 15:29:35 UTC (rev 4844)
@@ -0,0 +1,20 @@
+package org.jboss.cache.factories.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Method level annotation that indicates a (no-param) method to be called on a component registered in the ComponentRegistry
+ * when the cache starts.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Target(METHOD)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Start
+{
+}
Added: core/trunk/src/main/java/org/jboss/cache/factories/annotations/Stop.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/annotations/Stop.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/factories/annotations/Stop.java 2007-12-12 15:29:35 UTC (rev 4844)
@@ -0,0 +1,20 @@
+package org.jboss.cache.factories.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Method level annotation that indicates a (no-param) method to be called on a component registered in the ComponentRegistry
+ * when the cache stops.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Target(METHOD)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Stop
+{
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2007-12-12 15:22:27 UTC (rev 4843)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2007-12-12 15:29:35 UTC (rev 4844)
@@ -8,7 +8,6 @@
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Option;
-import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
@@ -32,13 +31,12 @@
private boolean usingBuddyReplication;
protected boolean defaultSynchronous;
- @Inject
public void setCache(CacheSPI cache)
{
super.setCache(cache);
buddyManager = cache.getBuddyManager();
usingBuddyReplication = buddyManager != null;
- CacheMode mode = configuration.getCacheMode();
+ CacheMode mode = cache.getConfiguration().getCacheMode();
defaultSynchronous = (mode == CacheMode.REPL_SYNC || mode == CacheMode.INVALIDATION_SYNC);
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-12 15:22:27 UTC (rev 4843)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-12 15:29:35 UTC (rev 4844)
@@ -28,6 +28,7 @@
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
import javax.transaction.Status;
import javax.transaction.SystemException;
@@ -65,17 +66,22 @@
return next;
}
- @Inject
public void setCache(CacheSPI cache)
{
- this.cache = cache;
- //this.configuration = cache.getConfiguration();
}
+ @Start
+ private void start()
+ {
+ // for backward compatibility, this must only be done when the cache starts.
+ setCache(cache);
+ }
+
@Inject
- private void injectDependencies(Configuration configuration)
+ private void injectDependencies(CacheSPI cache, Configuration configuration)
{
this.configuration = configuration;
+ this.cache = cache;
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java 2007-12-12 15:22:27 UTC (rev 4843)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java 2007-12-12 15:29:35 UTC (rev 4844)
@@ -60,6 +60,8 @@
{
assert cf.componentRegistry == cr;
assert cf.configuration == configuration;
+
+ System.out.println(cr.registry);
}
public void testDefaultFactoryScanning()
17 years, 3 months
JBoss Cache SVN: r4843 - in cache-bench-fwk/trunk: cache-products/terracotta-2.4.8/src/org/cachebench/cachewrappers and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2007-12-12 10:22:27 -0500 (Wed, 12 Dec 2007)
New Revision: 4843
Added:
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java
Modified:
cache-bench-fwk/trunk/build.xml
cache-bench-fwk/trunk/cache-products/terracotta-2.4.8/src/org/cachebench/cachewrappers/TerracottaWrapper.java
cache-bench-fwk/trunk/conf/cachebench.xml
cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkSlave.java
cache-bench-fwk/trunk/src/org/cachebench/TestResult.java
cache-bench-fwk/trunk/src/org/cachebench/config/Report.java
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java
Log:
enhance the framework so that all nodes are able to insert data into cache
Modified: cache-bench-fwk/trunk/build.xml
===================================================================
--- cache-bench-fwk/trunk/build.xml 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/build.xml 2007-12-12 15:22:27 UTC (rev 4843)
@@ -283,7 +283,7 @@
<delete dir="${coherence322-plugin.testoutput.dir}"/>
</target>
- <!-- Module terracotta-2.3.0 -->
+ <!-- Module terracotta-2.4.8 -->
<dirname property="module.terracotta-plugin.basedir" file="${ant.file}"/>
@@ -291,18 +291,18 @@
<property name="compiler.args.terracotta-plugin" value="${compiler.args}"/>
- <property name="terracotta-plugin.output.dir" value="${module.terracotta-plugin.basedir}/classes/production/terracotta-2.3.0"/>
- <property name="terracotta-plugin.testoutput.dir" value="${module.terracotta-plugin.basedir}/classes/test/terracotta-2.3.0"/>
+ <property name="terracotta-plugin.output.dir" value="${module.terracotta-plugin.basedir}/classes/production/terracotta-2.4.8"/>
+ <property name="terracotta-plugin.testoutput.dir" value="${module.terracotta-plugin.basedir}/classes/test/terracotta-2.4.8"/>
<path id="terracotta-plugin.module.bootclasspath">
<!-- Paths to be included in compilation bootclasspath -->
</path>
<path id="terracotta-plugin.module.classpath">
- <pathelement location="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.3.0/conf"/>
+ <pathelement location="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.4.8/conf"/>
<pathelement location="${framework.output.dir}"/>
<pathelement location="${framework.testoutput.dir}"/>
- <fileset dir="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.3.0/lib" includes="*.jar" />
+ <fileset dir="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.4.8/lib" includes="*.jar" />
<pathelement location="${terracotta-plugin.output.dir}" />
</path>
@@ -316,15 +316,15 @@
</patternset>
<path id="terracotta-plugin.module.sourcepath">
- <dirset dir="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.3.0">
+ <dirset dir="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.4.8">
<include name="src"/>
</dirset>
</path>
- <target name="compile.module.terracotta-plugin" depends="compile.module.terracotta-plugin.production,compile.module.terracotta-plugin.tests" description="Compile module terracotta-2.3.0"/>
+ <target name="compile.module.terracotta-plugin" depends="compile.module.terracotta-plugin.production,compile.module.terracotta-plugin.tests" description="Compile module terracotta-2.4.8"/>
- <target name="compile.module.terracotta-plugin.production" depends="compile.module.framework" description="Compile module terracotta-2.3.0; production classes">
+ <target name="compile.module.terracotta-plugin.production" depends="compile.module.framework" description="Compile module terracotta-2.4.8; production classes">
<mkdir dir="${terracotta-plugin.output.dir}"/>
<javac destdir="${terracotta-plugin.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true">
<compilerarg line="${compiler.args.terracotta-plugin}"/>
@@ -335,14 +335,14 @@
</javac>
<copy todir="${terracotta-plugin.output.dir}">
- <fileset dir="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.3.0/src">
+ <fileset dir="${module.terracotta-plugin.basedir}/cache-products/terracotta-2.4.8/src">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target>
- <target name="compile.module.terracotta-plugin.tests" depends="compile.module.terracotta-plugin.production" description="compile module terracotta-2.3.0; test classes" unless="skip.tests"/>
+ <target name="compile.module.terracotta-plugin.tests" depends="compile.module.terracotta-plugin.production" description="compile module terracotta-2.4.8; test classes" unless="skip.tests"/>
<target name="clean.module.terracotta-plugin" description="cleanup module">
<delete dir="${terracotta-plugin.output.dir}"/>
@@ -528,10 +528,11 @@
<java classname="${runtime.classname}" fork="${jvm.fork}" maxmemory="${jvm.maxmem}" clonevm="true">
<!--<bootclasspath>-->
- <!--<pathelement location="./cache-products/terracotta-2.3.0/lib/bootstrap/boot.jar" />-->
+ <!--<pathelement location="./cache-products/terracotta-2.4.8/lib/bootstrap/boot.jar" />-->
<!--</bootclasspath>-->
<sysproperty key="bind.address" value="${bind.address}" />
<sysproperty key="tangosol.coherence.localhost" value="${tangosol.coherence.localhost}" />
+ <sysproperty key="cluterReportGenerator" value="${cluterReportGenerator}" />
<sysproperty key="org.cachebench.debug" value="${org.cachebench.debug}" />
<sysproperty key="java.net.preferIPv4Stack" value="${java.net.preferIPv4Stack}" />
<classpath refid="framework.module.classpath" />
@@ -541,13 +542,15 @@
<target name="runSlave">
<antcall target="run">
- <param name="runtime.classname" value="org.cachebench.CacheBenchmarkSlave" />
+ <param name="runtime.classname" value="org.cachebench.CacheBenchmarkRunner" />
+ <param name="cluterReportGenerator" value="false"/>
</antcall>
</target>
<target name="runMaster">
<antcall target="run">
<param name="runtime.classname" value="org.cachebench.CacheBenchmarkRunner" />
+ <param name="cluterReportGenerator" value="true"/>
</antcall>
</target>
Modified: cache-bench-fwk/trunk/cache-products/terracotta-2.4.8/src/org/cachebench/cachewrappers/TerracottaWrapper.java
===================================================================
--- cache-bench-fwk/trunk/cache-products/terracotta-2.4.8/src/org/cachebench/cachewrappers/TerracottaWrapper.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/cache-products/terracotta-2.4.8/src/org/cachebench/cachewrappers/TerracottaWrapper.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -16,7 +16,7 @@
public class TerracottaWrapper implements CacheWrapper
{
// Since terracotta
- private Map cache;
+ private Map cache = new HashMap();
public void init(Properties parameters) throws Exception
{
@@ -24,13 +24,14 @@
public void setUp() throws Exception
{
- cache = new HashMap();
}
public void tearDown() throws Exception
{
- cache.clear();
- cache = null;
+ synchronized(cache)
+ {
+ cache.clear();
+ }
}
public void put(Object key, Object value) throws Exception
@@ -64,6 +65,9 @@
public String getInfo()
{
- return "There are " + cache.size() + " objects in cache";
+ synchronized(cache)
+ {
+ return "There are " + cache.size() + " objects in cache";
+ }
}
}
Modified: cache-bench-fwk/trunk/conf/cachebench.xml
===================================================================
--- cache-bench-fwk/trunk/conf/cachebench.xml 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/conf/cachebench.xml 2007-12-12 15:22:27 UTC (rev 4843)
@@ -7,7 +7,7 @@
emptyCacheBetweenTests - again, use if you're running out of mem.
numThreads - the number of executor threads to use to perform the required number of operations.
-->
-<cachebench sampleSize="1000000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true" numThreads="10">
+<cachebench sampleSize="10000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true" numThreads="10">
<!-- Each testcase represents either a single configuration or a cacheing product.
@@ -31,7 +31,7 @@
<!--<testcase name="JBossCache2x-Pessimistic-REPL_SYNC_BR" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper">-->
<!--<testcase name="JBossCache2x-Pessimistic-REPL_ASYNC" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper">-->
- <testcase name="Coherence-3.x" cacheWrapper="org.cachebench.cachewrappers.CoherenceWrapper">
+ <testcase name="JBossCache2.0" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper">
<!--
* The "name" attrib is just used for display in the reports.
@@ -62,12 +62,17 @@
</testcase>
- <!-- Currently we only have a CSVReportGenerator. See javadocs for org.cachebench.reportgenerators.ReportGenerator for writing your
- own report generators such as XML generators, graphic generators, etc -->
+ <!--
+ Available generators are: CSVReportGenerator and ClusterReportGenerator.
+ See javadocs for org.cachebench.reportgenerators.ReportGenerator for writing your
+ own report generators such as XML generators, graphic generators, etc
+ -->
+ <!-- The CSV report generated can be plugged in to a spreadsheet to generate graphs, cluster size is
+ needed so that the . -->
+ <report outputFile="performance.csv" generator="org.cachebench.reportgenerators.ClusterReportGenerator">
+ <param name="clusterSize" value="3"/>
+ <param name="masterHost" value="127.0.0.1"/>
+ <param name="masterPort" value="54334"/>
+ </report>
- <!-- The CSV report generated can be plugged in to a spreadsheet to generate graphs, etc. -->
- <report
- outputFile="performance.csv"
- generator="org.cachebench.reportgenerators.CSVReportGenerator" />
-
</cachebench>
Modified: cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -114,6 +114,11 @@
digester.addObjectCreate("cachebench/report", "org.cachebench.config.Report");
digester.addSetProperties("cachebench/report");
+
+ digester.addObjectCreate("cachebench/report/param", "org.cachebench.config.NVPair");
+ digester.addSetProperties("cachebench/report/param");
+ digester.addSetNext("cachebench/report/param", "addParam", "org.cachebench.config.NVPair");
+
digester.addSetNext("cachebench/report", "addReport", "org.cachebench.config.Report");
return (Configuration) digester.parse(url.openStream());
}
@@ -230,13 +235,14 @@
ReportGenerator generator;
try
{
- generator = getReportWrapper(report);
+ generator = getReportGenerator(report);
if (generator != null)
{
+ generator.setConfigParams(report.getParams());
generator.setResults(results);
generator.setOutputFile(new File(report.getOutputFile()));
generator.generate();
- logger.info("Report Generation Complted");
+ logger.info("Report Generation Completed");
}
else
{
@@ -301,7 +307,7 @@
return cache;
}
- private ReportGenerator getReportWrapper(Report reportClass)
+ private ReportGenerator getReportGenerator(Report reportClass)
{
ReportGenerator report = null;
try
Modified: cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkSlave.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkSlave.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkSlave.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -18,6 +18,7 @@
/**
* @author Manik Surtani (manik(a)surtani.org)
* @version $Id: CacheBenchmarkSlave.java,v 1.8 2007/05/21 16:30:00 msurtani Exp $
+ * @deprecated all tests should run in server mode, as all the test are putting data into the test
*/
public class CacheBenchmarkSlave
{
Modified: cache-bench-fwk/trunk/src/org/cachebench/TestResult.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/TestResult.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/src/org/cachebench/TestResult.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -2,6 +2,7 @@
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
+import java.io.Serializable;
import java.util.Date;
@@ -9,7 +10,7 @@
* @author Manik Surtani (manik(a)surtani.org)
* @version $Id: TestResult.java,v 1.4 2007/04/18 19:09:30 msurtani Exp $
*/
-public class TestResult
+public class TestResult implements Serializable
{
private String testName;
private String testType;
@@ -152,4 +153,22 @@
{
this.numThreads = numThreads;
}
+
+ public String toString()
+ {
+ return "TestResult{" +
+ "testName='" + testName + '\'' +
+ ", testType='" + testType + '\'' +
+ ", testTime=" + testTime +
+ ", putData=" + putData +
+ ", getData=" + getData +
+ ", testPassed=" + testPassed +
+ ", errorMsg='" + errorMsg + '\'' +
+ ", footNote='" + footNote + '\'' +
+ ", throughputTransactionsPerSecond=" + throughputTransactionsPerSecond +
+ ", throughputBytesPerSecond=" + throughputBytesPerSecond +
+ ", numMembers=" + numMembers +
+ ", numThreads=" + numThreads +
+ '}';
+ }
}
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/Report.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/Report.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/Report.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -1,16 +1,30 @@
package org.cachebench.config;
+import java.util.Map;
+import java.util.HashMap;
+
public class Report
{
private String generator;
private String outputFile;
+ private Map<String, String> params= new HashMap<String, String>();
public String getGenerator()
{
return generator;
}
+ public void addParam(NVPair nvPair)
+ {
+ params.put(nvPair.getName(), nvPair.getValue());
+ }
+
+ public Map<String, String> getParams()
+ {
+ return params;
+ }
+
public void setGenerator(String generator)
{
this.generator = generator;
Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -1,13 +1,11 @@
package org.cachebench.reportgenerators;
-import org.cachebench.TestResult;
import org.apache.commons.logging.Log;
+import org.cachebench.TestResult;
import java.io.File;
import java.util.List;
-import java.util.Enumeration;
-import java.net.NetworkInterface;
-import java.net.InetAddress;
+import java.util.Map;
/**
* Base implementation of {@link org.cachebench.reportgenerators.ReportGenerator}
Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
@@ -161,4 +162,9 @@
}
log.debug("Complted the Footnotes");
}
+
+ public void setConfigParams(Map configParams)
+ {
+ //we are not intereseted in any params, yet (e.g. may be we want to change separator from comma to tab)
+ }
}
Added: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -0,0 +1,152 @@
+package org.cachebench.reportgenerators;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.cachebench.TestResult;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Gathers info from all the nodes executing tests.
+ * Merges all the gathered information and generates an CSV file based on that.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @version 2.2
+ */
+public class ClusterReportGenerator extends AbstractReportGenerator
+{
+ private static Log log = LogFactory.getLog(ClusterReportGenerator.class);
+
+ private int clusterSize;
+
+ private int masterPort;
+
+ private String masterHost;
+
+ public void setConfigParams(Map<String, String> configParams)
+ {
+ log.trace("Received config params: " + configParams);
+ this.clusterSize = Integer.parseInt(configParams.get("clusterSize"));
+ this.masterPort = Integer.parseInt(configParams.get("masterPort"));
+ this.masterHost = configParams.get("masterHost");
+ }
+
+ public void generate() throws Exception
+ {
+ try
+ {
+ log.trace("Cluster report generator property value: " + System.getProperty("cluterReportGenerator"));
+ boolean isGeneratorNode = System.getProperty("cluterReportGenerator") != null
+ && "true".equalsIgnoreCase(System.getProperty("cluterReportGenerator"));
+ log.trace(" Starting generating. Is master? " + isGeneratorNode);
+ if (isGeneratorNode)
+ {
+ generateReport();
+ }
+ else
+ {
+ submitReportInfo();
+ }
+ } catch (Exception e)
+ {
+ log.error("Error while generating report!", e);
+ }
+ }
+
+ /**
+ * If not a master, sends report data to master.
+ */
+ private void submitReportInfo() throws IOException, ClassNotFoundException
+ {
+ log.trace("Sending the following results to master: " + results);
+ boolean connected = false;
+ Socket socket = null;
+ while (!connected)
+ {
+ try
+ {
+ log.trace("Connecting to master on " + masterHost + ":" + masterPort + "...");
+ socket = new Socket(masterHost, masterPort);
+ log.trace("Connected");
+ connected = true;
+ } catch (IOException e)
+ {
+ log.trace("Failed to connect(" + e.getMessage() + "), trying again..." );
+ connected = false;
+ }
+ }
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+ oos.writeObject(this.results);
+ oos.close();
+ socket.close();
+ log.trace("Following results were sent to server: " + results);
+ }
+
+ private void generateReport() throws Exception
+ {
+ List<List<TestResult>> results = retrieveResultsFromClients();
+ List<TestResult> mergedResults = mergerTestResultsAndGenerateReport(results);
+ generateReportFile(mergedResults);
+ }
+
+ @SuppressWarnings(value = "unchecked")
+ private List<List<TestResult>> retrieveResultsFromClients()
+ throws IOException, ClassNotFoundException
+ {
+ ServerSocket socket = new ServerSocket(masterPort);
+ List<List<TestResult>> results = new ArrayList<List<TestResult>>();
+ results.add(this.results);
+ //we go expect cluster size-1 because this is also a node, ant it does not sent report info
+ for (int i = 0; i < clusterSize - 1; i++)
+ {
+ log.trace("Expecting " + (clusterSize - i - 1) + " more client(s)");
+ log.trace(" Waiting for client to conect...");
+ Socket client = socket.accept();
+ log.trace("Client connected: " + client.getInetAddress());
+ ObjectInputStream ois = new ObjectInputStream(client.getInputStream());
+ List<TestResult> testResults = (List<TestResult>) ois.readObject();
+ results.add(testResults);
+ log.trace("Received following resullts from client: " + testResults);
+ ois.close();
+ client.close();
+ }
+ socket.close();
+ return results;
+ }
+
+
+ private void generateReportFile(List<TestResult> mergedResults) throws Exception
+ {
+ CSVReportGenerator generator = new CSVReportGenerator();
+ generator.setResults(mergedResults);
+ generator.setOutputFile(output);
+ generator.generate();
+ }
+
+ private List<TestResult> mergerTestResultsAndGenerateReport(List<List<TestResult>> results)
+ {
+ List<TestResult> mergedResults = new ArrayList<TestResult>();
+ for (int i = 0; i < results.get(0).size(); i++)
+ {
+ for (int j = 0; j < results.size(); j++)
+ {
+ //if one servers sent us more results that the other(s) fail!
+ if (j > 0 && results.get(j).size() != results.get(j - 1).size())
+ {
+ //not effcient as it gets execute each time but not really matters
+ throw new RuntimeException("Not all servers send the same number of responses. I.e. not all severs run the same number of tests!!!");
+ }
+ mergedResults.add(results.get(j).get(i));
+ }
+ }
+ log.trace("Merged tests are: " + mergedResults);
+ return mergedResults;
+ }
+
+}
Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java 2007-12-12 14:41:07 UTC (rev 4842)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java 2007-12-12 15:22:27 UTC (rev 4843)
@@ -4,6 +4,7 @@
import java.io.File;
import java.util.List;
+import java.util.Map;
/**
@@ -12,6 +13,8 @@
*/
public interface ReportGenerator
{
+ public abstract void setConfigParams(Map<String, String> configParams);
+
public void setOutputFile(File output);
public void setResults(List<TestResult> results);
17 years, 3 months
JBoss Cache SVN: r4842 - in core/trunk/src: main/java/org/jboss/cache/factories and 8 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-12 09:41:07 -0500 (Wed, 12 Dec 2007)
New Revision: 4842
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java
core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java
core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java
Log:
Updated stuff
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -20,6 +20,7 @@
import org.jboss.cache.factories.InterceptorChainFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.lock.IsolationLevel;
@@ -182,20 +183,13 @@
*/
private StateTransferManager stateTransferManager;
+ private RemoteCacheInvocationDelegate remoteDelegate;
+
/**
* Cache notifier handler class.
*/
private Notifier notifier;
- private ThreadLocal<InvocationContext> invocationContextContainer = new ThreadLocal<InvocationContext>()
- {
- @Override
- protected InvocationContext initialValue()
- {
- return new InvocationContext();
- }
- };
-
private final Configuration configuration;
private final ComponentRegistry componentRegistry;
private NodeFactory nodeFactory;
@@ -227,7 +221,7 @@
@Inject
private void injectDependencies(Notifier notifier, RegionManager regionManager, TransactionManager transactionManager,
TransactionTable transactionTable, StateTransferManager stateTransferManager, NodeFactory nodeFactory,
- CacheSPI spi, CacheMessageListener messageListener)
+ CacheSPI spi, CacheMessageListener messageListener, RemoteCacheInvocationDelegate remoteDelegate)
{
this.notifier = notifier;
this.regionManager = regionManager;
@@ -237,6 +231,7 @@
this.nodeFactory = nodeFactory;
this.spi = spi;
this.messageListener = messageListener;
+ this.remoteDelegate = remoteDelegate;
}
public Configuration getConfiguration()
@@ -561,10 +556,10 @@
if (root == null || !root.getClass().equals(tempRoot.getClass()))
root = tempRoot;
- if (configuration.getCacheLoaderConfig() != null && cacheLoaderManager == null)
- {
- initialiseCacheLoaderManager();
- }
+// if (configuration.getCacheLoaderConfig() != null && cacheLoaderManager == null)
+// {
+// initialiseCacheLoaderManager();
+// }
// first set up the Buddy Manager and an RPCManager
// if (configuration.getCacheMode() != Configuration.CacheMode.LOCAL)
// {
@@ -680,6 +675,19 @@
*/
private void internalStart() throws CacheException, IllegalArgumentException
{
+ // re-wire all dependencies in case stuff has changed since the cache was created?
+ // TODO: Do we really need to nuke old deps? :/
+ CacheSPI spi = componentRegistry.getComponent(CacheSPI.class);
+ componentRegistry.reset();
+
+ componentRegistry.registerComponent(configuration);
+ componentRegistry.registerComponent(this);
+ componentRegistry.registerComponent(CacheSPI.class, spi);
+ componentRegistry.registerComponent(componentRegistry);
+
+ componentRegistry.updateDependencies();
+ componentRegistry.wireDependencies(root);
+
cacheStatus = CacheStatus.STARTING;
// createTransactionManager();
@@ -786,7 +794,7 @@
regionManager.startEvictionThread();
}
- notifier.notifyCacheStarted(spi, getInvocationContext());
+ notifier.notifyCacheStarted(spi, spi.getInvocationContext());
addShutdownHook();
@@ -967,7 +975,7 @@
if (notifier != null)
{
- notifier.notifyCacheStopped(spi, getInvocationContext());
+ notifier.notifyCacheStopped(spi, spi.getInvocationContext());
notifier.removeAllCacheListeners();
}
@@ -1281,7 +1289,7 @@
public Object _get(Fqn<?> fqn, Object key, boolean sendNodeEvent) throws CacheException
{
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
if (log.isTraceEnabled())
{
log.trace(new StringBuffer("_get(").append("\"").append(fqn).append("\", \"").append(key).append("\", \"").
@@ -1489,7 +1497,7 @@
{
boolean result = true;
// we need to preserve options
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
Option o = ctx.getOptionOverrides();
for (Object childName : _getChildrenNames(fqn))
{
@@ -1523,7 +1531,7 @@
{
// special treatment for root eviction
// we need to preserve options
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
Option o = ctx.getOptionOverrides();
for (Object childName : _getChildrenNames(fqn))
{
@@ -1893,7 +1901,7 @@
{
int modeToUse = mode;
int preferredMode;
- if ((preferredMode = getInvocationContext().getOptionOverrides().getGroupRequestMode()) > -1)
+ if ((preferredMode = spi.getInvocationContext().getOptionOverrides().getGroupRequestMode()) > -1)
modeToUse = preferredMode;
RspList rsps = null;
@@ -2146,7 +2154,7 @@
{
log.trace("_put(" + tx + ", \"" + fqn + "\", " + data + " undo=" + create_undo_ops + " erase=" + erase_contents + ")");
}
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
NodeSPI n = findNodeCheck(tx, fqn, isRollback);
Map rawData = n.getDataDirect();
@@ -2211,7 +2219,7 @@
}
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
// if this is a rollback then don't fire notifications.
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
@@ -2308,7 +2316,7 @@
{
log.trace("_remove(" + tx + ", \"" + fqn + "\", undo=" + create_undo_ops + ")");
}
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
// check if this is triggered by a rollback operation ...
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
if (tx != null)
@@ -2438,7 +2446,7 @@
log.warn("node " + fqn + " not found");
return null;
}
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
if (!isRollback)
notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.REMOVE_DATA, n.getDataDirect(), ctx);
@@ -2520,7 +2528,7 @@
}
Map data = n.getDataDirect();
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
// create a compensating method call (reverting the effect of
// this modification) and put it into the TX's undo list.
@@ -2670,7 +2678,7 @@
log.trace("Node doesn't exist; creating a tombstone");
// create the node we need.
Map m = Collections.emptyMap();
- InvocationContext ic = getInvocationContext();
+ InvocationContext ic = spi.getInvocationContext();
boolean origCacheModeLocal = ic.getOptionOverrides().isCacheModeLocal();
ic.getOptionOverrides().setCacheModeLocal(true);
// if we are in a tx this call should happen outside of any tx
@@ -2748,7 +2756,7 @@
log.warn("node " + parent_fqn + " not found");
return;
}
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
Fqn fqn = new Fqn(parent_fqn, child_name);
if (!isRollback) notifier.notifyNodeCreated(fqn, true, ctx);
@@ -2873,7 +2881,7 @@
// we need to get the state for this Fqn and its sub-nodes.
// for now, perform a very simple series of getData calls.
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
if (log.isTraceEnabled()) log.trace("Caller is asking for " + fqn);
try
@@ -3163,22 +3171,6 @@
return notifier;
}
- public InvocationContext getInvocationContext()
- {
- InvocationContext ctx = invocationContextContainer.get();
- if (ctx == null)
- {
- ctx = new InvocationContext();
- invocationContextContainer.set(ctx);
- }
- return ctx;
- }
-
- public void setInvocationContext(InvocationContext ctx)
- {
- invocationContextContainer.set(ctx);
- }
-
/**
* New API to efficiently relocate a node
*
@@ -3221,7 +3213,7 @@
// first correct the pointers at the pruning point
oldParent.removeChildDirect(nodeName);
newParent.addChild(nodeName, node);
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
// parent pointer is calculated on the fly using Fqns.
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
@@ -3323,7 +3315,7 @@
// now notify listeners - *after* updating the coordinator. - JBCACHE-662
if (needNotification && notifier != null)
{
- InvocationContext ctx = getInvocationContext();
+ InvocationContext ctx = spi.getInvocationContext();
notifier.notifyViewChange(new_view, ctx);
}
@@ -3346,17 +3338,11 @@
public void block()
{
flushBlockGate.close();
- if (log.isDebugEnabled())
- {
- log.debug("Block received at " + getLocalAddress());
- }
- MethodCall m = MethodCallFactory.create(MethodDeclarations.blockChannelLocal);
- getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
- invokeMethod(m, true);
- if (log.isDebugEnabled())
- {
- log.debug("Block processed at " + getLocalAddress());
- }
+ if (log.isDebugEnabled()) log.debug("Block received at " + getLocalAddress());
+
+ remoteDelegate.block();
+
+ if (log.isDebugEnabled()) log.debug("Block processed at " + getLocalAddress());
}
/**
@@ -3364,17 +3350,11 @@
*/
public void unblock()
{
- if (log.isDebugEnabled())
- {
- log.debug("UnBlock received at " + getLocalAddress());
- }
- MethodCall m = MethodCallFactory.create(MethodDeclarations.unblockChannelLocal);
- getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
- invokeMethod(m, true);
- if (log.isDebugEnabled())
- {
- log.debug("UnBlock processed at " + getLocalAddress());
- }
+ if (log.isDebugEnabled()) log.debug("UnBlock received at " + getLocalAddress());
+
+ remoteDelegate.unblock();
+
+ if (log.isDebugEnabled()) log.debug("UnBlock processed at " + getLocalAddress());
flushBlockGate.open();
}
@@ -3682,14 +3662,14 @@
return toReturn;
}
- private void initialiseCacheLoaderManager() throws CacheException
- {
- if (cacheLoaderManager == null)
- {
- cacheLoaderManager = new CacheLoaderManager();
- }
- cacheLoaderManager.setConfig(configuration.getCacheLoaderConfig(), spi);
- }
+// private void initialiseCacheLoaderManager() throws CacheException
+// {
+// if (cacheLoaderManager == null)
+// {
+// cacheLoaderManager = new CacheLoaderManager();
+// }
+// cacheLoaderManager.setConfig(configuration.getCacheLoaderConfig(), spi);
+// }
/**
* Sets the CacheLoader to use.
@@ -3698,22 +3678,22 @@
* @param loader
* @deprecated only provided for backward compat
*/
- @Deprecated
- public void setCacheLoader(CacheLoader loader)
- {
- log.warn("Using deprecated config method setCacheLoader. This element will be removed in future, please use CacheLoaderConfiguration instead.");
+// @Deprecated
+// public void setCacheLoader(CacheLoader loader)
+// {
+// log.warn("Using deprecated config method setCacheLoader. This element will be removed in future, please use CacheLoaderConfiguration instead.");
+//
+// try
+// {
+// if (cacheLoaderManager == null) initialiseCacheLoaderManager();
+// }
+// catch (Exception e)
+// {
+// log.warn("Problem setting cache loader. Perhaps your cache loader config has not been set yet?");
+// }
+// cacheLoaderManager.setCacheLoader(loader);
+// }
- try
- {
- if (cacheLoaderManager == null) initialiseCacheLoaderManager();
- }
- catch (Exception e)
- {
- log.warn("Problem setting cache loader. Perhaps your cache loader config has not been set yet?");
- }
- cacheLoaderManager.setCacheLoader(loader);
- }
-
/**
* Purges the contents of all configured {@link CacheLoader}s
*/
@@ -3777,7 +3757,7 @@
// always use the InactiveRegionAwareRpcDispatcher - exceptions due to regions not being active should not propagate to remote
// nodes as errors. - Manik
- disp = new InactiveRegionAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(), this);
+ disp = new InactiveRegionAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(), remoteDelegate);
// disp = new RpcDispatcher(channel, ml, this, this);
disp.setRequestMarshaller(marshaller);
@@ -3930,7 +3910,7 @@
// if the node exists then this should be a no-op.
if (!exists(fqn))
{
- getInvocationContext().getOptionOverrides().setFailSilently(true);
+ spi.getInvocationContext().getOptionOverrides().setFailSilently(true);
GlobalTransaction tx = getCurrentTransaction();
MethodCall m = MethodCallFactory.create(MethodDeclarations.putForExternalReadMethodLocal, tx, fqn, key, value);
invokeMethod(m, true);
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -8,6 +8,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
@@ -109,6 +110,13 @@
this.delegate = delegate;
}
+ @Inject
+ private void injectDependencies(CacheSPI spi, CacheImpl impl)
+ {
+ this.cache = spi;
+ this.cacheImpl = impl;
+ }
+
/**
* Initializes with a name and FQN and cache.
*/
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -9,6 +9,7 @@
import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.util.BeanUtils;
import java.lang.annotation.Annotation;
@@ -248,6 +249,17 @@
for (Object component : components)
{
wireDependencies(component);
+ if (component instanceof Interceptor)
+ {
+ // special behaviour - need to wire for all chained interceptors
+ Interceptor i = (Interceptor) component;
+ Interceptor next = i.getNext();
+ if (next != null)
+ {
+ wireDependencies(next);
+ next = next.getNext();
+ }
+ }
}
}
@@ -404,7 +416,8 @@
{
if (defaultFactories == null) scanDefaultFactories();
Class<? extends ComponentFactory> cfClass = defaultFactories.get(componentClass);
-
+ if (cfClass == null)
+ throw new ConfigurationException("No registered default factory for component " + componentClass + " found!");
// a component factory is a component too! See if one has been created and exists in the registry
ComponentFactory cf = getComponent(cfClass);
if (cf == null)
@@ -499,4 +512,11 @@
return instance;
}
+ /**
+ * Wipes everything in the registry. Use with care.
+ */
+ public void reset()
+ {
+ registry.clear();
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -3,6 +3,7 @@
import org.jboss.cache.RegionManager;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.CacheMessageListener;
@@ -15,7 +16,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.1.0
*/
-@DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class})
+@DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class})
public class EmptyConstructorFactory extends ComponentFactory
{
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -8,6 +8,7 @@
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
@@ -31,6 +32,7 @@
private boolean usingBuddyReplication;
protected boolean defaultSynchronous;
+ @Inject
public void setCache(CacheSPI cache)
{
super.setCache(cache);
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,8 +1,8 @@
package org.jboss.cache.interceptors;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
@@ -22,11 +22,11 @@
protected TransactionTable txTable;
protected TransactionManager txManager;
- public void setCache(CacheSPI cache)
+ @Inject
+ private void injectDependencies(TransactionTable txTable, TransactionManager txManager)
{
- super.setCache(cache);
- txManager = cache.getTransactionManager();
- txTable = cache.getTransactionTable();
+ this.txManager = txManager;
+ this.txTable = txTable;
}
protected void copyInvocationScopeOptionsToTxScope(InvocationContext ctx)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -6,10 +6,12 @@
*/
package org.jboss.cache.interceptors;
+import org.apache.commons.logging.Log;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
@@ -21,7 +23,6 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
-import org.apache.commons.logging.Log;
import org.jgroups.Address;
import javax.transaction.SystemException;
@@ -56,11 +57,17 @@
public void setCache(CacheSPI cache)
{
super.setCache(cache);
- txTable = cache.getTransactionTable();
- optimistic=cache.getConfiguration().isNodeLockingOptimistic();
+// txTable = cache.getTransactionTable();
+ optimistic = configuration.isNodeLockingOptimistic();
if (optimistic) txMods = new ConcurrentHashMap<GlobalTransaction, List<MethodCall>>();
}
+ @Inject
+ private void injectDependencies(TransactionTable txTable)
+ {
+ this.txTable = txTable;
+ }
+
protected Log getLog()
{
return log;
@@ -68,9 +75,9 @@
protected boolean skipMethodCall(InvocationContext ctx)
{
- Option optionOverride = ctx.getOptionOverrides();
+ Option optionOverride = ctx.getOptionOverrides();
if (optionOverride != null && optionOverride.isCacheModeLocal() && (ctx.getTransaction() == null ||
- MethodDeclarations.isTransactionLifecycleMethod(ctx.getMethodCall().getMethodId())))
+ MethodDeclarations.isTransactionLifecycleMethod(ctx.getMethodCall().getMethodId())))
{
// skip replication!!
return true;
@@ -116,7 +123,7 @@
protected Object handleRemoveKeyMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Object key, boolean createUndoOps) throws Throwable
{
- return handleCrudMethod(ctx,fqn, null);
+ return handleCrudMethod(ctx, fqn, null);
}
protected Object handleRemoveDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps) throws Throwable
@@ -146,7 +153,7 @@
protected Object handleRemoveDataVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, boolean createUndoOps, DataVersion dv) throws Throwable
{
- return handleCrudMethod(ctx,fqn, null);
+ return handleCrudMethod(ctx, fqn, null);
}
protected Object handlePrepareMethod(InvocationContext ctx, GlobalTransaction gtx, List modification, Address coordinator, boolean onePhaseCommit) throws Throwable
@@ -196,7 +203,7 @@
{
Object retval = nextInterceptor(ctx);
Transaction tx = ctx.getTransaction();
- if (tx !=null && optimistic)
+ if (tx != null && optimistic)
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
List modifications = txMods.remove(gtx);
@@ -210,7 +217,7 @@
{
Object retval = nextInterceptor(ctx);
Transaction tx = ctx.getTransaction();
- if (tx !=null && optimistic)
+ if (tx != null && optimistic)
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
txMods.remove(gtx);
@@ -223,7 +230,7 @@
* @param from is only present for move operations, else pass it in as null
*/
private Object handleCrudMethod(InvocationContext ctx, Fqn targetFqn, Fqn from)
- throws Throwable
+ throws Throwable
{
Object retval = nextInterceptor(ctx);
Transaction tx = ctx.getTransaction();
@@ -282,7 +289,7 @@
private boolean containsPutForExternalRead(List<MethodCall> l)
{
if (l == null) return false;
-
+
for (MethodCall m : l)
if (m.getMethodId() == MethodDeclarations.putForExternalReadMethodLocal_id || m.getMethodId() == MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
return true;
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -67,11 +67,24 @@
*/
protected Object invoke(MethodCall call) throws CacheException
{
+ return invoke(call, false);
+ }
+
+ /**
+ * Passes a method call up the interceptor chain, optionally allowing you to skip cache status checks.
+ *
+ * @param call methodcall to pass
+ * @return an Object, the generic return type for the interceptors.
+ * @throws Throwable in the event of problems
+ */
+ protected Object invoke(MethodCall call, boolean skipCacheStatusCheck) throws CacheException
+ {
// never create a new one directly; always let the container do this if needed.
InvocationContext ctx = invocationContextContainer.get();
// BR methods should NOT block on the cache being started, since the cache depends on these completing to start.
- if (!MethodDeclarations.isBuddyGroupOrganisationMethod(call.getMethodId()) && !cache.getCacheStatus().allowInvocations() && !ctx.getOptionOverrides().isSkipCacheStatusCheck())
+ if (!MethodDeclarations.isBuddyGroupOrganisationMethod(call.getMethodId()) &&
+ !cache.getCacheStatus().allowInvocations() && !skipCacheStatusCheck)
{
// only throw an exception if this is a locally originating call - JBCACHE-1179
if (originLocal)
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -347,13 +347,14 @@
public void putAll(Map<K, V> data)
{
assertValid();
- cache.put(getFqn(), data);
+ spi.put(getFqn(), data);
}
public void replaceAll(Map<K, V> data)
{
assertValid();
- cache.put(getFqn(), data, true);
+ spi.clearData(getFqn());
+ spi.put(getFqn(), data);
}
public V get(K key)
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,6 +1,7 @@
package org.jboss.cache.invocation;
import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
import java.util.List;
@@ -55,4 +56,15 @@
for (MethodCall methodCall : methodCalls) _replicate(methodCall);
}
+ public void block()
+ {
+ MethodCall m = MethodCallFactory.create(MethodDeclarations.blockChannelLocal);
+ invoke(m, true);
+ }
+
+ public void unblock()
+ {
+ MethodCall m = MethodCallFactory.create(MethodDeclarations.unblockChannelLocal);
+ invoke(m, true);
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -13,6 +13,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -258,8 +259,8 @@
getNodeMethodLocal = CacheImpl.class.getDeclaredMethod("_get", Fqn.class);
getKeysMethodLocal = CacheImpl.class.getDeclaredMethod("_getKeys", Fqn.class);
getChildrenNamesMethodLocal = CacheImpl.class.getDeclaredMethod("_getChildrenNames", Fqn.class);
- replicateMethod = CacheImpl.class.getDeclaredMethod("_replicate", MethodCall.class);
- replicateAllMethod = CacheImpl.class.getDeclaredMethod("_replicate", List.class);
+ replicateMethod = RemoteCacheInvocationDelegate.class.getDeclaredMethod("_replicate", MethodCall.class);
+ replicateAllMethod = RemoteCacheInvocationDelegate.class.getDeclaredMethod("_replicate", List.class);
releaseAllLocksMethodLocal = CacheImpl.class.getDeclaredMethod("_releaseAllLocks", Fqn.class);
printMethodLocal = CacheImpl.class.getDeclaredMethod("_print", Fqn.class);
lockMethodLocal = CacheImpl.class.getDeclaredMethod("_lock", Fqn.class, NodeLock.LockType.class, boolean.class);
@@ -449,7 +450,7 @@
public static boolean isGetMethod(int methodId)
{
return methodId == getChildrenNamesMethodLocal_id || methodId == getDataMapMethodLocal_id || methodId == existsMethod_id
- || methodId == getKeysMethodLocal_id || methodId == getKeyValueMethodLocal_id || methodId == getNodeMethodLocal_id;
+ || methodId == getKeysMethodLocal_id || methodId == getKeyValueMethodLocal_id || methodId == getNodeMethodLocal_id;
}
public static boolean isBlockUnblockMethod(int id)
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -122,7 +122,8 @@
{
CacheLoaderManager loaderManager = cache.getCacheLoaderManager();
- if (loaderManager == null)
+ CacheLoader loader = loaderManager == null ? null : loaderManager.getCacheLoader();
+ if (loader == null)
{
if (log.isTraceEnabled())
{
@@ -131,7 +132,7 @@
}
else
{
- CacheLoader loader = loaderManager.getCacheLoader();
+
if (log.isTraceEnabled())
{
log.trace("integrating persistent state using " + loader.getClass().getName());
Modified: core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,12 +1,11 @@
package org.jboss.cache.api.nodevalidity;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.testng.annotations.Test;
/**
- *
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.1.0
*/
@@ -43,8 +42,8 @@
public void testTombstoneVersioningFailure() throws Exception
{
- CacheImpl modifierImpl = (CacheImpl) modifier;
- CacheImpl observerImpl = (CacheImpl) observer;
+ CacheSPI modifierImpl = (CacheSPI) modifier;
+ CacheSPI observerImpl = (CacheSPI) observer;
modifier.put(parent, K, V);
Modified: core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -2,7 +2,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
@@ -12,7 +12,6 @@
import org.testng.annotations.Test;
/**
- *
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.1.0
*/
@@ -58,8 +57,10 @@
cache.start();
- loader = (DummyInMemoryCacheLoader) ((CacheImpl) cache).getCacheLoader();
+ CacheSPI spi = (CacheSPI) cache;
+ loader = (DummyInMemoryCacheLoader) spi.getCacheLoaderManager().getCacheLoader();
+
return cache;
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,7 +1,7 @@
package org.jboss.cache.api.nodevalidity;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeNotValidException;
@@ -37,9 +37,10 @@
protected Cache<String, String> modifier;
protected Fqn parent = Fqn.fromString("/parent");
protected Fqn child = Fqn.fromString("/parent/child");
- protected String K="k", V="v";
+ protected String K = "k", V = "v";
protected abstract Cache<String, String> createObserver();
+
protected abstract Cache<String, String> createModifier();
protected void optimisticConfiguration(Configuration c)
@@ -115,7 +116,7 @@
assert obsNode.isValid() : "Node should be valid";
// new parent needs to exist first.
- modifier.getRoot().addChild(newParent);
+ modifier.getRoot().addChild(newParent);
modifier.move(parent, newParent.getParent());
// the old node is only marked as invalid if we use opt locking
@@ -289,8 +290,8 @@
public void testExistenceOfTombstones()
{
- CacheImpl modifierImpl = (CacheImpl) modifier;
- CacheImpl observerImpl = (CacheImpl) observer;
+ CacheSPI modifierImpl = (CacheSPI) modifier;
+ CacheSPI observerImpl = (CacheSPI) observer;
modifier.put(parent, K, V);
modifier.removeNode(parent);
@@ -321,8 +322,8 @@
public void testExistenceOfTombstonesWithChildren()
{
- CacheImpl modifierImpl = (CacheImpl) modifier;
- CacheImpl observerImpl = (CacheImpl) observer;
+ CacheSPI modifierImpl = (CacheSPI) modifier;
+ CacheSPI observerImpl = (CacheSPI) observer;
modifier.put(child, K, V);
modifier.removeNode(parent);
Modified: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -9,6 +9,7 @@
import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.invocation.CacheInvocationDelegate;
import org.jboss.cache.marshall.CacheMarshaller200;
import org.jboss.cache.marshall.CacheMarshaller210;
@@ -168,4 +169,54 @@
Configuration cfg = (Configuration) TestingUtil.extractField(bm, "configuration");
assert cfg == configuration;
}
+
+ public void testInjectionOrder()
+ {
+ // injection should only occur after dependent components have been fully wired.
+
+ // E.g. Test1 depends on Test2 and Test2 depends on Test3.
+ //cr.reset();
+
+ // DefaultFactoryFor annotation won't work since tests are compiled into a separate classpath
+ cr.defaultFactories.put(Test1.class, EmptyConstructorFactory.class);
+ cr.defaultFactories.put(Test2.class, EmptyConstructorFactory.class);
+ cr.defaultFactories.put(Test3.class, EmptyConstructorFactory.class);
+
+ Test1 t1 = cr.getOrCreateComponent(null, Test1.class);
+
+ assert t1 != null;
+ assert t1.test2 != null;
+ assert t1.test2.test3 != null;
+ assert t1.someValue == t1.test2.test3.someValue;
+ }
+
+ public static class Test1
+ {
+ private Test2 test2;
+ private boolean someValue = false;
+
+ @Inject
+ public void setTest2(Test2 test2)
+ {
+ this.test2 = test2;
+ someValue = test2.test3.someValue;
+ }
+ }
+
+ public static class Test2
+ {
+ private Test3 test3;
+
+ @Inject
+ public void setTest3(Test3 test3)
+ {
+ this.test3 = test3;
+ }
+ }
+
+ public static class Test3
+ {
+ private boolean someValue = true;
+ }
}
+
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -16,6 +16,8 @@
import org.jboss.cache.factories.InterceptorChainFactory;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
+import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.util.CachePrinter;
import java.io.File;
@@ -414,12 +416,12 @@
{
if (c != null && c.getCacheStatus() == CacheStatus.STARTED)
{
- CacheImpl ci = (CacheImpl) c;
- if (ci.getTransactionManager() != null)
+ CacheSPI spi = (CacheSPI) c;
+ if (spi.getTransactionManager() != null)
{
try
{
- ci.getTransactionManager().rollback();
+ spi.getTransactionManager().rollback();
}
catch (Exception e)
{
@@ -427,11 +429,13 @@
}
}
- if (ci.getCacheLoader() != null)
+ CacheLoaderManager clm = spi.getCacheLoaderManager();
+ CacheLoader cl = clm == null ? null : clm.getCacheLoader();
+ if (cl != null)
{
try
{
- ci.getCacheLoader().remove(Fqn.ROOT);
+ cl.remove(Fqn.ROOT);
}
catch (Exception e)
{
@@ -439,8 +443,8 @@
}
}
- ci.stop();
- ci.destroy();
+ spi.stop();
+ spi.destroy();
}
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java 2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java 2007-12-12 14:41:07 UTC (rev 4842)
@@ -7,7 +7,7 @@
package org.jboss.cache.options;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -29,7 +29,7 @@
@Test(groups = {"functional"})
public class FailSilentlyTest
{
- private CacheImpl cache;
+ private CacheSPI cache;
private TransactionManager manager;
private Transaction tx;
private Fqn<String> fqn = Fqn.fromString("/a");
@@ -41,7 +41,7 @@
if (cache != null)
tearDown();
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl) instance.createCache(false);
+ cache = (CacheSPI) instance.createCache(false);
// very short acquisition timeout
cache.getConfiguration().setLockAcquisitionTimeout(100);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -100,7 +100,7 @@
cache.get(fqn, key);
tx = manager.suspend();
cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
- cache.remove(fqn);
+ cache.removeNode(fqn);
}
public void testRemoveKey() throws Exception
@@ -122,7 +122,7 @@
cache.put(fqn, key, "value2");
tx = manager.suspend();
cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
- cache.get(fqn);
+ cache.getNode(fqn);
}
public void testGetKey() throws Exception
17 years, 3 months