Author: manik.surtani(a)jboss.com
Date: 2008-07-07 17:21:24 -0400 (Mon, 07 Jul 2008)
New Revision: 6199
Added:
core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
Removed:
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/Region.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.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/lock/MVCCLockManager.java
core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java
core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
Log:
reorganised region managers and state transfer managers to allow for mvcc customisation
Modified: core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2008-07-07 20:50:09 UTC (rev
6198)
+++ core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2008-07-07 21:21:24 UTC (rev
6199)
@@ -194,7 +194,7 @@
* From 2.1.0, Interceptor authors should obtain this by injection rather than this
method. See the
* {@link org.jboss.cache.factories.annotations.Inject} annotation.
*
- * @return the {@link org.jboss.cache.RegionManager}
+ * @return the {@link RegionManager}
*/
RegionManager getRegionManager();
Added: core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/LegacyRegionManagerImpl.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -0,0 +1,20 @@
+package org.jboss.cache;
+
+import net.jcip.annotations.ThreadSafe;
+
+/**
+ * For optimistic and pessimistically locked caches
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.0.0
+ */
+@ThreadSafe
+public class LegacyRegionManagerImpl extends RegionManagerImpl
+{
+ @Override
+ protected Object getOwnerForLock()
+ {
+ Object owner = cache.getCurrentTransaction();
+ return owner == null ? Thread.currentThread() : owner;
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-07-07 20:50:09 UTC
(rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-07-07 21:21:24 UTC
(rev 6199)
@@ -26,7 +26,7 @@
import org.jboss.cache.marshall.Marshaller;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.ChannelMessageListener;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionTable;
import org.jboss.cache.util.ThreadGate;
@@ -448,7 +448,7 @@
public void fetchPartialState(List<Address> sources, Fqn sourceTarget, Fqn
integrationTarget) throws Exception
{
- String encodedStateId = sourceTarget + StateTransferManager.PARTIAL_STATE_DELIMITER
+ integrationTarget;
+ String encodedStateId = sourceTarget +
DefaultStateTransferManager.PARTIAL_STATE_DELIMITER + integrationTarget;
fetchPartialState(sources, encodedStateId);
}
Modified: core/trunk/src/main/java/org/jboss/cache/Region.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Region.java 2008-07-07 20:50:09 UTC (rev
6198)
+++ core/trunk/src/main/java/org/jboss/cache/Region.java 2008-07-07 21:21:24 UTC (rev
6199)
@@ -28,7 +28,7 @@
* <p/>
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
- * @see org.jboss.cache.RegionManager
+ * @see RegionManager
* @since 2.0.0
*/
public interface Region extends Comparable<Region>
Deleted: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-07 20:50:09 UTC
(rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-07 21:21:24 UTC
(rev 6199)
@@ -1,929 +0,0 @@
-package org.jboss.cache;
-
-import net.jcip.annotations.ThreadSafe;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import static org.jboss.cache.Region.Type.*;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-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.EvictionPolicyConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.EvictionTimerTask;
-import org.jboss.cache.factories.annotations.Destroy;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.NonVolatile;
-import org.jboss.cache.factories.annotations.Start;
-import org.jboss.cache.factories.annotations.Stop;
-import org.jboss.cache.lock.LockManager;
-import static org.jboss.cache.lock.LockType.WRITE;
-import org.jgroups.Address;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Manages multiple {@link Region}s for a Cache instance.
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
- * @since 2.0.0
- */
-@ThreadSafe
-@NonVolatile
-public class RegionManager
-{
- /**
- * The default region used in XML configuration files when defining eviction policies.
Any
- * 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 =
Fqn.fromString("/_default_");
-
- /**
- * A registry of regions that have been defined.
- */
- private final Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn,
Region>();
- private boolean defaultInactive;
- private final Log log = LogFactory.getLog(RegionManager.class);
- private CacheSPI cache;
- private boolean usingEvictions;
- private EvictionConfig evictionConfig;
- private final EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
-
- protected final Set<Fqn> activationChangeNodes = Collections.synchronizedSet(new
HashSet<Fqn>());
- protected Configuration configuration;
- protected RPCManager rpcManager;
- private LockManager lockManager;
- private BuddyFqnTransformer buddyFqnTransformer;
- private boolean isUsingBR;
-
- @Inject
- void injectDependencies(CacheSPI cache, Configuration configuration, RPCManager
rpcManager, LockManager lockManager,
- BuddyFqnTransformer transformer)
- {
- this.cache = cache;
- this.rpcManager = rpcManager;
- this.configuration = configuration;
- this.lockManager = lockManager;
- this.buddyFqnTransformer = transformer;
- }
-
- @Start
- protected void start()
- {
- log.trace("Starting region manager");
- isUsingBR = configuration.getBuddyReplicationConfig() != null &&
configuration.getBuddyReplicationConfig().isEnabled();
- if (configuration.getEvictionConfig() != null
- && configuration.getEvictionConfig().isValidConfig())
- {
- // validate individual region configs now
- for (EvictionRegionConfig erc :
configuration.getEvictionConfig().getEvictionRegionConfigs())
- {
- EvictionPolicyConfig epc = erc.getEvictionPolicyConfig();
- if (epc != null) epc.validate();
- }
-
- setEvictionConfig(configuration.getEvictionConfig());
- setUsingEvictions(true);
- }
- else
- {
- setUsingEvictions(false);
- log.debug("Not using an EvictionPolicy");
- }
-
- setDefaultInactive(configuration.isInactiveOnStartup());
-
- if (isUsingEvictions()) startEvictionThread();
- }
-
- @Stop
- protected void stop()
- {
- if (isUsingEvictions()) stopEvictionThread();
- }
-
- @Destroy
- protected void destroy()
- {
- regionsRegistry.clear();
- activationChangeNodes.clear();
- }
-
- /**
- * @return true if evictions are being processed.
- */
- public boolean isUsingEvictions()
- {
- return usingEvictions;
- }
-
- /**
- * @return true if replication is by default inactive for new {@link Region}s.
- */
- public boolean isDefaultInactive()
- {
- return defaultInactive;
- }
-
- /**
- * Sets if replication for new {@link Region}s is by default inactive.
- */
- public void setDefaultInactive(boolean defaultInactive)
- {
- this.defaultInactive = defaultInactive;
- Region defaultRegion = regionsRegistry.get(Fqn.ROOT);
- if (defaultRegion != null) defaultRegion.setActive(!defaultInactive);
- }
-
- /**
- * Helper utility that checks for a {@link ClassLoader} registered for the
- * given {@link Fqn}, and if found sets it as the TCCL. If the given Fqn is
- * under the _BUDDY_BACKUP_ region, the equivalent region in the main
- * cache is used to find the {@link ClassLoader}.
- *
- * @param fqn Fqn pointing to a region for which a special classloader
- * may have been registered.
- */
- public void setContextClassLoaderAsCurrent(Fqn fqn)
- {
- if (fqn.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN))
- {
- if (fqn.size() <= 2)
- {
- fqn = Fqn.ROOT;
- }
- else
- {
- fqn = fqn.getSubFqn(2, fqn.size());
- }
- }
- Region region = getRegion(fqn, false);
- ClassLoader regionCL = (region == null) ? null : region.getClassLoader();
- if (regionCL != null)
- {
- Thread.currentThread().setContextClassLoader(regionCL);
- }
-
- }
-
- /**
- * Returns a region by {@link Fqn}, creating it optionally if absent. If the region
does not exist and <tt>createIfAbsent</tt>
- * is <tt>false</tt>, a parent region which may apply to the {@link Fqn}
is sought.
- * <p/>
- * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If
it is, the actual Fqn is calculated
- * and used instead.
- */
- public Region getRegion(Fqn fqn, boolean createIfAbsent)
- {
- return getRegion(fqn, ANY, createIfAbsent);
- }
-
- /**
- * Retrieves a valid marshalling {@link Region} after taking into account that this
may be a Buddy Backup Fqn.
- * If the fqn passed in is null, the region has been deactivated or if a region cannot
be found, this method returns a null.
- *
- * @param fqn of the region to locate
- * @return a region
- */
- public Region getValidMarshallingRegion(Fqn fqn)
- {
- if (fqn == null) return null;
- return getRegion(fqn, Region.Type.MARSHALLING, false);
- }
-
- /**
- * An overloaded form of {@link #getRegion(Fqn,boolean)} that takes an additional
{@link org.jboss.cache.Region.Type}
- * parameter to force regions of a specific type.
- * <p/>
- * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If
it is, the actual Fqn is calculated
- * and used instead.
- *
- * @see org.jboss.cache.Region.Type
- */
- public Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
- {
- if (isUsingBR && fqn != null &&
buddyFqnTransformer.isBackupFqn(fqn))
- {
- fqn = buddyFqnTransformer.getActualFqn(fqn);
- }
-
- 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
- if (regionsRegistry.containsKey(fqnToUse))
- {
- Region r = regionsRegistry.get(fqnToUse);
-
- // 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.
- if (type == ANY
- || (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
- {
- return r;
- }
- }
-
- // if not, attempt to create one ...
- if (createIfAbsent)
- {
- Region r = new RegionImpl(fqnToUse, this);
- regionsRegistry.put(fqnToUse, r);
- if (type == MARSHALLING)
- {
- // insert current class loader into region so at least it is recognised as a
marshalling region
- r.registerContextClassLoader(getClass().getClassLoader());
- }
- return r;
- }
-
- // else try and find a parent which has a defined region, may return null if
nothing is defined.
- Region nextBestThing = null;
- Fqn nextFqn = fqnToUse;
-
- while (nextBestThing == null)
- {
- nextFqn = nextFqn.getParent();
- 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.
- if (type == ANY
- || (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
- {
- nextBestThing = r;
- }
- }
- if (nextFqn.isRoot()) break;
- }
-
- // test if the default region has been defined. If not, and if the request
- // is for an eviction region, return null
- if (type == EVICTION && nextBestThing != null &&
nextBestThing.getFqn().isRoot() && !regionsRegistry.containsKey(Fqn.ROOT))
- {
- log.trace("No default eviction region; returning null");
- nextBestThing = null;
- }
-
- return nextBestThing;
- }
-
- /**
- * Returns a region using Fqn.fromString(fqn), calling {@link
#getRegion(Fqn,boolean)}
- *
- * @param fqn
- * @param createIfAbsent
- * @see #getRegion(Fqn,boolean)
- */
- public Region getRegion(String fqn, boolean createIfAbsent)
- {
- return getRegion(Fqn.fromString(fqn), createIfAbsent);
- }
-
- /**
- * Removes a {@link org.jboss.cache.Region} identified by the given fqn.
- *
- * @param fqn fqn of the region to remove
- * @return true if such a region existed and was removed.
- */
- public boolean removeRegion(Fqn fqn)
- {
- Region r = regionsRegistry.remove(fqn);
- if (r == null) return false;
-
- if (isUsingEvictions() && r.getEvictionPolicy() != null)
- {
- evictionTimerTask.removeRegionToProcess(r);
- }
- return true;
- }
-
- /**
- * @return the eviction timer task object associated with this Region Manager.
- */
- protected EvictionTimerTask getEvictionTimerTask()
- {
- return evictionTimerTask;
- }
-
- /**
- * Activates unmarshalling of replication messages for the region
- * rooted in the given Fqn.
- * <p/>
- * <strong>NOTE:</strong> This method will cause the creation of a node
- * in the local cache at <code>subtreeFqn</code> whether or not that
- * node exists anywhere else in the cluster. If the node does not exist
- * elsewhere, the local node will be empty. The creation of this node will
- * not be replicated.
- * <p/>
- *
- * @param fqn representing the region to be activated.
- * @throws RegionNotEmptyException if the node <code>fqn</code>
- * exists and already has either data or children
- */
- public void activate(Fqn fqn) throws RegionNotEmptyException
- {
- activate(fqn, false);
- }
-
- /**
- * Attempts to activate a given region rooted at a given Fqn, similar to {@link
#activate(Fqn)} except
- * that if the fqn is currently already in use (probably already been activated) this
method is a no-op.
- *
- * @param fqn which represents the region to activate
- */
- public void activateIfEmpty(Fqn fqn)
- {
- activate(fqn, true);
- }
-
- private void activate(Fqn fqn, boolean suppressRegionNotEmptyException)
- {
- try
- {
- if (log.isTraceEnabled()) log.trace("Activating region " + fqn);
- Region r = getRegion(fqn, false);
- if (r != null)
- {
- if (!defaultInactive && r.getClassLoader() == null)
- {
- // This region's state will no match that of a non-existent one
- // So, there is no reason to keep this region any more
-
- // (Brian) We shouldn't do this anymore; now outside code
- // can have a ref to the region!!
- removeRegion(fqn);
- }
- else
- {
- //r.activate();
- r.setStatus(Region.Status.ACTIVATING);
- if (configuration.isFetchInMemoryState())
- {
- activateRegion(r.getFqn(), suppressRegionNotEmptyException);
- }
- r.setActive(true);
- }
- }
- else if (defaultInactive)
- {
- // "Active" region is not the default, so create a region
- r = getRegion(fqn, true);
- // FIXME - persistent state transfer counts too!
- r.setStatus(Region.Status.ACTIVATING);
- if (configuration.isFetchInMemoryState())
- {
- activateRegion(r.getFqn(), suppressRegionNotEmptyException);
- }
- r.setActive(true);
- }
- }
- catch (RuntimeException re)
- {
- throw re;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Causes the cache to transfer state for the subtree rooted at
- * <code>subtreeFqn</code> and to begin accepting replication messages
- * for that subtree.
- * <p/>
- * <strong>NOTE:</strong> This method will cause the creation of a node
- * in the local cache at <code>subtreeFqn</code> whether or not that
- * node exists anywhere else in the cluster. If the node does not exist
- * elsewhere, the local node will be empty. The creation of this node will
- * not be replicated.
- *
- * @param fqn Fqn string indicating the uppermost node in the
- * portion of the cache that should be activated.
- * @throws RegionNotEmptyException if the node <code>subtreeFqn</code>
- * exists and has either data or children
- */
- private void activateRegion(Fqn fqn, boolean suppressRegionNotEmptyException)
- {
- // Check whether the node already exists and has data
- Node subtreeRoot = cache.peek(fqn, false, false);
-
- /*
- * Commented out on Nov 16,2006 Manik&Vladimir
- *
- * if (!(cache.isNodeEmpty(subtreeRoot)))
- {
- throw new RegionNotEmptyException("Node " + subtreeRoot.getFqn() +
" already exists and is not empty");
- }*/
-
- if (isActivatingDeactivating(fqn))
- {
- throw new CacheException("Region " + subtreeRoot.getFqn() + " is
already being activated/deactivated");
- }
-
- if (log.isDebugEnabled())
- {
- log.debug("activating " + fqn);
- }
-
- try
- {
-
- // Add this fqn to the set of those we are activating
- // so calls to _getState for the fqn can return quickly
- activationChangeNodes.add(fqn);
-
- BuddyManager buddyManager = cache.getBuddyManager();
- // Request partial state from the cluster and integrate it
- if (buddyManager == null)
- {
- // Get the state from any node that has it and put it
- // in the main cache
- if (subtreeRoot == null)
- {
- // We'll update this node with the state we receive
- // need to obtain all necessary locks.
-
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- subtreeRoot = cache.getRoot().addChild(fqn);
-
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
- }
-
- List<Address> members = cache.getMembers();
-
- // Don't bother trying to fetch state if we are in LOCAL mode
- if (members != null && !members.isEmpty())
- rpcManager.fetchPartialState(members, subtreeRoot.getFqn());
- }
- else if (!buddyFqnTransformer.isBackupFqn(fqn))
- {
- // Get the state from each DataOwner and integrate in their
- // respective buddy backup cache
- List<Address> buddies = buddyManager.getBackupDataOwners();
- for (Address buddy : buddies)
- {
- List<Address> sources = new ArrayList<Address>(1);
- if (!cache.getMembers().contains(buddy))
- continue;
- sources.add(buddy);
- Fqn buddyRoot = buddyFqnTransformer.getBackupFqn(buddy, fqn);
- subtreeRoot = cache.peek(buddyRoot, false, false);
- if (subtreeRoot == null)
- {
- // We'll update this node with the state we receive
- // need to obtain all necessary locks.
- // needs to be a LOCAL call!
- NodeSPI root = cache.getRoot();
-
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- subtreeRoot = root.addChild(buddyRoot);
-
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
- }
- rpcManager.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
- }
- }
- else
- {
- log.info("Attempting to activate a backup region. Not attempting to
retrieve any state as this will be pushed.");
- }
- }
- catch (Throwable t)
- {
- log.error("failed to activate " + fqn, t);
-
- // "Re-deactivate" the region
- try
- {
- inactivateRegion(fqn);
- }
- catch (Exception e)
- {
- log.error("failed inactivating " + fqn, e);
- // just swallow this one and throw the first one
- }
-
- // Throw the exception on, wrapping if necessary
- if (t instanceof RegionNotEmptyException)
- {
- if (!suppressRegionNotEmptyException) throw (RegionNotEmptyException) t;
- }
- else if (t instanceof CacheException)
- {
- throw (CacheException) t;
- }
- else
- {
- throw new CacheException(t.getClass().getName() + " " +
- t.getLocalizedMessage(), t);
- }
- }
- finally
- {
- activationChangeNodes.remove(fqn);
- }
- }
-
- /**
- * Convenienve method. If the region defined by fqn does not exist, {@link
#isDefaultInactive()} is returned, otherwise
- * !{@link Region#isActive()} is returned.
- *
- * @param fqn fqn to test
- * @return true if inactive
- */
- public boolean isInactive(Fqn fqn)
- {
- Region region = getRegion(fqn, false);
- return region == null ? defaultInactive : !region.isActive();
- }
-
-
- /**
- * Causes the cache to stop accepting replication events for the subtree
- * rooted at <code>subtreeFqn</code> and evict all nodes in that subtree.
- * <p/>
- * This is legacy code and should not be called directly. This is a private method
for now and will be refactored out.
- * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
- * <p/>
- *
- * @param fqn Fqn string indicating the uppermost node in the
- * portion of the cache that should be activated.
- * @throws RegionNameConflictException if <code>subtreeFqn</code>
indicates
- * a node that is part of another
- * subtree that is being specially
- * managed (either by activate/inactiveRegion()
- * or by registerClassLoader())
- * @throws CacheException if there is a problem evicting nodes
- * @throws IllegalStateException if {@link
org.jboss.cache.config.Configuration#isUseRegionBasedMarshalling()} is
<code>false</code>
- */
- private void inactivateRegion(Fqn fqn) throws CacheException
- {
- if (isActivatingDeactivating(fqn))
- {
- throw new CacheException("Region " + fqn + " is already being
activated/deactivated");
- }
-
- NodeSPI parent = null;
- NodeSPI subtreeRoot = null;
- boolean parentLocked = false;
- boolean subtreeLocked = false;
-
- try
- {
- // Record that this fqn is in status change, so can't provide state
- activationChangeNodes.add(fqn);
-
- if (!isInactive(fqn))
- {
- deactivate(fqn);
- }
-
- // Create a list with the Fqn in the main cache and any buddy backup trees
- BuddyManager buddyManager = cache.getBuddyManager();
- ArrayList<Fqn> list = new ArrayList<Fqn>();
- list.add(fqn);
-
- if (buddyManager != null)
- {
- Set buddies = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false,
false).getChildrenNames();
- if (buddies != null)
- {
- for (Object buddy : buddies)
- {
- list.add(buddyFqnTransformer.getBackupFqn((String) buddy, fqn));
- }
- }
- }
-
- long stateFetchTimeout = cache.getConfiguration().getLockAcquisitionTimeout() +
5000;
- // Remove the subtree from the main cache and any buddy backup trees
- for (Fqn subtree : list)
- {
- subtreeRoot = cache.peek(subtree, false);
- if (subtreeRoot != null)
- {
- // Acquire locks
-
- Object owner = getOwnerForLock();
- subtreeLocked = lockManager.lockAll(subtreeRoot, WRITE, owner,
stateFetchTimeout);
-
- // Lock the parent, as we're about to write to it
- parent = subtreeRoot.getParentDirect();
- if (parent != null) parentLocked = lockManager.lock(parent.getFqn(),
WRITE, owner, stateFetchTimeout);
-
- // Remove the subtree
- cache.evict(subtree, true);
- //cache._evictSubtree(subtree);
-
- // Release locks
- if (parent != null)
- {
- log.debug("forcing release of locks in parent");
- lockManager.unlockAll(parent);
- }
-
- parentLocked = false;
-
- log.debug("forcing release of all locks in subtree");
- lockManager.unlockAll(subtreeRoot);
- subtreeLocked = false;
- }
- }
- }
- catch (InterruptedException e)
- {
- throw new CacheException(e);
- }
- finally
- {
- // If we didn't succeed, undo the marshalling change
- // NO. Since we inactivated, we may have missed changes
- //if (!success && !inactive)
- // marshaller_.activate(subtreeFqn);
-
- // If necessary, release locks
- if (parentLocked)
- {
- log.debug("forcing release of locks in parent");
- try
- {
- if (parent != null) lockManager.unlockAll(parent);
- }
- catch (Throwable t)
- {
- log.error("failed releasing locks", t);
- }
- }
- if (subtreeLocked)
- {
- log.debug("forcing release of all locks in subtree");
- try
- {
- if (subtreeRoot != null) lockManager.unlockAll(subtreeRoot);
- }
- catch (Throwable t)
- {
- log.error("failed releasing locks", t);
- }
- }
-
- activationChangeNodes.remove(fqn);
- }
- }
-
- private Object getOwnerForLock()
- {
- Object owner = cache.getCurrentTransaction();
- return owner == null ? Thread.currentThread() : owner;
- }
-
-
- /**
- * <p/>
- * This is legacy code and should not be called directly. This is a private method
for now and will be refactored out.
- * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
- * <p/>
- *
- * @param fqn fqn of the region
- * @return true if the region defined by the fqn is in the process of
activating/deactivating
- */
- private boolean isActivatingDeactivating(Fqn fqn)
- {
- return activationChangeNodes.contains(fqn);
- }
-
- /**
- * Returns true if the region exists
- *
- * @param fqn FQN of the region
- * @param type type of region to search for
- * @return true if the region exists
- */
- public boolean hasRegion(Fqn fqn, Region.Type type)
- {
- Region r = regionsRegistry.get(fqn);
- if (r == null) return false;
- switch (type)
- {
- case ANY:
- return true;
- case EVICTION:
- return r.getEvictionPolicy() != null &&
evictionTimerTask.isRegionRegisteredForProcessing(r);
- case MARSHALLING:
- return r.isActive() && r.getClassLoader() != null;
- }
- // should never reach here?
- return false;
- }
-
- /**
- * Disables unmarshalling of replication messages for the region
- * rooted in the given Fqn.
- *
- * @param fqn
- */
- public void deactivate(Fqn fqn)
- {
- try
- {
- Region region = getRegion(fqn, false);
-
- if (region != null)
- {
- if (defaultInactive && region.getClassLoader() == null)
- {
- // This region's state will no match that of a non-existent one
- // So, there is no reason to keep this region any more
-
- // FIXME (Brian) We shouldn't do this anymore; now outside code can
have a ref to the region!!
- removeRegion(fqn);
- }
- else
- {
- //region.deactivate();
- region.setActive(false);
- // FIXME - we should always clean up; otherwise stale data is in memory!
- if (cache.getConfiguration().isFetchInMemoryState())
- {
- inactivateRegion(fqn);
- }
- }
- }
- else if (!defaultInactive)
- {
- region = getRegion(fqn, true);
- region.setActive(false);
- // FIXME - we should always clean up; otherwise stale data is in memory!
- if (cache.getConfiguration().isFetchInMemoryState())
- {
- inactivateRegion(fqn);
- }
- }
- }
- catch (RuntimeException re)
- {
- throw re;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Resets the region manager's regions registry
- */
- public void reset()
- {
- regionsRegistry.clear();
- }
-
- /**
- * Returns an ordered list of all regions.
- * Note that the ordered list returned is sorted according to the natural order
defined in the {@link Comparable} interface, which {@link org.jboss.cache.Region}
extends.
- *
- * @param type Type of region to return
- * @return an ordered list of all regions, based on the type requested.
- */
- public List<Region> getAllRegions(Region.Type type)
- {
- List<Region> regions;
-
- if (type != ANY)
- {
- regions = new ArrayList<Region>();
- // we need to loop thru the regions and only select specific regions to rtn.
- for (Region r : regionsRegistry.values())
- {
- if ((type == EVICTION && r.getEvictionPolicy() != null &&
evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
- (type == MARSHALLING && r.isActive() &&
r.getClassLoader() != null))
- regions.add(r);
- }
- }
- else
- {
- // put all regions
- regions = new ArrayList<Region>(regionsRegistry.values());
- }
-
- Collections.sort(regions);
-
- return regions;
- }
-
- /**
- * Sets if evictions are processed.
- */
- public void setUsingEvictions(boolean usingEvictions)
- {
- this.usingEvictions = usingEvictions;
- }
-
- /**
- * Sets the eviction configuration.
- */
- public void setEvictionConfig(EvictionConfig evictionConfig)
- {
- this.evictionConfig = evictionConfig;
-
- // JBAS-1288
- // Try to establish a default region if there isn't one already
- boolean needDefault;
- List<EvictionRegionConfig> ercs = evictionConfig.getEvictionRegionConfigs();
- // Only add a default region if there are no regions. This is
- // contrary to the idea that there *must* be a default region, but some
- // unit tests fail w/ APPROACH 1, so for now we go with this approach.
- needDefault = ercs.size() == 0;
-
- if (needDefault)
- {
- // This may throw ConfigurationException if there is no default
- // eviction policy class
- EvictionRegionConfig dflt = evictionConfig.createDefaultEvictionRegionConfig();
- ercs.add(0, dflt); // put it first
- // Need to pass this back into the evictionConfig so it knows
- // about the new region
- evictionConfig.setEvictionRegionConfigs(ercs);
- }
-
- // create regions for the regions defined in the evictionConfig.
- // scan to be sure the _default_ region isn't added twice
- boolean setDefault = false;
- for (EvictionRegionConfig erc : ercs)
- {
- Fqn fqn = erc.getRegionFqn();
- if (log.isTraceEnabled()) log.trace("Creating eviction region " +
fqn);
-
- if (fqn.equals(DEFAULT_REGION))
- {
- if (setDefault)
- {
- throw new ConfigurationException("A default region for evictions has
already been set for this cache");
- }
- if (log.isTraceEnabled()) log.trace("Applying settings for " +
DEFAULT_REGION + " to Fqn.ROOT");
- fqn = Fqn.ROOT;
- setDefault = true;
- }
- Region r = getRegion(fqn, true);
- r.setEvictionPolicy(erc.getEvictionPolicyConfig());
- }
- }
-
- /**
- * Starts the eviction processing thread.
- */
- public void startEvictionThread()
- {
- evictionTimerTask.init(evictionConfig.getWakeupInterval());
- }
-
- /**
- * Stops the eviction processing thread
- */
- public void stopEvictionThread()
- {
- evictionTimerTask.stop();
- }
-
-
- /**
- * Returns a string containing debug information on every region.
- *
- * @return Regions as a string
- */
- public String dumpRegions()
- {
- StringBuilder sb = new StringBuilder();
- for (Region r : regionsRegistry.values())
- {
- sb.append("\tRegion ").append(r);
- sb.append("\n");
- }
- return sb.toString();
- }
-
- /**
- * Returns a string containing debug information on every region.
- */
- @Override
- public String toString()
- {
- return "RegionManager " + dumpRegions();
- }
-
- public CacheSPI getCache()
- {
- return cache;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-07 21:21:24 UTC
(rev 6199)
@@ -0,0 +1,179 @@
+package org.jboss.cache;
+
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.eviction.EvictionTimerTask;
+
+import java.util.List;
+
+/**
+ * Manages regions.
+ * <p/>
+ * Prior to 3.0.0, this was a concrete class. An interface was introduced in 3.0.0 for
enhanced flexibility.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public interface RegionManager
+{
+ /**
+ * @return true if evictions are being processed.
+ */
+ boolean isUsingEvictions();
+
+ /**
+ * @return true if replication is by default inactive for new {@link
org.jboss.cache.Region}s.
+ */
+ boolean isDefaultInactive();
+
+ /**
+ * Sets if replication for new {@link org.jboss.cache.Region}s is by default
inactive.
+ */
+ void setDefaultInactive(boolean defaultInactive);
+
+ /**
+ * Helper utility that checks for a {@link ClassLoader} registered for the
+ * given {@link org.jboss.cache.Fqn}, and if found sets it as the TCCL. If the given
Fqn is
+ * under the _BUDDY_BACKUP_ region, the equivalent region in the main
+ * cache is used to find the {@link ClassLoader}.
+ *
+ * @param fqn Fqn pointing to a region for which a special classloader
+ * may have been registered.
+ */
+ void setContextClassLoaderAsCurrent(Fqn fqn);
+
+ /**
+ * Returns a region by {@link org.jboss.cache.Fqn}, creating it optionally if absent.
If the region does not exist and <tt>createIfAbsent</tt>
+ * is <tt>false</tt>, a parent region which may apply to the {@link
org.jboss.cache.Fqn} is sought.
+ * <p/>
+ * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If
it is, the actual Fqn is calculated
+ * and used instead.
+ */
+ Region getRegion(Fqn fqn, boolean createIfAbsent);
+
+ /**
+ * Retrieves a valid marshalling {@link org.jboss.cache.Region} after taking into
account that this may be a Buddy Backup Fqn.
+ * If the fqn passed in is null, the region has been deactivated or if a region cannot
be found, this method returns a null.
+ *
+ * @param fqn of the region to locate
+ * @return a region
+ */
+ Region getValidMarshallingRegion(Fqn fqn);
+
+ /**
+ * An overloaded form of {@link #getRegion(org.jboss.cache.Fqn,boolean)} that takes an
additional {@link org.jboss.cache.Region.Type}
+ * parameter to force regions of a specific type.
+ * <p/>
+ * Note that this takes into account the fact that this may be a Buddy Backup Fqn. If
it is, the actual Fqn is calculated
+ * and used instead.
+ *
+ * @see org.jboss.cache.Region.Type
+ */
+ Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent);
+
+ /**
+ * Returns a region using Fqn.fromString(fqn), calling {@link
#getRegion(org.jboss.cache.Fqn,boolean)}
+ *
+ * @param fqn
+ * @param createIfAbsent
+ * @see #getRegion(org.jboss.cache.Fqn,boolean)
+ */
+ Region getRegion(String fqn, boolean createIfAbsent);
+
+ /**
+ * Removes a {@link Region} identified by the given fqn.
+ *
+ * @param fqn fqn of the region to remove
+ * @return true if such a region existed and was removed.
+ */
+ boolean removeRegion(Fqn fqn);
+
+ /**
+ * Activates unmarshalling of replication messages for the region
+ * rooted in the given Fqn.
+ * <p/>
+ * <strong>NOTE:</strong> This method will cause the creation of a node
+ * in the local cache at <code>subtreeFqn</code> whether or not that
+ * node exists anywhere else in the cluster. If the node does not exist
+ * elsewhere, the local node will be empty. The creation of this node will
+ * not be replicated.
+ * <p/>
+ *
+ * @param fqn representing the region to be activated.
+ * @throws org.jboss.cache.RegionNotEmptyException
+ * if the node <code>fqn</code>
+ * exists and already has either data or children
+ */
+ void activate(Fqn fqn) throws RegionNotEmptyException;
+
+ /**
+ * Attempts to activate a given region rooted at a given Fqn, similar to {@link
#activate(org.jboss.cache.Fqn)} except
+ * that if the fqn is currently already in use (probably already been activated) this
method is a no-op.
+ *
+ * @param fqn which represents the region to activate
+ */
+ void activateIfEmpty(Fqn fqn);
+
+ /**
+ * Convenienve method. If the region defined by fqn does not exist, {@link
#isDefaultInactive()} is returned, otherwise
+ * !{@link org.jboss.cache.Region#isActive()} is returned.
+ *
+ * @param fqn fqn to test
+ * @return true if inactive
+ */
+ boolean isInactive(Fqn fqn);
+
+ /**
+ * Returns true if the region exists
+ *
+ * @param fqn FQN of the region
+ * @param type type of region to search for
+ * @return true if the region exists
+ */
+ boolean hasRegion(Fqn fqn, Region.Type type);
+
+ /**
+ * Disables unmarshalling of replication messages for the region
+ * rooted in the given Fqn.
+ *
+ * @param fqn
+ */
+ void deactivate(Fqn fqn);
+
+ /**
+ * Resets the region manager's regions registry
+ */
+ void reset();
+
+ /**
+ * Returns an ordered list of all regions.
+ * Note that the ordered list returned is sorted according to the natural order
defined in the {@link Comparable} interface, which {@link Region} extends.
+ *
+ * @param type Type of region to return
+ * @return an ordered list of all regions, based on the type requested.
+ */
+ List<Region> getAllRegions(Region.Type type);
+
+ /**
+ * Sets if evictions are processed.
+ */
+ void setUsingEvictions(boolean usingEvictions);
+
+ /**
+ * Sets the eviction configuration.
+ */
+ void setEvictionConfig(EvictionConfig evictionConfig);
+
+ /**
+ * Returns a string containing debug information on every region.
+ *
+ * @return Regions as a string
+ */
+ String dumpRegions();
+
+ CacheSPI getCache();
+
+ /**
+ * @return the eviction timer task attached to the region manager
+ */
+ EvictionTimerTask getEvictionTimerTask();
+}
Copied: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java (from rev 6183,
core/trunk/src/main/java/org/jboss/cache/RegionManager.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-07-07 21:21:24
UTC (rev 6199)
@@ -0,0 +1,789 @@
+package org.jboss.cache;
+
+import net.jcip.annotations.ThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import static org.jboss.cache.Region.Type.*;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+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.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.EvictionTimerTask;
+import org.jboss.cache.factories.annotations.Destroy;
+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.LockManager;
+import static org.jboss.cache.lock.LockType.WRITE;
+import org.jgroups.Address;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * The default region manager, used with MVCC locking.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 3.0.0
+ */
+@ThreadSafe
+public class RegionManagerImpl implements RegionManager
+{
+ /**
+ * The default region used in XML configuration files when defining eviction policies.
Any
+ * 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 =
Fqn.fromString("/_default_");
+
+ /**
+ * A registry of regions that have been defined.
+ */
+ private final Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn,
Region>();
+ private boolean defaultInactive;
+ private final Log log = LogFactory.getLog(RegionManagerImpl.class);
+ CacheSPI cache;
+ private boolean usingEvictions;
+ private EvictionConfig evictionConfig;
+ private final EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
+
+ protected final Set<Fqn> activationChangeNodes = Collections.synchronizedSet(new
HashSet<Fqn>());
+ protected Configuration configuration;
+ protected RPCManager rpcManager;
+ protected LockManager lockManager;
+ private BuddyFqnTransformer buddyFqnTransformer;
+ private boolean isUsingBR;
+
+ @Inject
+ void injectDependencies(CacheSPI cache, Configuration configuration, RPCManager
rpcManager, LockManager lockManager,
+ BuddyFqnTransformer transformer)
+ {
+ this.cache = cache;
+ this.rpcManager = rpcManager;
+ this.configuration = configuration;
+ this.lockManager = lockManager;
+ this.buddyFqnTransformer = transformer;
+ }
+
+ @Start
+ protected void start()
+ {
+ log.trace("Starting region manager");
+ isUsingBR = configuration.getBuddyReplicationConfig() != null &&
configuration.getBuddyReplicationConfig().isEnabled();
+ if (configuration.getEvictionConfig() != null
+ && configuration.getEvictionConfig().isValidConfig())
+ {
+ // validate individual region configs now
+ for (EvictionRegionConfig erc :
configuration.getEvictionConfig().getEvictionRegionConfigs())
+ {
+ EvictionPolicyConfig epc = erc.getEvictionPolicyConfig();
+ if (epc != null) epc.validate();
+ }
+
+ setEvictionConfig(configuration.getEvictionConfig());
+ setUsingEvictions(true);
+ }
+ else
+ {
+ setUsingEvictions(false);
+ log.debug("Not using an EvictionPolicy");
+ }
+
+ setDefaultInactive(configuration.isInactiveOnStartup());
+
+ if (isUsingEvictions())
evictionTimerTask.init(evictionConfig.getWakeupInterval());
+ }
+
+ @Stop
+ protected void stop()
+ {
+ if (isUsingEvictions()) evictionTimerTask.stop();
+ }
+
+ @Destroy
+ protected void destroy()
+ {
+ regionsRegistry.clear();
+ activationChangeNodes.clear();
+ }
+
+ public boolean isUsingEvictions()
+ {
+ return usingEvictions;
+ }
+
+ public boolean isDefaultInactive()
+ {
+ return defaultInactive;
+ }
+
+ public void setDefaultInactive(boolean defaultInactive)
+ {
+ this.defaultInactive = defaultInactive;
+ Region defaultRegion = regionsRegistry.get(Fqn.ROOT);
+ if (defaultRegion != null) defaultRegion.setActive(!defaultInactive);
+ }
+
+ public void setContextClassLoaderAsCurrent(Fqn fqn)
+ {
+ if (fqn.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN))
+ {
+ if (fqn.size() <= 2)
+ {
+ fqn = Fqn.ROOT;
+ }
+ else
+ {
+ fqn = fqn.getSubFqn(2, fqn.size());
+ }
+ }
+ Region region = getRegion(fqn, false);
+ ClassLoader regionCL = (region == null) ? null : region.getClassLoader();
+ if (regionCL != null)
+ {
+ Thread.currentThread().setContextClassLoader(regionCL);
+ }
+
+ }
+
+ public Region getRegion(Fqn fqn, boolean createIfAbsent)
+ {
+ return getRegion(fqn, ANY, createIfAbsent);
+ }
+
+ public Region getValidMarshallingRegion(Fqn fqn)
+ {
+ if (fqn == null) return null;
+ return getRegion(fqn, Region.Type.MARSHALLING, false);
+ }
+
+ public Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
+ {
+ if (isUsingBR && fqn != null &&
buddyFqnTransformer.isBackupFqn(fqn))
+ {
+ fqn = buddyFqnTransformer.getActualFqn(fqn);
+ }
+
+ 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
+ if (regionsRegistry.containsKey(fqnToUse))
+ {
+ Region r = regionsRegistry.get(fqnToUse);
+
+ // 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.
+ if (type == ANY
+ || (type == MARSHALLING && r.getClassLoader() != null)
+ || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ {
+ return r;
+ }
+ }
+
+ // if not, attempt to create one ...
+ if (createIfAbsent)
+ {
+ Region r = new RegionImpl(fqnToUse, this);
+ regionsRegistry.put(fqnToUse, r);
+ if (type == MARSHALLING)
+ {
+ // insert current class loader into region so at least it is recognised as a
marshalling region
+ r.registerContextClassLoader(getClass().getClassLoader());
+ }
+ return r;
+ }
+
+ // else try and find a parent which has a defined region, may return null if
nothing is defined.
+ Region nextBestThing = null;
+ Fqn nextFqn = fqnToUse;
+
+ while (nextBestThing == null)
+ {
+ nextFqn = nextFqn.getParent();
+ 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.
+ if (type == ANY
+ || (type == MARSHALLING && r.getClassLoader() != null)
+ || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ {
+ nextBestThing = r;
+ }
+ }
+ if (nextFqn.isRoot()) break;
+ }
+
+ // test if the default region has been defined. If not, and if the request
+ // is for an eviction region, return null
+ if (type == EVICTION && nextBestThing != null &&
nextBestThing.getFqn().isRoot() && !regionsRegistry.containsKey(Fqn.ROOT))
+ {
+ log.trace("No default eviction region; returning null");
+ nextBestThing = null;
+ }
+
+ return nextBestThing;
+ }
+
+ public Region getRegion(String fqn, boolean createIfAbsent)
+ {
+ return getRegion(Fqn.fromString(fqn), createIfAbsent);
+ }
+
+ public boolean removeRegion(Fqn fqn)
+ {
+ Region r = regionsRegistry.remove(fqn);
+ if (r == null) return false;
+
+ if (isUsingEvictions() && r.getEvictionPolicy() != null)
+ {
+ evictionTimerTask.removeRegionToProcess(r);
+ }
+ return true;
+ }
+
+ public EvictionTimerTask getEvictionTimerTask()
+ {
+ return evictionTimerTask;
+ }
+
+ public void activate(Fqn fqn) throws RegionNotEmptyException
+ {
+ activate(fqn, false);
+ }
+
+ public void activateIfEmpty(Fqn fqn)
+ {
+ activate(fqn, true);
+ }
+
+ private void activate(Fqn fqn, boolean suppressRegionNotEmptyException)
+ {
+ try
+ {
+ if (log.isTraceEnabled()) log.trace("Activating region " + fqn);
+ Region r = getRegion(fqn, false);
+ if (r != null)
+ {
+ if (!defaultInactive && r.getClassLoader() == null)
+ {
+ // This region's state will no match that of a non-existent one
+ // So, there is no reason to keep this region any more
+
+ // (Brian) We shouldn't do this anymore; now outside code
+ // can have a ref to the region!!
+ removeRegion(fqn);
+ }
+ else
+ {
+ //r.activate();
+ r.setStatus(Region.Status.ACTIVATING);
+ if (configuration.isFetchInMemoryState())
+ {
+ activateRegion(r.getFqn(), suppressRegionNotEmptyException);
+ }
+ r.setActive(true);
+ }
+ }
+ else if (defaultInactive)
+ {
+ // "Active" region is not the default, so create a region
+ r = getRegion(fqn, true);
+ // FIXME - persistent state transfer counts too!
+ r.setStatus(Region.Status.ACTIVATING);
+ if (configuration.isFetchInMemoryState())
+ {
+ activateRegion(r.getFqn(), suppressRegionNotEmptyException);
+ }
+ r.setActive(true);
+ }
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Causes the cache to transfer state for the subtree rooted at
+ * <code>subtreeFqn</code> and to begin accepting replication messages
+ * for that subtree.
+ * <p/>
+ * <strong>NOTE:</strong> This method will cause the creation of a node
+ * in the local cache at <code>subtreeFqn</code> whether or not that
+ * node exists anywhere else in the cluster. If the node does not exist
+ * elsewhere, the local node will be empty. The creation of this node will
+ * not be replicated.
+ *
+ * @param fqn Fqn string indicating the uppermost node in the
+ * portion of the cache that should be activated.
+ * @throws RegionNotEmptyException if the node <code>subtreeFqn</code>
+ * exists and has either data or children
+ */
+ private void activateRegion(Fqn fqn, boolean suppressRegionNotEmptyException)
+ {
+ // Check whether the node already exists and has data
+ Node subtreeRoot = cache.peek(fqn, false, false);
+
+ /*
+ * Commented out on Nov 16,2006 Manik&Vladimir
+ *
+ * if (!(cache.isNodeEmpty(subtreeRoot)))
+ {
+ throw new RegionNotEmptyException("Node " + subtreeRoot.getFqn() +
" already exists and is not empty");
+ }*/
+
+ if (isActivatingDeactivating(fqn))
+ {
+ throw new CacheException("Region " + subtreeRoot.getFqn() + " is
already being activated/deactivated");
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("activating " + fqn);
+ }
+
+ try
+ {
+
+ // Add this fqn to the set of those we are activating
+ // so calls to _getState for the fqn can return quickly
+ activationChangeNodes.add(fqn);
+
+ BuddyManager buddyManager = cache.getBuddyManager();
+ // Request partial state from the cluster and integrate it
+ if (buddyManager == null)
+ {
+ // Get the state from any node that has it and put it
+ // in the main cache
+ if (subtreeRoot == null)
+ {
+ // We'll update this node with the state we receive
+ // need to obtain all necessary locks.
+
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ subtreeRoot = cache.getRoot().addChild(fqn);
+
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ }
+
+ List<Address> members = cache.getMembers();
+
+ // Don't bother trying to fetch state if we are in LOCAL mode
+ if (members != null && !members.isEmpty())
+ rpcManager.fetchPartialState(members, subtreeRoot.getFqn());
+ }
+ else if (!buddyFqnTransformer.isBackupFqn(fqn))
+ {
+ // Get the state from each DataOwner and integrate in their
+ // respective buddy backup cache
+ List<Address> buddies = buddyManager.getBackupDataOwners();
+ for (Address buddy : buddies)
+ {
+ List<Address> sources = new ArrayList<Address>(1);
+ if (!cache.getMembers().contains(buddy))
+ continue;
+ sources.add(buddy);
+ Fqn buddyRoot = buddyFqnTransformer.getBackupFqn(buddy, fqn);
+ subtreeRoot = cache.peek(buddyRoot, false, false);
+ if (subtreeRoot == null)
+ {
+ // We'll update this node with the state we receive
+ // need to obtain all necessary locks.
+ // needs to be a LOCAL call!
+ NodeSPI root = cache.getRoot();
+
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ subtreeRoot = root.addChild(buddyRoot);
+
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
+ }
+ rpcManager.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
+ }
+ }
+ else
+ {
+ log.info("Attempting to activate a backup region. Not attempting to
retrieve any state as this will be pushed.");
+ }
+ }
+ catch (Throwable t)
+ {
+ log.error("failed to activate " + fqn, t);
+
+ // "Re-deactivate" the region
+ try
+ {
+ inactivateRegion(fqn);
+ }
+ catch (Exception e)
+ {
+ log.error("failed inactivating " + fqn, e);
+ // just swallow this one and throw the first one
+ }
+
+ // Throw the exception on, wrapping if necessary
+ if (t instanceof RegionNotEmptyException)
+ {
+ if (!suppressRegionNotEmptyException) throw (RegionNotEmptyException) t;
+ }
+ else if (t instanceof CacheException)
+ {
+ throw (CacheException) t;
+ }
+ else
+ {
+ throw new CacheException(t.getClass().getName() + " " +
+ t.getLocalizedMessage(), t);
+ }
+ }
+ finally
+ {
+ activationChangeNodes.remove(fqn);
+ }
+ }
+
+ public boolean isInactive(Fqn fqn)
+ {
+ Region region = getRegion(fqn, false);
+ return region == null ? defaultInactive : !region.isActive();
+ }
+
+
+ /**
+ * Causes the cache to stop accepting replication events for the subtree
+ * rooted at <code>subtreeFqn</code> and evict all nodes in that subtree.
+ * <p/>
+ * This is legacy code and should not be called directly. This is a private method
for now and will be refactored out.
+ * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
+ * <p/>
+ *
+ * @param fqn Fqn string indicating the uppermost node in the
+ * portion of the cache that should be activated.
+ * @throws RegionNameConflictException if <code>subtreeFqn</code>
indicates
+ * a node that is part of another
+ * subtree that is being specially
+ * managed (either by activate/inactiveRegion()
+ * or by registerClassLoader())
+ * @throws CacheException if there is a problem evicting nodes
+ * @throws IllegalStateException if {@link
org.jboss.cache.config.Configuration#isUseRegionBasedMarshalling()} is
<code>false</code>
+ */
+ private void inactivateRegion(Fqn fqn) throws CacheException
+ {
+ if (isActivatingDeactivating(fqn))
+ {
+ throw new CacheException("Region " + fqn + " is already being
activated/deactivated");
+ }
+
+ NodeSPI parent = null;
+ NodeSPI subtreeRoot = null;
+ boolean parentLocked = false;
+ boolean subtreeLocked = false;
+
+ try
+ {
+ // Record that this fqn is in status change, so can't provide state
+ activationChangeNodes.add(fqn);
+
+ if (!isInactive(fqn))
+ {
+ deactivate(fqn);
+ }
+
+ // Create a list with the Fqn in the main cache and any buddy backup trees
+ BuddyManager buddyManager = cache.getBuddyManager();
+ ArrayList<Fqn> list = new ArrayList<Fqn>();
+ list.add(fqn);
+
+ if (buddyManager != null)
+ {
+ Set buddies = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false,
false).getChildrenNames();
+ if (buddies != null)
+ {
+ for (Object buddy : buddies)
+ {
+ list.add(buddyFqnTransformer.getBackupFqn((String) buddy, fqn));
+ }
+ }
+ }
+
+ long stateFetchTimeout = cache.getConfiguration().getLockAcquisitionTimeout() +
5000;
+ // Remove the subtree from the main cache and any buddy backup trees
+ for (Fqn subtree : list)
+ {
+ subtreeRoot = cache.peek(subtree, false);
+ if (subtreeRoot != null)
+ {
+ // Acquire locks
+ subtreeLocked = lockManager.lockAll(subtreeRoot, WRITE, getOwnerForLock(),
stateFetchTimeout);
+
+ // Lock the parent, as we're about to write to it
+ parent = subtreeRoot.getParentDirect();
+ if (parent != null)
+ parentLocked = lockManager.lockAll(parent, WRITE, getOwnerForLock(),
stateFetchTimeout);
+
+ // Remove the subtree
+ cache.evict(subtree, true);
+ //cache._evictSubtree(subtree);
+
+ // Release locks
+ if (parent != null)
+ {
+ log.debug("forcing release of locks in parent");
+ lockManager.unlockAll(parent);
+ }
+
+ parentLocked = false;
+
+ log.debug("forcing release of all locks in subtree");
+ lockManager.unlockAll(subtreeRoot);
+ subtreeLocked = false;
+ }
+ }
+ }
+ catch (InterruptedException e)
+ {
+ throw new CacheException(e);
+ }
+ finally
+ {
+ // If we didn't succeed, undo the marshalling change
+ // NO. Since we inactivated, we may have missed changes
+ //if (!success && !inactive)
+ // marshaller_.activate(subtreeFqn);
+
+ // If necessary, release locks
+ if (parentLocked)
+ {
+ log.debug("forcing release of locks in parent");
+ try
+ {
+ if (parent != null) lockManager.unlockAll(parent);
+ }
+ catch (Throwable t)
+ {
+ log.error("failed releasing locks", t);
+ }
+ }
+ if (subtreeLocked)
+ {
+ log.debug("forcing release of all locks in subtree");
+ try
+ {
+ if (subtreeRoot != null) lockManager.unlockAll(subtreeRoot);
+ }
+ catch (Throwable t)
+ {
+ log.error("failed releasing locks", t);
+ }
+ }
+
+ activationChangeNodes.remove(fqn);
+ }
+ }
+
+ // MVCC deduces lock owners implicitly.
+ protected Object getOwnerForLock()
+ {
+ return null;
+ }
+
+ /**
+ * <p/>
+ * This is legacy code and should not be called directly. This is a private method
for now and will be refactored out.
+ * You should be using {@link #activate(Fqn)} and {@link #deactivate(Fqn)}
+ * <p/>
+ *
+ * @param fqn fqn of the region
+ * @return true if the region defined by the fqn is in the process of
activating/deactivating
+ */
+ private boolean isActivatingDeactivating(Fqn fqn)
+ {
+ return activationChangeNodes.contains(fqn);
+ }
+
+ public boolean hasRegion(Fqn fqn, Region.Type type)
+ {
+ Region r = regionsRegistry.get(fqn);
+ if (r == null) return false;
+ switch (type)
+ {
+ case ANY:
+ return true;
+ case EVICTION:
+ return r.getEvictionPolicy() != null &&
evictionTimerTask.isRegionRegisteredForProcessing(r);
+ case MARSHALLING:
+ return r.isActive() && r.getClassLoader() != null;
+ }
+ // should never reach here?
+ return false;
+ }
+
+ public void deactivate(Fqn fqn)
+ {
+ try
+ {
+ Region region = getRegion(fqn, false);
+
+ if (region != null)
+ {
+ if (defaultInactive && region.getClassLoader() == null)
+ {
+ // This region's state will no match that of a non-existent one
+ // So, there is no reason to keep this region any more
+
+ // FIXME (Brian) We shouldn't do this anymore; now outside code can
have a ref to the region!!
+ removeRegion(fqn);
+ }
+ else
+ {
+ //region.deactivate();
+ region.setActive(false);
+ // FIXME - we should always clean up; otherwise stale data is in memory!
+ if (cache.getConfiguration().isFetchInMemoryState())
+ {
+ inactivateRegion(fqn);
+ }
+ }
+ }
+ else if (!defaultInactive)
+ {
+ region = getRegion(fqn, true);
+ region.setActive(false);
+ // FIXME - we should always clean up; otherwise stale data is in memory!
+ if (cache.getConfiguration().isFetchInMemoryState())
+ {
+ inactivateRegion(fqn);
+ }
+ }
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void reset()
+ {
+ regionsRegistry.clear();
+ }
+
+ public List<Region> getAllRegions(Region.Type type)
+ {
+ List<Region> regions;
+
+ if (type != ANY)
+ {
+ regions = new ArrayList<Region>();
+ // we need to loop thru the regions and only select specific regions to rtn.
+ for (Region r : regionsRegistry.values())
+ {
+ if ((type == EVICTION && r.getEvictionPolicy() != null &&
evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
+ (type == MARSHALLING && r.isActive() &&
r.getClassLoader() != null))
+ regions.add(r);
+ }
+ }
+ else
+ {
+ // put all regions
+ regions = new ArrayList<Region>(regionsRegistry.values());
+ }
+
+ Collections.sort(regions);
+
+ return regions;
+ }
+
+ public void setUsingEvictions(boolean usingEvictions)
+ {
+ this.usingEvictions = usingEvictions;
+ }
+
+ public void setEvictionConfig(EvictionConfig evictionConfig)
+ {
+ this.evictionConfig = evictionConfig;
+
+ // JBAS-1288
+ // Try to establish a default region if there isn't one already
+ boolean needDefault;
+ List<EvictionRegionConfig> ercs = evictionConfig.getEvictionRegionConfigs();
+ // Only add a default region if there are no regions. This is
+ // contrary to the idea that there *must* be a default region, but some
+ // unit tests fail w/ APPROACH 1, so for now we go with this approach.
+ needDefault = ercs.size() == 0;
+
+ if (needDefault)
+ {
+ // This may throw ConfigurationException if there is no default
+ // eviction policy class
+ EvictionRegionConfig dflt = evictionConfig.createDefaultEvictionRegionConfig();
+ ercs.add(0, dflt); // put it first
+ // Need to pass this back into the evictionConfig so it knows
+ // about the new region
+ evictionConfig.setEvictionRegionConfigs(ercs);
+ }
+
+ // create regions for the regions defined in the evictionConfig.
+ // scan to be sure the _default_ region isn't added twice
+ boolean setDefault = false;
+ for (EvictionRegionConfig erc : ercs)
+ {
+ Fqn fqn = erc.getRegionFqn();
+ if (log.isTraceEnabled()) log.trace("Creating eviction region " +
fqn);
+
+ if (fqn.equals(DEFAULT_REGION))
+ {
+ if (setDefault)
+ {
+ throw new ConfigurationException("A default region for evictions has
already been set for this cache");
+ }
+ if (log.isTraceEnabled()) log.trace("Applying settings for " +
DEFAULT_REGION + " to Fqn.ROOT");
+ fqn = Fqn.ROOT;
+ setDefault = true;
+ }
+ Region r = getRegion(fqn, true);
+ r.setEvictionPolicy(erc.getEvictionPolicyConfig());
+ }
+ }
+
+ public String dumpRegions()
+ {
+ StringBuilder sb = new StringBuilder();
+ for (Region r : regionsRegistry.values())
+ {
+ sb.append("\tRegion ").append(r);
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns a string containing debug information on every region.
+ */
+ @Override
+ public String toString()
+ {
+ return "RegionManager " + dumpRegions();
+ }
+
+ public CacheSPI getCache()
+ {
+ return cache;
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -21,10 +21,9 @@
*/
package org.jboss.cache.config;
-import org.jboss.cache.RegionManager;
import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.util.Util;
import java.util.ArrayList;
import java.util.List;
@@ -45,7 +44,9 @@
@Deprecated
private int wakeupIntervalSeconds = WAKEUP_DEFAULT;
- /** value expressed in millis */
+ /**
+ * value expressed in millis
+ */
@Dynamic
private long wakeupInterval = WAKEUP_DEFAULT * 1000;
@@ -83,13 +84,13 @@
/**
* Creates an EvictionRegionConfig for the
- * {@link RegionManager.DEFAULT_REGION "_default_"} region using the
+ * {@link org.jboss.cache.RegionManagerImpl.DEFAULT_REGION "_default_"}
region using the
* {@link #getDefaultEvictionPolicyClass(String) default eviction policy class}.
Throws a
* {@link ConfigurationException} if
* {@link #setDefaultEvictionPolicyClass(String) a default eviction policy class}
* has not been set.
*
- * @return an EvictionRegionConfig whose FQN is {@link RegionManager.DEFAULT_REGION}
+ * @return an EvictionRegionConfig whose FQN is {@link
org.jboss.cache.RegionManagerImpl.DEFAULT_REGION}
* and whose EvictionPolicyConfig is the default config for the
* default eviction policy class.
* @throws ConfigurationException if a
@@ -107,7 +108,7 @@
EvictionRegionConfig erc = new EvictionRegionConfig();
EvictionPolicyConfig epc =
policy.getEvictionConfigurationClass().newInstance();
erc.setEvictionPolicyConfig(epc);
- erc.setRegionFqn(RegionManager.DEFAULT_REGION);
+ erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
return erc;
}
catch (Exception e)
@@ -157,18 +158,22 @@
this.evictionRegionConfigs = evictionRegionConfigs;
}
- /** value expressed in millis */
+ /**
+ * value expressed in millis
+ */
public long getWakeupInterval()
{
return wakeupInterval;
}
- /** value expressed in millis */
+ /**
+ * value expressed in millis
+ */
public void setWakeupInterval(long wakeupInterval)
{
testImmutability("WakeupInterval");
this.wakeupInterval = wakeupInterval;
- this.wakeupIntervalSeconds = (int)wakeupInterval/1000;
+ this.wakeupIntervalSeconds = (int) wakeupInterval / 1000;
}
/**
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,20 +1,20 @@
package org.jboss.cache.config.parsing.element;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.parsing.XmlParserBase;
import org.jboss.cache.config.parsing.ParsedAttributes;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.XmlParserBase;
import org.jboss.cache.eviction.EvictionPolicy;
import org.jboss.cache.util.Util;
-import org.jboss.cache.RegionManager;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import java.util.ArrayList;
import java.util.List;
-import java.util.ArrayList;
/**
* Knows how to parse the <b>eviction</b> xml element.
@@ -44,7 +44,7 @@
if (rootRegion != null)
{
EvictionRegionConfig erc = getEvictionRegionConfig(rootRegion,
defaultPolicyClass, defaultEvQueueSize);
- erc.setRegionName(RegionManager.DEFAULT_REGION.toString());
+ erc.setRegionName(RegionManagerImpl.DEFAULT_REGION.toString());
evictionRegionConfigs.add(erc);
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/BootstrapFactory.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -7,7 +7,7 @@
import org.jboss.cache.factories.annotations.NonVolatile;
/**
- * // TODO: MANIK: Document this
+ * Factory for setting up bootstrap components
*
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
* @since 2.2.0
@@ -28,8 +28,8 @@
protected <T> T construct(Class<T> componentType)
{
if (componentType.isAssignableFrom(CacheSPI.class) ||
- componentType.isAssignableFrom(Configuration.class) ||
- componentType.isAssignableFrom(ComponentRegistry.class))
+ componentType.isAssignableFrom(Configuration.class) ||
+ componentType.isAssignableFrom(ComponentRegistry.class))
{
return componentType.cast(cacheSPI);
}
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactory.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,115 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.buddyreplication.BuddyGroup;
-import org.jboss.cache.commands.DataCommand;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.commands.read.ExistsCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetKeysCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.read.GravitateDataCommand;
-import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
-import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ClusteredGetCommand;
-import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
-import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ReplicateCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
-import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
-import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.commands.write.*;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jgroups.Address;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Factory for all types of cache commands.
- * Here are some of the purposes of this class:
- * <pre>
- * - not creating <code>CacheCommands</code> directly (i.e. through new
usage) as this would reduce unit testability
- * - reduce the coupling between commands and other components. e.g. considering a
commands that needs to knwo whether
- * locking type is optimistic, we will pass in a 'optimistic' boolean flag
rather than entire Configuration object
- * </pre>
- * <p/>
- * <b>Note:</b> As of 3.0, this is now an interface.
- * <p/>
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 2.2
- */
-public interface CommandsFactory
-{
- PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data);
-
- PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn, Object key,
Object value);
-
- PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx, Fqn
fqn, Object key, Object value);
-
- ReplicateCommand buildReplicateCommand(ReplicableCommand command);
-
- ReplicateCommand buildReplicateCommand(List<ReplicableCommand> modifications);
-
- PrepareCommand buildPrepareCommand(GlobalTransaction gtx, WriteCommand command,
boolean onePhaseCommit);
-
- PrepareCommand buildPrepareCommand(GlobalTransaction gtx, List<WriteCommand>
modifications, Address address, boolean onePhaseCommit);
-
- CommitCommand buildCommitCommand(GlobalTransaction gtx);
-
- DataGravitationCleanupCommand buildDataGravitationCleanupCommand(Fqn primaryFqn, Fqn
backupFqn);
-
- GravitateDataCommand buildGravitateDataCommand(Fqn fqn, Boolean searchSubtrees);
-
- RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn);
-
- ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn);
-
- EvictCommand buildEvictFqnCommand(Fqn fqn);
-
- InvalidateCommand buildInvalidateCommand(Fqn fqn);
-
- RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn, Object
key);
-
- GetDataMapCommand buildGetDataMapCommand(Fqn fqn);
-
- ExistsCommand buildExistsNodeCommand(Fqn fqn);
-
- GetKeyValueCommand buildGetKeyValueCommand(Fqn<?> fqn, Object key, boolean
sendNodeEvent);
-
- GetNodeCommand buildGetNodeCommand(Fqn fqn);
-
- GetKeysCommand buildGetKeysCommand(Fqn fqn);
-
- GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn);
-
- MoveCommand buildMoveCommand(Fqn from, Fqn to);
-
- RollbackCommand buildRollbackCommand(GlobalTransaction gtx);
-
- OptimisticPrepareCommand buildOptimisticPrepareCommand(GlobalTransaction gtx,
List<WriteCommand> modifications, Address address, boolean onePhaseCommit);
-
- AnnounceBuddyPoolNameCommand buildAnnounceBuddyPoolNameCommand(Address address, String
buddyPoolName);
-
- RemoveFromBuddyGroupCommand buildRemoveFromBuddyGroupCommand(String groupName);
-
- AssignToBuddyGroupCommand buildAssignToBuddyGroupCommand(BuddyGroup group, Map<Fqn,
byte[]> state);
-
- ClusteredGetCommand buildClusteredGetCommand(Boolean searchBackupSubtrees, DataCommand
dataCommand);
-
- CreateNodeCommand buildCreateNodeCommand(Fqn fqn);
-
- /**
- * Builds a cache command based on the ID passed in and an object array of parameters
- *
- * @param id id of the command to build
- * @param parameters parameters attached to the command
- * @return a newly constructed cache command
- */
- ReplicableCommand fromStream(int id, Object[] parameters);
-}
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,511 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.RPCManager;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.buddyreplication.BuddyGroup;
-import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.commands.DataCommand;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.commands.read.ExistsCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetKeysCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.read.GravitateDataCommand;
-import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
-import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ClusteredGetCommand;
-import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
-import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand;
-import org.jboss.cache.commands.remote.ReplicateCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
-import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
-import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.CreateNodeCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-import org.jboss.cache.commands.write.InvalidateCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.commands.write.VersionedInvalidateCommand;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.interceptors.InterceptorChain;
-import org.jboss.cache.notifications.Notifier;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionTable;
-import org.jgroups.Address;
-
-import javax.transaction.TransactionManager;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This is the implementation to use for most commands and most locking schemes.
- */
-public class CommandsFactoryImpl implements CommandsFactory
-{
- protected RPCManager rpcManager;
- protected DataContainer dataContainer;
- protected Notifier notifier;
- protected InterceptorChain invoker;
- protected BuddyManager buddyManager;
- protected TransactionTable transactionTable;
- protected CacheSPI cacheSpi;
- protected Configuration configuration;
- protected TransactionManager txManager;
- protected BuddyFqnTransformer buddyFqnTransformer;
-
- public CommandsFactoryImpl()
- {
- }
-
- @Inject
- public void initialize(RPCManager rpc, DataContainer dataContainer, Notifier notifier,
BuddyManager buddyManager,
- InterceptorChain invoker, TransactionTable transactionTable,
CacheSPI cacheSpi,
- Configuration configuration, TransactionManager txManager,
BuddyFqnTransformer buddyFqnTransformer)
- {
- this.rpcManager = rpc;
- this.dataContainer = dataContainer;
- this.notifier = notifier;
- this.buddyManager = buddyManager;
- this.invoker = invoker;
- this.transactionTable = transactionTable;
- this.cacheSpi = cacheSpi;
- this.configuration = configuration;
- this.txManager = txManager;
- this.buddyFqnTransformer = buddyFqnTransformer;
- }
-
- public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map
data)
- {
- PutDataMapCommand cmd = new PutDataMapCommand(gtx, fqn, data);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn,
Object key, Object value)
- {
- PutKeyValueCommand cmd = new PutKeyValueCommand(gtx, fqn, key, value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx,
Fqn fqn, Object key, Object value)
- {
- PutForExternalReadCommand cmd = new PutForExternalReadCommand(gtx, fqn, key,
value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public ReplicateCommand buildReplicateCommand(ReplicableCommand command)
- {
- ReplicateCommand cmd = new ReplicateCommand(command);
- cmd.initialize(invoker);
- return cmd;
- }
-
- public ReplicateCommand buildReplicateCommand(List<ReplicableCommand>
modifications)
- {
- ReplicateCommand cmd = new ReplicateCommand(modifications);
- cmd.initialize(invoker);
- return cmd;
- }
-
- public PrepareCommand buildPrepareCommand(GlobalTransaction gtx, WriteCommand command,
boolean onePhaseCommit)
- {
- return buildPrepareCommand(gtx, Collections.singletonList(command),
rpcManager.getLocalAddress(), onePhaseCommit);
- }
-
- public PrepareCommand buildPrepareCommand(GlobalTransaction gtx,
List<WriteCommand> modifications, Address address, boolean onePhaseCommit)
- {
- return new PrepareCommand(gtx, modifications, address, onePhaseCommit);
- }
-
- public CommitCommand buildCommitCommand(GlobalTransaction gtx)
- {
- return new CommitCommand(gtx);
- }
-
- public DataGravitationCleanupCommand buildDataGravitationCleanupCommand(Fqn
primaryFqn, Fqn backupFqn)
- {
- DataGravitationCleanupCommand command = new
DataGravitationCleanupCommand(primaryFqn, backupFqn);
- command.initialize(buddyManager, invoker, transactionTable, this, dataContainer,
buddyFqnTransformer);
- return command;
- }
-
- public GravitateDataCommand buildGravitateDataCommand(Fqn fqn, Boolean
searchSubtrees)
- {
- GravitateDataCommand command = new GravitateDataCommand(fqn, searchSubtrees,
rpcManager.getLocalAddress());
- command.initialize(dataContainer, cacheSpi, buddyFqnTransformer);
- return command;
- }
-
- public EvictCommand buildEvictFqnCommand(Fqn fqn)
- {
- EvictCommand command = new EvictCommand(fqn);
- command.initialize(notifier, dataContainer);
- return command;
- }
-
- public InvalidateCommand buildInvalidateCommand(Fqn fqn)
- {
- if (configuration.getNodeLockingScheme().isVersionedScheme())
- {
- VersionedInvalidateCommand command = new VersionedInvalidateCommand(fqn);
- command.initialize(txManager);
- command.initialize(cacheSpi, dataContainer, notifier);
- return command;
- }
- else
- {
- InvalidateCommand command = new InvalidateCommand(fqn);
- command.initialize(cacheSpi, dataContainer, notifier);
- return command;
- }
- }
-
- public GetDataMapCommand buildGetDataMapCommand(Fqn fqn)
- {
- GetDataMapCommand command = new GetDataMapCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public ExistsCommand buildExistsNodeCommand(Fqn fqn)
- {
- ExistsCommand command = new ExistsCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public GetKeyValueCommand buildGetKeyValueCommand(Fqn<?> fqn, Object key,
boolean sendNodeEvent)
- {
- GetKeyValueCommand command = new GetKeyValueCommand(fqn, key, sendNodeEvent);
- command.initialize(dataContainer, notifier);
- return command;
- }
-
- public GetNodeCommand buildGetNodeCommand(Fqn fqn)
- {
- GetNodeCommand command = new GetNodeCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public GetKeysCommand buildGetKeysCommand(Fqn fqn)
- {
- GetKeysCommand command = new GetKeysCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn)
- {
- GetChildrenNamesCommand command = new GetChildrenNamesCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public RollbackCommand buildRollbackCommand(GlobalTransaction gtx)
- {
- return new RollbackCommand(gtx);
- }
-
- public OptimisticPrepareCommand buildOptimisticPrepareCommand(GlobalTransaction gtx,
List<WriteCommand> modifications, Address address, boolean onePhaseCommit)
- {
- return new OptimisticPrepareCommand(gtx, modifications, address, onePhaseCommit);
- }
-
- public AnnounceBuddyPoolNameCommand buildAnnounceBuddyPoolNameCommand(Address address,
String buddyPoolName)
- {
- AnnounceBuddyPoolNameCommand command = new AnnounceBuddyPoolNameCommand(address,
buddyPoolName);
- command.initialize(buddyManager);
- return command;
- }
-
- public RemoveFromBuddyGroupCommand buildRemoveFromBuddyGroupCommand(String groupName)
- {
- RemoveFromBuddyGroupCommand command = new RemoveFromBuddyGroupCommand(groupName);
- command.initialize(buddyManager);
- return command;
- }
-
- public AssignToBuddyGroupCommand buildAssignToBuddyGroupCommand(BuddyGroup group,
Map<Fqn, byte[]> state)
- {
- AssignToBuddyGroupCommand command = new AssignToBuddyGroupCommand(group, state);
- command.initialize(buddyManager);
- return command;
- }
-
- public ClusteredGetCommand buildClusteredGetCommand(Boolean searchBackupSubtrees,
DataCommand dataCommand)
- {
- ClusteredGetCommand command = new ClusteredGetCommand(searchBackupSubtrees,
dataCommand);
- command.initialize(dataContainer, invoker);
- return command;
- }
-
- public RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn)
- {
- RemoveNodeCommand cmd = new RemoveNodeCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn)
- {
- ClearDataCommand cmd = new ClearDataCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn,
Object key)
- {
- RemoveKeyCommand cmd = new RemoveKeyCommand(tx, fqn, key);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public MoveCommand buildMoveCommand(Fqn from, Fqn to)
- {
- MoveCommand cmd = new MoveCommand(from, to);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- public CreateNodeCommand buildCreateNodeCommand(Fqn fqn)
- {
- CreateNodeCommand command = new CreateNodeCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- public ReplicableCommand fromStream(int id, Object[] parameters)
- {
- ReplicableCommand command;
- switch (id)
- {
- case ExistsCommand.METHOD_ID:
- {
- ExistsCommand result = new ExistsCommand();
- result.initialize(dataContainer);
- command = result;
- break;
- }
- case GetChildrenNamesCommand.METHOD_ID:
- {
- GetChildrenNamesCommand returnValue = new GetChildrenNamesCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case GetDataMapCommand.METHOD_ID:
- {
- GetDataMapCommand returnValue = new GetDataMapCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case GetKeysCommand.METHOD_ID:
- {
- GetKeysCommand returnValue = new GetKeysCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case GetKeyValueCommand.METHOD_ID:
- {
- GetKeyValueCommand returnValue = new GetKeyValueCommand();
- returnValue.initialize(dataContainer, notifier);
- command = returnValue;
- break;
- }
- case GetNodeCommand.METHOD_ID:
- {
- GetNodeCommand returnValue = new GetNodeCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case MoveCommand.METHOD_ID:
- {
- MoveCommand returnValue = new MoveCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutDataMapCommand.METHOD_ID:
- case PutDataMapCommand.ERASE_METHOD_ID:
- case PutDataMapCommand.ERASE_VERSIONED_METHOD_ID:
- case PutDataMapCommand.VERSIONED_METHOD_ID:
- {
- PutDataMapCommand returnValue = new PutDataMapCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutKeyValueCommand.METHOD_ID:
- case PutKeyValueCommand.VERSIONED_METHOD_ID:
- {
- PutKeyValueCommand returnValue = new PutKeyValueCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutForExternalReadCommand.METHOD_ID:
- case PutForExternalReadCommand.VERSIONED_METHOD_ID:
- {
- PutForExternalReadCommand returnValue = new PutForExternalReadCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case ClearDataCommand.METHOD_ID:
- case ClearDataCommand.VERSIONED_METHOD_ID:
- {
- ClearDataCommand returnValue = new ClearDataCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case RemoveKeyCommand.METHOD_ID:
- case RemoveKeyCommand.VERSIONED_METHOD_ID:
- {
- RemoveKeyCommand returnValue = new RemoveKeyCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
-
- case RemoveNodeCommand.METHOD_ID:
- case RemoveNodeCommand.VERSIONED_METHOD_ID:
- {
- RemoveNodeCommand returnValue = new RemoveNodeCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case CreateNodeCommand.METHOD_ID:
- {
- CreateNodeCommand returnValue = new CreateNodeCommand(null);
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- // --- transactional method calls
-
- case PrepareCommand.METHOD_ID:
- {
- command = new PrepareCommand();
- break;
- }
-
- case OptimisticPrepareCommand.METHOD_ID:
- {
- command = new OptimisticPrepareCommand();
- break;
- }
-
- case CommitCommand.METHOD_ID:
- {
- command = new CommitCommand();
- break;
- }
-
- case RollbackCommand.METHOD_ID:
- {
- command = new RollbackCommand();
- break;
- }
-
- // --- replicate methods
- case ReplicateCommand.MULTIPLE_METHOD_ID:
- case ReplicateCommand.SINGLE_METHOD_ID:
- {
- ReplicateCommand returnValue = new ReplicateCommand();
- returnValue.initialize(invoker);
- command = returnValue;
- break;
- }
-
- case InvalidateCommand.METHOD_ID:
- {
- if (configuration.getNodeLockingScheme().isVersionedScheme())
- {
- VersionedInvalidateCommand returnValue = new
VersionedInvalidateCommand();
- returnValue.initialize(txManager);
- returnValue.initialize(cacheSpi, dataContainer, notifier);
- command = returnValue;
- }
- else
- {
- InvalidateCommand returnValue = new InvalidateCommand();
- returnValue.initialize(cacheSpi, dataContainer, notifier);
- command = returnValue;
- }
- break;
- }
-
- case ClusteredGetCommand.METHOD_ID:
- {
- ClusteredGetCommand returnValue = new ClusteredGetCommand();
- returnValue.initialize(dataContainer, invoker);
- command = returnValue;
- break;
- }
- // ---- Buddy replication - group organisation commands
- case AnnounceBuddyPoolNameCommand.METHOD_ID:
- {
- AnnounceBuddyPoolNameCommand returnValue = new
AnnounceBuddyPoolNameCommand();
- returnValue.initialize(buddyManager);
- command = returnValue;
- break;
- }
- case AssignToBuddyGroupCommand.METHOD_ID:
- {
- AssignToBuddyGroupCommand returnValue = new AssignToBuddyGroupCommand();
- returnValue.initialize(buddyManager);
- command = returnValue;
- break;
- }
- case RemoveFromBuddyGroupCommand.METHOD_ID:
- {
- RemoveFromBuddyGroupCommand returnValue = new RemoveFromBuddyGroupCommand();
- returnValue.initialize(buddyManager);
- command = returnValue;
- break;
- }
- case DataGravitationCleanupCommand.METHOD_ID:
- {
- DataGravitationCleanupCommand returnValue = new
DataGravitationCleanupCommand();
- returnValue.initialize(buddyManager, invoker, transactionTable, this,
dataContainer, buddyFqnTransformer);
- command = returnValue;
- break;
- }
- case GravitateDataCommand.METHOD_ID:
- {
- GravitateDataCommand returnValue = new
GravitateDataCommand(rpcManager.getLocalAddress());
- returnValue.initialize(dataContainer, cacheSpi, buddyFqnTransformer);
- command = returnValue;
- break;
- }
- default:
- throw new CacheException("Unknown command id " + id +
"!");
- }
-
- command.setParameters(id, parameters);
- return command;
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -176,6 +176,8 @@
s.add(LockManagerFactory.class);
s.add(ContextMetaFactory.class);
s.add(CommandsMetaFactory.class);
+ s.add(StateTransferManagerFactory.class);
+ s.add(RegionManagerFactory.class);
return s;
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,7 +1,6 @@
package org.jboss.cache.factories;
import org.jboss.cache.DataContainer;
-import org.jboss.cache.RegionManager;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
@@ -13,7 +12,6 @@
import org.jboss.cache.marshall.VersionAwareMarshaller;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.ChannelMessageListener;
-import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.TransactionTable;
/**
@@ -22,7 +20,7 @@
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
* @since 2.1.0
*/
-@DefaultFactoryFor(classes = {StateTransferManager.class, RegionManager.class,
Notifier.class,
+@DefaultFactoryFor(classes = {Notifier.class,
ChannelMessageListener.class, CacheLoaderManager.class, Marshaller.class,
InvocationContextContainer.class,
CacheInvocationDelegate.class, TransactionTable.class, DataContainer.class,
LockStrategyFactory.class, BuddyFqnTransformer.class})
Deleted:
core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,22 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.legacy.write.LegacyEvictCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-
-/**
- * Extends the default commands factory impl for optimistic locking.
- *
- * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
- * @since 3.0
- */
-public class OptimisticCommandsFactoryImpl extends CommandsFactoryImpl
-{
- @Override
- public EvictCommand buildEvictFqnCommand(Fqn fqn)
- {
- EvictCommand command = new LegacyEvictCommand(fqn);
- command.initialize(notifier, dataContainer);
- return command;
- }
-}
Deleted:
core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,199 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.legacy.read.PessGetChildrenNamesCommand;
-import org.jboss.cache.commands.legacy.write.PessClearDataCommand;
-import org.jboss.cache.commands.legacy.write.PessCreateNodeCommand;
-import org.jboss.cache.commands.legacy.write.PessMoveCommand;
-import org.jboss.cache.commands.legacy.write.PessPutDataMapCommand;
-import org.jboss.cache.commands.legacy.write.PessPutForExternalReadCommand;
-import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
-import org.jboss.cache.commands.legacy.write.PessRemoveKeyCommand;
-import org.jboss.cache.commands.legacy.write.PessRemoveNodeCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.CreateNodeCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.transaction.GlobalTransaction;
-
-import java.util.Map;
-
-/**
- * This specific implementation of {@link org.jboss.cache.factories.CommandsFactory}
specifically creates
- * pessimistic commands where appropriate, with the ability to roll back.
- *
- * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
- * @see org.jboss.cache.commands.legacy.ReversibleCommand
- * @since 3.0
- */
-public class PessimisticCommandsFactoryImpl extends OptimisticCommandsFactoryImpl
-{
- @Override
- public GetChildrenNamesCommand buildGetChildrenNamesCommand(Fqn fqn)
- {
- GetChildrenNamesCommand command = new PessGetChildrenNamesCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- @Override
- public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map
data)
- {
- PutDataMapCommand cmd = new PessPutDataMapCommand(gtx, fqn, data);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public PutKeyValueCommand buildPutKeyValueCommand(GlobalTransaction gtx, Fqn fqn,
Object key, Object value)
- {
- PutKeyValueCommand cmd = new PessPutKeyValueCommand(gtx, fqn, key, value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public PutForExternalReadCommand buildPutForExternalReadCommand(GlobalTransaction gtx,
Fqn fqn, Object key, Object value)
- {
- PutForExternalReadCommand cmd = new PessPutForExternalReadCommand(gtx, fqn, key,
value);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public RemoveNodeCommand buildRemoveNodeCommand(GlobalTransaction gtx, Fqn fqn)
- {
- RemoveNodeCommand cmd = new PessRemoveNodeCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public ClearDataCommand buildClearDataCommand(GlobalTransaction gtx, Fqn fqn)
- {
- ClearDataCommand cmd = new PessClearDataCommand(gtx, fqn);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public RemoveKeyCommand buildRemoveKeyCommand(GlobalTransaction tx, Fqn<?> fqn,
Object key)
- {
- RemoveKeyCommand cmd = new PessRemoveKeyCommand(tx, fqn, key);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public MoveCommand buildMoveCommand(Fqn from, Fqn to)
- {
- MoveCommand cmd = new PessMoveCommand(from, to);
- cmd.initialize(notifier, dataContainer);
- return cmd;
- }
-
- @Override
- public CreateNodeCommand buildCreateNodeCommand(Fqn fqn)
- {
- CreateNodeCommand command = new PessCreateNodeCommand(fqn);
- command.initialize(dataContainer);
- return command;
- }
-
- @Override
- public ReplicableCommand fromStream(int id, Object[] parameters)
- {
- ReplicableCommand command;
- boolean skipSetParams = false;
- switch (id)
- {
- case GetChildrenNamesCommand.METHOD_ID:
- {
- GetChildrenNamesCommand returnValue = new PessGetChildrenNamesCommand();
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- case MoveCommand.METHOD_ID:
- {
- MoveCommand returnValue = new PessMoveCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutDataMapCommand.METHOD_ID:
- case PutDataMapCommand.ERASE_METHOD_ID:
- case PutDataMapCommand.ERASE_VERSIONED_METHOD_ID:
- case PutDataMapCommand.VERSIONED_METHOD_ID:
- {
- PutDataMapCommand returnValue = new PessPutDataMapCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutKeyValueCommand.METHOD_ID:
- case PutKeyValueCommand.VERSIONED_METHOD_ID:
- {
- PutKeyValueCommand returnValue = new PessPutKeyValueCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case PutForExternalReadCommand.METHOD_ID:
- case PutForExternalReadCommand.VERSIONED_METHOD_ID:
- {
- PutForExternalReadCommand returnValue = new PessPutForExternalReadCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case ClearDataCommand.METHOD_ID:
- case ClearDataCommand.VERSIONED_METHOD_ID:
- {
- ClearDataCommand returnValue = new PessClearDataCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case RemoveKeyCommand.METHOD_ID:
- case RemoveKeyCommand.VERSIONED_METHOD_ID:
- {
- RemoveKeyCommand returnValue = new PessRemoveKeyCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
-
- case RemoveNodeCommand.METHOD_ID:
- case RemoveNodeCommand.VERSIONED_METHOD_ID:
- {
- RemoveNodeCommand returnValue = new PessRemoveNodeCommand();
- returnValue.initialize(notifier, dataContainer);
- command = returnValue;
- break;
- }
- case CreateNodeCommand.METHOD_ID:
- {
- CreateNodeCommand returnValue = new PessCreateNodeCommand(null);
- returnValue.initialize(dataContainer);
- command = returnValue;
- break;
- }
- default:
- // pass up to superclass
- command = super.fromStream(id, parameters);
- skipSetParams = true;
- }
- if (!skipSetParams)
- {
- command.setParameters(id, parameters);
- }
- return command;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -0,0 +1,28 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.LegacyRegionManagerImpl;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
+import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+
+/**
+ * Creates region managers
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+@DefaultFactoryFor(classes = RegionManager.class)
+public class RegionManagerFactory extends ComponentFactory
+{
+ @SuppressWarnings("unchecked")
+ protected <T> T construct(Class<T> componentType)
+ {
+ switch (configuration.getNodeLockingScheme())
+ {
+ case MVCC:
+ return (T) new RegionManagerImpl();
+ default:
+ return (T) new LegacyRegionManagerImpl();
+ }
+ }
+}
\ No newline at end of file
Added:
core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -0,0 +1,28 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
+import org.jboss.cache.statetransfer.LegacyStateTransferManager;
+import org.jboss.cache.statetransfer.StateTransferManager;
+
+/**
+ * Constructs {@link org.jboss.cache.statetransfer.StateTransferManager} instances.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+@DefaultFactoryFor(classes = StateTransferManager.class)
+public class StateTransferManagerFactory extends ComponentFactory
+{
+ @SuppressWarnings("unchecked")
+ protected <T> T construct(Class<T> componentType)
+ {
+ switch (configuration.getNodeLockingScheme())
+ {
+ case MVCC:
+ return (T) new DefaultStateTransferManager();
+ default:
+ return (T) new LegacyStateTransferManager();
+ }
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-07-07 20:50:09
UTC (rev 6198)
+++ core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-07-07 21:21:24
UTC (rev 6199)
@@ -224,7 +224,7 @@
public void unlockAll(NodeSPI node)
{
- throw new UnsupportedOperationException("Not supported in this impl.");
+ unlockAll(node, null);
}
public boolean ownsLock(Fqn fqn, LockType lockType, Object owner)
Modified:
core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/ChannelMessageListener.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -7,6 +7,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.NonVolatile;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.util.ExposedByteArrayOutputStream;
import org.jboss.util.stream.MarshalledValueInputStream;
@@ -186,10 +187,10 @@
String sourceRoot = state_id;
byte[] result;
- boolean hasDifferentSourceAndIntegrationRoots =
state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots =
state_id.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
+ sourceRoot =
state_id.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[0];
}
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
@@ -234,10 +235,10 @@
{
String sourceRoot = state_id;
MarshalledValueOutputStream out = null;
- boolean hasDifferentSourceAndIntegrationRoots =
state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots =
state_id.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
+ sourceRoot =
state_id.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[0];
}
try
{
@@ -293,10 +294,10 @@
MarshalledValueInputStream in = null;
String targetRoot = state_id;
- boolean hasDifferentSourceAndIntegrationRoots =
state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots =
state_id.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- targetRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
+ targetRoot =
state_id.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[1];
}
try
{
@@ -335,10 +336,10 @@
if (log.isTraceEnabled()) log.trace("**** Receiving state for " +
stateId);
String targetRoot = stateId;
MarshalledValueInputStream in = null;
- boolean hasDifferentSourceAndIntegrationRoots =
stateId.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ boolean hasDifferentSourceAndIntegrationRoots =
stateId.indexOf(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
if (hasDifferentSourceAndIntegrationRoots)
{
- targetRoot = stateId.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
+ targetRoot =
stateId.split(DefaultStateTransferManager.PARTIAL_STATE_DELIMITER)[1];
}
if (istream == null)
{
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -42,7 +42,7 @@
}
public void generateState(ObjectOutputStream out, Node rootNode, boolean
generateTransient,
- boolean generatePersistent, boolean suppressErrors) throws
Throwable
+ boolean generatePersistent, boolean suppressErrors) throws
Exception
{
Fqn fqn = rootNode.getFqn();
try
@@ -109,10 +109,10 @@
}
delimitStream(out);
}
- catch (Throwable t)
+ catch (Exception e)
{
- cache.getMarshaller().objectToObjectStream(new NodeDataExceptionMarker(t,
cache.getLocalAddress()), out);
- throw t;
+ cache.getMarshaller().objectToObjectStream(new NodeDataExceptionMarker(e,
cache.getLocalAddress()), out);
+ throw e;
}
}
@@ -124,7 +124,7 @@
*/
protected void delimitStream(ObjectOutputStream out) throws Exception
{
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
out);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
out);
}
/**
Copied:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
(from rev 6183,
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java)
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -0,0 +1,231 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.statetransfer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.RegionEmptyException;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.marshall.InactiveRegionException;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.marshall.NodeDataMarker;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * The default state transfer manager to be used when using MVCC locking.
+ */
+public class DefaultStateTransferManager implements StateTransferManager
+{
+ protected final static Log log =
LogFactory.getLog(DefaultStateTransferManager.class);
+
+ public static final NodeData STREAMING_DELIMITER_NODE = new NodeDataMarker();
+
+ public static final String PARTIAL_STATE_DELIMITER =
"_PARTIAL_STATE_DELIMITER";
+
+ protected CacheSPI cache;
+ protected Marshaller marshaller;
+ protected RegionManager regionManager;
+ protected Configuration configuration;
+ private CacheLoaderManager cacheLoaderManager;
+ private boolean fetchTransientState;
+ private boolean fetchPersistentState;
+ private long stateRetrievalTimeout;
+
+
+ @Inject
+ public void injectDependencies(CacheSPI cache, Marshaller marshaller, RegionManager
regionManager, Configuration configuration, CacheLoaderManager cacheLoaderManager)
+ {
+ this.cache = cache;
+ this.regionManager = regionManager;
+ this.marshaller = marshaller;
+ this.configuration = configuration;
+ this.cacheLoaderManager = cacheLoaderManager;
+ }
+
+ @Start(priority = 99)
+ public void start()
+ {
+ fetchTransientState = configuration.isFetchInMemoryState();
+ fetchPersistentState = cacheLoaderManager != null &&
cacheLoaderManager.isFetchPersistentState();
+ stateRetrievalTimeout = configuration.getStateRetrievalTimeout();
+ }
+
+ public void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force,
boolean suppressErrors) throws Exception
+ {
+ // can't give state for regions currently being activated/inactivated
+ boolean canProvideState = (!regionManager.isInactive(fqn) &&
cache.peek(fqn, false) != null);
+
+ if (canProvideState && (fetchPersistentState || fetchTransientState))
+ {
+ marshaller.objectToObjectStream(true, out);
+ StateTransferGenerator generator = getStateTransferGenerator();
+ long startTime = System.currentTimeMillis();
+ NodeSPI rootNode = cache.peek(fqn, false, false);
+
+ try
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("locking the " + fqn + " subtree to return the
in-memory (transient) state");
+ }
+ acquireLocksForStateTransfer(rootNode, timeout, force);
+ generator.generateState(out, rootNode, fetchTransientState,
fetchPersistentState, suppressErrors);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Successfully generated state in " +
(System.currentTimeMillis() - startTime) + " msec");
+ }
+ }
+ finally
+ {
+ releaseStateTransferLocks(rootNode);
+ }
+ }
+ else
+ {
+ marshaller.objectToObjectStream(false, out);
+ Exception e = null;
+ if (!canProvideState)
+ {
+ String exceptionMessage = "Cache instance at " +
cache.getLocalAddress() + " cannot provide state for fqn " + fqn +
".";
+
+ if (regionManager.isInactive(fqn))
+ {
+ exceptionMessage += " Region for fqn " + fqn + " is
inactive.";
+ e = new InactiveRegionException(exceptionMessage);
+ }
+ // this is not really an exception. Just provide empty state. The exception
is just a signal. Yes, lousy. - JBCACHE-1349
+ if (cache.peek(fqn, false, false) == null)
+ {
+ e = new RegionEmptyException();
+ }
+ }
+ if (!fetchPersistentState && !fetchTransientState)
+ {
+ e = new CacheException("Cache instance at " +
cache.getLocalAddress() + " is not configured to provide state");
+ }
+ marshaller.objectToObjectStream(e, out);
+ if (e != null) throw e;
+ }
+ }
+
+ public void setState(ObjectInputStream in, Fqn targetRoot) throws Exception
+ {
+ NodeSPI target = cache.peek(targetRoot, false, false);
+ if (target == null)
+ {
+ // Create the integration root, but do not replicate
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+
+ //needed for BR state transfers
+
cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
+ cache.put(targetRoot, null);
+ target = cache.peek(targetRoot, false, false);
+ }
+ Object o = marshaller.objectFromObjectStream(in);
+ Boolean hasState = (Boolean) o;
+ if (hasState)
+ {
+ setState(in, target);
+ }
+ else
+ {
+ throw new CacheException("Cache instance at " +
cache.getLocalAddress()
+ + " cannot integrate state since state provider could not provide
state due to " + marshaller.objectFromObjectStream(in));
+ }
+ }
+
+ /**
+ * Set the portion of the cache rooted in <code>targetRoot</code>
+ * to match the given state. Updates the contents of
<code>targetRoot</code>
+ * to reflect those in <code>new_state</code>.
+ * <p/>
+ * <strong>NOTE:</strong> This method performs no locking of nodes; it
+ * is up to the caller to lock <code>targetRoot</code> before calling
+ * this method.
+ *
+ * @param state a serialized byte[][] array where element 0 is the
+ * transient state (or null) , and element 1 is the
+ * persistent state (or null)
+ * @param targetRoot node into which the state should be integrated
+ */
+ private void setState(ObjectInputStream state, NodeSPI targetRoot) throws Exception
+ {
+ long startTime = System.currentTimeMillis();
+
+ try
+ {
+ // Acquire a lock on the root node
+ acquireLocksForStateTransfer(targetRoot, stateRetrievalTimeout, true);
+
+ /*
+ * Vladimir/Manik/Brian (Dec 7,2006)
+ *
+ * integrator.integrateState(in,targetRoot, cl) will call cache.put for each
+ * node read from stream. Having option override below allows nodes read
+ * to be directly stored into a tree since we bypass interceptor chain.
+ *
+ */
+
+// Option option = new Option();
+// option.setBypassInterceptorChain(true);
+// cache.getInvocationContext().setOptionOverrides(option);
+//
+ StateTransferIntegrator integrator = getStateTransferIntegrator(state,
targetRoot.getFqn());
+ if (log.isDebugEnabled())
+ {
+ log.debug("starting state integration at node " + targetRoot);
+ }
+ integrator.integrateState(state, targetRoot);
+ if (log.isDebugEnabled())
+ {
+ log.debug("successfully integrated state in " +
(System.currentTimeMillis() - startTime) + " msec");
+ }
+ }
+ finally
+ {
+ releaseStateTransferLocks(targetRoot);
+ }
+ }
+
+
+ /**
+ * Acquires locks on a root node for an owner for state transfer.
+ */
+ protected void acquireLocksForStateTransfer(NodeSPI root, long timeout, boolean force)
throws InterruptedException
+ {
+ // no op
+ }
+
+ /**
+ * Releases all state transfer locks acquired.
+ */
+ protected void releaseStateTransferLocks(NodeSPI root)
+ {
+ // no op
+ }
+
+ protected StateTransferGenerator getStateTransferGenerator()
+ {
+ return StateTransferFactory.getStateTransferGenerator(cache);
+ }
+
+ protected StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream
istream, Fqn fqn) throws Exception
+ {
+ return StateTransferFactory.getStateTransferIntegrator(istream, fqn, cache);
+ }
+}
Property changes on:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferManager.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -0,0 +1,66 @@
+package org.jboss.cache.statetransfer;
+
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.lock.LockManager;
+import static org.jboss.cache.lock.LockType.READ;
+import org.jboss.cache.lock.TimeoutException;
+
+/**
+ * This is to support legacy locking schemes such as Pessimistic and Optimistic locking.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public class LegacyStateTransferManager extends DefaultStateTransferManager
+{
+ protected LockManager lockManager;
+
+ @Inject
+ public void injectLockManager(LockManager lockManager)
+ {
+ this.lockManager = lockManager;
+ }
+
+ @Override
+ protected void acquireLocksForStateTransfer(NodeSPI root, long timeout, boolean force)
throws InterruptedException
+ {
+ try
+ {
+ lockManager.lockAll(root, READ, getLockOwner(), timeout, true);
+ }
+ catch (TimeoutException te)
+ {
+ log.error("Caught TimeoutException acquiring locks on region " +
+ root.getFqn(), te);
+ if (force)
+ {
+ throw te;
+ }
+ else
+ {
+ throw te;
+ }
+ }
+ }
+
+ @Override
+ protected void releaseStateTransferLocks(NodeSPI root)
+ {
+ try
+ {
+ lockManager.unlockAll(root, getLockOwner());
+ }
+ catch (Throwable t)
+ {
+ log.error("failed releasing locks", t);
+ }
+ }
+
+ private Object getLockOwner()
+ {
+ Object owner = cache.getCurrentTransaction();
+ if (owner == null) owner = Thread.currentThread();
+ return owner;
+ }
+}
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferGenerator.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -10,10 +10,11 @@
import java.io.ObjectOutputStream;
+/**
+ * @since 1.2.4
+ */
public interface StateTransferGenerator
{
+ void generateState(ObjectOutputStream stream, Node rootNode, boolean
generateTransient, boolean generatePersistent, boolean suppressErrors) throws Exception;
- void generateState(ObjectOutputStream stream, Node rootNode, boolean
generateTransient,
- boolean generatePersistent, boolean suppressErrors) throws
Throwable;
-
}
\ No newline at end of file
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferIntegrator.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -10,6 +10,9 @@
import java.io.ObjectInputStream;
+/**
+ * @since 1.2.4
+ */
public interface StateTransferIntegrator
{
Deleted: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,334 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-package org.jboss.cache.statetransfer;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.RegionEmptyException;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.NonVolatile;
-import org.jboss.cache.loader.CacheLoaderManager;
-import org.jboss.cache.lock.LockManager;
-import static org.jboss.cache.lock.LockType.READ;
-import org.jboss.cache.lock.TimeoutException;
-import org.jboss.cache.marshall.InactiveRegionException;
-import org.jboss.cache.marshall.Marshaller;
-import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.marshall.NodeDataMarker;
-
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-@NonVolatile
-public class StateTransferManager
-{
- protected final static Log log = LogFactory.getLog(StateTransferManager.class);
-
- public static final NodeData STREAMING_DELIMITER_NODE = new NodeDataMarker();
-
- public static final String PARTIAL_STATE_DELIMITER =
"_PARTIAL_STATE_DELIMITER";
-
- private CacheSPI cache;
- private Marshaller marshaller;
- private RegionManager regionManager;
- private Configuration configuration;
- private LockManager lockManager;
-
- public StateTransferManager()
- {
- }
-
- @Inject
- public void injectDependencies(CacheSPI cache, Marshaller marshaller, RegionManager
regionManager, Configuration configuration, LockManager lockManager)
- {
- this.cache = cache;
- this.regionManager = regionManager;
- this.marshaller = marshaller;
- this.configuration = configuration;
- this.lockManager = lockManager;
- }
-
- public StateTransferManager(CacheSPI cache)
- {
- this.cache = cache;
- }
-
- /**
- * Writes the state for the portion of the tree named by <code>fqn</code>
to
- * the provided OutputStream.
- * <p/>
- * <p/>
- *
- * @param out stream to write state to
- * @param fqn Fqn indicating the uppermost node in the
- * portion of the tree whose state should be returned.
- * @param timeout max number of ms this method should wait to acquire
- * a read lock on the nodes being transferred
- * @param force if a read lock cannot be acquired after
- * <code>timeout</code> ms, should the lock
acquisition
- * be forced, and any existing transactions holding locks
- * on the nodes be rolled back?
<strong>NOTE:</strong>
- * In release 1.2.4, this parameter has no effect.
- * @param suppressErrors should any Throwable thrown be suppressed?
- * @throws Throwable in event of error
- */
- public void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force,
boolean suppressErrors) throws Throwable
- {
- // can't give state for regions currently being activated/inactivated
- boolean canProvideState = (!regionManager.isInactive(fqn) &&
cache.peek(fqn, false) != null);
-
- boolean fetchTransientState = configuration.isFetchInMemoryState();
- CacheLoaderManager cacheLoaderManager = cache.getCacheLoaderManager();
- boolean fetchPersistentState = cacheLoaderManager != null &&
cacheLoaderManager.isFetchPersistentState();
-
- if (canProvideState && (fetchPersistentState || fetchTransientState))
- {
- marshaller.objectToObjectStream(true, out);
- StateTransferGenerator generator = getStateTransferGenerator();
- Object owner = getOwnerForLock();
- long startTime = System.currentTimeMillis();
- NodeSPI rootNode = cache.peek(fqn, false, false);
-
- try
- {
- if (log.isDebugEnabled())
- {
- log.debug("locking the " + fqn + " subtree to return the
in-memory (transient) state");
- }
- acquireLocksForStateTransfer(rootNode, owner, timeout, true, force);
- generator.generateState(out, rootNode, fetchTransientState,
fetchPersistentState, suppressErrors);
- if (log.isDebugEnabled())
- {
- log.debug("Successfully generated state in " +
(System.currentTimeMillis() - startTime) + " msec");
- }
- }
- finally
- {
- releaseStateTransferLocks(rootNode, owner, true);
- }
- }
- else
- {
- marshaller.objectToObjectStream(false, out);
- Exception e = null;
- if (!canProvideState)
- {
- String exceptionMessage = "Cache instance at " +
cache.getLocalAddress() + " cannot provide state for fqn " + fqn +
".";
-
- if (regionManager.isInactive(fqn))
- {
- exceptionMessage += " Region for fqn " + fqn + " is
inactive.";
- e = new InactiveRegionException(exceptionMessage);
- }
- // this is not really an exception. Just provide empty state. The exception
is just a signal. Yes, lousy. - JBCACHE-1349
- if (cache.peek(fqn, false, false) == null)
- {
- e = new RegionEmptyException();
- }
- }
- if (!fetchPersistentState && !fetchTransientState)
- {
- e = new CacheException("Cache instance at " +
cache.getLocalAddress() + " is not configured to provide state");
- }
- marshaller.objectToObjectStream(e, out);
- if (e != null) throw e;
- }
- }
-
- /**
- * Set the portion of the cache rooted in <code>targetRoot</code>
- * to match the given state. Updates the contents of
<code>targetRoot</code>
- * to reflect those in <code>new_state</code>.
- * <p/>
- * <strong>NOTE:</strong> This method performs no locking of nodes; it
- * is up to the caller to lock <code>targetRoot</code> before calling
- * this method.
- * <p/>
- * This method will use any {@link ClassLoader} needed as defined by the active {@link
org.jboss.cache.Region}
- * in the {@link org.jboss.cache.RegionManager}, pertaining to the targetRoot passed
in.
- *
- * @param in an input stream containing the state
- * @param targetRoot fqn of the node into which the state should be integrated
- * @throws Exception In event of error
- */
- public void setState(ObjectInputStream in, Fqn targetRoot) throws Exception
- {
- NodeSPI target = cache.peek(targetRoot, false, false);
- if (target == null)
- {
- // Create the integration root, but do not replicate
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
-
- //needed for BR state transfers
-
cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
- cache.put(targetRoot, null);
- target = cache.peek(targetRoot, false, false);
- }
- Object o = marshaller.objectFromObjectStream(in);
- Boolean hasState = (Boolean) o;
- if (hasState)
- {
- setState(in, target);
- }
- else
- {
- throw new CacheException("Cache instance at " +
cache.getLocalAddress()
- + " cannot integrate state since state provider could not provide
state due to " + marshaller.objectFromObjectStream(in));
- }
- }
-
- /**
- * Set the portion of the cache rooted in <code>targetRoot</code>
- * to match the given state. Updates the contents of
<code>targetRoot</code>
- * to reflect those in <code>new_state</code>.
- * <p/>
- * <strong>NOTE:</strong> This method performs no locking of nodes; it
- * is up to the caller to lock <code>targetRoot</code> before calling
- * this method.
- *
- * @param state a serialized byte[][] array where element 0 is the
- * transient state (or null) , and element 1 is the
- * persistent state (or null)
- * @param targetRoot node into which the state should be integrated
- */
- private void setState(ObjectInputStream state, NodeSPI targetRoot) throws Exception
- {
- Object owner = getOwnerForLock();
- long timeout = configuration.getStateRetrievalTimeout();
- long startTime = System.currentTimeMillis();
-
- try
- {
- // Acquire a lock on the root node
- acquireLocksForStateTransfer(targetRoot, owner, timeout, true, true);
-
- /*
- * Vladimir/Manik/Brian (Dec 7,2006)
- *
- * integrator.integrateState(in,targetRoot, cl) will call cache.put for each
- * node read from stream. Having option override below allows nodes read
- * to be directly stored into a tree since we bypass interceptor chain.
- *
- */
-
-// Option option = new Option();
-// option.setBypassInterceptorChain(true);
-// cache.getInvocationContext().setOptionOverrides(option);
-//
- StateTransferIntegrator integrator = getStateTransferIntegrator(state,
targetRoot.getFqn());
- if (log.isDebugEnabled())
- {
- log.debug("starting state integration at node " + targetRoot);
- }
- integrator.integrateState(state, targetRoot);
- if (log.isDebugEnabled())
- {
- log.debug("successfully integrated state in " +
(System.currentTimeMillis() - startTime) + " msec");
- }
- }
- finally
- {
- releaseStateTransferLocks(targetRoot, owner, true);
- }
- }
-
-
- /**
- * Acquires locks on a root node for an owner for state transfer.
- */
- protected void acquireLocksForStateTransfer(NodeSPI root,
- Object lockOwner,
- long timeout,
- boolean lockChildren,
- boolean force)
- throws Exception
- {
- try
- {
- if (lockChildren)
- {
- lockManager.lockAll(root, READ, lockOwner, timeout, true);
- }
- else
- {
- lockManager.lock(Fqn.ROOT, READ, lockOwner, timeout);
- }
- }
- catch (TimeoutException te)
- {
- log.error("Caught TimeoutException acquiring locks on region " +
- root.getFqn(), te);
- if (force)
- {
- // Until we have FLUSH in place, don't force locks
- // forceAcquireLock(root, lockOwner, lockChildren);
- throw te;
-
- }
- else
- {
- throw te;
- }
- }
- }
-
- /**
- * Releases all state transfer locks acquired.
- *
- * @see #acquireLocksForStateTransfer
- */
- protected void releaseStateTransferLocks(NodeSPI root,
- Object lockOwner,
- boolean childrenLocked)
- {
- try
- {
- if (childrenLocked)
- {
- lockManager.unlockAll(root, lockOwner);
- }
- else
- {
- lockManager.unlock(Fqn.ROOT, lockOwner);
- }
- }
- catch (Throwable t)
- {
- log.error("failed releasing locks", t);
- }
- }
-
- protected StateTransferGenerator getStateTransferGenerator()
- {
- return StateTransferFactory.getStateTransferGenerator(cache);
- }
-
- protected StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream
istream, Fqn fqn) throws Exception
- {
- return StateTransferFactory.getStateTransferIntegrator(istream, fqn, cache);
- }
-
- /**
- * Returns an object suitable for use in node locking, either the current
- * transaction or the current thread if there is no transaction.
- */
- private Object getOwnerForLock()
- {
- Object owner = cache.getCurrentTransaction();
- if (owner == null)
- {
- owner = Thread.currentThread();
- }
- return owner;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -0,0 +1,58 @@
+package org.jboss.cache.statetransfer;
+
+import org.jboss.cache.Fqn;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * This interface handles requests to generate or integrate state from neighbouring
caches in a cluster.
+ * <p/>
+ * This has existed prior to 3.0.0 as a concrete class. An interface was introduced in
3.0.0 to provide more flexibility
+ * in state transfer implementations.
+ * <p/>
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public interface StateTransferManager
+{
+ /**
+ * Writes the state for the portion of the tree named by <code>fqn</code>
to
+ * the provided OutputStream.
+ * <p/>
+ * <p/>
+ *
+ * @param out stream to write state to
+ * @param fqn Fqn indicating the uppermost node in the
+ * portion of the tree whose state should be returned.
+ * @param timeout max number of millis this method should wait to acquire
+ * any locks, if necessary, on the nodes being transferred
+ * @param force if locks are needed and cannot be acquired after
+ * <code>timeout</code> millis, should the lock
acquisition
+ * be forced, and any existing transactions holding locks
+ * on the nodes be rolled back?
+ * @param suppressErrors if true, all exceptions are logged but not propagated.
+ * @throws Exception in event of error
+ */
+ void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force, boolean
suppressErrors) throws Exception;
+
+ /**
+ * Set the portion of the cache rooted in <code>targetRoot</code>
+ * to match the given state. Updates the contents of
<code>targetRoot</code>
+ * to reflect those in <code>new_state</code>.
+ * <p/>
+ * <strong>NOTE:</strong> This method performs no locking of nodes; it
+ * is up to the caller to lock <code>targetRoot</code> before calling
+ * this method.
+ * <p/>
+ * This method will use any {@link ClassLoader} needed as defined by the active {@link
org.jboss.cache.Region}
+ * in the {@link org.jboss.cache.RegionManager}, pertaining to the targetRoot passed
in.
+ *
+ * @param in an input stream containing the state
+ * @param targetRoot fqn of the node into which the state should be integrated
+ * @throws Exception In event of error
+ */
+ void setState(ObjectInputStream in, Fqn targetRoot) throws Exception;
+
+}
Modified:
core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/config/EvictionRegionConfigurationTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -7,18 +7,17 @@
package org.jboss.cache.config;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
+import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.LRUPolicy;
import static org.testng.AssertJUnit.fail;
+import org.testng.annotations.Test;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.eviction.LRUPolicy;
-import org.testng.annotations.Test;
-
/**
* @author <a href="mailto:brian.stansberry@jboss.org">Brian
Stansberry</a>
*/
@@ -29,27 +28,27 @@
* This test duplicates the way the JBoss Microcontainer goes about
* building up an eviction config, and checks that at the
* end of the process there is only one _default_ region configured.
- *
+ *
* @throws Exception
*/
public void testDuplicateDefaultRegion() throws Exception
{
EvictionConfig ec = new EvictionConfig();
ec.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
-
+
List<EvictionRegionConfig> ercs = ec.getEvictionRegionConfigs();
-
+
EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionFqn(RegionManager.DEFAULT_REGION);
+ erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
EvictionPolicy policy = LRUPolicy.class.newInstance();
erc.setEvictionPolicyConfig(policy.getEvictionConfigurationClass().newInstance());
-
+
ercs.add(erc);
-
+
ec.setEvictionRegionConfigs(ercs);
-
+
ercs = ec.getEvictionRegionConfigs();
-
+
Set<Fqn> fqns = new HashSet<Fqn>();
for (EvictionRegionConfig cfg : ercs)
{
@@ -57,6 +56,6 @@
fail("duplicate region fqn " + cfg.getRegionFqn());
fqns.add(cfg.getRegionFqn());
}
-
+
}
}
Modified:
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -1,15 +1,15 @@
package org.jboss.cache.config.parsing;
-import org.testng.annotations.Test;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.eviction.MRUConfiguration;
-import org.jboss.cache.eviction.LRUConfiguration;
+import org.testng.annotations.Test;
import org.w3c.dom.Element;
/**
@@ -115,8 +115,8 @@
" </eviction>";
EvictionConfig evConfig = getEvictionConfig(xml);
EvictionRegionConfig evictionRegionConfig =
evConfig.getEvictionRegionConfigs().get(0);
- assert
evictionRegionConfig.getRegionName().equals(RegionManager.DEFAULT_REGION.toString());
- assert
evictionRegionConfig.getRegionName().equals(RegionManager.DEFAULT_REGION.toString());
+ assert
evictionRegionConfig.getRegionName().equals(RegionManagerImpl.DEFAULT_REGION.toString());
+ assert
evictionRegionConfig.getRegionName().equals(RegionManagerImpl.DEFAULT_REGION.toString());
assert ((LRUConfiguration)
evictionRegionConfig.getEvictionPolicyConfig()).getTimeToLiveSeconds() == 1000;
assert ((LRUConfiguration)
evictionRegionConfig.getEvictionPolicyConfig()).getTimeToLive() == 1000000;
}
@@ -140,7 +140,8 @@
{
getEvictionConfig(xml);
assert false : "exception expected as wake up interval is not set";
- } catch (ConfigurationException e)
+ }
+ catch (ConfigurationException e)
{
//expected
}
@@ -162,7 +163,8 @@
{
getEvictionConfig(xml);
assert false : "missing policy in both default and region, exception
expected.";
- } catch (MissingPolicyException e)
+ }
+ catch (MissingPolicyException e)
{
//expected
}
@@ -174,7 +176,8 @@
try
{
el = XmlConfigHelper.stringToElement(xml);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new ConfigurationException(e);
}
@@ -197,8 +200,9 @@
try
{
getEvictionConfig(xml);
- assert false : " excewption expectecd as root does not have a eviction
policy defined";
- } catch (MissingPolicyException e)
+ assert false : " excewption expectecd as root does not have a eviction
policy defined";
+ }
+ catch (MissingPolicyException e)
{
//expected
}
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -21,69 +21,69 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionPolicyConfig;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
/**
* Tests BaseEvictionAlgorithm class.
- *
+ *
* @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
*/
@Test(groups = "functional")
public class BaseEvictionAlgorithmTest
{
- private static final Log log = LogFactory.getLog(BaseEvictionAlgorithmTest.class);
-
+ private static final Log log = LogFactory.getLog(BaseEvictionAlgorithmTest.class);
+
private RegionManager regionManager;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
}
-
+
public void testFillUpRecycleQueue() throws Exception
{
final int recycleQueueCapacity = 10;
/* override recycle queue capacity to make the test shorter */
BaseEvictionAlgorithm algorithm = new MockEvictionAlgorithm(recycleQueueCapacity);
-
+
Region region = regionManager.getRegion("/a/b/c", true);
region.setEvictionPolicy(new MockEvictionPolicyConfig());
-
- for (int i = 0; i < (recycleQueueCapacity + 1); i ++)
+
+ for (int i = 0; i < (recycleQueueCapacity + 1); i++)
{
Fqn<String> fqn = Fqn.fromString("/a/b/c/" + Integer.toString(i
+ 1));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
}
-
+
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> future = executor.submit(new ProcessEvictionRegion(region,
algorithm));
-
+
try
{
future.get(20, TimeUnit.SECONDS);
}
- catch(TimeoutException te)
+ catch (TimeoutException te)
{
log.error("Region eviction processing did not finish on time", te);
fail("Region eviction processing should have finished by now, something is
wrong. Recycle queue may have filled up.");
@@ -93,16 +93,18 @@
log.info("recycle queue size: " + algorithm.recycleQueue.size());
}
}
-
- /** Classes **/
-
+
+ /**
+ * Classes *
+ */
+
public static class MockEvictionAlgorithm extends BaseEvictionAlgorithm
{
public MockEvictionAlgorithm(int recycleQueueCapacity)
{
recycleQueue = new LinkedBlockingQueue<Fqn>(recycleQueueCapacity);
}
-
+
@Override
protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
{
@@ -115,12 +117,12 @@
/* all node entries need evicting */
return true;
}
-
+
}
public static class MockEvictionPolicy extends BaseEvictionPolicy
{
-
+
@Override
public void evict(Fqn fqn) throws Exception
{
@@ -143,7 +145,7 @@
return MockEvictionPolicyConfig.class;
}
}
-
+
public static class MockEvictionPolicyConfig implements EvictionPolicyConfig
{
@@ -160,15 +162,15 @@
public void validate() throws ConfigurationException
{
/* no op */
- }
+ }
}
-
+
public class ProcessEvictionRegion implements Callable<Void>
{
private Region region;
-
+
private EvictionAlgorithm algorithm;
-
+
public ProcessEvictionRegion(Region region, EvictionAlgorithm algorithm)
{
this.region = region;
@@ -181,12 +183,12 @@
{
algorithm.process(region);
}
- catch(EvictionException e)
+ catch (EvictionException e)
{
log.error("Eviction exception reported", e);
fail("Eviction exception reported" + e);
}
-
+
return null;
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -6,15 +6,16 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.util.Iterator;
-
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.Iterator;
+
/**
* @author Daniel Huang
* @version $Revision$
@@ -29,7 +30,7 @@
public void setUp() throws Exception
{
algo = new ElementSizeAlgorithm();
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
ElementSizeConfiguration config = new ElementSizeConfiguration();
// We have to setCache maxElementsPerNode!!
config.setMaxElementsPerNode(0);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -6,16 +6,17 @@
*/
package org.jboss.cache.eviction;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.util.Iterator;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
-import org.jboss.cache.RegionManager;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
/**
* Unit tests for FIFOAlgorithm.
*
@@ -36,7 +37,7 @@
FIFOConfiguration config = new FIFOConfiguration();
// We have to setCache maxNodes!!
config.setMaxNodes(0);
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -9,6 +9,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -32,7 +33,7 @@
{
algo = new LFUAlgorithm();
LFUConfiguration config = new LFUConfiguration();
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
// doesn't this need a cache?!?? :-/
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -5,6 +5,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
@@ -34,7 +35,7 @@
// We have to setCache timeToLiveSeconds!!
config.setTimeToLiveSeconds(0);
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -6,15 +6,14 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
/**
* Unit tests for MRUAlgorithm.
*
@@ -35,7 +34,7 @@
// We have to setCache maxNodes!!
config.setMaxNodes(0);
config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- regionManager = new RegionManager();
+ regionManager = new RegionManagerImpl();
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -3,23 +3,19 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParser;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.interceptors.EvictionInterceptor;
-import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.util.TestingUtil;
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 org.w3c.dom.Element;
import javax.transaction.TransactionManager;
import java.util.Iterator;
@@ -65,7 +61,7 @@
lruConfiguration.setMaxNodes(10);
lruConfiguration.setTimeToLive(0);
lruConfiguration.setMaxAge(0);
- EvictionRegionConfig erConfig1 = new
EvictionRegionConfig(RegionManager.DEFAULT_REGION, lruConfiguration);
+ EvictionRegionConfig erConfig1 = new
EvictionRegionConfig(RegionManagerImpl.DEFAULT_REGION, lruConfiguration);
LRUConfiguration lruConfiguration2 = new LRUConfiguration();
lruConfiguration2.setMaxNodes(10);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -3,15 +3,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParser;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
import java.util.List;
@@ -44,7 +40,7 @@
public void testCreateRegion()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
@@ -58,7 +54,7 @@
public void testCreateRegion2()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
regionManager.getRegion(A_B, true).setEvictionPolicy(config);
@@ -83,7 +79,7 @@
public void testNoDefaultRegion()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
regionManager.getRegion(A_B, true).setEvictionPolicy(config);
@@ -93,7 +89,7 @@
public void testGetRegion()
{
- RegionManager regionManager = new RegionManager();
+ RegionManager regionManager = new RegionManagerImpl();
regionManager.setUsingEvictions(true);
regionManager.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
regionManager.getRegion(A_BC, true).setEvictionPolicy(config);
@@ -108,7 +104,7 @@
Fqn A_B_C_D_E = Fqn.fromString("/a/b/c/d/e/");
Fqn A_B_C_D = Fqn.fromString("/a/b/c/d/");
- RegionManager rm = new RegionManager();
+ RegionManager rm = new RegionManagerImpl();
rm.setUsingEvictions(true);
rm.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
rm.getRegion(A_B_C_D_E, true).setEvictionPolicy(config);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-07-07 20:50:09
UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-07-07 21:21:24
UTC (rev 6199)
@@ -1,14 +1,15 @@
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.EvictionConfig;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
/**
* @author Ben Wang, Feb 11, 2004
* @author Daniel Huang (dhuang(a)jboss.org)
@@ -23,7 +24,7 @@
public void setUp() throws Exception
{
algorithm = new LRUAlgorithm();
- regionManager_ = new RegionManager();
+ regionManager_ = new RegionManagerImpl();
regionManager_.getRegion("/a/b", true).setEvictionPolicy(new
DummyEvictionConfiguration());
}
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -3,11 +3,11 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
@@ -116,7 +116,7 @@
MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
newImpl.start();
newImpl.loadEntireState(newOs);
-
newImpl.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
newOs);
+
newImpl.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
newOs);
newOs.close();
newImpl.remove(Fqn.ROOT);
assertNull(newImpl.get(Fqn.fromString("/a/b/c")));
@@ -147,7 +147,7 @@
MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
newImpl.start();
newImpl.loadState(Fqn.fromString("/a/b"), newOs);
-
newImpl.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
newOs);
+
newImpl.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
newOs);
newOs.close();
newImpl.remove(Fqn.fromString("/a/b"));
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -6,7 +6,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.assertEquals;
@@ -138,7 +138,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
//os.close();
assertTrue(baos.size() > 0);
loader.remove(X);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java 2008-07-07 20:50:09 UTC
(rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java 2008-07-07 21:21:24 UTC
(rev 6199)
@@ -9,7 +9,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.loader.bdbje.BdbjeCacheLoaderConfig;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
@@ -530,7 +530,7 @@
loader.put(Fqn.fromString("/key0/\u0001"), null);
checkChildren(Fqn.fromString("/key0"),
new String[]{"a", "ab", "abc", "x",
"xx", "xxx",
- "\u0000", "\u0001"});
+ "\u0000", "\u0001"});
loader.put(Fqn.fromString("/\u0001"), null);
checkChildren(Fqn.ROOT, new String[]{"key0", "key1",
"\u0001"});
@@ -824,7 +824,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
@@ -956,7 +956,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
@@ -967,7 +967,7 @@
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
bais = new ByteArrayInputStream(baos.toByteArray());
@@ -978,7 +978,7 @@
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
assertEquals(null, loader.get(FQN));
@@ -998,7 +998,7 @@
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
assertTrue(baos.size() > STREAM_HEADER_LENGTH);
os.close();
@@ -1007,7 +1007,7 @@
/* Clear state. */
baos = new ByteArrayOutputStream(1024);
os = new MarshalledValueOutputStream(baos);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
bais = new ByteArrayInputStream(baos.toByteArray());
is = new MarshalledValueInputStream(bais);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -11,7 +11,7 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.transaction.TransactionSetup;
import org.jboss.cache.util.TestingUtil;
import org.jboss.util.stream.MarshalledValueInputStream;
@@ -1816,7 +1816,7 @@
}
finally
{
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
assertTrue(baos.size() > 0);
state = baos.toByteArray();
@@ -2004,7 +2004,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadState(SUBTREE_FQN, os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
assertTrue(baos.size() > 0);
loader.remove(SUBTREE_FQN);
@@ -2052,7 +2052,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadState(FQN, os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
assertTrue(baos.size() > 0);
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -2,6 +2,7 @@
import org.jboss.cache.CacheStatus;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.ComponentRegistry;
@@ -17,7 +18,7 @@
{
Configuration c = cr.getComponent(Configuration.class);
c.setReplVersionString(replVersion);
- return createVAMandRestartCache(new RegionManager());
+ return createVAMandRestartCache(new RegionManagerImpl());
}
protected VersionAwareMarshaller createVAMandRestartCache(RegionManager rm)
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -12,11 +12,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
-import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -9,6 +9,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.commands.remote.ClusteredGetCommand;
import org.testng.annotations.Test;
@@ -37,7 +38,7 @@
// need to test what's going on with
CacheMarshaller200 cm200 = new CacheMarshaller200();
c.setUseRegionBasedMarshalling(true);
- cm200.injectDependencies(new RegionManager(), c, getClass().getClassLoader());
+ cm200.injectDependencies(new RegionManagerImpl(), c, getClass().getClassLoader());
cm200.init();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -8,6 +8,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
@@ -41,7 +42,7 @@
c.setInactiveOnStartup(false);
c.setReplVersionString(currentVersion);
cr = new ComponentRegistry(c, new CacheInvocationDelegate());
- marshaller = createVAMandRestartCache(new RegionManager());
+ marshaller = createVAMandRestartCache(new RegionManagerImpl());
regionManager = cr.getComponent(RegionManager.class);
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java 2008-07-07
20:50:09 UTC (rev 6198)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -5,8 +5,8 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Modified:
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -13,7 +13,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
@@ -92,7 +92,7 @@
List<EvictionRegionConfig> ercs = new
ArrayList<EvictionRegionConfig>();
EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionFqn(RegionManager.DEFAULT_REGION);
+ erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
LRUConfiguration epc = new LRUConfiguration();
epc.setMaxNodes(0);
epc.setTimeToLiveSeconds(5);
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-07-07
20:50:09 UTC (rev 6198)
+++
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-07-07
21:21:24 UTC (rev 6199)
@@ -13,7 +13,7 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.util.TestingUtil;
import org.jboss.util.stream.MarshalledValueInputStream;
@@ -1510,7 +1510,7 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
loader.loadEntireState(os);
-
cache.getMarshaller().objectToObjectStream(StateTransferManager.STREAMING_DELIMITER_NODE,
os);
+
cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE,
os);
os.close();
assertTrue(baos.size() > 0);