JBoss Cache SVN: r5110 - benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-01-10 06:38:01 -0500 (Thu, 10 Jan 2008)
New Revision: 5110
Modified:
benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
Log:
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java 2008-01-10 11:36:51 UTC (rev 5109)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java 2008-01-10 11:38:01 UTC (rev 5110)
@@ -41,7 +41,7 @@
performWarmupOperations(cacheWrapper);
} catch (Exception e)
{
- log.warn("Received exception durring cache warmup" , e.getMessage());
+ log.warn("Received exception durring cache warmup" + e.getMessage());
}
log.info("The warmup took: " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds." );
try
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java 2008-01-10 11:36:51 UTC (rev 5109)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java 2008-01-10 11:38:01 UTC (rev 5110)
@@ -25,7 +25,7 @@
wrapper.put(String.valueOf(opCount), String.valueOf(opCount));
} catch (Exception e)
{
- log.warn("Exception on cache warmup:", e.getMessage());
+ log.warn("Exception on cache warmup:" + e.getMessage());
}
}
16 years, 12 months
JBoss Cache SVN: r5109 - benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-01-10 06:36:51 -0500 (Thu, 10 Jan 2008)
New Revision: 5109
Modified:
benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
Log:
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java 2008-01-10 11:28:01 UTC (rev 5108)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java 2008-01-10 11:36:51 UTC (rev 5109)
@@ -41,7 +41,7 @@
performWarmupOperations(cacheWrapper);
} catch (Exception e)
{
- log.warn("Received exception durring cache warmup");
+ log.warn("Received exception durring cache warmup" , e.getMessage());
}
log.info("The warmup took: " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds." );
try
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java 2008-01-10 11:28:01 UTC (rev 5108)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java 2008-01-10 11:36:51 UTC (rev 5109)
@@ -25,7 +25,7 @@
wrapper.put(String.valueOf(opCount), String.valueOf(opCount));
} catch (Exception e)
{
- log.warn("Exception on cache warmup:", e);
+ log.warn("Exception on cache warmup:", e.getMessage());
}
}
16 years, 12 months
JBoss Cache SVN: r5108 - benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-01-10 06:28:01 -0500 (Thu, 10 Jan 2008)
New Revision: 5108
Modified:
benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
Log:
warmup does not throw any exception now
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java 2008-01-09 22:24:49 UTC (rev 5107)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java 2008-01-10 11:28:01 UTC (rev 5108)
@@ -33,12 +33,24 @@
/**
* Calls {@link #performWarmupOperations(CacheWrapper)} amd clears the cache.
*/
- public final void warmup(CacheWrapper cacheWrapper) throws Exception
+ public final void warmup(CacheWrapper cacheWrapper)
{
long startTime = System.currentTimeMillis();
- performWarmupOperations(cacheWrapper);
+ try
+ {
+ performWarmupOperations(cacheWrapper);
+ } catch (Exception e)
+ {
+ log.warn("Received exception durring cache warmup");
+ }
log.info("The warmup took: " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds." );
- cacheWrapper.empty();
+ try
+ {
+ cacheWrapper.empty();
+ } catch (Exception e)
+ {
+ log.warn("Received exception durring cache warmup");
+ }
}
public abstract void performWarmupOperations(CacheWrapper wrapper) throws Exception;
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java 2008-01-09 22:24:49 UTC (rev 5107)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java 2008-01-10 11:28:01 UTC (rev 5108)
@@ -20,7 +20,13 @@
log.info("Cache launched, performing " + opCount + " put and get operations ");
for (int i = 0; i < opCount; i++)
{
- wrapper.put(String.valueOf(opCount), String.valueOf(opCount));
+ try
+ {
+ wrapper.put(String.valueOf(opCount), String.valueOf(opCount));
+ } catch (Exception e)
+ {
+ log.warn("Exception on cache warmup:", e);
+ }
}
for (int i = 0; i < opCount; i++)
16 years, 12 months
JBoss Cache SVN: r5107 - core/trunk/src/test/java/org/jboss/cache/notifications.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-09 17:24:49 -0500 (Wed, 09 Jan 2008)
New Revision: 5107
Modified:
core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
Log:
Fixed broken test
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2008-01-09 16:30:05 UTC (rev 5106)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2008-01-09 22:24:49 UTC (rev 5107)
@@ -658,6 +658,10 @@
List<Event> expected = new ArrayList<Event>();
// public EventImpl(boolean pre, Cache cache, ModificationType modificationType, Map data, Fqn fqn,
// Transaction transaction, boolean originLocal, Fqn targetFqn, boolean successful, View newView, Type type)
+ if (optLocking)
+ expected.add(new EventImpl(false, cache2, null, null, null, null, true, null, false, null, TRANSACTION_REGISTERED));
+ if (optLocking)
+ expected.add(new EventImpl(false, cache2, null, null, null, null, true, null, true, null, TRANSACTION_COMPLETED));
expected.add(new EventImpl(true, cache2, null, null, Fqn.ROOT, null, false, null, false, null, NODE_CREATED));
expected.add(new EventImpl(false, cache2, null, null, Fqn.ROOT, null, false, null, false, null, NODE_CREATED));
@@ -672,6 +676,9 @@
expected.add(new EventImpl(true, cache2, NodeModifiedEvent.ModificationType.PUT_MAP, Collections.emptyMap(), fqnB, null, false, null, false, null, NODE_MODIFIED));
expected.add(new EventImpl(false, cache2, NodeModifiedEvent.ModificationType.PUT_MAP, data, fqnB, null, false, null, false, null, NODE_MODIFIED));
+
+ scrubTransactions(expected);
+ if (optLocking) eventLog2.scrubImplicitTransactions();
assertEquals(expected, eventLog2.events);
}
17 years
JBoss Cache SVN: r5106 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-09 11:30:05 -0500 (Wed, 09 Jan 2008)
New Revision: 5106
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
Log:
Modified test to verify JBCACHE-1226
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java 2008-01-09 16:16:24 UTC (rev 5105)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/ForcedStateTransferTest.java 2008-01-09 16:30:05 UTC (rev 5106)
@@ -45,7 +45,8 @@
* @author Brian Stansberry
* @version $Revision$
*/
-@Test(groups = {"functional"}, enabled = false) // this has always been disabled since 1.4.x. See JBCACHE-315
+@Test(groups = {"functional"}, enabled = false)
+// this has always been disabled since 1.4.x. See JBCACHE-315
public class ForcedStateTransferTest extends StateTransferTestBase
{
/**
@@ -378,7 +379,7 @@
// Start threads that will do operations on the cache and then hang
TxRunner[] runners =
- initializeTransactionRunners(values, sender, "/LOCK", rollback);
+ initializeTransactionRunners(values, sender, "/LOCK", rollback);
// Create and start the cache that requests a state transfer
CacheSPI<Object, Object> receiver = startReceiver(isolationLevel, false, false);
@@ -455,11 +456,11 @@
while (!(runner.isAsleep()))
{
assertTrue(runner.getClass().getName() + " " + runner.value +
- " is alive", runner.isAlive());
+ " is alive", runner.isAlive());
// Avoid hanging test fixture by only waiting 1 sec before failing
assertFalse(runner.getClass().getName() + " " + runner.value +
- " has not timed out",
- (System.currentTimeMillis() - start) > 1000);
+ " has not timed out",
+ (System.currentTimeMillis() - start) > 1000);
}
}
@@ -496,12 +497,12 @@
if (allowValues)
{
assertEquals("Correct value in " + runners[i].fqn,
- runners[i].value, receiver.get(runners[i].fqn, "KEY"));
+ runners[i].value, receiver.get(runners[i].fqn, "KEY"));
}
else
{
assertNull("No value in " + runners[i].fqn,
- receiver.get(runners[i].fqn, "KEY"));
+ receiver.get(runners[i].fqn, "KEY"));
}
}
}
@@ -595,7 +596,7 @@
String[] values = {"A", "B", "C"};
SynchronizationTxRunner[] runners =
- initializeSynchronizationTxRunners(values, sender, "/LOCK", hangBefore);
+ initializeSynchronizationTxRunners(values, sender, "/LOCK", hangBefore);
CacheSPI<Object, Object> receiver = startReceiver("REPEATABLE_READ", false, false);
@@ -624,7 +625,7 @@
boolean hangBefore)
{
SynchronizationTxRunner[] runners =
- new SynchronizationTxRunner[values.length];
+ new SynchronizationTxRunner[values.length];
for (int i = 0; i < values.length; i++)
{
runners[i] = new SynchronizationTxRunner(sender, rootFqn, values[i], hangBefore);
@@ -704,23 +705,23 @@
// to catch; will create a separate locking test that shows it
String[] val1 = {"A", "B", "C"};
SynchronizationTxRunner[] after =
- initializeSynchronizationTxRunners(val1, sender, rootFqn, false);
+ initializeSynchronizationTxRunners(val1, sender, rootFqn, false);
String[] val2 = {"D", "E", "F"};
SynchronizationTxRunner[] before =
- initializeSynchronizationTxRunners(val2, sender, rootFqn, true);
+ initializeSynchronizationTxRunners(val2, sender, rootFqn, true);
String[] val3 = {"G", "H", "I"};
TxRunner[] active =
- initializeTransactionRunners(val3, sender, rootFqn, false);
+ initializeTransactionRunners(val3, sender, rootFqn, false);
String[] val4 = {"J", "K", "L"};
TxRunner[] rollback =
- initializeTransactionRunners(val4, sender, rootFqn, true);
+ initializeTransactionRunners(val4, sender, rootFqn, true);
String[] val5 = {"M", "N", "O"};
HangThreadRunner[] threads =
- initializeHangThreadRunners(val5, sender, rootFqn);
+ initializeHangThreadRunners(val5, sender, rootFqn);
CacheSPI<Object, Object> receiver = startReceiver(isolationLevel, replSync, useMarshalling);
@@ -779,10 +780,10 @@
boolean replSync,
boolean useMarshalling,
boolean startCache)
- throws Exception
+ throws Exception
{
CacheSPI<Object, Object> result = super.createCache(cacheID, replSync,
- useMarshalling, false, false, false);
+ useMarshalling, false, false, false, true);
result.getConfiguration().setStateRetrievalTimeout(0);
result.getConfiguration().setLockAcquisitionTimeout(1000);
result.getConfiguration().setIsolationLevel(isolationLevel);
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java 2008-01-09 16:16:24 UTC (rev 5105)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java 2008-01-09 16:30:05 UTC (rev 5106)
@@ -7,6 +7,7 @@
package org.jboss.cache.statetransfer;
+import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
@@ -41,7 +42,7 @@
public void testBuddyBackupExclusion() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, false, false, false);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, false, false, false, true);
cache1.getConfiguration().setBuddyReplicationConfig(getBuddyConfig());
@@ -64,7 +65,7 @@
public void testBuddyIntegration() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, false, false, false);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, false, false, false, true);
cache1.getConfiguration().setBuddyReplicationConfig(getBuddyConfig());
cache1.start();
@@ -75,7 +76,7 @@
cache1.put(A_C, "name", JANE);
// now start up cache 2
- CacheSPI<Object, Object> cache2 = createCache("cache2", false, false, false, false, false);
+ CacheSPI<Object, Object> cache2 = createCache("cache2", false, false, false, false, false, true);
cache2.getConfiguration().setBuddyReplicationConfig(getBuddyConfig());
cache2.start();
@@ -93,7 +94,7 @@
@SuppressWarnings("null")
public void testCacheLoaderFailure() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, CorruptedFileCacheLoader.class.getName(), false, true);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, CorruptedFileCacheLoader.class.getName(), false, true, true);
cache1.put(A_B, "name", JOE);
cache1.put(A_B, "age", TWENTY);
@@ -103,7 +104,7 @@
CacheSPI cache2 = null;
try
{
- cache2 = createCache("cache2", false, false, true, false, false);
+ cache2 = createCache("cache2", false, false, true, false, false, true);
cache2.create();
cache2.start();
@@ -360,7 +361,7 @@
false, // async
true, // use marshaller
true, // use cacheloader
- false, false);// don't start
+ false, false, true);// don't start
ClassLoader cl1 = getClassLoader();
cache1.getRegion(A, true).registerContextClassLoader(cl1);
startCache(cache1);
@@ -376,7 +377,7 @@
false, // async
true, // use marshalling
true, // use cacheloader
- false, true);// start
+ false, true, true);// start
// Pause to give caches time to see each other
TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
@@ -401,6 +402,35 @@
}
+ public void testStalePersistentState() throws Exception
+ {
+ CacheSPI c1 = createCache("1", true, false, true, false);
+ c1.put(A, "K", "V");
+
+ assert c1.get(A, "K").equals("V");
+ CacheLoader l1 = c1.getCacheLoaderManager().getCacheLoader();
+ assert l1 != null;
+
+ assert l1.exists(A);
+ assert l1.get(A).get("K").equals("V");
+
+ // test persistence
+ c1.stop();
+
+ assert l1.exists(A);
+ assert l1.get(A).get("K").equals("V");
+
+ Cache c2 = createCache("2", true, false, true, false);
+
+ c2.put(B, "K", "V");
+
+ c1.start();
+
+ assert c1.get(B, "K").equals("V");
+ assert c1.get(A, "K") == null;
+ assert !l1.exists(A);
+ }
+
private Object createBen(ClassLoader loader) throws Exception
{
Class addrClazz = loader.loadClass(ADDRESS_CLASSNAME);
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java 2008-01-09 16:16:24 UTC (rev 5105)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferTestBase.java 2008-01-09 16:30:05 UTC (rev 5106)
@@ -87,29 +87,38 @@
boolean useCacheLoader)
throws Exception
{
- return createCache(cacheID, sync, useMarshalling, useCacheLoader, false, true);
+ return createCache(cacheID, sync, useMarshalling, useCacheLoader, false, true, true);
}
protected CacheSPI<Object, Object> createCache(String cacheID,
boolean sync,
boolean useMarshalling,
+ boolean useCacheLoader, boolean fetchPersistentState)
+ throws Exception
+ {
+ return createCache(cacheID, sync, useMarshalling, useCacheLoader, false, true, fetchPersistentState);
+ }
+
+ protected CacheSPI<Object, Object> createCache(String cacheID,
+ boolean sync,
+ boolean useMarshalling,
boolean useCacheLoader,
boolean cacheLoaderAsync,
- boolean startCache)
+ boolean startCache, boolean fetchPersistentState)
throws Exception
{
if (useCacheLoader)
{
- return createCache(cacheID, sync, useMarshalling, "org.jboss.cache.loader.FileCacheLoader", cacheLoaderAsync, startCache);
+ return createCache(cacheID, sync, useMarshalling, "org.jboss.cache.loader.FileCacheLoader", cacheLoaderAsync, startCache, fetchPersistentState);
}
else
{
- return createCache(cacheID, sync, useMarshalling, null, cacheLoaderAsync, startCache);
+ return createCache(cacheID, sync, useMarshalling, null, cacheLoaderAsync, startCache, fetchPersistentState);
}
}
protected CacheSPI<Object, Object> createCache(String cacheID, boolean sync, boolean useMarshalling, String cacheLoaderClass,
- boolean cacheLoaderAsync, boolean startCache) throws Exception
+ boolean cacheLoaderAsync, boolean startCache, boolean fetchPersistentState) throws Exception
{
if (caches.get(cacheID) != null)
{
@@ -134,7 +143,7 @@
}
if (cacheLoaderClass != null && cacheLoaderClass.length() > 0)
{
- configureCacheLoader(c, cacheLoaderClass, cacheID, cacheLoaderAsync);
+ configureCacheLoader(c, cacheLoaderClass, cacheID, cacheLoaderAsync, fetchPersistentState);
}
// tree.setConfiguration(c);
//c.setLockAcquisitionTimeout(60000);
@@ -201,11 +210,11 @@
boolean async)
throws Exception
{
- configureCacheLoader(c, "org.jboss.cache.loader.FileCacheLoader", cacheID, async);
+ configureCacheLoader(c, "org.jboss.cache.loader.FileCacheLoader", cacheID, async, true);
}
protected void configureCacheLoader(Configuration c, String cacheloaderClass, String cacheID,
- boolean async) throws Exception
+ boolean async, boolean fetchPersistentState) throws Exception
{
if (cacheloaderClass != null)
{
@@ -243,21 +252,21 @@
tmp_location = escapeWindowsPath(tmp_location);
String props = "location = " + tmp_location + "\n";
- c.setCacheLoaderConfig(getSingleCacheLoaderConfig("", cacheloaderClass, props, async, true, false));
+ c.setCacheLoaderConfig(getSingleCacheLoaderConfig("", cacheloaderClass, props, async, fetchPersistentState, false));
}
}
}
protected void initialStateTferWithLoaderTest(String cacheLoaderClass1, String cacheLoaderClass2, boolean asyncLoader) throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, cacheLoaderClass1, false, true);
+ CacheSPI<Object, Object> cache1 = createCache("cache1", false, false, cacheLoaderClass1, false, true, true);
cache1.put(A_B, "name", JOE);
cache1.put(A_B, "age", TWENTY);
cache1.put(A_C, "name", BOB);
cache1.put(A_C, "age", FORTY);
- CacheSPI<Object, Object> cache2 = createCache("cache2", false, false, cacheLoaderClass2, asyncLoader, false);
+ CacheSPI<Object, Object> cache2 = createCache("cache2", false, false, cacheLoaderClass2, asyncLoader, false, true);
cache2.start();
17 years
JBoss Cache SVN: r5105 - in core/trunk/src: main/java/org/jboss/cache/marshall and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-09 11:16:24 -0500 (Wed, 09 Jan 2008)
New Revision: 5105
Added:
core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.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/VersionAwareMarshallerTest.java
Log:
JBCACHE-1232 - default class loader used by marshallers
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -85,6 +85,7 @@
public ComponentRegistry(Configuration configuration)
{
// bootstrap.
+ registerComponent("deployerClassLoader", getClass().getClassLoader(), ClassLoader.class);
registerComponent(this, ComponentRegistry.class);
registerComponent(configuration, Configuration.class);
}
@@ -554,6 +555,7 @@
public void reset()
{
// the bootstrap classes
+ Component deployerClassLoader = componentLookup.get("deployerClassLoader");
Component spi = componentLookup.get(CacheSPI.class.getName());
Component impl = componentLookup.get(CacheImpl.class.getName());
Component conf = componentLookup.get(Configuration.class.getName());
@@ -561,12 +563,13 @@
componentLookup.clear();
+ deployerClassLoader.changeState(CONSTRUCTED);
spi.changeState(CONSTRUCTED);
impl.changeState(CONSTRUCTED);
conf.changeState(CONSTRUCTED);
cr.changeState(CONSTRUCTED);
- bootstrap = new Bootstrap((CacheImpl) impl.instance, (CacheSPI) spi.instance, (ComponentRegistry) cr.instance, (Configuration) conf.instance);
+ bootstrap = new Bootstrap((ClassLoader) deployerClassLoader.instance, (CacheImpl) impl.instance, (CacheSPI) spi.instance, (ComponentRegistry) cr.instance, (Configuration) conf.instance);
overallState = null;
}
@@ -904,9 +907,11 @@
CacheSPI cacheSPI;
ComponentRegistry componentRegistry;
Configuration configuration;
+ private ClassLoader deployerClassLoader;
- Bootstrap(CacheImpl cacheImpl, CacheSPI cacheSPI, ComponentRegistry componentRegistry, Configuration configuration)
+ Bootstrap(ClassLoader deployerClassLoader, CacheImpl cacheImpl, CacheSPI cacheSPI, ComponentRegistry componentRegistry, Configuration configuration)
{
+ this.deployerClassLoader = deployerClassLoader;
this.cacheImpl = cacheImpl;
this.cacheSPI = cacheSPI;
this.componentRegistry = componentRegistry;
@@ -918,12 +923,14 @@
return componentLookup.containsKey(Configuration.class.getName()) &&
componentLookup.containsKey(CacheImpl.class.getName()) &&
componentLookup.containsKey(CacheSPI.class.getName()) &&
- componentLookup.containsKey(ComponentRegistry.class.getName());
+ componentLookup.containsKey(ComponentRegistry.class.getName()) &&
+ componentLookup.containsKey("deployerClassLoader");
}
void bootstrap()
{
overallState = CONSTRUCTED;
+ registerComponent("deployerClassLoader", deployerClassLoader, ClassLoader.class);
registerComponent(Configuration.class.getName(), configuration, Configuration.class);
registerComponent(ComponentRegistry.class.getName(), componentRegistry, ComponentRegistry.class);
registerComponent(CacheImpl.class.getName(), cacheImpl, CacheImpl.class);
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -13,6 +13,7 @@
import org.jboss.cache.RegionManager;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -43,10 +44,12 @@
*/
private Map<GlobalTransaction, Fqn> transactions = new ConcurrentHashMap<GlobalTransaction, Fqn>(16);
protected Configuration configuration;
+ protected ClassLoader defaultClassLoader;
@Inject
- void injectDependencies(RegionManager regionManager, Configuration configuration)
+ void injectDependencies(RegionManager regionManager, Configuration configuration, @ComponentName("deployerClassLoader")ClassLoader defaultClassLoader)
{
+ this.defaultClassLoader = defaultClassLoader;
this.regionManager = regionManager;
this.configuration = configuration;
}
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -117,8 +117,7 @@
{
// not region based!
if (trace) log.trace("Marshalling object " + o);
- Map<Object, Integer> refMap = new HashMap<Object, Integer>();
- marshallObject(o, out, refMap);
+ objectToObjectStream(o, out, null);
}
}
@@ -131,7 +130,7 @@
else
{
Map<Integer, Object> refMap = new HashMap<Integer, Object>();
- Object retValue = unmarshallObject(in, refMap);
+ Object retValue = unmarshallObject(in, defaultClassLoader, refMap);
if (trace) log.trace("Unmarshalled object " + retValue);
return retValue;
}
@@ -141,12 +140,31 @@
{
if (trace) log.trace("Marshalling object " + o);
Map<Object, Integer> refMap = new HashMap<Object, Integer>();
- if (useRegionBasedMarshalling) // got to check again in case this meth is called directly
+ ClassLoader toUse = defaultClassLoader;
+ Thread current = Thread.currentThread();
+ ClassLoader old = current.getContextClassLoader();
+
+ try
{
- log.trace("Writing region " + region + " to stream");
- marshallObject(region, out, refMap);
+ if (useRegionBasedMarshalling) // got to check again in case this meth is called directly
+ {
+ log.trace("Writing region " + region + " to stream");
+ Region r = null;
+ if (region != null) r = regionManager.getRegion(region, false);
+ if (r != null && r.getClassLoader() != null) toUse = r.getClassLoader();
+ current.setContextClassLoader(toUse);
+ marshallObject(region, out, refMap);
+ }
+ else
+ {
+ current.setContextClassLoader(toUse);
+ }
+ marshallObject(o, out, refMap);
}
- marshallObject(o, out, refMap);
+ finally
+ {
+ current.setContextClassLoader(old);
+ }
}
protected Object objectFromObjectStreamRegionBased(ObjectInputStream in) throws Exception
@@ -177,7 +195,7 @@
{
if (log.isDebugEnabled())
log.debug("Region does not exist for Fqn " + regionFqn + " - not using a context classloader.");
- retValue = unmarshallObject(in, refMap);
+ retValue = unmarshallObject(in, defaultClassLoader, refMap);
}
else
{
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2008-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -9,6 +9,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.util.Util;
@@ -31,16 +33,23 @@
*/
public class VersionAwareMarshaller extends AbstractMarshaller
{
-
private static final Log log = LogFactory.getLog(VersionAwareMarshaller.class);
private static final int VERSION_200 = 20;
private static final int VERSION_210 = 21;
private static final int CUSTOM_MARSHALLER = 999;
+ private ComponentRegistry componentRegistry;
+
Marshaller defaultMarshaller;
Map<Integer, Marshaller> marshallers = new HashMap<Integer, Marshaller>();
private int versionInt;
+ @Inject
+ void injectComponentRegistry(ComponentRegistry componentRegistry)
+ {
+ this.componentRegistry = componentRegistry;
+ }
+
@Start
public void initReplicationVersions()
{
@@ -225,7 +234,7 @@
{
am = new CacheMarshaller200();
marshaller = am;
- am.injectDependencies(regionManager, configuration);
+ componentRegistry.wireDependencies(am);
am.init();
marshallers.put(VERSION_200, marshaller);
}
@@ -240,7 +249,7 @@
{
am = new CacheMarshaller210();
marshaller = am;
- am.injectDependencies(regionManager, configuration);
+ componentRegistry.wireDependencies(am);
am.init();
marshallers.put(VERSION_210, marshaller);
}
Added: core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -0,0 +1,32 @@
+package org.jboss.cache.marshall;
+
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentRegistry;
+
+/**
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+public abstract class AbstractVersionAwareMarshallerTest
+{
+ protected VersionAwareMarshaller createVAM(String replVersion)
+ {
+ Configuration c = new Configuration();
+ c.setReplVersionString(replVersion);
+ return createVAM(c, new RegionManager());
+ }
+
+ protected VersionAwareMarshaller createVAM(Configuration c, RegionManager rm)
+ {
+ ComponentRegistry cr = new ComponentRegistry(c);
+ cr.registerComponent(rm, RegionManager.class);
+ c.setReplVersionString(c.getReplVersionString());
+ VersionAwareMarshaller vam = new VersionAwareMarshaller();
+
+ cr.wireDependencies(vam);
+ vam.init();
+ vam.initReplicationVersions();
+ return vam;
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2008-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -27,8 +27,8 @@
* @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
* @version $Revision$
*/
-@Test(groups = {"functional"})
-public class ActiveInactiveTest
+@Test(groups = "functional")
+public class ActiveInactiveTest extends AbstractVersionAwareMarshallerTest
{
RegionManager rman;
CacheSPI c;
@@ -166,10 +166,7 @@
Configuration c = new Configuration();
c.setUseRegionBasedMarshalling(true);
c.setInactiveOnStartup(true);
- VersionAwareMarshaller testee = new VersionAwareMarshaller();
- testee.injectDependencies(rman, c);
- testee.init();
- testee.initReplicationVersions();
+ VersionAwareMarshaller testee = createVAM(c, rman);
byte[] callBytes = testee.objectToByteBuffer(replicate);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2008-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -37,7 +37,7 @@
// need to test what's going on with
CacheMarshaller200 cm200 = new CacheMarshaller200();
c.setUseRegionBasedMarshalling(true);
- cm200.injectDependencies(new RegionManager(), c);
+ cm200.injectDependencies(new RegionManager(), c, getClass().getClassLoader());
cm200.init();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
@@ -85,7 +85,7 @@
RegionManager rm = new RegionManager();
final CacheMarshaller200 cm200 = new CacheMarshaller200();
c.setUseRegionBasedMarshalling(true);
- cm200.injectDependencies(new RegionManager(), c);
+ cm200.injectDependencies(new RegionManager(), 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-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -17,8 +17,8 @@
import java.util.ArrayList;
import java.util.List;
-@Test(groups = {"functional"})
-public abstract class CacheMarshallerTestBase
+@Test(groups = "functional")
+public abstract class CacheMarshallerTestBase extends AbstractVersionAwareMarshallerTest
{
protected String currentVersion;
protected int currentVersionShort;
@@ -35,10 +35,7 @@
c.setUseRegionBasedMarshalling(false);
c.setInactiveOnStartup(false);
c.setReplVersionString(currentVersion);
- marshaller = new VersionAwareMarshaller();
- marshaller.injectDependencies(regionManager, c);
- marshaller.init();
- marshaller.initReplicationVersions();
+ marshaller = createVAM(c, regionManager);
}
@AfterMethod(alwaysRun = true)
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-01-09 15:02:25 UTC (rev 5104)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-01-09 16:16:24 UTC (rev 5105)
@@ -6,9 +6,7 @@
*/
package org.jboss.cache.marshall;
-import org.jboss.cache.RegionManager;
import org.jboss.cache.Version;
-import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.Test;
@@ -20,52 +18,41 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
@Test(groups = {"functional"})
-public class VersionAwareMarshallerTest
+public class VersionAwareMarshallerTest extends AbstractVersionAwareMarshallerTest
{
public void testMarshallerSelection()
{
- VersionAwareMarshaller marshaller = createAndConfigure("2.1.0.GA");
+ VersionAwareMarshaller marshaller = createVAM("2.1.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("2.0.0.GA");
+ marshaller = createVAM("2.0.0.GA");
assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("1.4.0.GA");
+ marshaller = createVAM("1.4.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("1.5.0.GA");
+ marshaller = createVAM("1.5.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("1.3.0.GA");
+ marshaller = createVAM("1.3.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("1.3.0.SP2");
+ marshaller = createVAM("1.3.0.SP2");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("1.3.1.GA");
+ marshaller = createVAM("1.3.1.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("1.2.4.SP2");
+ marshaller = createVAM("1.2.4.SP2");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = createAndConfigure("1.2.3");
+ marshaller = createVAM("1.2.3");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
}
- private VersionAwareMarshaller createAndConfigure(String replVersion)
- {
- Configuration c = new Configuration();
- c.setReplVersionString(replVersion);
- VersionAwareMarshaller vam = new VersionAwareMarshaller();
- vam.injectDependencies(new RegionManager(), c);
- vam.init();
- vam.initReplicationVersions();
- return vam;
- }
-
public void testVersionHeaderDefaultCurrent() throws Exception
{
- VersionAwareMarshaller marshaller = createAndConfigure(Version.getVersionString(Version.getVersionShort()));
+ VersionAwareMarshaller marshaller = createVAM(Version.getVersionString(Version.getVersionShort()));
byte[] bytes = marshaller.objectToByteBuffer("Hello");
// expect that this has been serialized using JBoss Serialization so use this to get an OIS.
@@ -75,7 +62,7 @@
public void testVersionHeader200() throws Exception
{
- VersionAwareMarshaller marshaller = createAndConfigure("2.0.0.GA");
+ VersionAwareMarshaller marshaller = createVAM("2.0.0.GA");
byte[] bytes = marshaller.objectToByteBuffer("Hello");
// expect that this has been serialized using JBoss Serialization so use this to get an OIS.
17 years
JBoss Cache SVN: r5104 - in core/trunk/src: main/java/org/jboss/cache/loader and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-09 10:02:25 -0500 (Wed, 09 Jan 2008)
New Revision: 5104
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java
core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java
Log:
JBCACHE-1260 - TcpDelegatingCacheLoader to be made tolerant of TcpCacheServer restarts
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-09 11:52:25 UTC (rev 5103)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-09 15:02:25 UTC (rev 5104)
@@ -41,7 +41,6 @@
@Inject
void setRegionManager(RegionManager regionManager)
{
- if (trace) log.trace("Having region manager " + regionManager + " injected.");
this.regionManager = regionManager;
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java 2008-01-09 11:52:25 UTC (rev 5103)
+++ core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java 2008-01-09 15:02:25 UTC (rev 5104)
@@ -6,6 +6,9 @@
*/
package org.jboss.cache.loader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
@@ -16,7 +19,10 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.Socket;
+import java.net.SocketException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -41,27 +47,31 @@
private TcpDelegatingCacheLoaderConfig config;
ObjectInputStream in;
ObjectOutputStream out;
+ private static Log log = LogFactory.getLog(TcpDelegatingCacheLoader.class);
+ private static Method GET_CHILDREN_METHOD, GET_METHOD, PUT_KEY_METHOD, PUT_DATA_METHOD, REMOVE_KEY_METHOD, REMOVE_METHOD, PUT_MODS_METHOD, EXISTS_METHOD, REMOVE_DATA_METHOD;
-
- /**
- * Default constructor.
- */
- public TcpDelegatingCacheLoader()
+ static
{
- // Empty.
- }
+ try
+ {
+ GET_CHILDREN_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_getChildrenNames", Fqn.class);
+ GET_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_get", Fqn.class);
+ EXISTS_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_exists", Fqn.class);
+ PUT_KEY_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_put", Fqn.class, Object.class, Object.class);
+ PUT_DATA_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_put", Fqn.class, Map.class);
+ REMOVE_KEY_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_remove", Fqn.class, Object.class);
+ REMOVE_DATA_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_removeData", Fqn.class);
+ REMOVE_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_remove", Fqn.class);
+ PUT_MODS_METHOD = TcpDelegatingCacheLoader.class.getDeclaredMethod("_put", List.class);
- /**
- * Allows programmatic configuration.
- *
- * @param host The host on which to look up the remote object.
- * @param port The port on which to look up the remote object.
- */
- public TcpDelegatingCacheLoader(String host, int port)
- {
- this.config = new TcpDelegatingCacheLoaderConfig(host, port);
+ }
+ catch (Exception e)
+ {
+ log.fatal("Unable to initialise reflection methods", e);
+ }
}
+
/**
* Allows configuration via XML config file.
*/
@@ -82,9 +92,105 @@
return config;
}
+ /**
+ * Invokes the specified Method with the specified parameters, catching SocketExceptions and attempting to reconnect
+ * to the TcpCacheServer if necessary.
+ *
+ * @param m method to invoke
+ * @param params parameters
+ * @return method return value
+ */
+ protected Object invokeWithRetries(Method m, Object... params)
+ {
+ long endTime = System.currentTimeMillis() + config.getTimeout();
+ do
+ {
+ try
+ {
+ return m.invoke(this, params);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.error("Should never get here!", e);
+ }
+ catch (InvocationTargetException e)
+ {
+ if (e.getCause() instanceof SocketException)
+ {
+ try
+ {
+ // sleep 250 ms
+ Thread.sleep(config.getReconnectWaitTime());
+ restart();
+ }
+ catch (IOException e1)
+ {
+ // IOException starting; sleep a bit and retry
+ }
+ catch (InterruptedException e1)
+ {
+ // do nothing
+ }
+ }
+ }
+ } while (System.currentTimeMillis() < endTime);
+ throw new CacheException("Unable to communicate with TCPCacheServer(" + config.getHost() + ":" + config.getPort() + ") after " + config.getTimeout() + " millis, with reconnects every " + config.getReconnectWaitTime() + " millis.");
+ }
+
+ // ------------------ CacheLoader interface methods, which delegate to retry-aware methods
+
public Set<?> getChildrenNames(Fqn fqn) throws Exception
{
- Set cn = null;
+
+ return (Set<?>) invokeWithRetries(GET_CHILDREN_METHOD, fqn);
+ }
+
+ public Map<Object, Object> get(Fqn name) throws Exception
+ {
+ return (Map<Object, Object>) invokeWithRetries(GET_METHOD, name);
+ }
+
+ public boolean exists(Fqn name) throws Exception
+ {
+ return (Boolean) invokeWithRetries(EXISTS_METHOD, name);
+ }
+
+ public Object put(Fqn name, Object key, Object value) throws Exception
+ {
+ return invokeWithRetries(PUT_KEY_METHOD, name, key, value);
+ }
+
+ public void put(Fqn name, Map<Object, Object> attributes) throws Exception
+ {
+ invokeWithRetries(PUT_DATA_METHOD, name, attributes);
+ }
+
+ @Override
+ public void put(List<Modification> modifications) throws Exception
+ {
+ invokeWithRetries(PUT_MODS_METHOD, modifications);
+ }
+
+ public Object remove(Fqn fqn, Object key) throws Exception
+ {
+ return invokeWithRetries(REMOVE_KEY_METHOD, fqn, key);
+ }
+
+ public void remove(Fqn fqn) throws Exception
+ {
+ invokeWithRetries(REMOVE_METHOD, fqn);
+ }
+
+ public void removeData(Fqn fqn) throws Exception
+ {
+ invokeWithRetries(REMOVE_DATA_METHOD, fqn);
+ }
+
+ // ------------------ Retry-aware CacheLoader interface method counterparts
+
+ protected Set<?> _getChildrenNames(Fqn fqn) throws Exception
+ {
+ Set cn;
synchronized (out)
{
out.reset();
@@ -104,7 +210,7 @@
return cn;
}
- public Map<Object, Object> get(Fqn name) throws Exception
+ protected Map<Object, Object> _get(Fqn name) throws Exception
{
synchronized (out)
{
@@ -122,7 +228,7 @@
}
}
- public boolean exists(Fqn name) throws Exception
+ protected boolean _exists(Fqn name) throws Exception
{
synchronized (out)
{
@@ -140,7 +246,7 @@
}
}
- public Object put(Fqn name, Object key, Object value) throws Exception
+ protected Object _put(Fqn name, Object key, Object value) throws Exception
{
synchronized (out)
{
@@ -160,7 +266,7 @@
}
}
- public void put(Fqn name, Map<Object, Object> attributes) throws Exception
+ protected void _put(Fqn name, Map<Object, Object> attributes) throws Exception
{
synchronized (out)
{
@@ -178,51 +284,8 @@
}
}
- @Override
- public void start() throws Exception
+ protected void _put(List<Modification> modifications) throws Exception
{
- init();
- }
-
- @Override
- public void stop()
- {
- try
- {
- if (in != null) in.close();
- }
- catch (IOException e)
- {
- }
- try
- {
- if (out != null) out.close();
- }
- catch (IOException e)
- {
- }
- try
- {
- if (sock != null) sock.close();
- }
- catch (IOException e)
- {
- }
- }
-
-
- private void init() throws IOException
- {
- sock = new Socket(config.getHost(), config.getPort());
- out = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
- out.flush();
- in = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));
- }
-
-
- @Override
- public void put(List<Modification> modifications) throws Exception
- {
synchronized (out)
{
out.reset();
@@ -230,7 +293,7 @@
out.writeByte(TcpCacheOperations.PUT_LIST);
int length = modifications.size();
out.writeInt(length);
- for (Modification m : modifications)
+ for (Modification m : modifications)
{
m.writeExternal(out);
}
@@ -243,7 +306,7 @@
}
}
- public Object remove(Fqn fqn, Object key) throws Exception
+ protected Object _remove(Fqn fqn, Object key) throws Exception
{
synchronized (out)
{
@@ -262,7 +325,7 @@
}
}
- public void remove(Fqn fqn) throws Exception
+ protected void _remove(Fqn fqn) throws Exception
{
synchronized (out)
{
@@ -279,7 +342,7 @@
}
}
- public void removeData(Fqn fqn) throws Exception
+ protected void _removeData(Fqn fqn) throws Exception
{
synchronized (out)
{
@@ -296,7 +359,51 @@
}
}
+ // ----------------- Lifecycle and no-op methods
+
+
@Override
+ public void start() throws IOException
+ {
+ sock = new Socket(config.getHost(), config.getPort());
+ out = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
+ out.flush();
+ in = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));
+ }
+
+ @Override
+ public void stop()
+ {
+ try
+ {
+ if (in != null) in.close();
+ }
+ catch (IOException e)
+ {
+ }
+ try
+ {
+ if (out != null) out.close();
+ }
+ catch (IOException e)
+ {
+ }
+ try
+ {
+ if (sock != null) sock.close();
+ }
+ catch (IOException e)
+ {
+ }
+ }
+
+ protected void restart() throws IOException
+ {
+ stop();
+ start();
+ }
+
+ @Override
public void loadEntireState(ObjectOutputStream os) throws Exception
{
throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
@@ -319,5 +426,4 @@
{
throw new UnsupportedOperationException("operation is not currently supported - need to define semantics first");
}
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java 2008-01-09 11:52:25 UTC (rev 5103)
+++ core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoaderConfig.java 2008-01-09 15:02:25 UTC (rev 5104)
@@ -13,6 +13,8 @@
private String host = "localhost";
private int port = 7500;
+ private int timeout = 5000;
+ private int reconnectWaitTime = 500;
public TcpDelegatingCacheLoaderConfig()
{
@@ -33,14 +35,16 @@
/**
* For use by {@link TcpDelegatingCacheLoader}.
*
- * @param host hostname of the delegate
- * @param port port the delegate is listening on
+ * @param host hostname of the delegate
+ * @param port port the delegate is listening on
+ * @param timeout after which to throw an IOException
*/
- TcpDelegatingCacheLoaderConfig(String host, int port)
+ TcpDelegatingCacheLoaderConfig(String host, int port, int timeout)
{
setClassName(TcpDelegatingCacheLoader.class.getName());
this.host = host;
this.port = port;
+ this.timeout = timeout;
}
public String getHost()
@@ -65,6 +69,29 @@
this.port = port;
}
+ public int getTimeout()
+ {
+ return timeout;
+ }
+
+ public void setTimeout(int timeout)
+ {
+ testImmutability("timeout");
+ this.timeout = timeout;
+ }
+
+ public int getReconnectWaitTime()
+ {
+ return reconnectWaitTime;
+ }
+
+ public void setReconnectWaitTime(int reconnectWaitTime)
+ {
+ testImmutability("reconnectWaitTime");
+ this.reconnectWaitTime = reconnectWaitTime;
+ }
+
+ @Override
public void setProperties(Properties props)
{
super.setProperties(props);
@@ -78,8 +105,21 @@
{
this.port = Integer.parseInt(s);
}
+
+ s = props.getProperty("timeout");
+ if (s != null && s.length() > 0)
+ {
+ this.timeout = Integer.parseInt(s);
+ }
+
+ s = props.getProperty("reconnectWaitTime");
+ if (s != null && s.length() > 0)
+ {
+ this.reconnectWaitTime = Integer.parseInt(s);
+ }
}
+ @Override
public boolean equals(Object obj)
{
if (obj instanceof TcpDelegatingCacheLoaderConfig && equalsExcludingProperties(obj))
@@ -87,16 +127,19 @@
TcpDelegatingCacheLoaderConfig other = (TcpDelegatingCacheLoaderConfig) obj;
return safeEquals(host, other.host)
- && (port == other.port);
+ && (port == other.port) && (timeout == other.timeout) && (reconnectWaitTime == other.reconnectWaitTime);
}
return false;
}
+ @Override
public int hashCode()
{
int result = hashCodeExcludingProperties();
result = 31 * result + (host == null ? 0 : host.hashCode());
result = 31 * result + port;
+ result = 31 * result + timeout;
+ result = 31 * result + reconnectWaitTime;
return result;
}
@@ -106,6 +149,4 @@
{
return (TcpDelegatingCacheLoaderConfig) super.clone();
}
-
-
}
\ No newline at end of file
Modified: core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java 2008-01-09 11:52:25 UTC (rev 5103)
+++ core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java 2008-01-09 15:02:25 UTC (rev 5104)
@@ -1,21 +1,39 @@
package org.jboss.cache.loader;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
import org.jboss.cache.loader.tcp.TcpCacheServer;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.notifications.event.Event;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import javax.transaction.Synchronization;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Tests the TcpDelegatingCacheLoader
*
* @author Bela Ban
* @version $Id$
*/
+@Test(groups = "functional")
public class TcpCacheLoaderTest extends CacheLoaderTestsBase
{
+ protected static final int CACHE_SERVER_RESTART_DELAY_MS = 1000;
+ protected static final int TCP_CACHE_LOADER_TIMEOUT_MS = 2000;
+ protected static int START_COUNT = 0;
static TcpCacheServer cache_server = null;
- static
+ @BeforeClass
+ public static void startCacheServer()
{
- Thread runner = new Thread()
+ Thread t = new Thread()
{
public void run()
{
@@ -25,9 +43,10 @@
cache_server = new TcpCacheServer();
cache_server.setBindAddress("127.0.0.1");
cache_server.setPort(12121);
- cache_server.setConfig("META-INF/local-service.xml"); // must be in classpath (./etc/META-INF)
+ cache_server.setConfig("META-INF/local-service.xml"); // must be in classpath
cache_server.create();
cache_server.start();
+ START_COUNT++;
}
catch (Exception ex)
{
@@ -35,41 +54,194 @@
}
}
};
+ t.setDaemon(true);
+ t.start();
+ // give the cache server 2 secs to start up
+ TestingUtil.sleepThread(2000);
+ }
- Runtime.getRuntime().addShutdownHook(new Thread()
+ @AfterClass
+ public static void stopCacheServer()
+ {
+ if (cache_server != null)
{
- public void run()
- {
- if (cache_server != null)
- {
- System.out.println("Stopping TcpCacheServer");
- cache_server.stop();
- }
- }
- });
+ System.out.println("Stopping TcpCacheServer");
+ cache_server.stop();
+ }
+ }
- runner.start();
+ protected static void restartCacheServer()
+ {
+ stopCacheServer();
+ startCacheServer();
}
+ @Override
public void testPartialLoadAndStore()
{
// do nothing
}
+ @Override
public void testBuddyBackupStore()
{
// do nothing
}
-
protected void configureCache() throws Exception
{
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
- "org.jboss.cache.loader.TcpDelegatingCacheLoader",
- "host=127.0.0.1\nport=12121", false, true, false));
+ TcpDelegatingCacheLoader.class.getName(),
+ "host=127.0.0.1\nport=12121\ntimeout=" + TCP_CACHE_LOADER_TIMEOUT_MS, false, true, false));
// give the tcp cache server time to start up
- TestingUtil.sleepThread(2000);
+ //TestingUtil.sleepThread(2000);
}
+ // restart tests
+
+ public void testCacheServerRestartMidCall() throws Exception
+ {
+ CacheServerRestarter restarter = new CacheServerRestarter();
+ restarter.restart = true;
+ cache.addCacheListener(restarter);
+ int oldStartCount = START_COUNT;
+ // a restart of the cache server will happen before the cache loader interceptor is called.
+ cache.put(FQN, "key", "value");
+
+ assert oldStartCount + 1 == START_COUNT : "Cache server should have restarted!";
+ assert loader.get(FQN).equals(Collections.singletonMap("key", "value"));
+ }
+
+ public void testCacheServerDelayedRestartMidCall() throws Exception
+ {
+ CacheServerRestarter restarter = new CacheServerRestarter();
+ restarter.restart = false;
+ restarter.delayedRestart = true;
+ restarter.startAfter = CACHE_SERVER_RESTART_DELAY_MS;
+ cache.addCacheListener(restarter);
+ int oldStartCount = START_COUNT;
+
+ // the cache server will STOP before the cache laoder interceptor is called.
+ // it will be restarted in a separate thread, startAfter millis later.
+ // this should be less than the TcpCacheLoader timeout.
+ cache.put(FQN, "key", "value");
+
+ assert oldStartCount + 1 == START_COUNT : "Cache server should have restarted!";
+ assert loader.get(FQN).equals(Collections.singletonMap("key", "value"));
+ }
+
+ public void testCacheServerTimeoutMidCall() throws Exception
+ {
+ CacheServerRestarter restarter = new CacheServerRestarter();
+ restarter.restart = false;
+ restarter.delayedRestart = true;
+ restarter.startAfter = -1;
+ cache.addCacheListener(restarter);
+ int oldStartCount = START_COUNT;
+
+ // the cache server will STOP before the cache laoder interceptor is called.
+ // it will be restarted in a separate thread, startAfter millis later.
+ // this should be less than the TcpCacheLoader timeout.
+ try
+ {
+ cache.put(FQN, "key", "value");
+ assert false : "Should have failed";
+ }
+ catch (CacheException expected)
+ {
+
+ }
+
+ assert oldStartCount == START_COUNT : "Cache server should NOT have restarted!";
+ // start the TCP server again
+ startCacheServer();
+ assert loader.get(FQN) == null;
+ }
+
+ public void testCacheServerRestartMidTransaction() throws Exception
+ {
+ int oldStartCount = START_COUNT;
+ cache.getTransactionManager().begin();
+ cache.put(FQN, "key", "value");
+ restartCacheServer();
+ cache.put(FQN, "key2", "value2");
+ cache.getTransactionManager().commit();
+
+ Map m = new HashMap();
+ m.put("key", "value");
+ m.put("key2", "value2");
+
+ assert oldStartCount + 1 == START_COUNT : "Cache server should have restarted!";
+ assert loader.get(FQN).equals(m);
+ }
+
+ public void testCacheServerRestartMidTransactionAfterPrepare() throws Exception
+ {
+ int oldStartCount = START_COUNT;
+ cache.getTransactionManager().begin();
+ OrderedSynchronizationHandler.getInstance(cache.getTransactionManager().getTransaction()).registerAtTail(
+ new Synchronization()
+ {
+
+ public void beforeCompletion()
+ {
+ // this will be called after the cache's prepare() phase. Restart the cache server.
+ restartCacheServer();
+ }
+
+ public void afterCompletion(int i)
+ {
+ // do nothing
+ }
+ }
+ );
+
+ cache.put(FQN, "key", "value");
+ cache.put(FQN, "key2", "value2");
+ cache.getTransactionManager().commit();
+
+ Map m = new HashMap();
+ m.put("key", "value");
+ m.put("key2", "value2");
+
+ assert oldStartCount + 1 == START_COUNT : "Cache server should have restarted!";
+ assert loader.get(FQN).equals(m);
+
+ }
+
+ @CacheListener
+ public static class CacheServerRestarter
+ {
+ boolean restart;
+ boolean delayedRestart;
+ int startAfter;
+
+ @NodeCreated
+ public void restart(Event e)
+ {
+ if (e.isPre())
+ {
+ if (restart)
+ {
+ restartCacheServer();
+ }
+ else if (delayedRestart)
+ {
+ stopCacheServer();
+ new Thread()
+ {
+ public void run()
+ {
+ if (startAfter > 0)
+ {
+ TestingUtil.sleepThread(startAfter);
+ startCacheServer();
+ }
+ }
+ }.start();
+ }
+ }
+ }
+ }
}
\ No newline at end of file
17 years
JBoss Cache SVN: r5103 - in core/trunk/src: main/java/org/jboss/cache/config and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-09 06:52:25 -0500 (Wed, 09 Jan 2008)
New Revision: 5103
Added:
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java
core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
Log:
Fixed stuff, plus JBCACHE-1204 - shutdown hook
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -51,6 +51,7 @@
import org.jgroups.util.Rsp;
import org.jgroups.util.RspList;
+import javax.management.MBeanServerFactory;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
@@ -684,26 +685,37 @@
private void addShutdownHook()
{
- // *Always* register a shutdown hook. If cache.stop() is called manually or from an MBean server or microcontainer,
- // cache.stop will de-register the shutdown hook to prevent shutdown from happening again when the JVM exits.
+ ArrayList al = MBeanServerFactory.findMBeanServer(null);
+ boolean registerShutdownHook = (configuration.getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.DEFAULT && al.size() == 0)
+ || configuration.getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.REGISTER;
- shutdownHook = new Thread()
+ if (registerShutdownHook)
{
- public void run()
+ if (trace)
+ log.trace("Registering a shutdown hook. Configured behavior = " + configuration.getShutdownHookBehavior());
+ shutdownHook = new Thread()
{
- try
+ public void run()
{
- invokedFromShutdownHook = true;
- CacheImpl.this.stop();
+ try
+ {
+ invokedFromShutdownHook = true;
+ CacheImpl.this.stop();
+ }
+ finally
+ {
+ invokedFromShutdownHook = false;
+ }
}
- finally
- {
- invokedFromShutdownHook = false;
- }
- }
- };
+ };
- Runtime.getRuntime().addShutdownHook(shutdownHook);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ else
+ {
+ if (trace)
+ log.trace("Not registering a shutdown hook. Configured behavior = " + configuration.getShutdownHookBehavior());
+ }
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -6,6 +6,7 @@
*/
package org.jboss.cache.config;
+import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SingletonStoreCacheLoader;
import org.jboss.cache.xml.XmlHelper;
@@ -181,6 +182,7 @@
private Properties properties;
private SingletonStoreConfig singletonStoreConfig;
+ private CacheLoader cacheLoader;
protected void populateFromBaseConfig(IndividualCacheLoaderConfig base)
{
@@ -287,6 +289,30 @@
this.singletonStoreConfig = singletonStoreConfig;
}
+ /**
+ * Provides the ability to get and set a running cache loader, which, if exists, will be used rather than
+ * constructing a new one. Primarily to facilitate testing with mock objects.
+ *
+ * @return cache loader, if one exists
+ * @since 2.1.0
+ */
+ public CacheLoader getCacheLoader()
+ {
+ return cacheLoader;
+ }
+
+ /**
+ * Provides the ability to get and set a running cache loader, which, if exists, will be used rather than
+ * constructing a new one. Primarily to facilitate testing with mock objects.
+ *
+ * @param cacheLoader cacheLoader to set
+ * @since 2.1.0
+ */
+ public void setCacheLoader(CacheLoader cacheLoader)
+ {
+ this.cacheLoader = cacheLoader;
+ }
+
@Override
public boolean equals(Object obj)
{
@@ -342,7 +368,6 @@
.toString();
}
-
@Override
public IndividualCacheLoaderConfig clone() throws CloneNotSupportedException
{
@@ -351,10 +376,10 @@
clone.properties = (Properties) properties.clone();
if (singletonStoreConfig != null)
clone.setSingletonStoreConfig(singletonStoreConfig.clone());
+ clone.cacheLoader = cacheLoader;
return clone;
}
-
/**
* Configuration for a SingletonStoreCacheLoader
*/
@@ -460,8 +485,6 @@
clone.singletonStoreproperties = (Properties) singletonStoreproperties.clone();
return clone;
}
-
-
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -40,6 +40,25 @@
}
/**
+ * Behavior of the JVM shutdown hook registered by the cache
+ */
+ public enum ShutdownHookBehavior
+ {
+ /**
+ * By default a shutdown hook is registered if no MBean server (apart from the JDK default) is detected.
+ */
+ DEFAULT,
+ /**
+ * Forces the cache to register a shutdown hook even if an MBean server is detected.
+ */
+ REGISTER,
+ /**
+ * Forces the cache NOT to register a shutdown hook, even if no MBean server is detected.
+ */
+ DONT_REGISTER
+ }
+
+ /**
* Cache replication mode.
*/
public enum CacheMode
@@ -165,7 +184,8 @@
private String muxStackName = null;
private boolean usingMultiplexer = false;
private transient RuntimeConfig runtimeConfig;
- private String marshallerClass;// = "org.jboss.cache.marshall.VersionAwareMarshaller";
+ private String marshallerClass;
+ private ShutdownHookBehavior shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
// ------------------------------------------------------------------------------------------------------------
// SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
@@ -347,13 +367,6 @@
this.nodeLockingOptimistic = nodeLockingOptimistic;
}
- @Deprecated
- public void setInitialStateRetrievalTimeout(long stateRetrievalTimeout)
- {
- log.info("Do not use InitialStateRetrievalTimeout - this is deprecated and may disappear in future releases. Use StateRetrievalTimeout instead.");
- setStateRetrievalTimeout(stateRetrievalTimeout);
- }
-
public void setStateRetrievalTimeout(long stateRetrievalTimeout)
{
testImmutability("stateRetrievalTimeout");
@@ -444,11 +457,35 @@
this.usingMultiplexer = usingMultiplexer;
}
+ public void setShutdownHookBehavior(ShutdownHookBehavior shutdownHookBehavior)
+ {
+ testImmutability("shutdownHookBehavior");
+ this.shutdownHookBehavior = shutdownHookBehavior;
+ }
+
+ public void setShutdownHookBehavior(String shutdownHookBehavior)
+ {
+ testImmutability("shutdownHookBehavior");
+ if (shutdownHookBehavior == null)
+ throw new ConfigurationException("Shutdown hook behavior cannot be null", "ShutdownHookBehavior");
+ this.shutdownHookBehavior = ShutdownHookBehavior.valueOf(uc(shutdownHookBehavior));
+ if (this.shutdownHookBehavior == null)
+ {
+ log.warn("Unknown shutdown hook behavior '" + shutdownHookBehavior + "', using defaults.");
+ this.shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
+ }
+ }
+
// ------------------------------------------------------------------------------------------------------------
// GETTERS
// ------------------------------------------------------------------------------------------------------------
+ public ShutdownHookBehavior getShutdownHookBehavior()
+ {
+ return this.shutdownHookBehavior;
+ }
+
public boolean isNodeLockingOptimistic()
{
return nodeLockingOptimistic;
@@ -570,12 +607,6 @@
return nodeLockingScheme;
}
- @Deprecated
- public long getInitialStateRetrievalTimeout()
- {
- return getStateRetrievalTimeout();
- }
-
public long getStateRetrievalTimeout()
{
return stateRetrievalTimeout;
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -352,9 +352,14 @@
unregisterComponent(CacheSPI.class.getName());
unregisterComponent("remoteDelegate");
+ overallState = CONSTRUCTED;
+
registerComponent(CacheImpl.class.getName(), ci, CacheImpl.class);
registerComponent(CacheSPI.class.getName(), spi, CacheSPI.class);
registerComponent("remoteDelegate", rcid, RemoteCacheInvocationDelegate.class);
+
+ overallState = originalState;
+ moveComponentsToState(overallState);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -11,6 +11,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManager;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
@@ -69,10 +70,12 @@
private CacheLoader loader;
private boolean fetchPersistentState;
private Configuration configuration;
+ private RegionManager regionManager;
@Inject
- private void injectDependencies(CacheSPI cache, Configuration configuration)
+ private void injectDependencies(CacheSPI cache, Configuration configuration, RegionManager regionManager)
{
+ this.regionManager = regionManager;
this.config = configuration.getCacheLoaderConfig();
this.cache = cache;
this.configuration = configuration;
@@ -174,7 +177,7 @@
{
CacheLoaderConfig.IndividualCacheLoaderConfig cfg = config.getIndividualCacheLoaderConfigs().get(0);
tmpLoader = createCacheLoader(cfg, cache);
- finalConfigs.add(tmpLoader.getConfig());
+ finalConfigs.add(tmpLoader.getConfig() == null ? cfg : tmpLoader.getConfig());
fetchPersistentState = cfg.isFetchPersistentState();
}
@@ -196,7 +199,7 @@
private CacheLoader createCacheLoader(CacheLoaderConfig.IndividualCacheLoaderConfig cfg, CacheSPI cache) throws Exception
{
// create loader
- CacheLoader tmpLoader = createInstance(cfg.getClassName());
+ CacheLoader tmpLoader = cfg.getCacheLoader() == null ? createInstance(cfg.getClassName()) : cfg.getCacheLoader();
if (tmpLoader != null)
{
@@ -247,7 +250,7 @@
// tmpLoader.start();
if (configuration != null && configuration.isUseRegionBasedMarshalling())
{
- tmpLoader.setRegionManager(cache.getRegionManager());
+ tmpLoader.setRegionManager(regionManager);
}
}
return tmpLoader;
@@ -371,17 +374,6 @@
}
/**
- * Overrides generated cache loader with the one provided,for backward compat. Deprecated, may not prote to all interceptors that need it.
- *
- * @param loader
- */
- @Deprecated
- public void setCacheLoader(CacheLoader loader)
- {
- this.loader = loader;
- }
-
- /**
* Tests if we're using passivation
*/
public boolean isPassivation()
Modified: core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -40,18 +40,13 @@
IndividualCacheLoaderConfig config;
CacheSPI delegate = null;
- public LocalDelegatingCacheLoader()
- {
- }
-
- public LocalDelegatingCacheLoader(CacheSPI delegate)
- {
- this.delegate = delegate;
- }
-
public void setConfig(IndividualCacheLoaderConfig config)
{
this.config = config;
+ if (config instanceof LocalDelegatingCacheLoaderConfig)
+ {
+ delegate = (CacheSPI) ((LocalDelegatingCacheLoaderConfig) config).getDelegate();
+ }
}
public IndividualCacheLoaderConfig getConfig()
Copied: core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java (from rev 5102, core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoaderConfig.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderConfig.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -0,0 +1,65 @@
+package org.jboss.cache.loader;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+
+import java.util.Properties;
+
+public class LocalDelegatingCacheLoaderConfig extends IndividualCacheLoaderConfig
+{
+ private static final long serialVersionUID = 4626734068542420865L;
+
+ private Cache delegate;
+
+ public LocalDelegatingCacheLoaderConfig()
+ {
+ setClassName(LocalDelegatingCacheLoader.class.getName());
+ }
+
+ /**
+ * For use by {@link org.jboss.cache.loader.FileCacheLoader}.
+ *
+ * @param base generic config object created by XML parsing.
+ */
+ LocalDelegatingCacheLoaderConfig(IndividualCacheLoaderConfig base)
+ {
+ setClassName(LocalDelegatingCacheLoader.class.getName());
+ populateFromBaseConfig(base);
+ }
+
+ @Override
+ public void setProperties(Properties props)
+ {
+ super.setProperties(props);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return obj instanceof LocalDelegatingCacheLoaderConfig && equalsExcludingProperties(obj) && delegate == ((LocalDelegatingCacheLoaderConfig) obj).delegate;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return 31 * hashCodeExcludingProperties() + (delegate == null ? 0 : delegate.hashCode());
+ }
+
+ @Override
+ public LocalDelegatingCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ LocalDelegatingCacheLoaderConfig clone = (LocalDelegatingCacheLoaderConfig) super.clone();
+ clone.delegate = delegate;
+ return clone;
+ }
+
+ public Cache getDelegate()
+ {
+ return delegate;
+ }
+
+ public void setDelegate(Cache delegate)
+ {
+ this.delegate = delegate;
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -8,15 +8,18 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
/**
* A simple non-failing unit test to measure how many times each method on a cache loader is called.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
+@Test(groups = "functional")
public class CacheLoaderMethodCallCounterTest extends AbstractCacheLoaderTestBase
{
private CacheSPI cache;
@@ -35,12 +38,7 @@
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- if (cache != null)
- {
- cache.stop();
- }
- cache.destroy();
- cache = null;
+ TestingUtil.killCaches(cache);
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -43,7 +43,8 @@
//setCacheLoader(new TestSlowCacheLoader());
CacheLoaderConfig clc = new CacheLoaderConfig();
IndividualCacheLoaderConfig iclc = new IndividualCacheLoaderConfig();
- iclc.setClassName(TestSlowCacheLoader.class.getName());
+ //iclc.setClassName(TestSlowCacheLoader.class.getName());
+ iclc.setCacheLoader(new TestSlowCacheLoader());
clc.addIndividualCacheLoaderConfig(iclc);
cache.getConfiguration().setCacheLoaderConfig(clc);
cache.start();
Modified: core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -2,11 +2,8 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.interceptors.ActivationInterceptor;
-import org.jboss.cache.interceptors.PassivationInterceptor;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.util.reflect.ReflectionUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -22,14 +19,13 @@
delegating_cache.create();
delegating_cache.start();
- // setCache first ...
- cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false, false, false));
-
- // force our own cache loader instance
- LocalDelegatingCacheLoader cacheLoader = new LocalDelegatingCacheLoader(delegating_cache);
-
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, PassivationInterceptor.class), "loader", cacheLoader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, ActivationInterceptor.class), "loader", cacheLoader);
+ LocalDelegatingCacheLoaderConfig cfg = new LocalDelegatingCacheLoaderConfig();
+ cfg.setDelegate(delegating_cache);
+ cfg.setAsync(false);
+ cfg.setFetchPersistentState(false);
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(cfg);
+ cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
}
protected void postConfigure()
Modified: core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -1,16 +1,11 @@
package org.jboss.cache.loader;
-import org.easymock.EasyMock;
import static org.easymock.EasyMock.*;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.interceptors.CacheLoaderInterceptor;
-import org.jboss.cache.interceptors.CacheStoreInterceptor;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.util.reflect.ReflectionUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -35,31 +30,55 @@
private CacheLoader mockCacheLoader;
@BeforeMethod(alwaysRun = true)
- public void setUp()
+ public void setUp() throws Exception
{
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
CacheLoaderConfig clc = new CacheLoaderConfig();
CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
- iclc.setClassName(DummyInMemoryCacheLoader.class.getName());
clc.addIndividualCacheLoaderConfig(iclc);
cache.getConfiguration().setCacheLoaderConfig(clc);
- cache.start();
- mockCacheLoader = EasyMock.createMock(CacheLoader.class);
+ mockCacheLoader = createMock(CacheLoader.class);
- cache.getCacheLoaderManager().setCacheLoader(mockCacheLoader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, CacheLoaderInterceptor.class), "loader", mockCacheLoader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, CacheStoreInterceptor.class), "loader", mockCacheLoader);
-
- // lifecycle stuff
+ expect(mockCacheLoader.getConfig()).andReturn(null).anyTimes();
+ mockCacheLoader.setCache((CacheSPI) anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.setConfig((CacheLoaderConfig.IndividualCacheLoaderConfig) anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.create();
+ expectLastCall().anyTimes();
+ mockCacheLoader.start();
+ expectLastCall().anyTimes();
mockCacheLoader.stop();
- EasyMock.expectLastCall().times(0, 1);
+ expectLastCall().anyTimes();
mockCacheLoader.destroy();
- EasyMock.expectLastCall().times(0, 1);
+ expectLastCall().anyTimes();
+ replay(mockCacheLoader);
+
+ iclc.setCacheLoader(mockCacheLoader);
+ cache.start();
+
+ reset(mockCacheLoader);
}
@AfterMethod(alwaysRun = true)
- public void tearDown()
+ public void tearDown() throws Exception
{
+ reset(mockCacheLoader);
+ expect(mockCacheLoader.getConfig()).andReturn(null).anyTimes();
+ mockCacheLoader.setCache((CacheSPI) anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.setConfig((CacheLoaderConfig.IndividualCacheLoaderConfig) anyObject());
+ expectLastCall().anyTimes();
+ mockCacheLoader.create();
+ expectLastCall().anyTimes();
+ mockCacheLoader.start();
+ expectLastCall().anyTimes();
+ mockCacheLoader.stop();
+ expectLastCall().anyTimes();
+ mockCacheLoader.destroy();
+ expectLastCall().anyTimes();
+ replay(mockCacheLoader);
+
cache.stop();
}
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java 2008-01-09 00:45:11 UTC (rev 5102)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java 2008-01-09 11:52:25 UTC (rev 5103)
@@ -2,13 +2,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.interceptors.ActivationInterceptor;
-import org.jboss.cache.interceptors.PassivationInterceptor;
import org.jboss.cache.loader.CacheLoader;
-import org.jboss.cache.loader.LocalDelegatingCacheLoader;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.util.reflect.ReflectionUtil;
+import org.jboss.cache.loader.LocalDelegatingCacheLoaderConfig;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -24,20 +21,21 @@
CacheSPI delegating_cache;
CacheLoader cache_loader;
- @SuppressWarnings("deprecation")
protected void configureCache() throws Exception
{
delegating_cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
delegating_cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
delegating_cache.create();
delegating_cache.start();
- cache_loader = new LocalDelegatingCacheLoader(delegating_cache);
- // setCache first ...
- cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig("", "org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false, false));
- cache.getCacheLoaderManager().setCacheLoader(cache_loader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, PassivationInterceptor.class), "loader", cache_loader);
- ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, ActivationInterceptor.class), "loader", cache_loader);
+ LocalDelegatingCacheLoaderConfig cfg = new LocalDelegatingCacheLoaderConfig();
+ cfg.setDelegate(delegating_cache);
+ cfg.setAsync(false);
+ cfg.setFetchPersistentState(false);
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(cfg);
+ cacheLoaderConfig.setPassivation(true);
+ cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
}
@AfterMethod(alwaysRun = true)
17 years
JBoss Cache SVN: r5102 - core/trunk/src/main/java/org/jboss/cache/factories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-08 19:45:11 -0500 (Tue, 08 Jan 2008)
New Revision: 5102
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
Log:
Fixed proper bootstrapping after a reset
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-08 22:57:05 UTC (rev 5101)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-01-09 00:45:11 UTC (rev 5102)
@@ -75,6 +75,7 @@
Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
private static Log log = LogFactory.getLog(ComponentRegistry.class);
+ private Bootstrap bootstrap;
/**
* Creates an instance of the component registry. The configuration passed in is automatically registered.
@@ -560,13 +561,8 @@
conf.changeState(CONSTRUCTED);
cr.changeState(CONSTRUCTED);
- componentLookup.put(Configuration.class.getName(), conf);
- componentLookup.put(ComponentRegistry.class.getName(), cr);
- componentLookup.put(CacheImpl.class.getName(), impl);
- componentLookup.put(CacheSPI.class.getName(), spi);
+ bootstrap = new Bootstrap((CacheImpl) impl.instance, (CacheSPI) spi.instance, (ComponentRegistry) cr.instance, (Configuration) conf.instance);
- spi.changeState(WIRED);
-
overallState = null;
}
@@ -591,15 +587,20 @@
*/
public void wire()
{
+ if (bootstrap != null && !bootstrap.isBootstrapped())
+ {
+ bootstrap.bootstrap();
+ }
+
moveComponentsToState(WIRED);
}
void moveComponentsToState(State state)
{
- if (overallState == null)
+ if (overallState == null && bootstrap != null && !bootstrap.isBootstrapped())
{
// we have been destroyed! Need to bootstrap again.
- bootstrap();
+ bootstrap.bootstrap();
}
for (Component c : componentLookup.values())
@@ -610,22 +611,6 @@
}
/**
- * Always assumes that the 4 core bootstrap components are in the registry. Will now attempt to make sure their dependencies are built.
- */
- void bootstrap()
- {
- // the bootstrap classes
- Component spi = componentLookup.get(CacheSPI.class.getName());
- Component impl = componentLookup.get(CacheImpl.class.getName());
- Component conf = componentLookup.get(Configuration.class.getName());
- Component cr = componentLookup.get(ComponentRegistry.class.getName());
- addComponentDependencies(spi, true);
- addComponentDependencies(impl, true);
- addComponentDependencies(conf, true);
- addComponentDependencies(cr, true);
- }
-
- /**
* Represents the state of a component
*/
enum State
@@ -797,10 +782,6 @@
// of we are "moving up" - only do this if the component is lower than what is needed.
if ((increase && newState.isGreaterThan(c.state)) || (!increase && newState.isLessThan(c.state)))
{
- if (c.name.endsWith("CacheLoaderManager"))
- {
- boolean itrue = true;
- }
c.changeState(newState);
}
@@ -911,4 +892,37 @@
return "Component (name = " + name + ", state = " + state + ")";
}
}
+
+ class Bootstrap
+ {
+ CacheImpl cacheImpl;
+ CacheSPI cacheSPI;
+ ComponentRegistry componentRegistry;
+ Configuration configuration;
+
+ Bootstrap(CacheImpl cacheImpl, CacheSPI cacheSPI, ComponentRegistry componentRegistry, Configuration configuration)
+ {
+ this.cacheImpl = cacheImpl;
+ this.cacheSPI = cacheSPI;
+ this.componentRegistry = componentRegistry;
+ this.configuration = configuration;
+ }
+
+ boolean isBootstrapped()
+ {
+ return componentLookup.containsKey(Configuration.class.getName()) &&
+ componentLookup.containsKey(CacheImpl.class.getName()) &&
+ componentLookup.containsKey(CacheSPI.class.getName()) &&
+ componentLookup.containsKey(ComponentRegistry.class.getName());
+ }
+
+ void bootstrap()
+ {
+ overallState = CONSTRUCTED;
+ registerComponent(Configuration.class.getName(), configuration, Configuration.class);
+ registerComponent(ComponentRegistry.class.getName(), componentRegistry, ComponentRegistry.class);
+ registerComponent(CacheImpl.class.getName(), cacheImpl, CacheImpl.class);
+ registerComponent(CacheSPI.class.getName(), cacheSPI, CacheSPI.class);
+ }
+ }
}
\ No newline at end of file
17 years