JBoss Cache SVN: r7784 - core/trunk/src/main/release/licenses.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-25 07:06:48 -0500 (Wed, 25 Feb 2009)
New Revision: 7784
Modified:
core/trunk/src/main/release/licenses/README-bdbje-lib.txt
Log:
Updated berkeleydb license details
Modified: core/trunk/src/main/release/licenses/README-bdbje-lib.txt
===================================================================
--- core/trunk/src/main/release/licenses/README-bdbje-lib.txt 2009-02-25 12:04:57 UTC (rev 7783)
+++ core/trunk/src/main/release/licenses/README-bdbje-lib.txt 2009-02-25 12:06:48 UTC (rev 7784)
@@ -2,14 +2,13 @@
$Id$
NAME: Sleepycat Berkeley DB Java Edition
-VERSION: 1.7.0
PROJECT: http://www.oracle.com/database/berkeley-db/je/index.html
PURPOSE: Used for Berkeley DB-based CacheLoader (org.jboss.cache.loader.bdbje.BdbjeCacheLoader) in JBossCache
RESTRICTION: JBossCache can use Berkeley DB Java Edition from Oracle
for persistent, reliable and transaction-protected
data storage. If you choose to use Berkeley DB Java Edition
with JBossCache, you must comply with the terms of
- Oracle's public license, included in the file LICENSE.txt.
+ Oracle's public license, included in the file LICENSE-bdbje-lib.txt.
If you prefer not to release the source code for your own
application in order to comply with the Oracle public
license, you may purchase a different license for use of
15 years, 10 months
JBoss Cache SVN: r7783 - core/trunk.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-25 07:04:57 -0500 (Wed, 25 Feb 2009)
New Revision: 7783
Modified:
core/trunk/pom.xml
Log:
Updated berkeleydb version
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2009-02-25 12:02:25 UTC (rev 7782)
+++ core/trunk/pom.xml 2009-02-25 12:04:57 UTC (rev 7783)
@@ -66,9 +66,9 @@
<optional>true</optional>
</dependency>
<dependency>
- <groupId>sleepycat</groupId>
+ <groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>
- <version>3.2.43</version>
+ <version>3.3.75</version>
<optional>true</optional>
</dependency>
<dependency>
@@ -238,6 +238,11 @@
<id>e-xml.sourceforge.net</id>
<url>http://e-xml.sourceforge.net/maven2/repository</url>
</repository>
+ <!-- For Sleepycat -->
+ <repository>
+ <id>berkeleydb-je.repository</id>
+ <url>http://download.oracle.com/maven/</url>
+ </repository>
</repositories>
<profiles>
15 years, 10 months
JBoss Cache SVN: r7782 - in core/branches/flat/src: main/java/org/horizon/atomic and 28 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-25 07:02:25 -0500 (Wed, 25 Feb 2009)
New Revision: 7782
Modified:
core/branches/flat/src/main/java/org/horizon/CacheDelegate.java
core/branches/flat/src/main/java/org/horizon/Version.java
core/branches/flat/src/main/java/org/horizon/atomic/AtomicMap.java
core/branches/flat/src/main/java/org/horizon/commands/remote/ClusteredGetCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java
core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java
core/branches/flat/src/main/java/org/horizon/container/NullMarkerEntry.java
core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java
core/branches/flat/src/main/java/org/horizon/container/RepeatableReadEntry.java
core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java
core/branches/flat/src/main/java/org/horizon/eviction/DefaultEvictionAction.java
core/branches/flat/src/main/java/org/horizon/eviction/EvictionAction.java
core/branches/flat/src/main/java/org/horizon/eviction/algorithms/BaseEvictionAlgorithm.java
core/branches/flat/src/main/java/org/horizon/eviction/events/EvictionEvent.java
core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java
core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java
core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java
core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/CallInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/InvocationContextInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/PassivationInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/base/BaseRpcInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java
core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java
core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java
core/branches/flat/src/main/java/org/horizon/lock/IsolationLevel.java
core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java
core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
core/branches/flat/src/main/java/org/horizon/remoting/ReplicationQueue.java
core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java
core/branches/flat/src/main/java/org/horizon/statetransfer/StateTransferManager.java
core/branches/flat/src/main/java/org/horizon/transaction/GenericTransactionManagerLookup.java
core/branches/flat/src/main/java/org/horizon/util/concurrent/locks/OwnableReentrantLock.java
core/branches/flat/src/main/release/JBossORG-EULA.txt
core/branches/flat/src/main/release/README-Demo.txt
core/branches/flat/src/main/release/README-libs.txt
core/branches/flat/src/main/release/README.txt
core/branches/flat/src/main/release/licenses/README-bdbje-lib.txt
core/branches/flat/src/test/java/org/horizon/api/tree/TreeCacheAPITest.java
core/branches/flat/src/test/java/org/horizon/eviction/algorithms/lru/LruQueueTest.java
core/branches/flat/src/test/java/org/horizon/eviction/algorithms/mru/MruQueueTest.java
core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java
core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java
core/branches/flat/src/test/java/org/horizon/test/TestNameVerifier.java
core/branches/flat/src/test/java/org/horizon/test/TestingUtil.java
core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java
Log:
Naming, Javadocs and Comments
Modified: core/branches/flat/src/main/java/org/horizon/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/CacheDelegate.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/CacheDelegate.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -207,8 +207,7 @@
if (transactionManager != null && (ongoingTransaction = transactionManager.getTransaction()) != null) {
transactionManager.suspend();
}
-
- // if the node exists then this should be a no-op.
+ // if the entry exists then this should be a no-op.
putIfAbsent(key, value, Options.FAIL_SILENTLY, Options.FORCE_ASYNCHRONOUS, Options.ZERO_LOCK_ACQUISITION_TIMEOUT);
}
catch (Exception e) {
Modified: core/branches/flat/src/main/java/org/horizon/Version.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/Version.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/Version.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -24,7 +24,7 @@
import net.jcip.annotations.Immutable;
/**
- * Contains version information about this release of JBoss Cache.
+ * Contains version information about this release of Horizon.
*
* @author Bela Ban
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/atomic/AtomicMap.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/atomic/AtomicMap.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/atomic/AtomicMap.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -24,7 +24,7 @@
import java.util.Map;
/**
- * This is a special type of Map geared for use in JBoss Cache. This map type supports JBoss Cache atomicizing writes
+ * This is a special type of Map geared for use in Horizon. This map type supports Horizon atomicizing writes
* on the cache such that a coarse grained locking is used if this map is stored in the cache, such that the entire map
* is locked for writes or is isolated for safe concurrent read.
* <p/>
Modified: core/branches/flat/src/main/java/org/horizon/commands/remote/ClusteredGetCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/remote/ClusteredGetCommand.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/commands/remote/ClusteredGetCommand.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -45,15 +45,13 @@
public static final byte METHOD_ID = 22;
private DataCommand dataCommand;
- private boolean searchBackupSubtrees;
private DataContainer dataContainer;
private InterceptorChain interceptorChain;
private static final Log log = LogFactory.getLog(ClusteredGetCommand.class);
private static final boolean trace = log.isTraceEnabled();
- public ClusteredGetCommand(boolean searchBackupSubtrees, DataCommand dataCommand) {
- this.searchBackupSubtrees = searchBackupSubtrees;
+ public ClusteredGetCommand(boolean unused, DataCommand dataCommand) {
this.dataCommand = dataCommand;
}
@@ -74,7 +72,7 @@
*/
public Object perform(InvocationContext context) throws Throwable {
if (trace)
- log.trace("Clustered Get called with params: " + dataCommand + ", " + searchBackupSubtrees);
+ log.trace("Clustered Get called with param: " + dataCommand);
Object callResults = null;
try {
@@ -112,21 +110,16 @@
return null;
}
- public Boolean getSearchBackupSubtrees() {
- return searchBackupSubtrees;
- }
-
public DataCommand getDataCommand() {
return dataCommand;
}
public Object[] getParameters() {
- return new Object[]{dataCommand, searchBackupSubtrees}; //To change body of implemented methods use File | Settings | File Templates.
+ return new Object[]{dataCommand}; //To change body of implemented methods use File | Settings | File Templates.
}
public void setParameters(int commandId, Object[] args) {
dataCommand = (DataCommand) args[0];
- searchBackupSubtrees = (Boolean) args[1];
}
@Override
@@ -136,16 +129,13 @@
ClusteredGetCommand that = (ClusteredGetCommand) o;
- if (dataCommand != null ? !dataCommand.equals(that.dataCommand) : that.dataCommand != null)
- return false;
- return searchBackupSubtrees == that.searchBackupSubtrees;
+ return !(dataCommand != null ? !dataCommand.equals(that.dataCommand) : that.dataCommand != null);
}
@Override
public int hashCode() {
int result;
result = (dataCommand != null ? dataCommand.hashCode() : 0);
- result = 31 * result + (searchBackupSubtrees ? 1 : 0);
return result;
}
@@ -153,7 +143,6 @@
public String toString() {
return "ClusteredGetCommand{" +
"dataCommand=" + dataCommand +
- ", searchBackupSubtrees=" + searchBackupSubtrees +
'}';
}
}
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -31,8 +31,7 @@
/**
- * Removes a node's content from memory - never removes the node. It also clenups data for resident nodes - which are
- * not being touched by eviction.
+ * Removes an entry from memory - never removes the entry.
*
* @author Mircea.Markus(a)jboss.com
* @since 1.0
@@ -52,7 +51,7 @@
}
/**
- * Performs an invalidation on a specified node
+ * Performs an invalidation on a specified entry
*
* @param ctx invocation context
* @return null
Modified: core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -431,14 +431,14 @@
}
/**
- * Tests whether the element passed in is a modern (3.0) config element rather than a legacy one.
+ * Tests whether the element passed in is a valid config element.
*
* @param element element to test
* @return true of the element is a modern one and can be parsed using the current parser.
*/
public boolean isValidElementRoot(Element element) {
- // simply test for the "jbosscache" element.
- NodeList elements = element.getElementsByTagName("jbosscache");
+ // simply test for the "horizon" element.
+ NodeList elements = element.getElementsByTagName("horizon");
return elements != null && elements.getLength() > 0;
}
}
Modified: core/branches/flat/src/main/java/org/horizon/container/NullMarkerEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/NullMarkerEntry.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/container/NullMarkerEntry.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -22,7 +22,7 @@
package org.horizon.container;
/**
- * A marker node to represent a null node for repeatable read, so that a read that returns a null can continue to return
+ * A marker entry to represent a null for repeatable read, so that a read that returns a null can continue to return
* null.
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
@@ -38,7 +38,7 @@
}
/**
- * @return always returns true so that any get commands, upon getting this node, will ignore the node as though it
+ * @return always returns true so that any get commands, upon getting this entry, will ignore the entry as though it
* were removed.
*/
@Override
@@ -47,7 +47,7 @@
}
/**
- * @return always returns true so that any get commands, upon getting this node, will ignore the node as though it
+ * @return always returns true so that any get commands, upon getting this entry, will ignore the entry as though it
* were invalid.
*/
@Override
Modified: core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -26,7 +26,7 @@
import org.horizon.logging.LogFactory;
/**
- * A node delegate that encapsulates read committed semantics when writes are initiated, committed or rolled back.
+ * A wrapper around a cached entry that encapsulates read committed semantics when writes are initiated, committed or rolled back.
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/container/RepeatableReadEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/RepeatableReadEntry.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/container/RepeatableReadEntry.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -27,7 +27,7 @@
import org.horizon.logging.LogFactory;
/**
- * A node delegate that encapsulates repeatable read semantics when writes are initiated, committed or rolled back.
+ * An extension of {@link org.horizon.container.ReadCommittedEntry} that provides Repeatable Read semantics
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 1.0
@@ -43,7 +43,7 @@
public void copyForUpdate(DataContainer container, boolean writeSkewCheck) {
if (isFlagSet(CHANGED)) return; // already copied
- // mark node as changed.
+ // mark entry as changed.
setFlag(CHANGED);
if (writeSkewCheck) {
Modified: core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -36,7 +36,7 @@
/**
* Retrieves an entry from the collection of looked up entries in the current scope.
* <p/>
- * If a transaction is in progress, implementations should delegate to {@link org.horizon.context.TransactionContext#lookupEntry(Object)}
+ * If a transaction is in progress, implementations should delegate to the same method in {@link TransactionContext}.
* <p/>
*
* @param key key to look up
@@ -47,7 +47,7 @@
/**
* Retrieves a map of entries looked up within the current scope.
* <p/>
- * If a transaction is in progress, implementations should delegate to {@link org.horizon.context.TransactionContext#getLookedUpEntries()}.
+ * If a transaction is in progress, implementations should delegate to the same method in {@link TransactionContext}.
* <p/>
*
* @return a map of looked up entries.
@@ -55,10 +55,9 @@
Map<Object, MVCCEntry> getLookedUpEntries();
/**
- * Puts an entry in the registry of looked up nodes in the current scope.
+ * Puts an entry in the registry of looked up entries in the current scope.
* <p/>
- * If a transaction is in progress, implementations should delegate to {@link TransactionContext#putLookedUpEntry(Object,
- * org.horizon.container.MVCCEntry)}
+ * If a transaction is in progress, implementations should delegate to the same method in {@link TransactionContext}.
* <p/>
*
* @param key key to store
Modified: core/branches/flat/src/main/java/org/horizon/eviction/DefaultEvictionAction.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/eviction/DefaultEvictionAction.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/eviction/DefaultEvictionAction.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -26,7 +26,7 @@
import org.horizon.logging.LogFactory;
/**
- * Default eviction action policy that calls {@link Cache#evict(Object)} to evict a node.
+ * Default eviction action policy that calls {@link Cache#evict(Object)} to evict an entry.
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 1.0
@@ -42,11 +42,11 @@
@SuppressWarnings("unchecked")
public boolean evict(Object key) {
- if (trace) log.trace("Attempting to evict cache node with key of {0}", key);
+ if (trace) log.trace("Attempting to evict cached entry with key of {0}", key);
try {
cache.evict(key);
- log.trace("Eviction of cache node with key of {0} successful", key);
+ log.trace("Eviction of cached entry with key of {0} successful", key);
return true;
}
catch (Exception e) {
Modified: core/branches/flat/src/main/java/org/horizon/eviction/EvictionAction.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/eviction/EvictionAction.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/eviction/EvictionAction.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -38,7 +38,7 @@
void setCache(Cache<?, ?> cache);
/**
- * Performs an eviction on a given node.
+ * Performs an eviction on a given entry.
*
* @param key key of entry to evict
* @return true if the eviction was successful, false if not.
Modified: core/branches/flat/src/main/java/org/horizon/eviction/algorithms/BaseEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/eviction/algorithms/BaseEvictionAlgorithm.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/eviction/algorithms/BaseEvictionAlgorithm.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -192,10 +192,10 @@
processClearCacheEvent();
break;
case MARK_IN_USE_EVENT:
- processMarkInUseNodes(event.getKey(), ((InUseEvictionEvent) event).getInUseTimeout());
+ processMarkInUse(event.getKey(), ((InUseEvictionEvent) event).getInUseTimeout());
break;
case UNMARK_IN_USE_EVENT:
- processUnmarkInUseNodes(event.getKey());
+ processUnmarkInUse(event.getKey());
break;
case EXPIRED_DATA_PURGE_START:
if (keysToRetainInQueue == null) keysToRetainInQueue = new HashSet<Object>();
@@ -225,7 +225,7 @@
if (!result) {
log.warn("Unable to add key {0} to the recycle queue." +
"This is often sign that " +
- "evictions are not occurring and nodes that should be " +
+ "evictions are not occurring and entries that should be " +
"evicted are piling up waiting to be evicted.", key);
}
}
@@ -235,13 +235,13 @@
}
}
- protected void processMarkInUseNodes(Object key, long inUseTimeout) throws EvictionException {
+ protected void processMarkInUse(Object key, long inUseTimeout) throws EvictionException {
log.trace("Marking {0} as in use with a usage timeout of {1}", key, inUseTimeout);
keysInUse.put(key, inUseTimeout + System.currentTimeMillis());
}
- protected void processUnmarkInUseNodes(Object key) throws EvictionException {
- log.trace("Unmarking node {0} as in use", key);
+ protected void processUnmarkInUse(Object key) throws EvictionException {
+ log.trace("Unmarking {0} as in use", key);
keysInUse.remove(key);
}
@@ -273,7 +273,7 @@
/**
* Empty the Recycle Queue.
* <p/>
- * This method will go through the recycle queue and retry to evict the nodes from cache.
+ * This method will go through the recycle queue and retry to evict the entries from cache.
*
* @throws EvictionException
*/
Modified: core/branches/flat/src/main/java/org/horizon/eviction/events/EvictionEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/eviction/events/EvictionEvent.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/eviction/events/EvictionEvent.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -22,7 +22,7 @@
package org.horizon.eviction.events;
/**
- * An eviction event records activity on nodes in the cache. These are recorded for processing later.
+ * An eviction event records activity on entries in the cache. These are recorded for processing later.
*
* @author (various)
* @since 1.0
@@ -65,19 +65,9 @@
@Override
public String toString() {
- return "EvictedEventNode[key=" + key + " event=" + type + "]";
+ return "EvictionEvent[key=" + key + " event=" + type + "]";
}
- /**
- * Copies this evicted event node to create a new one with the same values, except with a new Fqn root.
- *
- * @param key new Fqn root to use
- * @return a new EvictedEventNode instance
- */
- public EvictionEvent copy(Object key) {
- return new EvictionEvent(key, type);
- }
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
Modified: core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentFactory.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -30,7 +30,7 @@
import org.horizon.logging.LogFactory;
/**
- * Factory that creates components used internally within JBoss Cache, and also wires dependencies into the components.
+ * Factory that creates components used internally within Horizon, and also wires dependencies into the components.
* <p/>
* The {@link DefaultCacheFactory} is a special subclass of this, which bootstraps the construction of other components.
* When this class is loaded, it maintains a static list of known default factories for known components, which it then
Modified: core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/factories/AbstractComponentRegistry.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -110,7 +110,7 @@
* Wires an object instance with dependencies annotated with the {@link Inject} annotation, creating more components
* as needed based on the Configuration passed in if these additional components don't exist in the {@link
* ComponentRegistry}. Strictly for components that don't otherwise live in the registry and have a lifecycle, such
- * as Nodes.
+ * as Commands.
*
* @param target object to wire
* @throws ConfigurationException if there is a problem wiring the instance
Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -35,7 +35,7 @@
void releaseLock(InvocationContext ctx, Object key);
/**
- * Attempts to lock a node if the lock isn't already held in the current scope, and records the lock in the context.
+ * Attempts to lock an entry if the lock isn't already held in the current scope, and records the lock in the context.
*
* @param ctx context
* @param key Key to lock
Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -85,7 +85,7 @@
return wrapEntryForWriting(ctx, key, false, false);
} else if ((mvccEntry = ctx.lookupEntry(key)) == null) {
if (trace) log.trace("Key " + key + " is not in context, fetching from container.");
- // simple implementation. Peek the node, wrap it, put wrapped node in the context.
+ // simple implementation. Peek the entry, wrap it, put wrapped entry in the context.
StoredEntry se = container.createEntryForStorage(key);
mvccEntry = se == null ?
createWrappedEntry(key, null, false, -1) :
@@ -105,12 +105,12 @@
{
// acquire lock if needed
if (acquireLock(ctx, key)) {
- // create a copy of the underlying node
+ // create a copy of the underlying entry
mvccEntry.copyForUpdate(container, writeSkewCheck);
}
if (trace) log.trace("Exists in context.");
if (mvccEntry.isDeleted() && createIfAbsent) {
- if (trace) log.trace("Node is deleted in current scope. Need to un-delete.");
+ if (trace) log.trace("Entry is deleted in current scope. Need to un-delete.");
mvccEntry.setDeleted(false);
mvccEntry.setValid(true);
}
@@ -129,7 +129,7 @@
} else if (createIfAbsent) {
// this is the *only* point where new entries can be created!!
if (trace) log.trace("Creating new entry.");
- // now to lock and create the node. Lock first to prevent concurrent creation!
+ // now to lock and create the entry. Lock first to prevent concurrent creation!
acquireLock(ctx, key);
notifier.notifyCacheEntryCreated(key, true, ctx);
mvccEntry = createWrappedEntry(key, null, true, -1);
@@ -147,7 +147,7 @@
}
/**
- * Attempts to lock a node if the lock isn't already held in the current scope, and records the lock in the context.
+ * Attempts to lock an entry if the lock isn't already held in the current scope, and records the lock in the context.
*
* @param ctx context
* @param key Key to lock
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -119,7 +119,7 @@
}
/**
- * Loads a node from loader
+ * Loads an entry from loader
*/
private MVCCEntry loadEntry(InvocationContext ctx, Object key, MVCCEntry entry) throws Exception {
log.trace("Loading key {0}", key);
@@ -153,12 +153,12 @@
notifier.notifyCacheEntryLoaded(key, pre, ctx);
}
- @ManagedAttribute(description = "number of cache loader node loads")
+ @ManagedAttribute(description = "number of cache loader loads")
public long getCacheLoaderLoads() {
return cacheLoads.get();
}
- @ManagedAttribute(description = "number of cache loader node misses")
+ @ManagedAttribute(description = "number of cache loader misses")
public long getCacheLoaderMisses() {
return cacheMisses.get();
}
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/CallInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/CallInterceptor.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/CallInterceptor.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -40,9 +40,6 @@
* Always at the end of the chain, directly in front of the cache. Simply calls into the cache using reflection. If the
* call resulted in a modification, add the Modification to the end of the modification list keyed by the current
* transaction.
- * <p/>
- * Although always added to the end of an optimistically locked chain as well, calls should not make it down to this
- * interceptor unless it is a call the OptimisticNodeInterceptor knows nothing about.
*
* @author Bela Ban
* @since 1.0
@@ -102,12 +99,6 @@
return handleAlterCacheMethod(ctx, command);
}
-
- /**
- * only add the modification to the modification list if we are using pessimistic locking. Optimistic locking calls
- * *should* not make it this far down the interceptor chain, but just in case a method has been invoked that the
- * OptimisticNodeInterceptor knows nothing about, it will filter down here.
- */
private Object handleAlterCacheMethod(InvocationContext ctx, VisitableCommand command)
throws Throwable {
Object result = invokeCommand(ctx, command);
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/InvocationContextInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/InvocationContextInterceptor.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/InvocationContextInterceptor.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -167,7 +167,7 @@
// TODO: Calling ctx.reset() here breaks stuff. Check whether this is just becuse UTs expect stuff in the ctx or whether this really breaks functionality.
// ctx.reset();
- // instead, for now, just wipe contents of the looked up node map
+ // instead, for now, just wipe contents of the looked up entries
ctx.clearLookedUpEntries();
}
}
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/PassivationInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/PassivationInterceptor.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/PassivationInterceptor.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -18,7 +18,7 @@
import java.util.concurrent.atomic.AtomicLong;
/**
- * Writes evicted nodes back to the store on the way in through the CacheStore
+ * Writes evicted entries back to the store on the way in through the CacheStore
*
* @since 1.0
*/
@@ -46,7 +46,7 @@
@Override
public Object visitEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable {
- // notify listeners that this node is about to be passivated
+ // notify listeners that this entry is about to be passivated
Object key = command.getKey();
notifier.notifyCacheEntryPassivated(key, true, ctx);
log.trace("Passivating entry {0}", key);
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -37,7 +37,7 @@
import org.horizon.transaction.GlobalTransaction;
/**
- * Takes care of replicating modifications to other nodes in a cluster. Also listens for prepare(), commit() and
+ * Takes care of replicating modifications to other caches in a cluster. Also listens for prepare(), commit() and
* rollback() messages which are received 'side-ways' (see docs/design/Refactoring.txt).
*
* @author Bela Ban
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/base/BaseRpcInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/base/BaseRpcInterceptor.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/base/BaseRpcInterceptor.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -77,7 +77,7 @@
if (rsp != null && rsp instanceof Throwable) {
// lets print a stack trace first.
if (log.isDebugEnabled())
- log.debug("Received Throwable from remote node", (Throwable) rsp);
+ log.debug("Received Throwable from remote cache", (Throwable) rsp);
throw (Throwable) rsp;
}
}
@@ -161,7 +161,7 @@
}
/**
- * The call runs in a transaction and it was initiated on this node of the cluster.
+ * The call runs in a transaction and it was initiated on this cache instance of the cluster.
*/
protected final boolean isTransactionalAndLocal(InvocationContext ctx) {
GlobalTransaction gtx = ctx.getGlobalTransaction();
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/base/CommandInterceptor.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -103,8 +103,7 @@
/**
* Invokes the next interceptor in the chain. This is how interceptor implementations should pass a call up the
- * chain to the next interceptor. In previous (pre-2.2.0) implementations of JBoss Cache, this was done by calling
- * <pre>super.invoke()</pre>.
+ * chain to the next interceptor.
*
* @param ctx invocation context
* @param command command to pass up the chain.
Modified: core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -41,10 +41,10 @@
* <b>ManagedOperation</b> or/and <b>MBean</b>. If no <b>MBean</b> server is provided, then the {@link
* java.lang.management.ManagementFactory#getPlatformMBeanServer()} is being used. <p/> It is immutable: both cache
* instance and MBeanServer are being passed as arguments to the constructor. <p /> <p> Note that by default object
- * names used are prefixed with <tt>jboss.cache:service=JBossCache</tt>. While this format works for and is consistent
+ * names used are prefixed with <tt>jboss.cache:service=Horizon</tt>. While this format works for and is consistent
* with JBoss AS and the JMX console, it has been known to cause problems with other JMX servers such as Websphere. To
* work around this, you can provide the following VM system property to override this prefix with a prefix of your
- * choice: <tt><b>-Djbosscache.jmx.prefix=JBossCache</b></tt> </p>
+ * choice: <tt><b>-Dhorizon.jmx.prefix=Horizon</b></tt> </p>
*
* @author Mircea.Markus(a)jboss.com
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -63,7 +63,7 @@
if (config.isExposeManagementStatistics()) {
JmxRegistrationManager jmxRegistrationManager = new JmxRegistrationManager(cache);
jmxRegistrationManager.registerAllMBeans();
- log.info("JBossCache MBeans were successfully registered to the platform mbean server.");
+ log.info("MBeans were successfully registered to the platform mbean server.");
}
}
@@ -79,7 +79,7 @@
if (config.isExposeManagementStatistics()) {
JmxRegistrationManager jmxRegistrationManager = new JmxRegistrationManager(cache);
jmxRegistrationManager.unregisterAllMBeans();
- log.trace("JBossCache MBeans were successfully unregistered from the platform mbean server.");
+ log.trace("MBeans were successfully unregistered from the platform mbean server.");
}
cache = null;
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -80,7 +80,7 @@
private Address localAddress;
/**
- * Whether the the current node is the coordinator and therefore SingletonStore is active. Being active means
+ * Whether the the current cache is the coordinator and therefore SingletonStore is active. Being active means
* delegating calls to the underlying cache loader.
*/
private volatile boolean active;
@@ -173,11 +173,10 @@
}
/**
- * Pushes the state of a specific node by reading the node's data from the cache and putting in the cache store via
- * the cache loader. This method is call recursively so that it iterates through the whole cache.
+ * Pushes the state of a specific cache by reading the cache's data and putting in the cache store. This method is
+ * called recursively so that it iterates through the whole cache.
*
- * @throws Exception if there's any issues reading the data from the cache or pushing the node's data to the cache
- * loader.
+ * @throws Exception if there's any issues reading the data from the cache or pushing data to the cache store.
*/
protected void pushState(final Cache cache) throws Exception {
DataContainer dc = cache.getAdvancedCache().getDataContainer();
@@ -216,10 +215,10 @@
/**
- * Method called when the node either becomes the coordinator or stops being the coordinator. If it becomes the
+ * Method called when the cache either becomes the coordinator or stops being the coordinator. If it becomes the
* coordinator, it can optionally start the in-memory state transfer to the underlying cache store.
*
- * @param newActiveState true if the node just became the coordinator, false if the nodes stopped being the
+ * @param newActiveState true if the cache just became the coordinator, false if the cache stopped being the
* coordinator.
*/
protected void activeStatusChanged(boolean newActiveState) throws PushStateException {
@@ -229,11 +228,11 @@
}
/**
- * Indicates whether the current nodes is the coordinator of the cluster. This implementation assumes that the
+ * Indicates whether the current cache is the coordinator of the cluster. This implementation assumes that the
* coordinator is the first member in the list.
*
* @param newView View instance containing the new view of the cluster
- * @return whether the current node is the coordinator or not.
+ * @return whether the current cache is the coordinator or not.
*/
private boolean isCoordinator(List<Address> newView, Address currentAddress) {
if (!currentAddress.equals(localAddress)) localAddress = currentAddress;
@@ -246,7 +245,7 @@
}
/**
- * Called when the SingletonStore discovers that the node has become the coordinator and push in memory state has
+ * Called when the SingletonStore discovers that the cache has become the coordinator and push in memory state has
* been enabled. It might not actually push the state if there's an ongoing push task running, in which case will
* wait for the push task to finish.
*
@@ -299,13 +298,13 @@
/**
* Cache listener that reacts to cluster topology changes to find out whether a new coordinator is elected.
- * SingletonStore reacts to these changes in order to decide which node should interact with the underlying cache
+ * SingletonStore reacts to these changes in order to decide which cache should interact with the underlying cache
* store.
*/
@Listener
public class SingletonStoreListener {
/**
- * Cache started, check whether the node is the coordinator and set the singleton store's active status.
+ * Cache started, check whether the cache is the coordinator and set the singleton store's active status.
*/
@CacheStarted
public void cacheStarted(Event e) {
@@ -314,8 +313,8 @@
}
/**
- * The cluster formation changed, so determine whether the current node stopped being the coordinator or became
- * the coordinator. This method can lead to an optional in memory to cache loader state push, if the current node
+ * The cluster formation changed, so determine whether the current cache stopped being the coordinator or became
+ * the coordinator. This method can lead to an optional in memory to cache loader state push, if the current cache
* became the coordinator. This method will report any issues that could potentially arise from this push.
*/
@ViewChanged
@@ -327,7 +326,7 @@
activeStatusChanged(tmp);
}
catch (PushStateException e) {
- log.error("exception reported changing nodes active status", e);
+ log.error("exception reported changing cache active status", e);
}
}
Modified: core/branches/flat/src/main/java/org/horizon/lock/IsolationLevel.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/lock/IsolationLevel.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/lock/IsolationLevel.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -23,10 +23,10 @@
/**
* Various transaction isolation levels as an enumerated class. Note that <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">MVCC</a>
- * in JBoss Cache 3.0.0 and above only supports {@link #READ_COMMITTED} and {@link #REPEATABLE_READ}, upgrading where
+ * only supports {@link #READ_COMMITTED} and {@link #REPEATABLE_READ}, upgrading where
* possible.
* <p/>
- * Also note that JBoss Cache defaults to {@link #REPEATABLE_READ}.
+ * Also note that Horizon defaults to {@link #READ_COMMITTED}.
* <p/>
*
* @author (various)
Modified: core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/manager/DefaultCacheManager.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -87,7 +87,7 @@
@Scope(Scopes.GLOBAL)
@NonVolatile
public class DefaultCacheManager implements CacheManager {
- public static final String DEFAULT_CACHE_NAME = "org.jboss.starobrno.manager.DefaultCacheManager.DEFAULT_CACHE_NAME";
+ public static final String DEFAULT_CACHE_NAME = "org.horizon.manager.DefaultCacheManager.DEFAULT_CACHE_NAME";
protected GlobalConfiguration globalConfiguration;
private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
private final ConcurrentMap<String, Configuration> configurationOverrides = new ConcurrentHashMap<String, Configuration>();
Modified: core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -47,7 +47,7 @@
import java.util.*;
/**
- * Abstract AbstractMarshaller for JBoss Cache.
+ * Abstract marshaller
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/marshall/Marshaller.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -33,7 +33,7 @@
/**
* A marshaller is a class that is able to marshall and unmarshall objects efficiently.
* <p/>
- * The reason why this is implemented specially in JBoss Cache rather than resorting to Java serialization or even the
+ * The reason why this is implemented specially in Horizon rather than resorting to Java serialization or even the
* more efficient JBoss serialization is that a lot of efficiency can be gained when a majority of the serialization
* that occurs has to do with a small set of known types such as {@link org.horizon.transaction.GlobalTransaction} or
* {@link org.horizon.commands.ReplicableCommand}, and class type information can be replaced with simple magic
@@ -43,7 +43,7 @@
* <p/>
* In addition, using a marshaller allows adding additional data to the byte stream, such as context class loader
* information on which class loader to use to deserialize the object stream, or versioning information to allow streams
- * to interoperate between different versions of JBoss Cache (see {@link VersionAwareMarshaller}
+ * to interoperate between different versions of Horizon (see {@link VersionAwareMarshaller}
* <p/>
* This interface is used to marshall {@link org.horizon.commands.ReplicableCommand}s, their parameters and their
* response values.
Modified: core/branches/flat/src/main/java/org/horizon/remoting/ReplicationQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/remoting/ReplicationQueue.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/remoting/ReplicationQueue.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -141,7 +141,7 @@
try {
log.trace("Flushing {0} elements", toReplicateSize);
ReplicateCommand replicateCommand = commandsFactory.buildReplicateCommand(toReplicate);
- // send to all live nodes in the cluster
+ // send to all live caches in the cluster
rpcManager.invokeRemotely(null, replicateCommand, ResponseMode.ASYNCHRONOUS, configuration.getSyncReplTimeout());
}
catch (Throwable t) {
Modified: core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -21,173 +21,32 @@
*/
package org.horizon.statetransfer;
-import org.horizon.config.Configuration;
import org.horizon.factories.annotations.Inject;
import org.horizon.factories.annotations.Start;
-import org.horizon.loader.CacheLoaderManager;
-import org.horizon.logging.Log;
-import org.horizon.logging.LogFactory;
-import org.horizon.marshall.Marshaller;
-import org.horizon.tree.Fqn;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-/**
- * The default state transfer manager to be used when using MVCC locking. // TODO: implement me
- *
- * @author (various)
- * @since 1.0
- */
public class DefaultStateTransferManager implements StateTransferManager {
- protected final static Log log = LogFactory.getLog(DefaultStateTransferManager.class);
- protected static final boolean trace = log.isTraceEnabled();
- public static final Object STREAMING_DELIMITER_NODE = new Object();
-
- 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;
- boolean fetchTransientState;
- boolean fetchPersistentState;
- protected long stateRetrievalTimeout;
-// protected StateTransferIntegrator integrator;
-// protected StateTransferGenerator generator;
-
-
@Inject
public void injectDependencies() {
-// this.cache = cache;
-// this.regionManager = regionManager;
- this.marshaller = marshaller;
- this.configuration = configuration;
- this.cacheLoaderManager = cacheLoaderManager;
-// this.integrator = integrator;
-// this.generator = generator;
}
@Start(priority = 14)
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 {
+ public void getState(ObjectOutputStream out, Object o, long timeout, boolean force, boolean suppressErrors) throws Exception {
throw new UnsupportedOperationException("Implement me properly!");
- /*
-
- // can't give state for regions currently being activated/inactivated
- boolean canProvideState = (!evictionCacheManager.isInactive(fqn) && cache.peek(fqn, false) != null);
- if (trace) log.trace("Can provide state? " + canProvideState);
- if (canProvideState && (fetchPersistentState || fetchTransientState))
- {
- marshaller.objectToObjectStream(true, out);
- long startTime = System.currentTimeMillis();
- InternalNode subtreeRoot = fqn.isRoot() ? cache.getRoot().getDelegationTarget() : cache.getNode(fqn).getDelegationTarget();
-
- // we don't need READ locks for MVCC based state transfer!
- if (log.isDebugEnabled())
- log.debug("Generating in-memory (transient) state for subtree " + fqn);
-
- generator.generateState(out, subtreeRoot, fetchTransientState, fetchPersistentState, suppressErrors);
-
- if (log.isDebugEnabled())
- log.debug("Successfully generated state in " + (System.currentTimeMillis() - startTime) + " msec");
- }
- else
- {
- marshaller.objectToObjectStream(false, out);
- Exception e = null;
- if (!canProvideState)
- {
- String exceptionMessage = "Cache instance at " + cache.getLocalAddress() + " cannot provide state for fqn " + fqn + ".";
-
- if (evictionCacheManager.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 {
+ public void setState(ObjectInputStream in, Object o) throws Exception {
throw new UnsupportedOperationException("fix me!");
- /*
- cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
- NodeSPI target = cache.getNode(targetRoot);
- 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);
- cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
- target = cache.getNode(targetRoot);
- }
- 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
- */
// TODO: implement me
protected void setState()
-// protected void setState(ObjectInputStream state, NodeSPI targetRoot) throws Exception
{
- long startTime = System.currentTimeMillis();
- /*
- * 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.
- *
- */
- // TODO: implement me
-// if (log.isDebugEnabled())
-// log.debug("starting state integration at node " + targetRoot + ". Fetch Persistent State = " + fetchPersistentState);
-// integrator.integrateState(state, targetRoot.getDelegationTarget(), targetRoot.getFqn(), fetchPersistentState);
-
- if (log.isDebugEnabled())
- log.debug("successfully integrated state in " + (System.currentTimeMillis() - startTime) + " msec");
}
}
Modified: core/branches/flat/src/main/java/org/horizon/statetransfer/StateTransferManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/statetransfer/StateTransferManager.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/statetransfer/StateTransferManager.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -21,52 +21,12 @@
*/
package org.horizon.statetransfer;
-import org.horizon.tree.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(a)jboss.org</a>)
- * @since 1.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/>
- *
- * @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;
+ void getState(ObjectOutputStream out, Object o, long timeout, boolean force, boolean suppressErrors) throws Exception;
+ void setState(ObjectInputStream in, Object o) throws Exception;
}
Modified: core/branches/flat/src/main/java/org/horizon/transaction/GenericTransactionManagerLookup.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/transaction/GenericTransactionManagerLookup.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/transaction/GenericTransactionManagerLookup.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -96,9 +96,9 @@
if (tm != null)
return tm;
if (lookupFailed) {
- //fall back to a dummy from JBossCache
+ //fall back to a dummy from Horizon
tm = DummyTransactionManager.getInstance();
- log.warn("Falling back to DummyTransactionManager from JBossCache");
+ log.warn("Falling back to DummyTransactionManager from Horizon");
}
return tm;
}
Modified: core/branches/flat/src/main/java/org/horizon/util/concurrent/locks/OwnableReentrantLock.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/concurrent/locks/OwnableReentrantLock.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/java/org/horizon/util/concurrent/locks/OwnableReentrantLock.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -34,7 +34,7 @@
* constructed with a reference to the {@link InvocationContextContainer}, so it is able to determine whether the
* caller's "owner" reference is the current thread or a {@link GlobalTransaction} instance.
* <p/>
- * This makes this lock implementation very closely tied to JBoss Cache internals, but it provides for a very clean,
+ * This makes this lock implementation very closely tied to Horizon internals, but it provides for a very clean,
* efficient and moreover familiar interface to work with, since it implements {@link java.util.concurrent.locks.Lock}.
* <p/>
* For the sake of performance, this lock only supports nonfair queueing.
Modified: core/branches/flat/src/main/release/JBossORG-EULA.txt
===================================================================
--- core/branches/flat/src/main/release/JBossORG-EULA.txt 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/release/JBossORG-EULA.txt 2009-02-25 12:02:25 UTC (rev 7782)
@@ -11,7 +11,7 @@
(b) JBoss Rules, which is licensed pursuant to the Apache License v.2.0;
-(c) an optional download for JBoss Cache for the Berkeley DB for Java database, which is licensed under the
+(c) an optional download for Horizon for the Berkeley DB for Java database, which is licensed under the
(open source) Sleepycat License (if Client does not wish to use the open source version of this database,
it may purchase a license from Sleepycat Software);
Modified: core/branches/flat/src/main/release/README-Demo.txt
===================================================================
--- core/branches/flat/src/main/release/README-Demo.txt 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/release/README-Demo.txt 2009-02-25 12:02:25 UTC (rev 7782)
@@ -1,7 +1,7 @@
-JBoss Cache GUI Demo
---------------------
+Horizon GUI Demo
+-----------------
-JBoss Cache comes with a GUI demo, to visually demonstrate state being moved around a cluster.
+Horizon comes with a GUI demo, to visually demonstrate state being moved around a cluster.
The demo is available for download on
Modified: core/branches/flat/src/main/release/README-libs.txt
===================================================================
--- core/branches/flat/src/main/release/README-libs.txt 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/release/README-libs.txt 2009-02-25 12:02:25 UTC (rev 7782)
@@ -3,16 +3,14 @@
1) REQUIRED JARs
----------------
-The following JARs are REQUIRED for the proper operation of JBoss Cache, in addition to the jbosscache-core.jar file:
+The following JARs are REQUIRED for the proper operation of Horizon, in addition to the horizon.jar file:
-* commons-logging.jar - Used for logging.
-
* jcip-annotations.jar - (http://jcip.net) - Annotations used to assert concurrency behaviour of internal classes.
-* jgroups.jar (http://jgroups.com) - Group communications library that is the backbone of JBoss Cache's replication.
+* jgroups.jar (http://jgroups.com) - Group communications library that is the backbone of Horizon's replication.
Necessary even when the cache is run in LOCAL mode.
-* jboss-common-core.jar - JBoss utilities used by JBoss Cache. Version 2.0.5.GA or above needed if run with JDK 6.
+* jboss-common-core.jar - JBoss utilities used by Horizon. Version 2.0.5.GA or above needed if run with JDK 6.
* jboss-logging-spi.jar - Required by jboss-common-core.
Modified: core/branches/flat/src/main/release/README.txt
===================================================================
--- core/branches/flat/src/main/release/README.txt 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/release/README.txt 2009-02-25 12:02:25 UTC (rev 7782)
@@ -1,31 +1,17 @@
-JBossCache -- a replicated, transactional, and fine-grained cache system
-========================================================================
+Horizon -- a replicated, transactional data grid
+================================================
Note:
- We offer different packaging for download:
- + jbosscache-core-2.1.x-bin, just the core jar file and dependencies.
- + jbosscache-core-2.1.x-all, everything including docs, sources and tests.
- + jbosscache-core-2.1.x-doc, just the documentation.
+ + horizon-x.y.z-bin, just the core jar file and dependencies.
+ + horizon-x.y.z-all, everything including docs and tests.
+ + horizon-x.y.z-doc, just the documentation.
+ + horizon-x.y.z-src, a snapshot of the source tree.
- - If you are looking for JBoss Cache POJO edition, this is a separate distribution:
- + jbosscache-pojo-2.1.x-bin, just the core jar file and dependencies. Note that this will include jbosscache-core.jar as a dependency.
- + jbosscache-pojo-2.1.x-all, everything including docs, sources and tests.
- + jbosscache-pojo-2.1.x-doc, just the documentation.
-
-
Requirements:
- JDK 5.0 and up
-Running the tutorial:
- - The bin and all distros come with a build.xml file in the directory root, which contains targets for running
- tests as well as the demo outlined in the tutorial. You need an installation of Jakarta Ant 1.6.0 or higher
- to run the script.
-
-- Just run 'ant' in the root directry for instructions.
-
-
Problems:
- - Please report problems to the JBoss cache forum
+ - Please report problems on the Horizon forum
(http://www.jboss.org/forum.jsp?forum=157)
or the JBoss dev mailing list
-
Modified: core/branches/flat/src/main/release/licenses/README-bdbje-lib.txt
===================================================================
--- core/branches/flat/src/main/release/licenses/README-bdbje-lib.txt 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/main/release/licenses/README-bdbje-lib.txt 2009-02-25 12:02:25 UTC (rev 7782)
@@ -2,18 +2,17 @@
$Id$
NAME: Sleepycat Berkeley DB Java Edition
-VERSION: 1.7.0
PROJECT: http://www.oracle.com/database/berkeley-db/je/index.html
-PURPOSE: Used for Berkeley DB-based CacheLoader (org.jboss.cache.loader.bdbje.BdbjeCacheLoader) in JBossCache
-RESTRICTION: JBossCache can use Berkeley DB Java Edition from Oracle
+PURPOSE: Used for Berkeley DB-based CacheLoader (org.horizon.loader.bdbje.BdbjeCacheStore) in Horizon
+RESTRICTION: Horizon can use Berkeley DB Java Edition from Oracle
for persistent, reliable and transaction-protected
data storage. If you choose to use Berkeley DB Java Edition
- with JBossCache, you must comply with the terms of
- Oracle's public license, included in the file LICENSE.txt.
+ with Horizon, you must comply with the terms of
+ Oracle's public license, included in the file LICENSE-bdbje-lib.txt.
If you prefer not to release the source code for your own
application in order to comply with the Oracle public
license, you may purchase a different license for use of
- Berkeley DB Java Edition with JBossCache. For details,
+ Berkeley DB Java Edition with Horizon. For details,
please go to:
http://www.oracle.com/database/berkeley-db/je/index.html
Modified: core/branches/flat/src/test/java/org/horizon/api/tree/TreeCacheAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/TreeCacheAPITest.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/TreeCacheAPITest.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -49,13 +49,6 @@
cache = null;
}
- /**
- * All cache operations should happen on a {@link Node} - I.e., you look up a {@link Node} and perform data
- * operations on this {@link Node}. For convenience and familiarity with JBoss Cache 1.x, we provide some helpers in
- * {@link Cache} which dives you direct data access to nodes.
- * <p/>
- * This test exercises these.
- */
public void testConvenienceMethods() {
Fqn fqn = Fqn.fromString("/test/fqn");
String key = "key", value = "value";
Modified: core/branches/flat/src/test/java/org/horizon/eviction/algorithms/lru/LruQueueTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/eviction/algorithms/lru/LruQueueTest.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/eviction/algorithms/lru/LruQueueTest.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -58,14 +58,14 @@
int count = 0;
for (Iterator<Object> it = queue.iterator(); it.hasNext();) {
- int nodeIndex = (Integer) it.next();
+ int entryIndex = (Integer) it.next();
if (count < 50) {
// the top 50 should be all odds in the lruQueue/
- assert nodeIndex % 2 != 0;
+ assert entryIndex % 2 != 0;
} else {
// the bottom fifty should all be even #'s (and 0)
- assert nodeIndex % 2 == 0;
+ assert entryIndex % 2 == 0;
}
it.remove();
count++;
Modified: core/branches/flat/src/test/java/org/horizon/eviction/algorithms/mru/MruQueueTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/eviction/algorithms/mru/MruQueueTest.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/eviction/algorithms/mru/MruQueueTest.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -57,14 +57,14 @@
int count = 0;
for (Iterator<Object> it = queue.iterator(); it.hasNext();) {
- int nodeIndex = (Integer) it.next();
+ int entryIndex = (Integer) it.next();
if (count < 50) {
// the top 50 should be all evens in the mruQueue
- assert nodeIndex % 2 == 0;
+ assert entryIndex % 2 == 0;
} else {
// the bottom fifty should all be odd #'s (and 0)
- assert nodeIndex % 2 != 0;
+ assert entryIndex % 2 != 0;
}
it.remove();
count++;
Modified: core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/marshall/MarshalledValueTest.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -115,7 +115,7 @@
assert mvli.invocationCount == 0 : "Call should not have gone beyond the MarshalledValueInterceptor";
}
- public void testNodeReleaseObjectValueReferences() {
+ public void testReleaseObjectValueReferences() {
Pojo value = new Pojo();
cache1.put("key", value);
assertSerializationCounts(1, 0);
@@ -150,7 +150,7 @@
assertSerialized(mv);
}
- public void testNodeReleaseObjectKeyReferences() throws IOException, ClassNotFoundException {
+ public void testReleaseObjectKeyReferences() throws IOException, ClassNotFoundException {
Pojo key = new Pojo();
cache1.put(key, "value");
@@ -305,7 +305,7 @@
Object newValue;
@CacheEntryModified
- public void nodeModified(CacheEntryModifiedEvent e) {
+ public void modified(CacheEntryModifiedEvent e) {
if (!e.isPre()) newValue = e.getValue();
}
}
Modified: core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -20,9 +20,6 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
-/**
- * Unit test for replicated async CacheSPI. Use locking and multiple threads to test concurrent access to the tree.
- */
@Test(groups = "functional", testName = "replication.AsyncReplTest")
public class AsyncReplTest extends MultipleCacheManagersTest {
Modified: core/branches/flat/src/test/java/org/horizon/test/TestNameVerifier.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/test/TestNameVerifier.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/test/TestNameVerifier.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -127,7 +127,6 @@
builder.append(line + "\n");
}
this.fileCache = builder.toString();
-// fileReader.close();
return fileCache;
}
@@ -185,25 +184,4 @@
if (!existingTestName.equals(expectedTestName)) return expectedTestName;
return null;
}
-
-
-// @Test(enabled = false)
-// public static void main(String[] args) throws Exception {
-// File file = new File("C:\\jboss\\brainstoriming\\horizon\\src\\test\\java\\org\\horizon\\api\\tree\\NodeMoveAPITest.java");
-// String incorrectName = new TestNameVerifier().incorrectTestName(file);
-// System.out.println("incorrectName = " + incorrectName);
-
-
-// new TestNameVerifier().process();
-// Pattern classLinePattern = Pattern.compile("@Test[^)]*");
-// String totest = "aaaa\n" + "@Test(groups = {\"functional\", \"pessimistic\"})\n" + "{ dsadsadsa";
-// Matcher matcher = classLinePattern.matcher(totest);
-// boolean found = matcher.find();
-// System.out.println("found = " + found);
-// String theMatch = matcher.group();
-// String result = matcher.replaceFirst(theMatch + ", testName=\"alaBala\"");
-// System.out.println("theMatch = " + theMatch);
-// System.out.println("result = " + result);
-
-// }
}
\ No newline at end of file
Modified: core/branches/flat/src/test/java/org/horizon/test/TestingUtil.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/test/TestingUtil.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/test/TestingUtil.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -34,12 +34,6 @@
import java.util.Random;
import java.util.Properties;
-/**
- * Utilities for unit testing JBossCache.
- *
- * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
- * @since 1.0
- */
public class TestingUtil {
private static Random random = new Random();
public static final String TEST_FILES = "testFiles";
Modified: core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java 2009-02-25 11:22:30 UTC (rev 7781)
+++ core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java 2009-02-25 12:02:25 UTC (rev 7782)
@@ -30,7 +30,7 @@
realConfig.setDataColumnName("bucket");
realConfig.setDataColumnType("BINARY");
realConfig.setDriverClass("org.hsqldb.jdbcDriver");
- realConfig.setConnectionUrl("jdbc:hsqldb:mem:jbosscache");
+ realConfig.setConnectionUrl("jdbc:hsqldb:mem:horizon");
realConfig.setUserName("sa");
}
@@ -73,7 +73,6 @@
}
public static String getDatabaseName(Properties prop) {
- //jdbc:hsqldb:mem:jbosscache
StringTokenizer tokenizer = new StringTokenizer(prop.getProperty("cache.jdbc.url"), ":");
tokenizer.nextToken();
tokenizer.nextToken();
@@ -84,17 +83,15 @@
private static String getShutdownUrl(JdbcCacheStoreConfig props) {
String url = props.getConnectionUrl();
assert url != null;
- //jdbc:derby:jbossdb;create=true
StringTokenizer tokenizer = new StringTokenizer(url, ";");
String result = tokenizer.nextToken() + ";" + "shutdown=true";
return result;
}
private static JdbcCacheStoreConfig returnBasedOnDifferentInstance() {
- //jdbc:hsqldb:mem:jbosscache
JdbcCacheStoreConfig result = realConfig.clone();
String jdbcUrl = result.getConnectionUrl();
- Pattern pattern = Pattern.compile("jbosscache");
+ Pattern pattern = Pattern.compile("horizon");
Matcher matcher = pattern.matcher(jdbcUrl);
boolean found = matcher.find();
assert found;
@@ -109,7 +106,7 @@
for (int i = stack.length - 1; i > 0; i--) {
StackTraceElement e = stack[i];
String className = e.getClassName();
- if (className.indexOf("org.jboss.cache") != -1) return className.replace('.', '_') + "_" + e.getMethodName();
+ if (className.indexOf("org.horizon") != -1) return className.replace('.', '_') + "_" + e.getMethodName();
}
return null;
}
15 years, 10 months
JBoss Cache SVN: r7781 - core/branches/flat.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-25 06:22:30 -0500 (Wed, 25 Feb 2009)
New Revision: 7781
Modified:
core/branches/flat/pom.xml
Log:
Removed docbook generation
Modified: core/branches/flat/pom.xml
===================================================================
--- core/branches/flat/pom.xml 2009-02-25 11:21:03 UTC (rev 7780)
+++ core/branches/flat/pom.xml 2009-02-25 11:22:30 UTC (rev 7781)
@@ -263,168 +263,15 @@
<!-- override to generate javadocs in the "package" phase -->
<javadocPhase>package</javadocPhase>
</properties>
- <build>
- <plugins>
- <!-- the docbook generation plugin for the user guide -->
- <plugin>
- <groupId>org.jboss.maven.plugins</groupId>
- <artifactId>maven-jdocbook-plugin</artifactId>
- <version>2.0.0</version>
- <extensions>true</extensions>
- <dependencies>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jbossorg-docbook-xslt</artifactId>
- <version>1.1.0</version>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jbossorg-jdocbook-style</artifactId>
- <version>1.1.0</version>
- <type>jdocbook-style</type>
- </dependency>
- </dependencies>
- <executions>
-
- <!-- The User Guide-->
- <execution>
- <id>userguide_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
- <sourceDirectory>${basedir}/src/main/docbook/userguide/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
- <targetDirectory>${basedir}/target/docbook/userguide_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/pdf.xsl</stylesheetResource>
- <finalName>userguide_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/xhtml.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/xhtml-single.xsl
- </stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- The Tutorial -->
- <execution>
- <id>tutorial_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
- <sourceDirectory>${basedir}/src/main/docbook/tutorial/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
- <targetDirectory>${basedir}/target/docbook/tutorial_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/pdf.xsl</stylesheetResource>
- <finalName>tutorial_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/xhtml.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/xhtml-single.xsl
- </stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
-
- <!-- the FAQs -->
- <execution>
- <id>faq_en</id>
- <phase>package</phase>
- <goals>
- <goal>resources</goal>
- <goal>generate</goal>
- </goals>
- <configuration>
- <sourceDocumentName>master.xml</sourceDocumentName>
- <sourceDirectory>${basedir}/src/main/docbook/faq/en</sourceDirectory>
- <imageResource>
- <directory>${basedir}/src/main/docbook/images</directory>
- </imageResource>
- <cssResource>
- <directory>${basedir}/src/main/docbook/css</directory>
- </cssResource>
- <targetDirectory>${basedir}/target/docbook/faq_en</targetDirectory>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/pdf.xsl</stylesheetResource>
- <finalName>faq_en.pdf</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/xhtml.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/jboss/xhtml-single.xsl
- </stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>false</xincludeSupported>
- </options>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
- <version>2.4.3-JBOSS</version>
+ <version>2.4.3</version>
</plugin>
</plugins>
</reporting>
-
</profile>
<profile>
15 years, 10 months
JBoss Cache SVN: r7780 - core/branches/flat/src/main.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-25 06:21:03 -0500 (Wed, 25 Feb 2009)
New Revision: 7780
Removed:
core/branches/flat/src/main/docbook/
Log:
Removed docbook docs. Horizon will use JBoss.org's CMS for documentation
15 years, 10 months
JBoss Cache SVN: r7779 - core/branches/flat/src/main/java/org/horizon/loader/jdbc.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-25 05:58:33 -0500 (Wed, 25 Feb 2009)
New Revision: 7779
Removed:
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java
Log:
removed obsolete files
Deleted: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java 2009-02-25 10:23:49 UTC (rev 7778)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStore.java 2009-02-25 10:58:33 UTC (rev 7779)
@@ -1,67 +0,0 @@
-package org.horizon.loader.jdbc;
-
-import org.horizon.Cache;
-import org.horizon.loader.AbstractCacheStore;
-import org.horizon.loader.CacheLoaderConfig;
-import org.horizon.loader.CacheLoaderException;
-import org.horizon.loader.StoredEntry;
-import org.horizon.marshall.Marshaller;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Set;
-
-/**
- * // TODO: Manik: Document this!
- *
- * @author Manik Surtani
- */
-public class JDBCCacheStore extends AbstractCacheStore {
- public void store(StoredEntry ed) {
- // TODO: Manik: Customise this generated block
- }
-
- public void fromStream(InputStream inputStream) {
- // TODO: Manik: Customise this generated block
- }
-
- public void toStream(OutputStream outputStream) {
- // TODO: Manik: Customise this generated block
- }
-
- public void clear() {
- // TODO: Manik: Customise this generated block
- }
-
- public boolean remove(Object key) {
- return false; // TODO: Manik: Customise this generated block
- }
-
- public void purgeExpired() {
- // TODO: Manik: Customise this generated block
- }
-
- public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
- // TODO: Manik: Customise this generated block
- }
-
- public StoredEntry load(Object key) {
- return null; // TODO: Manik: Customise this generated block
- }
-
- public Set<StoredEntry> loadAll() throws CacheLoaderException {
- return null; // TODO: Manik: Customise this generated block
- }
-
- public Class<? extends CacheLoaderConfig> getConfigurationClass() {
- return JDBCCacheStoreConfig.class;
- }
-
- public void start() {
- // TODO: Manik: Customise this generated block
- }
-
- public void stop() {
- // TODO: Manik: Customise this generated block
- }
-}
Deleted: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java 2009-02-25 10:23:49 UTC (rev 7778)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JDBCCacheStoreConfig.java 2009-02-25 10:58:33 UTC (rev 7779)
@@ -1,51 +0,0 @@
-package org.horizon.loader.jdbc;
-
-import org.horizon.loader.AbstractCacheLoaderConfig;
-
-/**
- * // TODO: Manik: Document this!
- *
- * @author Manik Surtani
- */
-public class JDBCCacheStoreConfig extends AbstractCacheLoaderConfig {
- String dataSource;
- String tableNamePrefix = "horizon";
- boolean createTable = true;
- boolean dropTable = false;
-
- public JDBCCacheStoreConfig() {
- className = JDBCCacheStore.class.getName();
- }
-
- public String getDataSource() {
- return dataSource;
- }
-
- public void setDataSource(String dataSource) {
- this.dataSource = dataSource;
- }
-
- public String getTableNamePrefix() {
- return tableNamePrefix;
- }
-
- public void setTableNamePrefix(String tableNamePrefix) {
- this.tableNamePrefix = tableNamePrefix;
- }
-
- public boolean isCreateTable() {
- return createTable;
- }
-
- public void setCreateTable(boolean createTable) {
- this.createTable = createTable;
- }
-
- public boolean isDropTable() {
- return dropTable;
- }
-
- public void setDropTable(boolean dropTable) {
- this.dropTable = dropTable;
- }
-}
15 years, 10 months
JBoss Cache SVN: r7778 - in core/branches/flat/src: main/java/org/horizon/loader and 11 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-02-25 05:23:49 -0500 (Wed, 25 Feb 2009)
New Revision: 7778
Added:
core/branches/flat/src/main/java/org/horizon/loader/bucket/
core/branches/flat/src/main/java/org/horizon/loader/bucket/Bucket.java
core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStoreConfig.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/ConnectionFactory.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcUtil.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/NonManagedConnectionFactory.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/
core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/TableManipulationTest.java
core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java
Modified:
core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java
core/branches/flat/src/main/java/org/horizon/loader/CacheLoader.java
core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/AsyncStore.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java
core/branches/flat/src/main/java/org/horizon/lock/StripedLock.java
core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java
core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java
core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java
core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java
core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java
Log:
added support for replication queues
Modified: core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -276,7 +276,7 @@
throw new ConfigurationException("Unable to configure eviction", e);
}
- if (p != null && !p.isEmpty()) XmlConfigHelper.setValues(cfg, p, false, true);
+ if (p != null && !p.isEmpty()) XmlConfigHelper. setValues(cfg, p, false, true);
evictionConfig.setAlgorithmConfig(cfg);
config.setEvictionConfig(evictionConfig);
Modified: core/branches/flat/src/main/java/org/horizon/loader/CacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/CacheLoader.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/CacheLoader.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -1,7 +1,6 @@
package org.horizon.loader;
import org.horizon.Cache;
-import org.horizon.lifecycle.Lifecycle;
import org.horizon.marshall.Marshaller;
import java.util.Set;
@@ -12,7 +11,7 @@
* @author Manik Surtani
* @since 1.0
*/
-public interface CacheLoader extends Lifecycle {
+public interface CacheLoader {
/**
* Used to initialize a cache loader. Typically invoked by the {@link org.horizon.loader.CacheLoaderManager} when
@@ -50,7 +49,11 @@
*/
boolean containsKey(Object key) throws CacheLoaderException;
+ public void start() throws CacheLoaderException;
+ public void stop() throws CacheLoaderException;
+
+
/**
* @return the type of the {@link org.horizon.loader.CacheLoaderConfig} bean used to configure this implementation of
* {@link org.horizon.loader.CacheLoader}
Modified: core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/CacheLoaderManagerImpl.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -130,7 +130,11 @@
@Stop
public void stop() {
- if (loader != null) loader.stop();
+ if (loader != null) try {
+ loader.stop();
+ } catch (CacheLoaderException e) {
+ throw new CacheException(e);
+ }
loader = null;
}
Added: core/branches/flat/src/main/java/org/horizon/loader/bucket/Bucket.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/bucket/Bucket.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/bucket/Bucket.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,83 @@
+package org.horizon.loader.bucket;
+
+import org.horizon.loader.StoredEntry;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Collection;
+
+/**
+ * A bucket is where entries are stored.
+ */
+public final class Bucket implements Externalizable {
+ private Map<Object, StoredEntry> entries = new HashMap<Object, StoredEntry>();
+ private transient String bucketName;
+
+ public final void addEntry(StoredEntry se) {
+ entries.put(se.getKey(), se);
+ }
+
+ public final boolean removeEntry(Object key) {
+ return entries.remove(key) != null;
+ }
+
+ public final StoredEntry getEntry(Object key) {
+ return entries.get(key);
+ }
+
+ public final void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt(entries.size());
+ for (StoredEntry se : entries.values()) out.writeObject(se);
+ }
+
+ public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ int sz = in.readInt();
+ entries = new HashMap<Object, StoredEntry>(sz);
+ for (int i = 0; i < sz; i++) {
+ StoredEntry se = (StoredEntry) in.readObject();
+ entries.put(se.getKey(), se);
+ }
+ }
+
+ public Map<Object, StoredEntry> getEntries() {
+ return entries;
+ }
+
+ public String getBucketName() {
+ return bucketName;
+ }
+
+ public void setBucketName(String bucketName) {
+ this.bucketName = bucketName;
+ }
+
+ public boolean removeExpiredEntries() {
+ boolean result = false;
+ Iterator<Map.Entry<Object, StoredEntry>> entryIterator = entries.entrySet().iterator();
+ while (entryIterator.hasNext()) {
+ Map.Entry<Object, StoredEntry> entry = entryIterator.next();
+ if (entry.getValue().isExpired()) {
+ entryIterator.remove();
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ public Collection<? extends StoredEntry> getStoredEntries() {
+ return entries.values();
+ }
+
+ @Override
+ public String toString() {
+ return "Bucket{" +
+ "entries=" + entries +
+ ", bucketName='" + bucketName + '\'' +
+ '}';
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/bucket/Bucket.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,175 @@
+package org.horizon.loader.bucket;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.horizon.lock.StripedLock;
+import org.horizon.loader.AbstractCacheStore;
+import org.horizon.loader.StoredEntry;
+import org.horizon.loader.CacheLoaderException;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.Cache;
+import org.horizon.marshall.Marshaller;
+
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * //TODO comment this
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 1.0
+ */
+public abstract class BucketBasedCacheStore extends AbstractCacheStore {
+
+ private static Log log = LogFactory.getLog(BucketBasedCacheStore.class);
+
+ private StripedLock bucketLocks;
+ private BucketBasedCacheStoreConfig config;
+ private long globalLockTimeoutMillis;
+
+ /**
+ * This global lock guards against direct store access via clear() and the stream APIs. These three methods would
+ * need exclusive (write) access to this lock while all others can use shared (read) access to this lock since other
+ * methods will use finer grained bucket locks.
+ */
+ private final ReentrantReadWriteLock globalLock = new ReentrantReadWriteLock();
+
+ public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+ this.config = (BucketBasedCacheStoreConfig) config;
+ }
+
+ public void start() throws CacheLoaderException {
+ bucketLocks = new StripedLock(config.getLockConcurrencyLevel());
+ globalLockTimeoutMillis = config.getLockAcquistionTimeout();
+ }
+
+ public StoredEntry load(Object key) throws CacheLoaderException {
+ if (log.isTraceEnabled()) log.trace("Loading entry " + key);
+ String keyHashCode = String.valueOf(key.hashCode());
+ lockForReading(keyHashCode);
+ Bucket bucket;
+ try {
+ bucket = loadBucket(keyHashCode);
+ if (bucket == null) return null;
+ StoredEntry se = bucket.getEntry(key);
+ if (se != null && se.isExpired()) {
+ bucket.removeEntry(key);
+ saveBucket(bucket);
+ return null;
+ } else {
+ return se;
+ }
+ } catch (Exception e) {
+ throw new CacheLoaderException("Problems loading key " + key, e);
+ } finally {
+ unlock(keyHashCode);
+ }
+ }
+
+ public void store(StoredEntry ed) throws CacheLoaderException {
+ if (ed == null) return;
+ if (ed.isExpired()) {
+ log.trace("Entry " + ed + " is expired! Not doing anything.");
+ return;
+ }
+ if (log.isTraceEnabled()) log.trace("Storing entry " + ed);
+ String keyHashCode = String.valueOf(ed.getKey().hashCode());
+
+ lockForWritting(keyHashCode);
+
+ try {
+ Bucket bucket = loadBucket(keyHashCode);
+ if (bucket != null) {
+ bucket.addEntry(ed);
+ saveBucket(bucket);
+ } else {
+ bucket = new Bucket();
+ bucket.setBucketName(keyHashCode);
+ bucket.addEntry(ed);
+ insertBucket(bucket);
+ }
+ }
+ catch (Exception ex) {
+ throw new CacheLoaderException("Problems storing entry with key " + ed.getKey(), ex);
+ } finally {
+ unlock(keyHashCode);
+ }
+ }
+
+ public boolean remove(Object key) throws CacheLoaderException {
+ if (log.isTraceEnabled()) log.trace("Removing key " + key);
+ String keyHashCodeStr = String.valueOf(key.hashCode());
+ Bucket bucket;
+ try {
+ lockForWritting(keyHashCodeStr);
+ bucket = loadBucket(keyHashCodeStr);
+ if (bucket == null) {
+ return false;
+ } else {
+ boolean success = bucket.removeEntry(key);
+ if (success) saveBucket(bucket);
+ return success;
+ }
+ } catch (Exception e) {
+ throw new CacheLoaderException("Problems removing key " + key, e);
+ } finally {
+ unlock(keyHashCodeStr);
+ }
+ }
+
+
+ protected void unlock(String keyHashCode) {
+ bucketLocks.releaseLock(keyHashCode);
+ globalLock.readLock().unlock();
+ }
+
+ protected void lockForWritting(String keyHashCode) throws CacheLoaderException {
+ try {
+ globalLock.readLock().tryLock(globalLockTimeoutMillis, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ log.warn("Received interrupt signal while waiting for global lock aquisition");
+ throw new CacheLoaderException(e);
+ }
+ bucketLocks.acquireLock(keyHashCode, true);
+ }
+
+ protected void lockForReading(String keyHashCode) throws CacheLoaderException {
+ try {
+ globalLock.readLock().tryLock(globalLockTimeoutMillis, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ log.warn("Received interrupt signal while waiting for global lock aquisition");
+ throw new CacheLoaderException(e);
+ }
+ bucketLocks.acquireLock(keyHashCode, false);
+ }
+
+ protected void acquireGlobalLock(boolean exclusive) throws TimeoutException, InterruptedException {
+ Lock l = exclusive ? globalLock.writeLock() : globalLock.readLock();
+ if (!l.tryLock(globalLockTimeoutMillis, TimeUnit.MILLISECONDS))
+ throw new TimeoutException("Timed out trying to acquire " + (exclusive ? "exclusive" : "shared") + " global lock after " + globalLockTimeoutMillis + " millis. Lock is " + l);
+ }
+
+ protected void releaseGlobalLock(boolean exclusive) {
+ Lock lock = exclusive ? globalLock.writeLock() : globalLock.readLock();
+ lock.unlock();
+ }
+
+ public int getGlobalLockCount() {
+ return globalLock.getReadLockCount() + (globalLock.isWriteLocked() ? +1 : 0);
+ }
+
+ public int getBucketLockCount() {
+ return bucketLocks.getTotalLockCount();
+ }
+
+ protected abstract void insertBucket(Bucket bucket) throws CacheLoaderException;
+
+ /**
+ * This method assumes that the bucket is already persisted in the database.
+ */
+ protected abstract void saveBucket(Bucket bucket) throws CacheLoaderException;
+
+ protected abstract Bucket loadBucket(String keyHashCode) throws CacheLoaderException;
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStore.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStoreConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStoreConfig.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,32 @@
+package org.horizon.loader.bucket;
+
+import org.horizon.loader.AbstractCacheLoaderConfig;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+public class BucketBasedCacheStoreConfig extends AbstractCacheLoaderConfig {
+
+ private int lockConcurrencyLevel = 2048;
+ private long lockAcquistionTimeout = 60000;
+
+ public int getLockConcurrencyLevel() {
+ return lockConcurrencyLevel;
+ }
+
+ public void setLockConcurrencyLevel(int lockConcurrencyLevel) {
+ testImmutability("lockConcurrencyLevel");
+ this.lockConcurrencyLevel = lockConcurrencyLevel;
+ }
+
+ public long getLockAcquistionTimeout() {
+ return lockAcquistionTimeout;
+ }
+
+ public void setLockAcquistionTimeout(long lockAcquistionTimeout) {
+ testImmutability("lockAcquistionTimeout");
+ this.lockAcquistionTimeout = lockAcquistionTimeout;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/bucket/BucketBasedCacheStoreConfig.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/decorators/AbstractDelegatingStore.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -98,11 +98,11 @@
return delegate.getConfigurationClass();
}
- public void start() {
+ public void start() throws CacheLoaderException {
delegate.start();
}
- public void stop() {
+ public void stop() throws CacheLoaderException {
delegate.stop();
}
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/decorators/AsyncStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/decorators/AsyncStore.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/decorators/AsyncStore.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -91,7 +91,7 @@
}
@Override
- public void start() {
+ public void start() throws CacheLoaderException {
queue = new LinkedBlockingQueue<Modification>(asyncStoreConfig.getQueueSize());
log.info("Async cache loader starting {0}", this);
stopped.set(false);
@@ -109,7 +109,7 @@
}
@Override
- public void stop() {
+ public void stop() throws CacheLoaderException {
stopped.set(true);
if (executor != null) {
for (Future f : processorFutures) f.cancel(true);
Modified: core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/decorators/ChainingCacheStore.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -123,11 +123,11 @@
return null;
}
- public void start() {
+ public void start() throws CacheLoaderException {
for (CacheLoader l : loaders.keySet()) l.start();
}
- public void stop() {
+ public void stop() throws CacheLoaderException {
for (CacheLoader l : loaders.keySet()) l.stop();
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/decorators/SingletonStore.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -147,7 +147,7 @@
}
@Override
- public void start() {
+ public void start() throws CacheLoaderException {
cacheManager.addListener(new SingletonStoreListener());
super.start();
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStore.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -2,27 +2,21 @@
import org.horizon.Cache;
import org.horizon.config.ConfigurationException;
-import org.horizon.loader.AbstractCacheStore;
import org.horizon.loader.CacheLoaderConfig;
import org.horizon.loader.CacheLoaderException;
import org.horizon.loader.StoredEntry;
-import org.horizon.lock.StripedLock;
+import org.horizon.loader.bucket.Bucket;
+import org.horizon.loader.bucket.BucketBasedCacheStore;
import org.horizon.logging.Log;
import org.horizon.logging.LogFactory;
import org.horizon.marshall.Marshaller;
import org.horizon.util.concurrent.WithinThreadExecutor;
import java.io.*;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* A filesystem-based implementation of a {@link org.horizon.loader.CacheStore}. This file store stores stuff in the
@@ -45,138 +39,44 @@
* @author Manik Surtani
* @since 1.0
*/
-public class FileCacheStore extends AbstractCacheStore {
+public class FileCacheStore extends BucketBasedCacheStore {
private static final Log log = LogFactory.getLog(FileCacheStore.class);
- // doesn't matter that we have such a large amount of file buckets since they are created on disk on demand and
- // take up no extra memory
- private static final int NUM_BUCKETS = Integer.MAX_VALUE;
private int streamBufferSize;
ExecutorService purgerService;
- StripedLock bucketLocks;
- // This global lock guards against direct file system access via clear() and the stream APIs. These three methods
- // would need exclusive (write) access to this lock while all others can use shared (read) access to this lock since
- // other methods will use finer grained bucket locks.
- final ReentrantReadWriteLock globalLock = new ReentrantReadWriteLock();
FileCacheStoreConfig cfg;
Cache cache;
Marshaller m;
File root;
- long lockTimeout;
public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+ super.init(config, cache, m);
this.cfg = (FileCacheStoreConfig) config;
this.cache = cache;
this.m = m;
}
- public StoredEntry load(Object key) throws CacheLoaderException {
- log.trace("Loading entry {0}", key);
- Bucket b = null;
- try {
- b = lockAndGetBucket(key, false, false);
- if (b == null) return null;
- StoredEntry se = b.getEntry(key);
- if (se != null && se.isExpired()) {
- b.removeEntry(key);
- saveBucket(b);
- return null;
- } else {
- return se;
- }
- } catch (Exception e) {
- CacheLoaderException cle = (e instanceof CacheLoaderException) ? (CacheLoaderException) e :
- new CacheLoaderException("Problems loading key " + key, e);
- throw cle;
- } finally {
- unlockBucket(b);
- }
- }
-
public Set<StoredEntry> loadAll() throws CacheLoaderException {
log.trace("Loading all entries");
- Set<StoredEntry> set = new HashSet<StoredEntry>();
- try {
- for (File f : root.listFiles()) {
- Bucket b = null;
- try {
- b = lockAndGetBucket(f, false, false);
- if (b != null) {
- Set<Object> expiredOnBucket = new HashSet<Object>();
- for (StoredEntry e : b.entries.values()) {
- if (e.isExpired())
- expiredOnBucket.add(e.getKey());
- else
- set.add(e);
- }
- for (Object expired : expiredOnBucket) b.removeEntry(expired);
- saveBucket(b);
+ Set<StoredEntry> result = new HashSet<StoredEntry>();
+ for (File bucketFile : root.listFiles()) {
+ String bucketName = bucketFile.getName();
+ try {
+ lockForReading(bucketName);
+ Bucket bucket = loadBucket(bucketFile);
+ if (bucket != null) {
+ if (bucket.removeExpiredEntries()) {
+ saveBucket(bucket);
}
- } finally {
- unlockBucket(b);
+ result.addAll(bucket.getStoredEntries());
}
+ } finally {
+ unlock(bucketName);
}
- } catch (Exception e) {
- CacheLoaderException cle = (e instanceof CacheLoaderException) ? (CacheLoaderException) e :
- new CacheLoaderException("Problems loading keys", e);
- throw cle;
}
- return set;
+ return result;
}
- public Class<? extends CacheLoaderConfig> getConfigurationClass() {
- return FileCacheStoreConfig.class;
- }
-
- public void start() {
- String location = cfg.getLocation();
- if (location == null || location.trim().length() == 0) location = "Horizon-FileCacheStore"; // use relative path!
- location += File.separator + cache.getName();
- root = new File(location);
- if (!root.exists()) {
- if (!root.mkdirs())
- throw new ConfigurationException("Directory " + root.getAbsolutePath() + " does not exist and cannot be created!");
- }
-
- if (cfg.isPurgeSynchronously()) {
- purgerService = new WithinThreadExecutor();
- } else {
- purgerService = Executors.newSingleThreadExecutor();
- }
-
- streamBufferSize = cfg.getStreamBufferSize();
- int lockConcurrencyLevel = cfg.getLockConcurrencyLevel();
- bucketLocks = new StripedLock(lockConcurrencyLevel);
- lockTimeout = cfg.getLockAcquistionTimeout();
- }
-
- public void stop() {
- purgerService.shutdownNow();
- }
-
- public void store(StoredEntry ed) throws CacheLoaderException {
- if (ed == null) return;
- if (ed.isExpired()) {
- log.trace("Entry {0} is expired! Not doing anything.", ed);
- return;
- }
-
- log.trace("Storing entry {0}", ed);
-
- Bucket b = null;
- try {
- b = lockAndGetBucket(ed.getKey(), true, true);
- b.addEntry(ed);
- saveBucket(b);
- } catch (Exception e) {
- CacheLoaderException cle = (e instanceof CacheLoaderException) ? (CacheLoaderException) e :
- new CacheLoaderException("Problems storing entry with key " + ed.getKey(), e);
- throw cle;
- } finally {
- unlockBucket(b);
- }
- }
-
public void fromStream(InputStream inputStream) throws CacheLoaderException {
ObjectInputStream ois = null;
try {
@@ -213,7 +113,7 @@
throw cle;
}
finally {
- releaseGlobalLock();
+ releaseGlobalLock(true);
// we should close the stream we created!
if (inputStream != ois) safeClose(ois);
}
@@ -225,15 +125,14 @@
acquireGlobalLock(true);
oos = (outputStream instanceof ObjectOutputStream) ? (ObjectOutputStream) outputStream :
new ObjectOutputStream(outputStream);
-
File[] files = root.listFiles();
oos.writeInt(files.length);
byte[] buffer = new byte[streamBufferSize];
- int bytesRead, totalBytesRead = 0;
for (File file : files) {
- FileInputStream is = new FileInputStream(file);
- int sz = is.available();
- BufferedInputStream bis = new BufferedInputStream(is);
+ int bytesRead, totalBytesRead = 0;
+ FileInputStream fileInStream = new FileInputStream(file);
+ int sz = fileInStream.available();
+ BufferedInputStream bis = new BufferedInputStream(fileInStream);
oos.writeObject(file.getName());
oos.writeInt(sz);
@@ -244,12 +143,12 @@
oos.write(buffer, 0, bytesRead);
}
bis.close();
- is.close();
+ fileInStream.close();
}
} catch (Exception ioe) {
throw new CacheLoaderException("Problems handling stream", ioe);
} finally {
- releaseGlobalLock();
+ releaseGlobalLock(true);
// we should close the stream we created!
if (oos != outputStream) safeClose(oos);
}
@@ -265,31 +164,10 @@
} catch (Exception e) {
throw new CacheLoaderException("Problems clearing cache store", e);
} finally {
- releaseGlobalLock();
+ releaseGlobalLock(true);
}
}
- public boolean remove(Object key) throws CacheLoaderException {
- log.trace("Removing key {0}", key);
- Bucket b = null;
- try {
- b = lockAndGetBucket(key, false, true);
- if (b == null) {
- return false;
- } else {
- boolean success = b.removeEntry(key);
- if (success) saveBucket(b);
- return success;
- }
- } catch (Exception e) {
- CacheLoaderException cle = (e instanceof CacheLoaderException) ? (CacheLoaderException) e :
- new CacheLoaderException("Problems removing key " + key, e);
- throw cle;
- } finally {
- unlockBucket(b);
- }
- }
-
public void purgeExpired() {
purgerService.execute(new Runnable() {
public void run() {
@@ -302,133 +180,91 @@
});
}
- // ------------------------------------------------------------------------------------------------------------------
- // Buckets and bucket manipulators
- // ------------------------------------------------------------------------------------------------------------------
-
- private int hash(Object key) {
- int h = key.hashCode();
- h ^= (h >>> 20) ^ (h >>> 12);
- return h ^ (h >>> 7) ^ (h >>> 4);
+ protected Bucket loadBucket(String bucketName) throws CacheLoaderException {
+ return loadBucket(new File(root, bucketName));
}
- private int index(int h) {
- return h & (NUM_BUCKETS - 1);
+ protected Bucket loadBucket(File bucketFile) throws CacheLoaderException {
+ Bucket bucket = null;
+ if (bucketFile.exists()) {
+ FileInputStream is = null;
+ ObjectInputStream ois = null;
+ try {
+ is = new FileInputStream(bucketFile);
+ ois = new ObjectInputStream(is);
+ bucket = (Bucket) ois.readObject();
+ } catch (Exception e) {
+ String message = "Error while reading from file: " + bucketFile.getAbsoluteFile();
+ log.error(message);
+ throw new CacheLoaderException(message, e);
+ } finally {
+ safeClose(is);
+ safeClose(ois);
+ }
+ }
+ if (bucket != null) {
+ bucket.setBucketName(bucketFile.getName());
+ }
+ return bucket;
}
- final Bucket lockAndGetBucket(Object key, boolean create, boolean exclusiveLock) throws IOException, ClassNotFoundException, TimeoutException, InterruptedException {
- int bucketNumber = index(hash(key));
- File bucket = new File(root, bucketNumber + ".bucket");
- return lockAndGetBucket(bucket, create, exclusiveLock);
+ protected void insertBucket(Bucket bucket) throws CacheLoaderException {
+ saveBucket(bucket);
}
- final Bucket lockAndGetBucket(File f, boolean create, boolean exclusiveLock) throws IOException, ClassNotFoundException, TimeoutException, InterruptedException {
- Bucket b = null;
- String bucketName = f.getName();
- // first get a shared lock on the global lock to make sure no state tfr is going on
- acquireGlobalLock(false);
- bucketLocks.acquireLock(bucketName, exclusiveLock);
+ public final void saveBucket(Bucket b) throws CacheLoaderException {
+ File f = new File(root, b.getBucketName());
if (f.exists()) {
- FileInputStream is = new FileInputStream(f);
- ObjectInputStream ois = new ObjectInputStream(is);
- b = (Bucket) ois.readObject();
- ois.close();
- is.close();
- } else if (create) {
- b = new Bucket();
- b.entries = new HashMap<Object, StoredEntry>();
+ if (!f.delete()) log.warn("Had problems removing file {0}", f);
}
- if (b == null) {
- bucketLocks.releaseLock(bucketName); // don't bother holding locks for null buckets
- releaseGlobalLock();
- } else b.fileName = bucketName;
-
- return b;
- }
-
- final void unlockBucket(Bucket b) {
- if (b != null) bucketLocks.releaseLock(b.fileName);
- releaseGlobalLock();
- }
-
- final void acquireGlobalLock(boolean exclusive) throws TimeoutException, InterruptedException {
- Lock l = exclusive ? globalLock.writeLock() : globalLock.readLock();
- if (!l.tryLock(lockTimeout, TimeUnit.MILLISECONDS))
- throw new TimeoutException("Timed out trying to acquire " + (exclusive ? "exclusive" : "shared") + " global lock after " + lockTimeout + " millis. Lock is " + l);
- }
-
- final void releaseGlobalLock() {
- try {
- globalLock.readLock().unlock();
- } catch (IllegalMonitorStateException imse) {
- // no op
- }
- }
-
- final void saveBucket(Bucket b) throws IOException, CacheLoaderException {
- if (b.modified) {
- File f = new File(root, b.fileName);
- if (f.exists()) {
- if (!f.delete()) log.warn("Had problems removing file {0}", f);
+ if (!b.getEntries().isEmpty()) {
+ FileOutputStream fos = null;
+ ObjectOutputStream oos = null;
+ try {
+ fos = new FileOutputStream(f);
+ oos = new ObjectOutputStream(fos);
+ oos.writeObject(b);
+ oos.flush();
+ fos.flush();
+ } catch (IOException ex) {
+ log.error("Exception while saving bucket " + b, ex);
+ throw new CacheLoaderException(ex);
}
-
- if (!b.entries.isEmpty()) {
- FileOutputStream fos = null;
- ObjectOutputStream oos = null;
- try {
- fos = new FileOutputStream(f);
- oos = new ObjectOutputStream(fos);
- oos.writeObject(b);
- oos.flush();
- fos.flush();
- } finally {
- safeClose(oos);
- safeClose(fos);
- }
+ finally {
+ safeClose(oos);
+ safeClose(fos);
}
-
- b.modified = false; // reset this
}
}
- /**
- * A bucket is where entries are stored.
- */
- public final static class Bucket implements Externalizable {
- Map<Object, StoredEntry> entries;
- transient String fileName;
- transient boolean modified = false;
+ public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+ return FileCacheStoreConfig.class;
+ }
- final void addEntry(StoredEntry se) {
- entries.put(se.getKey(), se);
- modified = true;
+ public void start() throws CacheLoaderException {
+ super.start();
+ String location = cfg.getLocation();
+ if (location == null || location.trim().length() == 0) location = "Horizon-FileCacheStore"; // use relative path!
+ location += File.separator + cache.getName();
+ root = new File(location);
+ if (!root.exists()) {
+ if (!root.mkdirs())
+ throw new ConfigurationException("Directory " + root.getAbsolutePath() + " does not exist and cannot be created!");
}
-
- final boolean removeEntry(Object key) {
- if (entries.remove(key) != null) {
- modified = true;
- return true;
- }
- return false;
+ if (cfg.isPurgeSynchronously()) {
+ purgerService = new WithinThreadExecutor();
+ } else {
+ purgerService = Executors.newSingleThreadExecutor();
}
+ streamBufferSize = cfg.getStreamBufferSize();
+ }
- final StoredEntry getEntry(Object key) {
- return entries.get(key);
- }
+ public void stop() {
+ purgerService.shutdownNow();
+ }
- public final void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(entries.size());
- for (StoredEntry se : entries.values()) out.writeObject(se);
- }
-
- public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- int sz = in.readInt();
- entries = new HashMap<Object, StoredEntry>(sz);
- for (int i = 0; i < sz; i++) {
- StoredEntry se = (StoredEntry) in.readObject();
- entries.put(se.getKey(), se);
- }
- }
+ public Bucket loadBucketContainingKey(String key) throws CacheLoaderException {
+ return loadBucket(key.hashCode() + "");
}
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/loader/file/FileCacheStoreConfig.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -1,6 +1,6 @@
package org.horizon.loader.file;
-import org.horizon.loader.AbstractCacheLoaderConfig;
+import org.horizon.loader.bucket.BucketBasedCacheStoreConfig;
/**
* Configures {@link org.horizon.loader.file.FileCacheStore}. This allows you to tune a number of characteristics of
@@ -20,12 +20,10 @@
* @author Manik Surtani
* @since 1.0
*/
-public class FileCacheStoreConfig extends AbstractCacheLoaderConfig {
+public class FileCacheStoreConfig extends BucketBasedCacheStoreConfig {
String location = "Horizon-FileCacheStore";
private boolean purgeSynchronously = false;
private int streamBufferSize = 8192;
- private int lockConcurrencyLevel = 2048;
- private long lockAcquistionTimeout = 60000;
public FileCacheStoreConfig() {
setClassName(FileCacheStore.class.getName());
@@ -57,22 +55,4 @@
testImmutability("steamBufferSize");
this.streamBufferSize = streamBufferSize;
}
-
- public int getLockConcurrencyLevel() {
- return lockConcurrencyLevel;
- }
-
- public void setLockConcurrencyLevel(int lockConcurrencyLevel) {
- testImmutability("lockConcurrencyLevel");
- this.lockConcurrencyLevel = lockConcurrencyLevel;
- }
-
- public long getLockAcquistionTimeout() {
- return lockAcquistionTimeout;
- }
-
- public void setLockAcquistionTimeout(long lockAcquistionTimeout) {
- testImmutability("lockAcquistionTimeout");
- this.lockAcquistionTimeout = lockAcquistionTimeout;
- }
}
Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/ConnectionFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/ConnectionFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/ConnectionFactory.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,30 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.loader.CacheLoaderException;
+import org.horizon.util.Util;
+
+import java.sql.Connection;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+public abstract class ConnectionFactory {
+
+ public static ConnectionFactory getConnectionFactory(JdbcCacheStoreConfig config) throws CacheLoaderException {
+ try {
+ return (ConnectionFactory) Util.getInstance(config.getConnectionFactoryClass());
+ } catch (Exception e) {
+ throw new CacheLoaderException(e);
+ }
+ }
+
+ public abstract void start(JdbcCacheStoreConfig config) throws CacheLoaderException;
+
+ public abstract void stop();
+
+ public abstract Connection getConnection() throws CacheLoaderException;
+
+ public abstract void releaseConnection(Connection conn);
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/ConnectionFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,240 @@
+package org.horizon.loader.jdbc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.horizon.Cache;
+import org.horizon.io.ByteBuffer;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.CacheLoaderException;
+import org.horizon.loader.StoredEntry;
+import org.horizon.loader.bucket.Bucket;
+import org.horizon.loader.bucket.BucketBasedCacheStore;
+import org.horizon.marshall.Marshaller;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class JdbcCacheStore extends BucketBasedCacheStore {
+
+ private static final Log log = LogFactory.getLog(JdbcCacheStore.class);
+
+ private JdbcCacheStoreConfig config;
+ private ConnectionFactory connectionFactory;
+ private Marshaller marshaller;
+
+ public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+ if (log.isTraceEnabled())
+ log.trace("Initializing JdbcCacheStore " + config);
+ super.init(config, cache, m);
+ this.config = (JdbcCacheStoreConfig) config;
+ this.marshaller = m;
+ }
+
+ public void start() throws CacheLoaderException {
+ super.start();
+ this.connectionFactory = ConnectionFactory.getConnectionFactory(config);
+ connectionFactory.start(config);
+
+ //create table if needed
+ if (config.isCreateTableOnStart()) {
+ Connection conn = getConnection();
+ try {
+ TableManipulation tm = new TableManipulation(conn, config);
+ if (!tm.tableExists()) {
+ tm.createTable();
+ }
+ } finally {
+ releaseConnection(conn);
+ }
+ }
+ }
+
+ public void stop() throws CacheLoaderException {
+ if (config.isDropTableOnExit()) {
+ Connection connection = getConnection();
+ try {
+ TableManipulation tm = new TableManipulation(connection, config);
+ tm.dropTable();
+ } finally {
+ releaseConnection(connection);
+ }
+ }
+ connectionFactory.stop();
+ }
+
+ protected void insertBucket(Bucket bucket) throws CacheLoaderException {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ try {
+ String sql = config.getInsertBucketSql();
+ if (log.isTraceEnabled()) {
+ log.trace("Running insertBucket. Sql: '" + sql + "', on bucket: " + bucket);
+ }
+ conn = getConnection();
+ ps = conn.prepareStatement(sql);
+ ps.setString(1, bucket.getBucketName());
+ ByteBuffer byteBuffer = marshall(bucket);
+ ps.setBinaryStream(2, byteBuffer.getStream(), byteBuffer.getLength());
+ int insertedRows = ps.executeUpdate();
+ if (insertedRows != 1) {
+ throw new CacheLoaderException("Unexpected insert result: '" + insertedRows + "'. Expected values is 1");
+ }
+ } catch (SQLException ex) {
+ logAndThrow(ex, "sql failure while inserting bucket: " + bucket);
+ } finally {
+ JdbcUtil.safeClose(ps);
+ releaseConnection(conn);
+ }
+ }
+
+ protected void saveBucket(Bucket bucket) throws CacheLoaderException {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ try {
+ String sql = config.getSaveBucketSql();
+ if (log.isTraceEnabled()) {
+ log.trace("Running saveBucket. Sql: '" + sql + "', on bucket: " + bucket);
+ }
+ conn = getConnection();
+ ps = conn.prepareStatement(sql);
+ ByteBuffer buffer = marshall(bucket);
+ ps.setBinaryStream(1, buffer.getStream(), buffer.getLength());
+ ps.setString(2, bucket.getBucketName());
+ int updatedRows = ps.executeUpdate();
+ if (updatedRows != 1) {
+ throw new CacheLoaderException("Unexpected update result: '" + updatedRows + "'. Expected values is 1");
+ }
+
+ } catch (SQLException e) {
+ logAndThrow(e, "sql failure while updating bucket: " + bucket);
+ } finally {
+ JdbcUtil.safeClose(ps);
+ releaseConnection(conn);
+ }
+ }
+
+ protected Bucket loadBucket(String keyHashCode) throws CacheLoaderException {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ try {
+ String sql = config.getLoadBucketSql();
+ if (log.isTraceEnabled()) {
+ log.trace("Running loadBucket. Sql: '" + sql + "', on key: " + keyHashCode);
+ }
+ conn = getConnection();
+ ps = conn.prepareStatement(sql);
+ ps.setString(1, keyHashCode);
+ rs = ps.executeQuery();
+ if (!rs.next()) return null;
+ String bucketName = rs.getString(1);
+ InputStream inputStream = rs.getBinaryStream(2);
+ Bucket bucket = unmarshall(inputStream);
+ bucket.setBucketName(bucketName);//bucket name is volatile, so not persisted.
+ return bucket;
+ } catch (SQLException e) {
+ String message = "sql failure while loading key: " + keyHashCode;
+ log.error(message, e);
+ throw new CacheLoaderException(message, e);
+ } finally {
+ JdbcUtil.safeClose(rs);
+ JdbcUtil.safeClose(ps);
+ releaseConnection(conn);
+ }
+ }
+
+
+ public Set<StoredEntry> loadAll() throws CacheLoaderException {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ try {
+ String sql = config.getLoadAllSql();
+ if (log.isTraceEnabled()) {
+ log.trace("Running loadAll. Sql: '" + sql + "'");
+ }
+ conn = getConnection();
+ ps = conn.prepareStatement(sql);
+ rs = ps.executeQuery();
+ Set<StoredEntry> result = new HashSet<StoredEntry>();
+ } catch (SQLException e) {
+ String message = "sql failure while loading key: ";
+ log.error(message, e);
+ throw new CacheLoaderException(message, e);
+ } finally {
+ JdbcUtil.safeClose(rs);
+ JdbcUtil.safeClose(ps);
+ releaseConnection(conn);
+ }
+ return null;
+ }
+
+ public void fromStream(InputStream inputStream) throws CacheLoaderException {
+ throw new IllegalStateException("TODO - please implement me!!!"); //todo implement!!!
+ }
+
+ public void toStream(OutputStream outputStream) throws CacheLoaderException {
+ throw new IllegalStateException("TODO - please implement me!!!"); //todo implement!!!
+ }
+
+ public void clear() throws CacheLoaderException {
+ throw new IllegalStateException("TODO - please implement me!!!"); //todo implement!!!
+ }
+
+ public void purgeExpired() throws CacheLoaderException {
+ throw new IllegalStateException("TODO - please implement me!!!"); //todo implement!!!
+ }
+
+ public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+ return JdbcCacheStoreConfig.class;
+ }
+
+ private Connection getConnection() throws CacheLoaderException {
+ return connectionFactory.getConnection();
+ }
+
+ private void releaseConnection(Connection conn) {
+ connectionFactory.releaseConnection(conn);
+ }
+
+ private ByteBuffer marshall(Bucket bucket) throws CacheLoaderException {
+ try {
+ return marshaller.objectToBuffer(bucket);
+ } catch (IOException e) {
+ String message = "I/O failure while marshalling " + bucket;
+ log.error(message, e);
+ throw new CacheLoaderException(message, e);
+ }
+ }
+
+ private Bucket unmarshall(InputStream inputStream) throws CacheLoaderException {
+ try {
+ return (Bucket) marshaller.objectFromStream(inputStream);
+ } catch (IOException e) {
+ String message = "I/O error while unmarshalling from stram";
+ log.error(message, e);
+ throw new CacheLoaderException(message, e);
+ } catch (ClassNotFoundException e) {
+ String message = "*UNEXPECTED* ClassNotFoundException. This should not happen as Bucket class exists";
+ log.error(message, e);
+ throw new CacheLoaderException(message, e);
+ }
+ }
+
+ private void logAndThrow(Exception e, String message) throws CacheLoaderException {
+ log.error(message, e);
+ throw new CacheLoaderException(message, e);
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,181 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.loader.bucket.BucketBasedCacheStoreConfig;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public class JdbcCacheStoreConfig extends BucketBasedCacheStoreConfig {
+
+ /*
+ * following two params manage creation and destruction during start up/shutdown.
+ */
+ boolean createTableOnStart = true;
+ boolean dropTableOnExit = false;
+
+ private String connectionFactoryClass;
+
+ /* required by NonManagedConnectionFactory */
+ private String connectionUrl;
+ private String userName;
+ private String password;
+ private String driverClass;
+
+ /* attributes defining the table where data will be persisted */
+ private String tableName;
+ private String primaryKey;
+ private String keyColumnName;
+ private String keyColumnType;
+ private String dataColumnName;
+ private String dataColumnType;
+ private String insertBucketSql;
+ private String saveBucketSql;
+ private String loadBucketSql;
+ private String loadAllSql;
+
+ public JdbcCacheStoreConfig() {
+ className = JdbcCacheStore.class.getName();
+ }
+
+ public void setCreateTableOnStart(boolean createTableOnStart) {
+ this.createTableOnStart = createTableOnStart;
+ }
+
+ public boolean isCreateTableOnStart() {
+ return createTableOnStart;
+ }
+
+ public boolean isDropTableOnExit() {
+ return dropTableOnExit;
+ }
+
+ public void setDropTableOnExit(boolean dropTableOnExit) {
+ this.dropTableOnExit = dropTableOnExit;
+ }
+
+
+ public String getConnectionUrl() {
+ return connectionUrl;
+ }
+
+ public void setConnectionUrl(String connectionUrl) {
+ this.connectionUrl = connectionUrl;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getDriverClass() {
+ return driverClass;
+ }
+
+ public void setDriverClass(String driverClass) {
+ this.driverClass = driverClass;
+ }
+
+ public String getConnectionFactoryClass() {
+ return connectionFactoryClass;
+ }
+
+ public void setConnectionFactoryClass(String connectionFactoryClass) {
+ this.connectionFactoryClass = connectionFactoryClass;
+ }
+
+ public void setTableName(String tableName) {
+ this.tableName = tableName;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public String getPrimaryKey() {
+ return primaryKey;
+ }
+
+ public void setPrimaryKey(String primaryKey) {
+ this.primaryKey = primaryKey;
+ }
+
+ public String getKeyColumnName() {
+ return keyColumnName;
+ }
+
+ public void setKeyColumnName(String keyColumnName) {
+ this.keyColumnName = keyColumnName;
+ }
+
+ public String getKeyColumnType() {
+ return keyColumnType;
+ }
+
+ public void setKeyColumnType(String keyColumnType) {
+ this.keyColumnType = keyColumnType;
+ }
+
+ public String getDataColumnName() {
+ return dataColumnName;
+ }
+
+ public void setDataColumnName(String dataColumnName) {
+ this.dataColumnName = dataColumnName;
+ }
+
+ public String getDataColumnType() {
+ return dataColumnType;
+ }
+
+ public void setDataColumnType(String dataColumnType) {
+ this.dataColumnType = dataColumnType;
+ }
+
+ @Override
+ public JdbcCacheStoreConfig clone() {
+ JdbcCacheStoreConfig dolly = (JdbcCacheStoreConfig) super.clone();
+ //don't have to assign any variables as all are primitives, and cannot change
+ return dolly;
+ }
+
+ public String getInsertBucketSql() {
+ if (insertBucketSql == null) {
+ insertBucketSql = "INSERT INTO " + tableName + " (" + keyColumnName + ", " + dataColumnName + ")";
+ }
+ return insertBucketSql;
+ }
+
+ public String getSaveBucketSql() {
+ if (saveBucketSql == null) {
+ saveBucketSql = "UPDATE " + tableName + " SET " + dataColumnName + " = ? WHERE " + keyColumnName + " = ?";
+ }
+ return saveBucketSql;
+ }
+
+ public String getLoadBucketSql() {
+ if (loadBucketSql == null) {
+ loadBucketSql = "SELECT " + keyColumnName + ", " + dataColumnName + " FROM " + tableName + " WHERE " + keyColumnName + " = ?";
+ }
+ return loadBucketSql;
+ }
+
+ public String getLoadAllSql() {
+ if (loadAllSql == null) {
+ loadAllSql = "SELECT " + dataColumnName + " FROM " + tableName;
+ }
+ return loadAllSql;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcUtil.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcUtil.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcUtil.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,32 @@
+package org.horizon.loader.jdbc;
+
+import java.sql.Statement;
+import java.sql.SQLException;
+import java.sql.ResultSet;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+public class JdbcUtil {
+ public static void safeClose(Statement ps) {
+ if (ps != null) {
+ try {
+ ps.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static void safeClose(ResultSet rs) {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcUtil.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/NonManagedConnectionFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/NonManagedConnectionFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/NonManagedConnectionFactory.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,64 @@
+package org.horizon.loader.jdbc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.horizon.loader.CacheLoaderException;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+public class NonManagedConnectionFactory extends ConnectionFactory {
+
+ private static Log log = LogFactory.getLog(NonManagedConnectionFactory.class);
+
+ private String connectionUrl;
+ private String userName;
+ private String password;
+
+ public void start(JdbcCacheStoreConfig config) throws CacheLoaderException {
+ loadDriver(config.getDriverClass());
+ this.connectionUrl = config.getConnectionUrl();
+ this.userName = config.getUserName();
+ this.password = config.getPassword();
+ }
+
+ public void stop() {
+ //do nothing
+ }
+
+ public Connection getConnection() throws CacheLoaderException {
+ try {
+ return DriverManager.getConnection(connectionUrl, userName, password);
+ } catch (SQLException e) {
+ throw new CacheLoaderException("Could not obtain a new connection", e);
+ }
+ }
+
+ public void releaseConnection(Connection conn) {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ log.warn("Failure while closing the connection to the database ", e);
+ }
+ }
+
+ private void loadDriver(String driverClass) throws CacheLoaderException {
+ try {
+ if (log.isTraceEnabled()) {
+ log.trace("Attempting to load driver " + driverClass);
+ }
+ Class.forName(driverClass).newInstance();
+ }
+ catch (Throwable th) {
+ String message = "Failed loading driver with class: '" + driverClass + "'";
+ log.error(message, th);
+ throw new CacheLoaderException(message, th);
+ }
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/NonManagedConnectionFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,133 @@
+package org.horizon.loader.jdbc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.horizon.loader.CacheLoaderException;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Locale;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class TableManipulation {
+
+ private Connection connection;
+ private JdbcCacheStoreConfig config;
+ private static Log log = LogFactory.getLog(TableManipulation.class);
+
+ public TableManipulation(Connection connection, JdbcCacheStoreConfig config) {
+ this.connection = connection;
+ this.config = config;
+ }
+
+ public boolean tableExists() throws CacheLoaderException {
+ return tableExists(config.getTableName());
+ }
+
+ public boolean tableExists(String tableName) throws CacheLoaderException {
+ assrtNotNull(config.getTableName(), "table name is mandatory");
+ ResultSet rs = null;
+ try {
+ // (a j2ee spec compatible jdbc driver has to fully
+ // implement the DatabaseMetaData)
+ DatabaseMetaData dmd = connection.getMetaData();
+ String catalog = connection.getCatalog();
+ String schema = null;
+ String quote = dmd.getIdentifierQuoteString();
+ if (tableName.startsWith(quote)) {
+ if (!tableName.endsWith(quote)) {
+ throw new IllegalStateException("Mismatched quote in table name: " + tableName);
+ }
+ int quoteLength = quote.length();
+ tableName = tableName.substring(quoteLength, tableName.length() - quoteLength);
+ if (dmd.storesLowerCaseQuotedIdentifiers()) {
+ tableName = toLowerCase(tableName);
+ } else if (dmd.storesUpperCaseQuotedIdentifiers()) {
+ tableName = toUpperCase(tableName);
+ }
+ } else {
+ if (dmd.storesLowerCaseIdentifiers()) {
+ tableName = toLowerCase(tableName);
+ } else if (dmd.storesUpperCaseIdentifiers()) {
+ tableName = toUpperCase(tableName);
+ }
+ }
+
+ int dotIndex;
+ if ((dotIndex = tableName.indexOf('.')) != -1) {
+ // Yank out schema name ...
+ schema = tableName.substring(0, dotIndex);
+ tableName = tableName.substring(dotIndex + 1);
+ }
+
+ rs = dmd.getTables(catalog, schema, tableName, null);
+ return rs.next();
+ }
+ catch (SQLException e) {
+ // This should not happen. A J2EE compatible JDBC driver is
+ // required fully support meta data.
+ throw new IllegalStateException("Error while checking if table aleady exists " + tableName, e);
+ }
+ finally {
+ JdbcUtil.safeClose(rs);
+ }
+ }
+
+ public void createTable() throws CacheLoaderException {
+ // removed CONSTRAINT clause as this causes problems with some databases, like Informix.
+ assertMandatoryElemenetsPresent();
+ String creatTableDdl = "CREATE TABLE " + config.getTableName() + "(" + config.getKeyColumnName() + " " + config.getKeyColumnType()
+ + " NOT NULL, " + config.getDataColumnName() + " " + config.getDataColumnType() +
+ ", PRIMARY KEY (" + config.getKeyColumnName() + "))";
+ if (log.isTraceEnabled())
+ log.trace("Creating table with following DDL: '" + creatTableDdl + "'.");
+ executeDdlStatement(creatTableDdl);
+ }
+
+ private void assertMandatoryElemenetsPresent() throws CacheLoaderException {
+ assrtNotNull(config.getKeyColumnType(), "keyColumnType needed in order to create table");
+ assrtNotNull(config.getKeyColumnName(), "keyColumnName needed in order to create table");
+ assrtNotNull(config.getTableName(), "tableName needed in order to create table");
+ assrtNotNull(config.getDataColumnName(), "dataColumnName needed in order to create table");
+ assrtNotNull(config.getDataColumnType(), "dataColumnType needed in order to create table");
+ }
+
+ private void assrtNotNull(String keyColumnType, String message) throws CacheLoaderException {
+ if (keyColumnType == null || keyColumnType.trim().length() == 0) throw new CacheLoaderException(message);
+ }
+
+ private void executeDdlStatement(String creatTableDdl) throws CacheLoaderException {
+ Statement statement = null;
+ try {
+ statement = connection.createStatement();
+ statement.executeUpdate(creatTableDdl);
+ } catch (SQLException e) {
+ log.error("Error while creating table",e);
+ throw new CacheLoaderException(e);
+ } finally {
+ JdbcUtil.safeClose(statement);
+ }
+ }
+
+ public void dropTable() throws CacheLoaderException {
+ String dropTableDdl = "DROP TABLE " + config.getTableName();
+ if (log.isTraceEnabled())
+ log.trace("Dropping table with following DDL '" + dropTableDdl + "\'");
+ executeDdlStatement(dropTableDdl);
+ }
+
+ private static String toLowerCase(String s) {
+ return s.toLowerCase((Locale.ENGLISH));
+ }
+
+ private static String toUpperCase(String s) {
+ return s.toUpperCase(Locale.ENGLISH);
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: core/branches/flat/src/main/java/org/horizon/lock/StripedLock.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/lock/StripedLock.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/main/java/org/horizon/lock/StripedLock.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -142,4 +142,16 @@
public void acquireAllLocks(List<Object> keys, boolean exclusive) {
for (Object k : keys) acquireLock(k, exclusive);
}
+
+ /**
+ * Returns the total number of locks held by this class.
+ */
+ public int getTotalLockCount() {
+ int count = 0;
+ for (ReentrantReadWriteLock lock : sharedLocks) {
+ count += lock.getReadLockCount();
+ count += lock.isWriteLocked() ? 1 : 0;
+ }
+ return count;
+ }
}
Modified: core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -8,7 +8,7 @@
import org.horizon.eviction.algorithms.fifo.FIFOAlgorithmConfig;
import org.horizon.loader.CacheLoaderConfig;
import org.horizon.loader.decorators.SingletonStoreConfig;
-import org.horizon.loader.jdbc.JDBCCacheStoreConfig;
+import org.horizon.loader.jdbc.JdbcCacheStoreConfig;
import org.horizon.lock.IsolationLevel;
import org.horizon.transaction.GenericTransactionManagerLookup;
import org.testng.annotations.Test;
@@ -152,16 +152,17 @@
assert !c.isUseReplQueue();
}
+ @Test (enabled = false)
public void testCacheLoaders() throws Exception {
XmlConfigurationParserImpl parser = new XmlConfigurationParserImpl();
String xml = "<loaders passivation=\"true\" shared=\"true\" preload=\"true\">\n" +
- " <loader class=\"org.horizon.loader.jdbc.JDBCCacheStore\" fetchPersistentState=\"true\"\n" +
+ " <loader class=\"org.horizon.loader.jdbc.JdbcCacheStore\" fetchPersistentState=\"true\"\n" +
" ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
" <properties>\n" +
" dataSource=HorizonDS\n" +
" tableNamePrefix=horizon\n" +
" createTable=true\n" +
- " dropTable=false\n" +
+ " dropTableOnExit=false\n" +
" </properties>\n" +
" <singletonStore enabled=\"true\" pushStateWhenCoordinator=\"true\" pushStateTimeout=\"20000\" />\n" +
" <async enabled=\"true\" batchSize=\"15\" />\n" +
@@ -180,7 +181,7 @@
assert clc.isPreload();
CacheLoaderConfig iclc = clc.getFirstCacheLoaderConfig();
- assert iclc.getClassName().equals("org.horizon.loader.jdbc.JDBCCacheStore");
+ assert iclc.getClassName().equals("org.horizon.loader.jdbc.JdbcCacheStore");
assert iclc.getAsyncStoreConfig().isEnabled();
assert iclc.getAsyncStoreConfig().getBatchSize() == 15;
assert iclc.getAsyncStoreConfig().getPollWait() == 100;
@@ -190,11 +191,12 @@
assert !iclc.isIgnoreModifications();
assert !iclc.isPurgeOnStartup();
- JDBCCacheStoreConfig jdbcclc = (JDBCCacheStoreConfig) iclc;
- assert jdbcclc.getDataSource().equals("HorizonDS");
- assert jdbcclc.getTableNamePrefix().equals("horizon");
- assert jdbcclc.isCreateTable();
- assert !jdbcclc.isDropTable();
+ JdbcCacheStoreConfig jdbcclc = (JdbcCacheStoreConfig) iclc;
+// assert jdbcclc.getDataSource().equals("HorizonDS");
+// assert jdbcclc.getTableNamePrefix().equals("horizon");
+ assert false : "todo update test according to config";
+ assert jdbcclc.isCreateTableOnStart();
+ assert !jdbcclc.isDropTableOnExit();
SingletonStoreConfig ssc = iclc.getSingletonStoreConfig();
assert ssc.isSingletonStoreEnabled();
@@ -205,7 +207,7 @@
public void testCacheLoadersDefaults() throws Exception {
XmlConfigurationParserImpl parser = new XmlConfigurationParserImpl();
String xml = "<loaders>\n" +
- " <loader class=\"org.horizon.loader.jdbc.JDBCCacheStore\">\n" +
+ " <loader class=\"org.horizon.loader.jdbc.JdbcCacheStore\">\n" +
" <properties />\n" +
" </loader>\n" +
" </loaders>";
@@ -222,7 +224,7 @@
assert !clc.isPreload();
CacheLoaderConfig iclc = clc.getFirstCacheLoaderConfig();
- assert iclc.getClassName().equals("org.horizon.loader.jdbc.JDBCCacheStore");
+ assert iclc.getClassName().equals("org.horizon.loader.jdbc.JdbcCacheStore");
assert !iclc.getAsyncStoreConfig().isEnabled();
assert !iclc.isFetchPersistentState();
assert !iclc.isIgnoreModifications();
Modified: core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/test/java/org/horizon/loader/BaseCacheStoreTest.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -29,12 +29,12 @@
// this needs to be here for the test to run in an IDE
public abstract class BaseCacheStoreTest {
- protected abstract CacheStore createCacheStore();
+ protected abstract CacheStore createCacheStore() throws Exception;
protected CacheStore cs;
@BeforeMethod
- public void setUp() {
+ public void setUp() throws Exception {
cs = createCacheStore();
}
@@ -225,7 +225,7 @@
assert expected.isEmpty();
}
- public void testPurgeExpired() throws InterruptedException, Exception {
+ public void testPurgeExpired() throws Exception {
long now = System.currentTimeMillis();
long lifespan = 1000;
cs.store(new StoredEntry("k1", "v1", now, now + lifespan));
@@ -271,8 +271,8 @@
}
public void testConcurrency() throws Exception {
- int numThreads = 5;
- final int loops = 1000;
+ int numThreads = 3;
+ final int loops = 500;
final String[] keys = new String[10];
final String[] values = new String[10];
for (int i = 0; i < 10; i++) keys[i] = "k" + i;
@@ -319,7 +319,7 @@
Thread[] threads = new Thread[numThreads];
for (int i = 0; i < numThreads; i++) {
- threads[i] = new Thread() {
+ threads[i] = new Thread(getClass().getSimpleName() + "-" + i) {
public void run() {
for (int i = 0; i < loops; i++) {
store.run();
Modified: core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/test/java/org/horizon/loader/decorators/AsyncTest.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -2,6 +2,7 @@
import org.horizon.CacheException;
import org.horizon.loader.StoredEntry;
+import org.horizon.loader.CacheLoaderException;
import org.horizon.loader.dummy.DummyInMemoryCacheStore;
import org.horizon.test.TestingUtil;
import org.testng.annotations.AfterMethod;
@@ -19,7 +20,7 @@
@BeforeTest
- public void setUp() {
+ public void setUp() throws CacheLoaderException {
store = new AsyncStore(new DummyInMemoryCacheStore(), new AsyncStoreConfig());
DummyInMemoryCacheStore.Cfg cfg = new DummyInMemoryCacheStore.Cfg();
cfg.setStore(AsyncTest.class.getName());
@@ -29,7 +30,7 @@
}
@AfterTest
- public void tearDown() {
+ public void tearDown() throws CacheLoaderException {
if (store != null) store.stop();
}
Modified: core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/test/java/org/horizon/loader/decorators/ChainingCacheLoaderTest.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -33,7 +33,7 @@
DummyInMemoryCacheStore[] stores; // for convenient iteration
private static final long lifespan = 6000000;
- protected CacheStore createCacheStore() {
+ protected CacheStore createCacheStore() throws CacheLoaderException {
ChainingCacheStore store = new ChainingCacheStore();
CacheLoaderConfig cfg;
store1 = new DummyInMemoryCacheStore();
Modified: core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java 2009-02-24 22:02:12 UTC (rev 7777)
+++ core/branches/flat/src/test/java/org/horizon/loader/file/FileCacheStoreTest.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -1,30 +1,43 @@
package org.horizon.loader.file;
import org.horizon.loader.BaseCacheStoreTest;
+import org.horizon.loader.CacheLoaderException;
import org.horizon.loader.CacheStore;
import org.horizon.loader.StoredEntry;
+import org.horizon.loader.bucket.Bucket;
import org.horizon.test.TestingUtil;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.ObjectInputStream;
-@Test(groups = "unit", enabled = true, testName = "loader.file.FileCacheStoreTest")
+@Test(groups = "unit", testName = "loader.file.FileCacheStoreTest")
public class FileCacheStoreTest extends BaseCacheStoreTest {
private final String tmpDirectory = TestingUtil.TEST_FILES + File.separator + getClass().getSimpleName();
+ private FileCacheStore fcs;
- protected CacheStore createCacheStore() {
- CacheStore cs = new FileCacheStore();
+ protected CacheStore createCacheStore() throws CacheLoaderException {
+ fcs = new FileCacheStore();
FileCacheStoreConfig cfg = new FileCacheStoreConfig();
cfg.setLocation(tmpDirectory);
cfg.setPurgeSynchronously(true); // for more accurate unit testing
- cs.init(cfg, getCache(), getMarshaller());
- cs.start();
- return cs;
+ fcs.init(cfg, getCache(), getMarshaller());
+ fcs.start();
+ return fcs;
}
+ @AfterMethod
+ public void assertNoLocksHeldAfterTest() {
+ assert fcs.getBucketLockCount() == 0;
+ assert fcs.getGlobalLockCount() == 0;
+ }
+
@AfterTest
@BeforeTest
public void removeTempDirectory() {
@@ -32,6 +45,11 @@
}
@Override
+ public void testPreload() throws CacheLoaderException {
+ super.testPreload();
+ }
+
+ @Override
public void testPurgeExpired() throws Exception {
long now = System.currentTimeMillis();
long lifespan = 1000;
@@ -44,36 +62,45 @@
Thread.sleep(lifespan + 100);
cs.purgeExpired();
FileCacheStore fcs = (FileCacheStore) cs;
- assert fcs.lockAndGetBucket("k1", false, false) == null;
- assert fcs.lockAndGetBucket("k2", false, false) == null;
- assert fcs.lockAndGetBucket("k3", false, false) == null;
- System.out.println("Global lock: " + fcs.globalLock.readLock().toString());
+ assert fcs.load("k1") == null;
+ assert fcs.load("k2") == null;
+ assert fcs.load("k3") == null;
}
public void testBucketRemoval() throws Exception {
- FileCacheStore fcs = (FileCacheStore) cs;
- FileCacheStore.Bucket b = null;
- try {
- b = fcs.lockAndGetBucket("test", true, false);
- assert b != null;
- assert !b.modified;
- b.addEntry(new StoredEntry("test", "value"));
- assert b.modified;
+ Bucket b;
+ StoredEntry se = new StoredEntry("test", "value");
+ fcs.store(se);
+ b = fcs.loadBucketContainingKey("test");
+ assert b != null;
- fcs.saveBucket(b);
- assert !b.modified;
- assert !b.entries.isEmpty();
+ assert !b.getEntries().isEmpty();
- assert new File(fcs.root, b.fileName).exists();
+ assert new File(fcs.root, b.getBucketName()).exists();
- b.removeEntry("test");
- assert b.entries.isEmpty();
- assert b.modified;
+ b.removeEntry("test");
+ assert b.getEntries().isEmpty();
- fcs.saveBucket(b);
- assert !new File(fcs.root, b.fileName).exists();
+ fcs.saveBucket(b);
+ assert !new File(fcs.root, b.getBucketName()).exists();
+ }
+
+ public void testToStream() throws Exception {
+ cs.store(new StoredEntry("k1", "v1", -1, -1));
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ cs.toStream(out);
+ out.flush();
+ out.close();
+
+ ObjectInputStream ois = null;
+ try {
+ ois = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
+ assert ois.readInt() == 1 : "we have 3 different buckets";
+ assert ois.readObject().equals("k1".hashCode() + "");
+ assert ois.readInt() > 0; //size on disk
} finally {
- fcs.unlockBucket(b);
+ if (ois != null) ois.close();
}
}
}
Added: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,38 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.loader.CacheStore;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+@Test(groups = "functional", testName = "loader.jdbc.JdbcCacheStoreTest", enabled = false)
+public class JdbcCacheStoreTest /*extends BaseCacheStoreTest*/ {
+
+ private JdbcCacheStore jdbcCacheStore;
+
+ protected CacheStore createCacheStore() throws Exception {
+ try {
+ jdbcCacheStore = new JdbcCacheStore();
+ JdbcCacheStoreConfig config = new JdbcCacheStoreConfig();
+ config.setConnectionFactoryClass(NonManagedConnectionFactory.class.getName());
+ config.setConnectionUrl("jdbc:mysql://localhost/horizon");
+ config.setUserName("root");
+ config.setPassword("root");
+ config.setDriverClass("com.mysql.jdbc.Driver");
+ config.setTableName("horizon_jdc");
+ config.setKeyColumnName("key_name");
+ config.setKeyColumnType("varchar(255)");
+ config.setDataColumnName("BUCKET");
+ config.setDataColumnType("BINARY");
+ jdbcCacheStore.init(config, null, null);
+ jdbcCacheStore.start();
+ return jdbcCacheStore;
+ } catch (Throwable e) {
+ e.printStackTrace(); // TODO: Mircea: Customise this generated block
+ throw (Exception) e;
+ }
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/test/java/org/horizon/loader/jdbc/TableManipulationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/TableManipulationTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/TableManipulationTest.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,139 @@
+package org.horizon.loader.jdbc;
+
+import static org.easymock.EasyMock.*;
+import org.horizon.loader.CacheLoaderException;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+@Test(groups = "functional", testName ="loader.jdbc.TableManipulationTest", enabled = false)
+public class TableManipulationTest {
+
+ Connection connection;
+ TableManipulation tableManipulation;
+ JdbcCacheStoreConfig config;
+
+ @BeforeTest
+ public void createConnection() throws Exception {
+ Class.forName("com.mysql.jdbc.Driver").newInstance();
+ connection = DriverManager.getConnection("jdbc:mysql://localhost/horizon", "root", "root");
+ Statement st = connection.createStatement();
+ try {
+ st.executeUpdate("DROP TABLE horizon_test");
+ } catch (SQLException e) {
+ //ignore, might be the table does not exist
+ }
+ JdbcUtil.safeClose(st);
+ config = new JdbcCacheStoreConfig();
+ config.setKeyColumnType("VARCHAR(255)");
+ config.setDataColumnType("BLOB");
+ config.setTableName("horizon_test");
+ config.setKeyColumnName("KEY_HASH");
+ config.setDataColumnName("BUCKET");
+ tableManipulation = new TableManipulation(connection, config);
+ }
+
+ @AfterTest
+ public void closeConnection() throws SQLException {
+ connection.close();
+ }
+
+ public void testInsufficientConfigParams() throws Exception {
+ JdbcCacheStoreConfig config = new JdbcCacheStoreConfig();
+ config.setKeyColumnType("VARCHAR(255)");
+ config.setDataColumnType("BLOB");
+ config.setTableName("horizon");
+ config.setKeyColumnName("dsadsa");
+ config.setDataColumnName("dsadsa");
+ Connection mockConnection = createMock(Connection.class);
+ Statement mockStatement = createNiceMock(Statement.class);
+ expect(mockConnection.createStatement()).andReturn(mockStatement);
+ replay(mockConnection, mockStatement);
+ TableManipulation other = new TableManipulation(mockConnection, config);
+ try {
+ other.createTable();
+ } catch (CacheLoaderException e) {
+ assert false : "We do not expect a failure here";
+ }
+
+ config.setKeyColumnType(null);
+ try {
+ other.createTable();
+ assert false : "missing config param, exception expected";
+ } catch (CacheLoaderException e) {
+ config.setKeyColumnType("VARCHAR(255)");
+ assert true : "We do not expect a failure here";
+ }
+
+ config.setKeyColumnName("");
+ try {
+ other.createTable();
+ assert false : "missing config param, exception expected";
+ } catch (CacheLoaderException e) {
+ config.setKeyColumnName("abc");
+ assert true : "We do not expect a failure here";
+ }
+
+ config.setTableName(null);
+ try {
+ other.createTable();
+ assert false : "missing config param, exception expected";
+ } catch (CacheLoaderException e) {
+ config.setTableName("abc");
+ assert true : "We do not expect a failure here";
+ }
+
+ config.setDataColumnName(null);
+ try {
+ other.createTable();
+ assert false : "missing config param, exception expected";
+ } catch (CacheLoaderException e) {
+ config.setDataColumnName("abc");
+ assert true : "We do not expect a failure here";
+ }
+ }
+
+ public void testCreateTable() throws Exception {
+ assert !existsTable(config.getTableName());
+ tableManipulation.createTable();
+ assert existsTable(config.getTableName());
+ }
+
+ @Test(dependsOnMethods = "testCreateTable")
+ public void testExists() throws CacheLoaderException {
+ assert tableManipulation.tableExists();
+ assert !tableManipulation.tableExists("does_not_exist");
+ }
+
+ @Test(dependsOnMethods = "testExists")
+ public void testDrop() throws CacheLoaderException {
+ assert tableManipulation.tableExists();
+ tableManipulation.dropTable();
+ assert !tableManipulation.tableExists();
+ }
+
+ private boolean existsTable(String tableName) throws Exception {
+ Statement st = connection.createStatement();
+ ResultSet rs = null;
+ try {
+ rs = st.executeQuery("select * from " + tableName);
+ return true;
+ } catch (SQLException e) {
+ return false;
+ } finally {
+ JdbcUtil.safeClose(rs);
+ JdbcUtil.safeClose(st);
+ }
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/loader/jdbc/TableManipulationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java 2009-02-25 10:23:49 UTC (rev 7778)
@@ -0,0 +1,116 @@
+package org.horizon.test;
+
+import org.horizon.loader.jdbc.JdbcCacheStoreConfig;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class UnitTestDatabaseManager {
+ private static final JdbcCacheStoreConfig realConfig = new JdbcCacheStoreConfig();
+
+ private static AtomicInteger userIndex = new AtomicInteger(0);
+
+ static {
+ realConfig.setTableName("horizon");
+ realConfig.setCreateTableOnStart(true);
+ realConfig.setPrimaryKey("horizon_pk");
+ realConfig.setKeyColumnName("key");
+ realConfig.setKeyColumnType("varchar(255)");
+ realConfig.setDataColumnName("bucket");
+ realConfig.setDataColumnType("BINARY");
+ realConfig.setDriverClass("org.hsqldb.jdbcDriver");
+ realConfig.setConnectionUrl("jdbc:hsqldb:mem:jbosscache");
+ realConfig.setUserName("sa");
+ }
+
+ public static JdbcCacheStoreConfig getUniqueJdbcCacheStoreConfig() {
+ synchronized (realConfig) {
+ return returnBasedOnDifferentInstance();
+ }
+ }
+
+ public static void shutdownInMemoryDatabase(JdbcCacheStoreConfig config) {
+ Connection conn = null;
+ Statement st = null;
+ try {
+ String shutDownConnection = getShutdownUrl(config);
+ String url = config.getConnectionUrl();
+ assert url != null;
+ conn = DriverManager.getConnection(shutDownConnection);
+ st = conn.createStatement();
+ st.execute("SHUTDOWN");
+ }
+ catch (Throwable e) {
+ throw new IllegalStateException(e);
+ }
+ finally {
+ try {
+ conn.close();
+ st.close();
+ }
+ catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static void clearDatabaseFiles(Properties props) {
+ //now delete the disk folder
+ String dbName = getDatabaseName(props);
+ String toDel = TestingUtil.TEST_FILES + File.separator + dbName;
+ TestingUtil.recursiveFileRemove(toDel);
+ }
+
+ public static String getDatabaseName(Properties prop) {
+ //jdbc:hsqldb:mem:jbosscache
+ StringTokenizer tokenizer = new StringTokenizer(prop.getProperty("cache.jdbc.url"), ":");
+ tokenizer.nextToken();
+ tokenizer.nextToken();
+ tokenizer.nextToken();
+ return tokenizer.nextToken();
+ }
+
+ private static String getShutdownUrl(JdbcCacheStoreConfig props) {
+ String url = props.getConnectionUrl();
+ assert url != null;
+ //jdbc:derby:jbossdb;create=true
+ StringTokenizer tokenizer = new StringTokenizer(url, ";");
+ String result = tokenizer.nextToken() + ";" + "shutdown=true";
+ return result;
+ }
+
+ private static JdbcCacheStoreConfig returnBasedOnDifferentInstance() {
+ //jdbc:hsqldb:mem:jbosscache
+ JdbcCacheStoreConfig result = realConfig.clone();
+ String jdbcUrl = result.getConnectionUrl();
+ Pattern pattern = Pattern.compile("jbosscache");
+ Matcher matcher = pattern.matcher(jdbcUrl);
+ boolean found = matcher.find();
+ assert found;
+ String newJdbcUrl = matcher.replaceFirst(extractTestName() + userIndex.incrementAndGet());
+ result.setConnectionUrl(newJdbcUrl);
+ return result;
+ }
+
+ private static String extractTestName() {
+ StackTraceElement[] stack = Thread.currentThread().getStackTrace();
+ if (stack.length == 0) return null;
+ for (int i = stack.length - 1; i > 0; i--) {
+ StackTraceElement e = stack[i];
+ String className = e.getClassName();
+ if (className.indexOf("org.jboss.cache") != -1) return className.replace('.', '_') + "_" + e.getMethodName();
+ }
+ return null;
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/test/UnitTestDatabaseManager.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
15 years, 10 months
JBoss Cache SVN: r7777 - core/branches/flat.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-24 17:02:12 -0500 (Tue, 24 Feb 2009)
New Revision: 7777
Modified:
core/branches/flat/pom.xml
Log:
Updated BDBJE
Modified: core/branches/flat/pom.xml
===================================================================
--- core/branches/flat/pom.xml 2009-02-24 17:55:14 UTC (rev 7776)
+++ core/branches/flat/pom.xml 2009-02-24 22:02:12 UTC (rev 7777)
@@ -61,9 +61,9 @@
</dependency>
<dependency>
- <groupId>sleepycat</groupId>
+ <groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>
- <version>3.2.43</version>
+ <version>3.3.75</version>
<optional>true</optional>
</dependency>
@@ -163,7 +163,7 @@
<property>
<name>java.net.preferIPv4Stack</name>
<value>true</value>
- </property>
+ </property>
</systemProperties>
<trimStackTrace>false</trimStackTrace>
<properties>
@@ -245,6 +245,11 @@
<id>e-xml.sourceforge.net</id>
<url>http://e-xml.sourceforge.net/maven2/repository</url>
</repository>
+ <!-- For Sleepycat -->
+ <repository>
+ <id>berkeleydb-je.repository</id>
+ <url>http://download.oracle.com/maven/</url>
+ </repository>
</repositories>
<profiles>
@@ -425,7 +430,7 @@
<profile>
<id>test-hudson</id>
<activation>
- <activeByDefault>true</activeByDefault>
+ <activeByDefault>true</activeByDefault>
</activation>
<properties>
<defaultTestGroup>functional,unit</defaultTestGroup>
15 years, 10 months
JBoss Cache SVN: r7776 - core/tags.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-24 12:55:14 -0500 (Tue, 24 Feb 2009)
New Revision: 7776
Removed:
core/tags/3.0.3.SP1/
Log:
15 years, 10 months
JBoss Cache SVN: r7775 - core/tags.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-24 12:54:57 -0500 (Tue, 24 Feb 2009)
New Revision: 7775
Added:
core/tags/3.0.3.SP1/
Log:
Copied: core/tags/3.0.3.SP1 (from rev 7774, core/tags/3.0.3.GA)
15 years, 10 months