JBoss Cache SVN: r7865 - benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 12:45:29 -0500 (Thu, 05 Mar 2009)
New Revision: 7865
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
Log:
New snapshot
Modified: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
===================================================================
(Binary files differ)
15 years, 9 months
JBoss Cache SVN: r7864 - in core/branches/flat/src/main/java/org/horizon: factories and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 12:45:03 -0500 (Thu, 05 Mar 2009)
New Revision: 7864
Modified:
core/branches/flat/src/main/java/org/horizon/container/CachedValue.java
core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.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/LockingInterceptor.java
core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java
Log:
Minor performance tweaks after a brief profiling session
Modified: core/branches/flat/src/main/java/org/horizon/container/CachedValue.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/CachedValue.java 2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/container/CachedValue.java 2009-03-05 17:45:03 UTC (rev 7864)
@@ -1,6 +1,6 @@
package org.horizon.container;
-public class CachedValue {
+public class CachedValue implements MVCCEntry {
protected Object value;
protected long modifiedTime;
@@ -20,15 +20,61 @@
return modifiedTime;
}
+ public Object getKey() {
+ return null;
+ }
+
public final Object getValue() {
return value;
}
- public final void setValue(Object value) {
+ public final Object setValue(Object value) {
this.value = value;
+ return null;
}
+ public final boolean isNullEntry() {
+ return false;
+ }
+
+ public void copyForUpdate(DataContainer container, boolean writeSkewCheck) {
+ }
+
+ public void commitUpdate(DataContainer container) {
+ }
+
+ public void rollbackUpdate() {
+ }
+
+ public final boolean isChanged() {
+ return false;
+ }
+
+ public final boolean isCreated() {
+ return false;
+ }
+
+ public void setCreated(boolean created) {
+ }
+
+ public final boolean isDeleted() {
+ return false;
+ }
+
+ public void setDeleted(boolean deleted) {
+ }
+
+ public final boolean isValid() {
+ return false;
+ }
+
+ public void setValid(boolean valid) {
+ }
+
public long getLifespan() {
return -1;
}
+
+ public void setLifespan(long lifespan) {
+ }
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java 2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java 2009-03-05 17:45:03 UTC (rev 7864)
@@ -21,15 +21,13 @@
*/
package org.horizon.container;
-import java.util.Map.Entry;
-
/**
* // TODO: MANIK: Document this
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 1.0
*/
-public interface MVCCEntry extends Entry {
+public interface MVCCEntry {
boolean isNullEntry();
void copyForUpdate(DataContainer container, boolean writeSkewCheck);
@@ -55,4 +53,10 @@
long getLifespan();
void setLifespan(long lifespan);
+
+ Object getKey();
+
+ Object getValue();
+
+ Object setValue(Object value);
}
Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java 2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java 2009-03-05 17:45:03 UTC (rev 7864)
@@ -35,7 +35,8 @@
void releaseLock(InvocationContext ctx, Object key);
/**
- * Attempts to lock an entry 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
@@ -49,7 +50,5 @@
MVCCEntry wrapEntryForWriting(InvocationContext ctx, Object key, boolean createIfAbsent, boolean forceLockIfAbsent) throws InterruptedException;
- MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext, boolean forceWriteLock) throws InterruptedException;
-
- MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext) throws InterruptedException;
+ MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key) throws InterruptedException;
}
Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-03-05 17:45:03 UTC (rev 7864)
@@ -71,26 +71,27 @@
return useRepeatableRead ? new RepeatableReadEntry(key, value, lifespan) : new ReadCommittedEntry(key, value, lifespan);
}
- public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext) throws InterruptedException {
- return wrapEntryForReading(ctx, key, putInContext, false);
- }
-
- public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext, boolean forceWriteLock) throws InterruptedException {
- // TODO: Do we need to wrap for reading if we are not in a TX?
- // TODO: Also, do we need to wrap for reading even IN a TX if we are using read-committed?
-
+ public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key) throws InterruptedException {
MVCCEntry mvccEntry;
- if (forceWriteLock) {
+ if (ctx.hasOption(Options.FORCE_WRITE_LOCK)) {
if (trace) log.trace("Forcing lock on reading");
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 entry, wrap it, put wrapped entry in the context.
CachedValue se = container.getEntry(key);
- mvccEntry = se == null ?
- createWrappedEntry(key, null, false, -1) :
- createWrappedEntry(key, se.getValue(), false, se.getLifespan());
- if (mvccEntry != null && putInContext) ctx.putLookedUpEntry(key, mvccEntry);
+
+ // do not bother wrapping though if this is not in a tx. repeatable read etc are all meaningless unless there is a tx.
+ // TODO: Do we need to wrap for reading even IN a TX if we are using read-committed?
+ if (ctx.getTransaction() == null) {
+ if (se != null) ctx.putLookedUpEntry(key, se);
+ } else {
+ mvccEntry = se == null ?
+ createWrappedEntry(key, null, false, -1) :
+ createWrappedEntry(key, se.getValue(), false, se.getLifespan());
+ if (mvccEntry != null) ctx.putLookedUpEntry(key, mvccEntry);
+ }
+
return mvccEntry;
} else {
if (trace) log.trace("Key is already in context");
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java 2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java 2009-03-05 17:45:03 UTC (rev 7864)
@@ -109,7 +109,7 @@
@Override
public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {
try {
- entryFactory.wrapEntryForReading(ctx, command.getKey(), true);
+ entryFactory.wrapEntryForReading(ctx, command.getKey());
return invokeNextInterceptor(ctx, command);
}
finally {
Modified: core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java 2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java 2009-03-05 17:45:03 UTC (rev 7864)
@@ -34,6 +34,7 @@
setLifespan(lifespan);
}
+ @Override
public final Object getKey() {
return key;
}
15 years, 9 months
JBoss Cache SVN: r7863 - benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 12:22:27 -0500 (Thu, 05 Mar 2009)
New Revision: 7863
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
Log:
New snapshot
Modified: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
===================================================================
(Binary files differ)
15 years, 9 months
JBoss Cache SVN: r7862 - in core/branches/flat/src/main/java/org/horizon: factories and 3 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 12:20:15 -0500 (Thu, 05 Mar 2009)
New Revision: 7862
Modified:
core/branches/flat/src/main/java/org/horizon/container/CachedValue.java
core/branches/flat/src/main/java/org/horizon/container/DataContainer.java
core/branches/flat/src/main/java/org/horizon/container/ExpirableCachedValue.java
core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java
core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java
core/branches/flat/src/main/java/org/horizon/remoting/RPCManager.java
core/branches/flat/src/main/java/org/horizon/remoting/transport/Transport.java
Log:
Minor performance tweaks after a brief profiling session
Modified: core/branches/flat/src/main/java/org/horizon/container/CachedValue.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/CachedValue.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/container/CachedValue.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -27,4 +27,8 @@
public final void setValue(Object value) {
this.value = value;
}
+
+ public long getLifespan() {
+ return -1;
+ }
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/horizon/container/DataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/DataContainer.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/container/DataContainer.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -60,5 +60,7 @@
StoredEntry createEntryForStorage(Object key);
+ CachedValue getEntry(Object k);
+
Set<StoredEntry> getAllEntriesForStorage();
}
Modified: core/branches/flat/src/main/java/org/horizon/container/ExpirableCachedValue.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/ExpirableCachedValue.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/container/ExpirableCachedValue.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -34,4 +34,10 @@
public final void setLifespan(long lifespan) {
expiryTime = lifespan < 0 ? -1 : lifespan + createdTime;
}
+
+ @Override
+ public final long getLifespan() {
+ if (createdTime < 0 || expiryTime < 0) return -1;
+ return expiryTime - createdTime;
+ }
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -46,6 +46,7 @@
* @since 1.0
*/
public class UnsortedDataContainer implements DataContainer {
+ // TODO this should ideally have its own hash table rather than delegate to a concurrent map, which in turn will wrap things up in Entries again. Remove this unneccessary delegation
// data with expiry and without expiry are stored in different maps, for efficiency. E.g., so that when purging expired
// stuff, we don't need to iterate through immortal data.
final ConcurrentMap<Object, CachedValue> immortalData = new ConcurrentHashMap<Object, CachedValue>();
@@ -205,9 +206,22 @@
return new StoredEntry(key, ecv.getValue(), ecv.getCreatedTime(), ecv.getExpiryTime());
}
+ public CachedValue getEntry(Object key) {
+ CachedValue immortal = immortalData.get(key);
+ if (immortal != null)
+ return immortal;
+ ExpirableCachedValue ecv = expirableData.get(key);
+ if (ecv == null) return null;
+ if (ecv.isExpired()) {
+ expirableData.remove(key);
+ return null;
+ }
+ return ecv;
+ }
+
public Set<StoredEntry> getAllEntriesForStorage() {
Set<StoredEntry> set = new HashSet<StoredEntry>(immortalData.size() + expirableData.size());
- for (Map.Entry<Object, CachedValue> entry: immortalData.entrySet())
+ for (Map.Entry<Object, CachedValue> entry : immortalData.entrySet())
set.add(new StoredEntry(entry.getKey(), entry.getValue().getValue()));
for (Iterator<Map.Entry<Object, ExpirableCachedValue>> it = expirableData.entrySet().iterator(); it.hasNext();) {
Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -22,6 +22,7 @@
package org.horizon.factories;
import org.horizon.config.Configuration;
+import org.horizon.container.CachedValue;
import org.horizon.container.DataContainer;
import org.horizon.container.MVCCEntry;
import org.horizon.container.NullMarkerEntry;
@@ -31,7 +32,6 @@
import org.horizon.factories.annotations.Inject;
import org.horizon.factories.annotations.Start;
import org.horizon.invocation.Options;
-import org.horizon.loader.StoredEntry;
import org.horizon.lock.IsolationLevel;
import org.horizon.lock.LockManager;
import org.horizon.lock.TimeoutException;
@@ -65,17 +65,17 @@
writeSkewCheck = configuration.isWriteSkewCheck();
}
- public MVCCEntry createWrappedEntry(Object key, Object value, boolean isForInsert, long lifespan) {
+ public final MVCCEntry createWrappedEntry(Object key, Object value, boolean isForInsert, long lifespan) {
if (value == null && !isForInsert) return useRepeatableRead ? NULL_MARKER : null;
return useRepeatableRead ? new RepeatableReadEntry(key, value, lifespan) : new ReadCommittedEntry(key, value, lifespan);
}
- public MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext) throws InterruptedException {
+ public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext) throws InterruptedException {
return wrapEntryForReading(ctx, key, putInContext, false);
}
- public MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext, boolean forceWriteLock) throws InterruptedException {
+ public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext, boolean forceWriteLock) throws InterruptedException {
// TODO: Do we need to wrap for reading if we are not in a TX?
// TODO: Also, do we need to wrap for reading even IN a TX if we are using read-committed?
@@ -86,7 +86,7 @@
} else if ((mvccEntry = ctx.lookupEntry(key)) == null) {
if (trace) log.trace("Key " + key + " is not in context, fetching from container.");
// simple implementation. Peek the entry, wrap it, put wrapped entry in the context.
- StoredEntry se = container.createEntryForStorage(key);
+ CachedValue se = container.getEntry(key);
mvccEntry = se == null ?
createWrappedEntry(key, null, false, -1) :
createWrappedEntry(key, se.getValue(), false, se.getLifespan());
@@ -98,7 +98,7 @@
}
}
- public MVCCEntry wrapEntryForWriting(InvocationContext ctx, Object key, boolean createIfAbsent, boolean forceLockIfAbsent) throws InterruptedException {
+ public final MVCCEntry wrapEntryForWriting(InvocationContext ctx, Object key, boolean createIfAbsent, boolean forceLockIfAbsent) throws InterruptedException {
MVCCEntry mvccEntry = ctx.lookupEntry(key);
if (createIfAbsent && mvccEntry != null && mvccEntry.isNullEntry()) mvccEntry = null;
if (mvccEntry != null) // exists in context! Just acquire lock if needed, and wrap.
@@ -116,14 +116,14 @@
}
} else {
// else, fetch from dataContainer.
- StoredEntry storedEntry = container.createEntryForStorage(key);
- if (storedEntry != null) {
+ CachedValue cachedValue = container.getEntry(key);
+ if (cachedValue != null) {
if (trace) log.trace("Retrieved from container.");
// exists in cache! Just acquire lock if needed, and wrap.
// do we need a lock?
boolean needToCopy = false;
if (acquireLock(ctx, key)) needToCopy = true;
- mvccEntry = createWrappedEntry(key, storedEntry.getValue(), false, storedEntry.getLifespan());
+ mvccEntry = createWrappedEntry(key, cachedValue.getValue(), false, cachedValue.getLifespan());
ctx.putLookedUpEntry(key, mvccEntry);
if (needToCopy) mvccEntry.copyForUpdate(container, writeSkewCheck);
} else if (createIfAbsent) {
@@ -147,7 +147,8 @@
}
/**
- * Attempts to lock an entry 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
@@ -157,7 +158,7 @@
* @throws org.horizon.lock.TimeoutException
* if we are unable to acquire the lock after a specified timeout.
*/
- public boolean acquireLock(InvocationContext ctx, Object key) throws InterruptedException, TimeoutException {
+ public final boolean acquireLock(InvocationContext ctx, Object key) throws InterruptedException, TimeoutException {
// don't EVER use lockManager.isLocked() since with lock striping it may be the case that we hold the relevant
// lock which may be shared with another key that we have a lock for already.
// nothing wrong, just means that we fail to record the lock. And that is a problem.
@@ -181,7 +182,7 @@
0 : configuration.getLockAcquisitionTimeout();
}
- public void releaseLock(InvocationContext ctx, Object key) {
+ public final void releaseLock(InvocationContext ctx, Object key) {
lockManager.unlock(key, lockManager.getOwner(key));
ctx.removeKeyLocked(key);
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -38,11 +38,6 @@
return key;
}
- public final long getLifespan() {
- if (createdTime < 0 || expiryTime < 0) return -1;
- return expiryTime - createdTime;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
Modified: core/branches/flat/src/main/java/org/horizon/remoting/RPCManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/remoting/RPCManager.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/remoting/RPCManager.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -45,7 +45,7 @@
@Scope(Scopes.GLOBAL)
@NonVolatile
public interface RPCManager extends Lifecycle {
-
+ // TODO this needs to be re-thought regarding adding a transport-independent mechanism of unicasts for distribution based on consistent hashes
/**
* Invokes an RPC call on other caches in the cluster.
*
Modified: core/branches/flat/src/main/java/org/horizon/remoting/transport/Transport.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/remoting/transport/Transport.java 2009-03-05 16:24:07 UTC (rev 7861)
+++ core/branches/flat/src/main/java/org/horizon/remoting/transport/Transport.java 2009-03-05 17:20:15 UTC (rev 7862)
@@ -27,6 +27,7 @@
@Scope(Scopes.GLOBAL)
@NonVolatile
public interface Transport extends Lifecycle {
+ // TODO discovery should be abstracted away into a separate set of interfaces such that it is not tightly coupled to the transport
/**
* Initializes the transport with global cache configuration and transport-specific properties.
15 years, 9 months
JBoss Cache SVN: r7861 - benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 11:24:07 -0500 (Thu, 05 Mar 2009)
New Revision: 7861
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
Log:
Updated horizon snapshot
Modified: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
===================================================================
(Binary files differ)
15 years, 9 months
JBoss Cache SVN: r7860 - in core/branches/flat/src: main/java/org/horizon/eviction/algorithms/lru and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 11:22:12 -0500 (Thu, 05 Mar 2009)
New Revision: 7860
Added:
core/branches/flat/src/main/java/org/horizon/util/HorizonCollections.java
core/branches/flat/src/main/java/org/horizon/util/ReversibleOrderedSet.java
core/branches/flat/src/main/java/org/horizon/util/VisitableBidirectionalLinkedHashSet.java
core/branches/flat/src/test/java/org/horizon/util/VisitableBidirectionalLinkedHashSetTest.java
Removed:
core/branches/flat/src/main/java/org/horizon/util/ReversibleSet.java
core/branches/flat/src/main/java/org/horizon/util/VisitableLinkedHashSet.java
core/branches/flat/src/test/java/org/horizon/util/VisitableLinkedHashSetTest.java
Modified:
core/branches/flat/src/main/java/org/horizon/context/AbstractContext.java
core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java
core/branches/flat/src/main/java/org/horizon/context/InvocationContextImpl.java
core/branches/flat/src/main/java/org/horizon/context/TransactionContextImpl.java
core/branches/flat/src/main/java/org/horizon/eviction/algorithms/lru/LRUQueue.java
core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java
core/branches/flat/src/main/java/org/horizon/lock/StripedLockManager.java
core/branches/flat/src/main/java/org/horizon/util/BidirectionalLinkedHashMap.java
core/branches/flat/src/main/java/org/horizon/util/Immutables.java
core/branches/flat/src/main/java/org/horizon/util/ObjectDuplicator.java
Log:
Minor performance tweaks after a brief profiling session
Modified: core/branches/flat/src/main/java/org/horizon/context/AbstractContext.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/context/AbstractContext.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/context/AbstractContext.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -3,14 +3,12 @@
import org.horizon.container.MVCCEntry;
import org.horizon.invocation.Options;
import org.horizon.util.FastCopyHashMap;
-import org.horizon.util.Immutables;
+import org.horizon.util.ReversibleOrderedSet;
+import org.horizon.util.VisitableBidirectionalLinkedHashSet;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.EnumSet;
-import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -24,11 +22,7 @@
protected EnumSet<Options> options;
protected byte contextFlags;
- /**
- * LinkedHashSet of locks acquired by the invocation. We use a LinkedHashSet because we need efficient Set semantics
- * but also need guaranteed ordering for use by lock release code (see JBCCACHE-874).
- */
- protected LinkedHashSet<Object> locks;
+ protected ReversibleOrderedSet<Object> locks;
protected FastCopyHashMap<Object, MVCCEntry> lookedUpEntries = null;
@@ -96,7 +90,7 @@
public void addKeyLocked(Object lock) {
// no need to worry about concurrency here - a context is only valid for a single thread.
- if (locks == null) locks = new LinkedHashSet<Object>(getLockSetSize());
+ if (locks == null) locks = new VisitableBidirectionalLinkedHashSet<Object>(false, getLockSetSize());
locks.add(lock);
}
@@ -108,20 +102,15 @@
if (locks != null) locks.clear();
}
- public void addAllKeysLocked(List<Object> newLocks) {
- // no need to worry about concurrency here - a context is only valid for a single thread.
- if (locks == null) locks = new LinkedHashSet<Object>(getLockSetSize());
- locks.addAll(newLocks);
- }
-
- public List<Object> getKeysLocked() {
- return locks == null || locks.isEmpty() ? Collections.emptyList() : Immutables.immutableListConvert(locks);
- }
-
public boolean hasLockedKey(Object lock) {
return locks != null && locks.contains(lock);
}
+ public void addAllKeysLocked(Collection<Object> keys) {
+ if (locks == null) locks = new VisitableBidirectionalLinkedHashSet<Object>(false, getLockSetSize());
+ locks.addAll(keys);
+ }
+
public MVCCEntry lookupEntry(Object key) {
return lookedUpEntries.get(key);
}
@@ -182,7 +171,7 @@
protected void copyInto(AbstractContext ctx) {
if (options != null) ctx.options = EnumSet.copyOf(options);
ctx.contextFlags = contextFlags;
- if (locks != null) ctx.locks = new LinkedHashSet<Object>(locks);
+ if (locks != null) ctx.locks = new VisitableBidirectionalLinkedHashSet<Object>(false, locks);
if (lookedUpEntries != null) ctx.lookedUpEntries = (FastCopyHashMap<Object, MVCCEntry>) lookedUpEntries.clone();
}
}
Modified: core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/context/EntryLookup.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -22,8 +22,9 @@
package org.horizon.context;
import org.horizon.container.MVCCEntry;
+import org.horizon.util.ReversibleOrderedSet;
-import java.util.List;
+import java.util.Collection;
import java.util.Map;
/**
@@ -36,7 +37,8 @@
/**
* 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 the same method in {@link TransactionContext}.
+ * 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 +49,8 @@
/**
* Retrieves a map of entries looked up within the current scope.
* <p/>
- * If a transaction is in progress, implementations should delegate to the same method in {@link TransactionContext}.
+ * If a transaction is in progress, implementations should delegate to the same method in {@link
+ * TransactionContext}.
* <p/>
*
* @return a map of looked up entries.
@@ -57,7 +60,8 @@
/**
* 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 the same method in {@link TransactionContext}.
+ * If a transaction is in progress, implementations should delegate to the same method in {@link
+ * TransactionContext}.
* <p/>
*
* @param key key to store
@@ -75,7 +79,7 @@
void clearLookedUpEntries();
/**
- * Returns an immutable, defensive copy of the List of locks currently maintained for the current scope.
+ * Returns the set of locks currently maintained for the current scope. Note that this set is ordered.
* <p/>
* Note that if a transaction is in scope, implementations should retrieve these locks from the {@link
* TransactionContext}. Retrieving locks from this method should always ensure they are retrieved from the
@@ -83,7 +87,7 @@
*
* @return keys locked in current scope.
*/
- List<Object> getKeysLocked();
+ ReversibleOrderedSet<Object> getKeysLocked();
/**
* Adds a List of locks to the currently maintained collection of locks acquired.
@@ -94,7 +98,7 @@
*
* @param keys keys locked
*/
- void addAllKeysLocked(List<Object> keys);
+ void addAllKeysLocked(Collection<Object> keys);
/**
* Adds a lock to the currently maintained collection of locks acquired.
Modified: core/branches/flat/src/main/java/org/horizon/context/InvocationContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/context/InvocationContextImpl.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/context/InvocationContextImpl.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -25,10 +25,12 @@
import org.horizon.transaction.GlobalTransaction;
import org.horizon.transaction.TransactionTable;
import org.horizon.util.FastCopyHashMap;
+import org.horizon.util.HorizonCollections;
+import org.horizon.util.ReversibleOrderedSet;
import javax.transaction.Transaction;
+import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
public class InvocationContextImpl extends AbstractContext implements InvocationContext {
@@ -183,21 +185,19 @@
return isFlagSet(ContextFlags.ORIGIN_LOCAL);
}
- @Override
- public List<Object> getKeysLocked() {
+ public ReversibleOrderedSet<Object> getKeysLocked() {
// first check transactional scope
if (transactionContext != null) return transactionContext.getKeysLocked();
- return super.getKeysLocked();
+ return locks == null ? HorizonCollections.emptyReversibleOrderedSet() : locks;
}
@Override
- public void addAllKeysLocked(List<Object> keys) {
+ public void addAllKeysLocked(Collection<Object> keys) {
// first check transactional scope
if (transactionContext != null)
transactionContext.addAllKeysLocked(keys);
else
super.addAllKeysLocked(keys);
-
}
@Override
Modified: core/branches/flat/src/main/java/org/horizon/context/TransactionContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/context/TransactionContextImpl.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/context/TransactionContextImpl.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -25,6 +25,9 @@
import org.horizon.container.MVCCEntry;
import org.horizon.transaction.GlobalTransaction;
import org.horizon.util.FastCopyHashMap;
+import org.horizon.util.HorizonCollections;
+import org.horizon.util.Immutables;
+import org.horizon.util.ReversibleOrderedSet;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
@@ -194,6 +197,10 @@
return hasModifications() || hasLocalModifications();
}
+ public ReversibleOrderedSet<Object> getKeysLocked() {
+ return locks == null ? HorizonCollections.emptyReversibleOrderedSet() : Immutables.immutableReversibleOrderedSetCopy(locks);
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
Modified: core/branches/flat/src/main/java/org/horizon/eviction/algorithms/lru/LRUQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/eviction/algorithms/lru/LRUQueue.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/eviction/algorithms/lru/LRUQueue.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -22,7 +22,7 @@
package org.horizon.eviction.algorithms.lru;
import org.horizon.eviction.algorithms.BaseEvictionQueue;
-import org.horizon.util.VisitableLinkedHashSet;
+import org.horizon.util.VisitableBidirectionalLinkedHashSet;
import java.util.Iterator;
@@ -35,7 +35,7 @@
*/
public class LRUQueue extends BaseEvictionQueue {
- protected VisitableLinkedHashSet<Object> keys = new VisitableLinkedHashSet<Object>();
+ protected VisitableBidirectionalLinkedHashSet<Object> keys = new VisitableBidirectionalLinkedHashSet<Object>(true);
@Override
public void visit(Object key) {
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -42,10 +42,11 @@
import org.horizon.interceptors.base.CommandInterceptor;
import org.horizon.lock.IsolationLevel;
import org.horizon.lock.LockManager;
+import org.horizon.util.ReversibleOrderedSet;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
/**
@@ -211,7 +212,7 @@
private void doAfterCall(InvocationContext ctx) {
// for non-transactional stuff.
if (ctx.getTransactionContext() == null) {
- List<Object> locks;
+ ReversibleOrderedSet<Object> locks;
if (!(locks = ctx.getKeysLocked()).isEmpty()) {
cleanupLocks(locks, ctx, Thread.currentThread(), true);
} else {
@@ -237,14 +238,14 @@
}
}
- private void cleanupLocks(List<Object> keysLocked, InvocationContext ctx, Object owner, boolean commit) {
+ private void cleanupLocks(ReversibleOrderedSet<Object> keysLocked, InvocationContext ctx, Object owner, boolean commit) {
// clean up.
// unlocking needs to be done in reverse order.
- ListIterator<Object> it = keysLocked.listIterator(keysLocked.size());
+ Iterator<Object> it = keysLocked.reverseIterator();
if (commit) {
- while (it.hasPrevious()) {
- Object key = it.previous();
+ while (it.hasNext()) {
+ Object key = it.next();
MVCCEntry entry = ctx.lookupEntry(key);
// could be null with read-committed
if (entry != null) entry.commitUpdate(dataContainer);
@@ -253,8 +254,8 @@
lockManager.unlock(key, owner);
}
} else {
- while (it.hasPrevious()) {
- Object key = it.previous();
+ while (it.hasNext()) {
+ Object key = it.next();
MVCCEntry entry = ctx.lookupEntry(key);
// could be null with read-committed
if (entry != null) entry.rollbackUpdate();
@@ -269,7 +270,7 @@
@SuppressWarnings("unchecked")
private void transactionalCleanup(boolean commit, InvocationContext ctx) {
if (ctx.getTransactionContext() != null) {
- List<Object> locks = ctx.getTransactionContext().getKeysLocked();
+ ReversibleOrderedSet<Object> locks = ctx.getTransactionContext().getKeysLocked();
if (!locks.isEmpty())
cleanupLocks(locks, ctx, ctx.getGlobalTransaction(), commit);
else if (trace)
Modified: core/branches/flat/src/main/java/org/horizon/lock/StripedLockManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/lock/StripedLockManager.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/lock/StripedLockManager.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -29,14 +29,14 @@
import org.horizon.invocation.Options;
import org.horizon.logging.Log;
import org.horizon.logging.LogFactory;
+import org.horizon.util.ReversibleOrderedSet;
import org.horizon.util.concurrent.locks.LockContainer;
import org.horizon.util.concurrent.locks.OwnableReentrantLock;
import org.horizon.util.concurrent.locks.OwnableReentrantLockContainer;
import org.horizon.util.concurrent.locks.ReentrantLockContainer;
import javax.transaction.TransactionManager;
-import java.util.List;
-import java.util.ListIterator;
+import java.util.Iterator;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.concurrent.locks.Lock;
@@ -107,12 +107,12 @@
@SuppressWarnings("unchecked")
public void unlock(InvocationContext ctx) {
- List<Object> locks = ctx.getKeysLocked();
+ ReversibleOrderedSet<Object> locks = ctx.getKeysLocked();
if (!locks.isEmpty()) {
// unlocking needs to be done in reverse order.
- ListIterator<Object> it = locks.listIterator(locks.size());
- while (it.hasPrevious()) {
- Object k = it.previous();
+ Iterator<Object> it = locks.reverseIterator();
+ while (it.hasNext()) {
+ Object k = it.next();
if (trace) log.trace("Attempting to unlock " + k);
lockContainer.getLock(k).unlock();
}
Modified: core/branches/flat/src/main/java/org/horizon/util/BidirectionalLinkedHashMap.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/BidirectionalLinkedHashMap.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/util/BidirectionalLinkedHashMap.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -12,9 +12,9 @@
* Similar to the JDK's {@link java.util.LinkedHashMap} except that this version makes use of the fact that entries are
* bidirectionally linked and can hence be nagigated either from the start <i>or</i> from the end. It exposes such
* navigability by overriding {@link java.util.Map#keySet()} and {@link java.util.Map#entrySet()} to return {@link
- * org.horizon.util.ReversibleSet} rather than a standard JDK {@link java.util.Set}. {@link
- * org.horizon.util.ReversibleSet}s allow you to access 2 iterators: one that iterates from start to end, as usual, and
- * a reversed one that iterates from end to start instead.
+ * ReversibleOrderedSet} rather than a standard JDK {@link java.util.Set}. {@link ReversibleOrderedSet}s allow you to
+ * access 2 iterators: one that iterates from start to end, as usual, and a reversed one that iterates from end to start
+ * instead.
* <p/>
* Unline the JDK {@link java.util.LinkedHashMap}, this implementation does not support null keys.
* <p/>
@@ -22,7 +22,7 @@
* @author Manik Surtani
* @since 1.0
*/
-public class BidirectionalLinkedHashMap<K, V> extends AbstractMap<K, V> {
+public class BidirectionalLinkedHashMap<K, V> extends AbstractMap<K, V> implements Cloneable {
/**
* The head of the doubly linked list.
@@ -206,7 +206,7 @@
* mapping for the key.
*/
final LinkedEntry<K, V> getEntry(Object key) {
- int hash = (key == null) ? 0 : hash(key.hashCode());
+ int hash = (key == null) ? 0 : hash(key);
for (LinkedEntry<K, V> e = table[indexFor(hash, table.length)];
e != null;
e = e.next) {
@@ -231,7 +231,7 @@
*/
public V put(K key, V value) {
assertKeyNotNull(key);
- int hash = hash(key.hashCode());
+ int hash = hash(key);
int i = indexFor(hash, table.length);
for (LinkedEntry<K, V> e = table[i]; e != null; e = e.next) {
Object k;
@@ -253,7 +253,7 @@
* the table, check for comodification, etc. It calls createEntry rather than addEntry.
*/
private void putForCreate(K key, V value) {
- int hash = (key == null) ? 0 : hash(key.hashCode());
+ int hash = (key == null) ? 0 : hash(key);
int i = indexFor(hash, table.length);
/**
@@ -361,7 +361,7 @@
* contains no mapping for this key.
*/
final LinkedEntry<K, V> removeEntryForKey(Object key) {
- int hash = hash(key.hashCode());
+ int hash = hash(key);
int i = indexFor(hash, table.length);
LinkedEntry<K, V> prev = table[i];
LinkedEntry<K, V> e = prev;
@@ -396,7 +396,7 @@
Map.Entry<K, V> entry = (Map.Entry<K, V>) o;
Object key = entry.getKey();
- int hash = (key == null) ? 0 : hash(key.hashCode());
+ int hash = (key == null) ? 0 : hash(key);
int i = indexFor(hash, table.length);
LinkedEntry<K, V> prev = table[i];
LinkedEntry<K, V> e = prev;
@@ -717,13 +717,13 @@
}
}
- public ReversibleSet<K> keySet() {
+ public ReversibleOrderedSet<K> keySet() {
if (keySet == null) keySet = new KeySet();
- return (ReversibleSet<K>) keySet;
+ return (ReversibleOrderedSet<K>) keySet;
}
private class KeySet extends AbstractSet<K>
- implements ReversibleSet<K> {
+ implements ReversibleOrderedSet<K> {
public Iterator<K> reverseIterator() {
return new KeyIterator(true);
@@ -752,13 +752,13 @@
}
}
- public ReversibleSet<Map.Entry<K, V>> entrySet() {
+ public ReversibleOrderedSet<Entry<K, V>> entrySet() {
if (entrySet == null) entrySet = new EntrySet();
- return (ReversibleSet<Map.Entry<K, V>>) entrySet;
+ return (ReversibleOrderedSet<Entry<K, V>>) entrySet;
}
private final class EntrySet extends AbstractSet<Map.Entry<K, V>>
- implements ReversibleSet<Map.Entry<K, V>> {
+ implements ReversibleOrderedSet<Entry<K, V>> {
public Iterator<Map.Entry<K, V>> reverseIterator() {
return new EntryIterator(true);
@@ -789,4 +789,28 @@
BidirectionalLinkedHashMap.this.clear();
}
}
+
+ /**
+ * Returns a shallow copy of this <tt>Map</tt> instance: the keys and values themselves are not cloned.
+ *
+ * @return a shallow copy of this map.
+ */
+ @SuppressWarnings("unchecked")
+ public BidirectionalLinkedHashMap clone() {
+
+ BidirectionalLinkedHashMap<K, V> result;
+ try {
+ result = (BidirectionalLinkedHashMap<K, V>) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException("Should never happen!", e);
+ }
+ result.table = new LinkedEntry[table.length];
+ result.entrySet = null;
+ result.modCount = 0;
+ result.size = 0;
+ result.init();
+ result.putAllForCreate(this);
+
+ return result;
+ }
}
Added: core/branches/flat/src/main/java/org/horizon/util/HorizonCollections.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/HorizonCollections.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/util/HorizonCollections.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -0,0 +1,50 @@
+package org.horizon.util;
+
+import java.util.AbstractSet;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * Static helpers for Horizon-specific collections
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class HorizonCollections {
+ private static final ReversibleOrderedSet EMPTY_ROS = new EmptyReversibleOrderedSet();
+
+ @SuppressWarnings("unchecked")
+ public static final <T> ReversibleOrderedSet<T> emptyReversibleOrderedSet() {
+ return (ReversibleOrderedSet<T>) EMPTY_ROS;
+ }
+
+ private static final class EmptyReversibleOrderedSet extends AbstractSet implements ReversibleOrderedSet {
+
+ Iterator it = new Iterator() {
+
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ public Iterator iterator() {
+ return it;
+ }
+
+ public int size() {
+ return 0;
+ }
+
+ public Iterator reverseIterator() {
+ return it;
+ }
+ }
+}
Modified: core/branches/flat/src/main/java/org/horizon/util/Immutables.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/Immutables.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/util/Immutables.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -184,7 +184,18 @@
return null;
}
+ public static <T> ReversibleOrderedSet<T> immutableReversibleOrderedSetCopy(ReversibleOrderedSet<T> set) {
+ Set<? extends T> copy = ObjectDuplicator.duplicateSet(set);
+ if (copy == null)
+ // Set uses Collection copy-ctor
+ copy = attemptCopyConstructor(set, ReversibleOrderedSet.class);
+ if (copy == null)
+ copy = new VisitableBidirectionalLinkedHashSet<T>(false, set);
+ return new ImmutableReversibleOrderedSetWrapper<T>(copy);
+ }
+
+
public interface Immutable {
}
@@ -298,7 +309,18 @@
}
}
+ private static class ImmutableReversibleOrderedSetWrapper<E> extends ImmutableCollectionWrapper<E> implements ReversibleOrderedSet<E>, Serializable, Immutable {
+ private static final long serialVersionUID = 7991492805176142615L;
+ public ImmutableReversibleOrderedSetWrapper(Set<? extends E> set) {
+ super(set);
+ }
+
+ public Iterator<E> reverseIterator() {
+ return new ImmutableIteratorWrapper<E>(((ReversibleOrderedSet<? extends E>) collection).reverseIterator());
+ }
+ }
+
static class ImmutableEntry<K, V> implements Entry<K, V> {
private K key;
private V value;
Modified: core/branches/flat/src/main/java/org/horizon/util/ObjectDuplicator.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/ObjectDuplicator.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/util/ObjectDuplicator.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -37,6 +37,15 @@
}
@SuppressWarnings("unchecked")
+ public static <E> ReversibleOrderedSet<E> duplicateReversibleOrderedSet(ReversibleOrderedSet<E> original) {
+ if (original instanceof VisitableBidirectionalLinkedHashSet)
+ return (ReversibleOrderedSet<E>) ((VisitableBidirectionalLinkedHashSet) original).clone();
+
+ return attemptClone(original);
+ }
+
+
+ @SuppressWarnings("unchecked")
public static <E> Collection<E> duplicateCollection(Collection<E> original) {
if (original instanceof HashSet)
return (Set<E>) ((HashSet) original).clone();
Copied: core/branches/flat/src/main/java/org/horizon/util/ReversibleOrderedSet.java (from rev 7856, core/branches/flat/src/main/java/org/horizon/util/ReversibleSet.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/ReversibleOrderedSet.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/util/ReversibleOrderedSet.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -0,0 +1,15 @@
+package org.horizon.util;
+
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A set that allows reverse iteration of the set elements, exposed via the {@link #reverseIterator()} method. This
+ * only really makes sense for ordered Set implementations, such as sets which are linked.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public interface ReversibleOrderedSet<E> extends Set<E> {
+ Iterator<E> reverseIterator();
+}
Deleted: core/branches/flat/src/main/java/org/horizon/util/ReversibleSet.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/ReversibleSet.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/util/ReversibleSet.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -1,15 +0,0 @@
-package org.horizon.util;
-
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A set that allows reverse iteration of the set elements, exposed via the {@link #reverseIterator()} method. This
- * only really makes sense for ordered Set implementations.
- *
- * @author Manik Surtani
- * @since 1.0
- */
-public interface ReversibleSet<E> extends Set<E> {
- Iterator<E> reverseIterator();
-}
Copied: core/branches/flat/src/main/java/org/horizon/util/VisitableBidirectionalLinkedHashSet.java (from rev 7856, core/branches/flat/src/main/java/org/horizon/util/VisitableLinkedHashSet.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/VisitableBidirectionalLinkedHashSet.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/util/VisitableBidirectionalLinkedHashSet.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -0,0 +1,170 @@
+package org.horizon.util;
+
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Similar to the JDK's {@link java.util.LinkedHashSet} except that it sets the underlying {@link
+ * java.util.LinkedHashMap}'s <tt>accessOrder</tt> constructor parameter to <tt>true</tt>, allowing for recording of
+ * visits. To do this, this implementation exposes a {@link #visit(Object)} method to visit a key.
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public class VisitableBidirectionalLinkedHashSet<E> extends AbstractSet<E> implements ReversibleOrderedSet<E>, Cloneable {
+
+ private transient BidirectionalLinkedHashMap<E, Object> map;
+
+ // Dummy value to associate with an Object in the backing Map
+ private static final Object DUMMY_VALUE = new Object();
+
+
+ /**
+ * Constructs a new, empty linked hash set with the specified initial capacity and load factor.
+ *
+ * @param visitable if true, visiting an element (using {@link #visit(Object)}) will cause that element to be
+ * moved to the end of the linked list that connects entries.
+ * @param initialCapacity the initial capacity of the linked hash set
+ * @param loadFactor the load factor of the linked hash set
+ * @throws IllegalArgumentException if the initial capacity is less than zero, or if the load factor is nonpositive
+ */
+ public VisitableBidirectionalLinkedHashSet(boolean visitable, int initialCapacity, float loadFactor) {
+ map = new BidirectionalLinkedHashMap<E, Object>(initialCapacity, loadFactor, visitable);
+ }
+
+ /**
+ * Constructs a new, empty linked hash set with the specified initial capacity and the default load factor (0.75).
+ *
+ * @param visitable if true, visiting an element (using {@link #visit(Object)}) will cause that element to be
+ * moved to the end of the linked list that connects entries.
+ * @param initialCapacity the initial capacity of the LinkedHashSet
+ * @throws IllegalArgumentException if the initial capacity is less than zero
+ */
+ public VisitableBidirectionalLinkedHashSet(boolean visitable, int initialCapacity) {
+ this(visitable, initialCapacity, .75f);
+ }
+
+ /**
+ * Constructs a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).
+ *
+ * @param visitable if true, visiting an element (using {@link #visit(Object)}) will cause that element to be moved
+ * to the end of the linked list that connects entries.
+ */
+ public VisitableBidirectionalLinkedHashSet(boolean visitable) {
+ this(visitable, 16, .75f);
+ }
+
+ /**
+ * Constructs a new linked hash set with the same elements as the specified collection. The linked hash set is
+ * created with an initial capacity sufficient to hold the elements in the specified collection and the default load
+ * factor (0.75).
+ *
+ * @param visitable if true, visiting an element (using {@link #visit(Object)}) will cause that element to be moved
+ * to the end of the linked list that connects entries.
+ * @param c the collection whose elements are to be placed into this set
+ * @throws NullPointerException if the specified collection is null
+ */
+ public VisitableBidirectionalLinkedHashSet(boolean visitable, Collection<? extends E> c) {
+ this(visitable, Math.max(2 * c.size(), 11), .75f);
+ addAll(c);
+ }
+
+ /**
+ * Returns an iterator over the elements in this set. The elements are returned in no particular order.
+ *
+ * @return an Iterator over the elements in this set
+ * @see java.util.ConcurrentModificationException
+ */
+ public Iterator<E> iterator() {
+ return map.keySet().iterator();
+ }
+
+ public Iterator<E> reverseIterator() {
+ return map.keySet().reverseIterator();
+ }
+
+ /**
+ * Returns the number of elements in this set (its cardinality).
+ *
+ * @return the number of elements in this set (its cardinality)
+ */
+ public int size() {
+ return map.size();
+ }
+
+ /**
+ * Returns <tt>true</tt> if this set contains no elements.
+ *
+ * @return <tt>true</tt> if this set contains no elements
+ */
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ /**
+ * Returns <tt>true</tt> if this set contains the specified element. More formally, returns <tt>true</tt> if and only
+ * if this set contains an element <tt>e</tt> such that <tt>(o==null ? e==null : o.equals(e))</tt>.
+ *
+ * @param o element whose presence in this set is to be tested
+ * @return <tt>true</tt> if this set contains the specified element
+ */
+ public boolean contains(Object o) {
+ return map.containsKey(o);
+ }
+
+ /**
+ * Adds the specified element to this set if it is not already present. More formally, adds the specified element
+ * <tt>e</tt> to this set if this set contains no element <tt>e2</tt> such that <tt>(e==null ? e2==null : e.equals(e2))</tt>.
+ * If this set already contains the element, the call leaves the set unchanged and returns <tt>false</tt>.
+ *
+ * @param e element to be added to this set
+ * @return <tt>true</tt> if this set did not already contain the specified element
+ */
+ public boolean add(E e) {
+ return map.put(e, DUMMY_VALUE) == null;
+ }
+
+ /**
+ * Removes the specified element from this set if it is present. More formally, removes an element <tt>e</tt> such
+ * that <tt>(o==null ? e==null : o.equals(e))</tt>, if this set contains such an element. Returns
+ * <tt>true</tt> if this set contained the element (or equivalently, if this set changed as a result of the call).
+ * (This set will not contain the element once the call returns.)
+ *
+ * @param o object to be removed from this set, if present
+ * @return <tt>true</tt> if the set contained the specified element
+ */
+ public boolean remove(Object o) {
+ return map.remove(o) == DUMMY_VALUE;
+ }
+
+ /**
+ * Visits the key in the underlying Map, by performing a {@link java.util.Map#get(Object)}. This records the access
+ * and updates the ordering accordingly.
+ *
+ * @param key key to visit
+ */
+ public void visit(E key) {
+ map.get(key);
+ }
+
+ /**
+ * Removes all of the elements from this set. The set will be empty after this call returns.
+ */
+ public void clear() {
+ map.clear();
+ }
+
+ @SuppressWarnings("unchecked")
+ public VisitableBidirectionalLinkedHashSet clone() {
+ VisitableBidirectionalLinkedHashSet result;
+ try {
+ result = (VisitableBidirectionalLinkedHashSet) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException("Should never happen", e);
+ }
+
+ result.map = map.clone();
+ return result;
+ }
+}
Deleted: core/branches/flat/src/main/java/org/horizon/util/VisitableLinkedHashSet.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/VisitableLinkedHashSet.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/main/java/org/horizon/util/VisitableLinkedHashSet.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -1,148 +0,0 @@
-package org.horizon.util;
-
-import java.util.AbstractSet;
-import java.util.Collection;
-import java.util.Iterator;
-
-/**
- * Similar to the JDK's {@link java.util.LinkedHashSet} except that it sets the underlying {@link
- * java.util.LinkedHashMap}'s <tt>accessOrder</tt> constructor parameter to <tt>true</tt>, allowing for recording of
- * visits. To do this, this implementation exposes a {@link #visit(Object)} method to visit a key.
- *
- * @author Manik Surtani
- * @since 1.0
- */
-public class VisitableLinkedHashSet<E> extends AbstractSet<E> implements ReversibleSet<E> {
-
- private transient BidirectionalLinkedHashMap<E, Object> map;
-
- // Dummy value to associate with an Object in the backing Map
- private static final Object DUMMY_VALUE = new Object();
-
-
- /**
- * Constructs a new, empty linked hash set with the specified initial capacity and load factor.
- *
- * @param initialCapacity the initial capacity of the linked hash set
- * @param loadFactor the load factor of the linked hash set
- * @throws IllegalArgumentException if the initial capacity is less than zero, or if the load factor is nonpositive
- */
- public VisitableLinkedHashSet(int initialCapacity, float loadFactor) {
- map = new BidirectionalLinkedHashMap<E, Object>(initialCapacity, loadFactor, true);
- }
-
- /**
- * Constructs a new, empty linked hash set with the specified initial capacity and the default load factor (0.75).
- *
- * @param initialCapacity the initial capacity of the LinkedHashSet
- * @throws IllegalArgumentException if the initial capacity is less than zero
- */
- public VisitableLinkedHashSet(int initialCapacity) {
- this(initialCapacity, .75f);
- }
-
- /**
- * Constructs a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).
- */
- public VisitableLinkedHashSet() {
- this(16, .75f);
- }
-
- /**
- * Constructs a new linked hash set with the same elements as the specified collection. The linked hash set is
- * created with an initial capacity sufficient to hold the elements in the specified collection and the default load
- * factor (0.75).
- *
- * @param c the collection whose elements are to be placed into this set
- * @throws NullPointerException if the specified collection is null
- */
- public VisitableLinkedHashSet(Collection<? extends E> c) {
- this(Math.max(2 * c.size(), 11), .75f);
- addAll(c);
- }
-
- /**
- * Returns an iterator over the elements in this set. The elements are returned in no particular order.
- *
- * @return an Iterator over the elements in this set
- * @see java.util.ConcurrentModificationException
- */
- public Iterator<E> iterator() {
- return map.keySet().iterator();
- }
-
- public Iterator<E> reverseIterator() {
- return map.keySet().reverseIterator();
- }
-
- /**
- * Returns the number of elements in this set (its cardinality).
- *
- * @return the number of elements in this set (its cardinality)
- */
- public int size() {
- return map.size();
- }
-
- /**
- * Returns <tt>true</tt> if this set contains no elements.
- *
- * @return <tt>true</tt> if this set contains no elements
- */
- public boolean isEmpty() {
- return map.isEmpty();
- }
-
- /**
- * Returns <tt>true</tt> if this set contains the specified element. More formally, returns <tt>true</tt> if and only
- * if this set contains an element <tt>e</tt> such that <tt>(o==null ? e==null : o.equals(e))</tt>.
- *
- * @param o element whose presence in this set is to be tested
- * @return <tt>true</tt> if this set contains the specified element
- */
- public boolean contains(Object o) {
- return map.containsKey(o);
- }
-
- /**
- * Adds the specified element to this set if it is not already present. More formally, adds the specified element
- * <tt>e</tt> to this set if this set contains no element <tt>e2</tt> such that <tt>(e==null ? e2==null : e.equals(e2))</tt>.
- * If this set already contains the element, the call leaves the set unchanged and returns <tt>false</tt>.
- *
- * @param e element to be added to this set
- * @return <tt>true</tt> if this set did not already contain the specified element
- */
- public boolean add(E e) {
- return map.put(e, DUMMY_VALUE) == null;
- }
-
- /**
- * Removes the specified element from this set if it is present. More formally, removes an element <tt>e</tt> such
- * that <tt>(o==null ? e==null : o.equals(e))</tt>, if this set contains such an element. Returns
- * <tt>true</tt> if this set contained the element (or equivalently, if this set changed as a result of the call).
- * (This set will not contain the element once the call returns.)
- *
- * @param o object to be removed from this set, if present
- * @return <tt>true</tt> if the set contained the specified element
- */
- public boolean remove(Object o) {
- return map.remove(o) == DUMMY_VALUE;
- }
-
- /**
- * Visits the key in the underlying Map, by performing a {@link java.util.Map#get(Object)}. This records the access
- * and updates the ordering accordingly.
- *
- * @param key key to visit
- */
- public void visit(E key) {
- map.get(key);
- }
-
- /**
- * Removes all of the elements from this set. The set will be empty after this call returns.
- */
- public void clear() {
- map.clear();
- }
-}
Copied: core/branches/flat/src/test/java/org/horizon/util/VisitableBidirectionalLinkedHashSetTest.java (from rev 7856, core/branches/flat/src/test/java/org/horizon/util/VisitableLinkedHashSetTest.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/util/VisitableBidirectionalLinkedHashSetTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/util/VisitableBidirectionalLinkedHashSetTest.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -0,0 +1,69 @@
+package org.horizon.util;
+
+import org.testng.annotations.Test;
+
+import java.util.Iterator;
+import java.util.Set;
+
+@Test(groups = "unit", testName = "util.VisitableBidirectionalLinkedHashSetTest")
+public class VisitableBidirectionalLinkedHashSetTest {
+
+ public void testVisitableSet() {
+ VisitableBidirectionalLinkedHashSet<Integer> set = new VisitableBidirectionalLinkedHashSet<Integer>(true);
+ initSet(set);
+
+ testOrderBeforeRemoval(set);
+
+ // now attemp a visit and test that the visits are NOT recorded
+ set.visit(200);
+
+ // check the forward iterator that everything is in order of entry
+ Iterator<Integer> it = set.iterator();
+ int index = 0;
+ while (it.hasNext()) {
+ if (index == 200) index = 201;
+ if (index == 1000) index = 200;
+ Integer value = it.next();
+ assert value == index++ : "Expecting " + (index - 1) + " but was " + value;
+ }
+
+ // now check the reverse iterator.
+ it = set.reverseIterator();
+ index = 200; // this should be the first
+ while (it.hasNext()) {
+ assert it.next() == index--;
+ if (index == 199) index = 999;
+ if (index == 200) index = 199;
+ }
+
+ for (Iterator i = set.iterator(); i.hasNext();) {
+ i.next();
+ i.remove();
+ }
+
+ assert set.isEmpty();
+ assert set.size() == 0 : "Expecting size to be 0 but was " + set.size();
+ }
+
+
+ private void initSet(Set<Integer> set) {
+ for (int i = 0; i < 1000; i++) set.add(i);
+ }
+
+ private void testOrderBeforeRemoval(VisitableBidirectionalLinkedHashSet<Integer> set) {
+ // check the forward iterator that everything is in order of entry
+ Iterator<Integer> it = set.iterator();
+ int index = 0;
+ while (it.hasNext()) assert it.next() == index++;
+ assert index == 1000 : "Expected 1000, index was " + index;
+ assert set.size() == 1000;
+ // now check the reverse iterator.
+ it = set.reverseIterator();
+ index = 999;
+ while (it.hasNext()) {
+ Integer value = it.next();
+ assert value == index-- : "failed, expecting " + (index + 1) + " but was " + value;
+ }
+ assert index == -1 : "Was " + index + ", instead of -1";
+ }
+}
Deleted: core/branches/flat/src/test/java/org/horizon/util/VisitableLinkedHashSetTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/util/VisitableLinkedHashSetTest.java 2009-03-05 16:20:54 UTC (rev 7859)
+++ core/branches/flat/src/test/java/org/horizon/util/VisitableLinkedHashSetTest.java 2009-03-05 16:22:12 UTC (rev 7860)
@@ -1,69 +0,0 @@
-package org.horizon.util;
-
-import org.testng.annotations.Test;
-
-import java.util.Iterator;
-import java.util.Set;
-
-@Test(groups = "unit", testName = "util.VisitableLinkedHashSetTest")
-public class VisitableLinkedHashSetTest {
-
- public void testVisitableSet() {
- VisitableLinkedHashSet<Integer> set = new VisitableLinkedHashSet<Integer>();
- initSet(set);
-
- testOrderBeforeRemoval(set);
-
- // now attemp a visit and test that the visits are NOT recorded
- set.visit(200);
-
- // check the forward iterator that everything is in order of entry
- Iterator<Integer> it = set.iterator();
- int index = 0;
- while (it.hasNext()) {
- if (index == 200) index = 201;
- if (index == 1000) index = 200;
- Integer value = it.next();
- assert value == index++ : "Expecting " + (index - 1) + " but was " + value;
- }
-
- // now check the reverse iterator.
- it = set.reverseIterator();
- index = 200; // this should be the first
- while (it.hasNext()) {
- assert it.next() == index--;
- if (index == 199) index = 999;
- if (index == 200) index = 199;
- }
-
- for (Iterator i = set.iterator(); i.hasNext();) {
- i.next();
- i.remove();
- }
-
- assert set.isEmpty();
- assert set.size() == 0 : "Expecting size to be 0 but was " + set.size();
- }
-
-
- private void initSet(Set<Integer> set) {
- for (int i = 0; i < 1000; i++) set.add(i);
- }
-
- private void testOrderBeforeRemoval(VisitableLinkedHashSet<Integer> set) {
- // check the forward iterator that everything is in order of entry
- Iterator<Integer> it = set.iterator();
- int index = 0;
- while (it.hasNext()) assert it.next() == index++;
- assert index == 1000 : "Expected 1000, index was " + index;
- assert set.size() == 1000;
- // now check the reverse iterator.
- it = set.reverseIterator();
- index = 999;
- while (it.hasNext()) {
- Integer value = it.next();
- assert value == index-- : "failed, expecting " + (index + 1) + " but was " + value;
- }
- assert index == -1 : "Was " + index + ", instead of -1";
- }
-}
15 years, 9 months
JBoss Cache SVN: r7859 - core/branches/flat/src/test/java/org/horizon/profiling.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 11:20:54 -0500 (Thu, 05 Mar 2009)
New Revision: 7859
Modified:
core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java
core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java
Log:
Updated profile tests
Modified: core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java 2009-03-05 15:28:11 UTC (rev 7858)
+++ core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java 2009-03-05 16:20:54 UTC (rev 7859)
@@ -11,6 +11,7 @@
protected CacheManager createCacheManager() throws Exception {
Configuration cfg = new Configuration();
+ cfg.setConcurrencyLevel(2000);
cacheManager = new DefaultCacheManager(cfg);
cache = cacheManager.getCache();
return cacheManager;
Modified: core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java 2009-03-05 15:28:11 UTC (rev 7858)
+++ core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java 2009-03-05 16:20:54 UTC (rev 7859)
@@ -1,8 +1,5 @@
package org.horizon.profiling;
-import org.horizon.Cache;
-import org.horizon.config.Configuration;
-import org.horizon.lock.IsolationLevel;
import org.horizon.profiling.testinternals.Generator;
import org.horizon.profiling.testinternals.TaskRunner;
import org.horizon.test.TestingUtil;
@@ -24,7 +21,7 @@
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
*/
-@Test(groups = "profiling", enabled = false, testName = "profiling.ProfileTest")
+@Test(groups = "profiling", enabled = true, testName = "profiling.ProfileTest")
public class ProfileTest extends AbstractProfileTest {
/*
Test configuration options
@@ -38,12 +35,8 @@
private List<Object> keys = new ArrayList<Object>(MAX_OVERALL_KEYS);
- @Test(enabled = false)
+ @Test(enabled = true)
public void testLocalMode() throws Exception {
- Cache c = (Cache) cache;
- c.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
- c.getConfiguration().setConcurrencyLevel(2000);
- c.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
runCompleteTest();
}
@@ -86,7 +79,7 @@
protected void startup() {
long startTime = System.currentTimeMillis();
log.warn("Starting cache");
- ((Cache) cache).start();
+ cache.start();
long duration = System.currentTimeMillis() - startTime;
log.warn("Started cache. " + printDuration(duration));
}
@@ -120,7 +113,7 @@
long duration = System.currentTimeMillis() - startTime;
log.warn("Finished warmup. " + printDuration(duration));
- ((Cache) cache).stop();
+ cache.stop();
startup();
}
15 years, 9 months
JBoss Cache SVN: r7858 - core/branches/flat/src/test/java/org/horizon/loader.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 10:28:11 -0500 (Thu, 05 Mar 2009)
New Revision: 7858
Modified:
core/branches/flat/src/test/java/org/horizon/loader/AbstractCacheStoreTest.java
Log:
Fixed vararg warning
Modified: core/branches/flat/src/test/java/org/horizon/loader/AbstractCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/AbstractCacheStoreTest.java 2009-03-05 13:47:19 UTC (rev 7857)
+++ core/branches/flat/src/test/java/org/horizon/loader/AbstractCacheStoreTest.java 2009-03-05 15:28:11 UTC (rev 7858)
@@ -1,13 +1,12 @@
package org.horizon.loader;
-import static org.easymock.classextension.EasyMock.*;
+import static org.easymock.classextension.EasyMock.createMock;
import org.horizon.util.ReflectionUtil;
import org.horizon.util.concurrent.WithinThreadExecutor;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-import java.lang.reflect.Method;
import java.util.concurrent.ExecutorService;
/**
@@ -24,9 +23,9 @@
@BeforeTest
public void setUp() throws NoSuchMethodException {
- cs = createMock(AbstractCacheStore.class,new Method[] { AbstractCacheStore.class.getMethod("clear", null) });
+ cs = createMock(AbstractCacheStore.class, AbstractCacheStore.class.getMethod("clear"));
cfg = new AbstractCacheStoreConfig();
- cs.init(cfg,null,null);
+ cs.init(cfg, null, null);
}
@AfterTest
15 years, 9 months
JBoss Cache SVN: r7857 - in core/branches/flat/src: main/java/org/horizon/loader/jdbc and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-03-05 08:47:19 -0500 (Thu, 05 Mar 2009)
New Revision: 7857
Added:
core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/
core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/
core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java
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
core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
Modified:
core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java
core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java
core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java
Log:
ongoing jdbc cache store work
Modified: core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -61,7 +61,7 @@
try {
purgeInternal();
} catch (CacheLoaderException e) {
- log.info("Problems encountered while purging expired", e);
+ log.error("Problems encountered while purging expired", e);
}
}
});
Modified: core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -6,9 +6,12 @@
* @author Mircea.Markus(a)jboss.com
*/
public class LockSupportCacheStoreConfig extends AbstractCacheStoreConfig {
- private int lockConcurrencyLevel = 2048;
- private long lockAcquistionTimeout = 60000;
+ public static final int DEFAULT_CONCURRENCY_LEVEL = 2048;
+ public static final int DEFAULT_LOCK_ACQUISITION_TIMEOUT = 60000;
+ private int lockConcurrencyLevel = DEFAULT_CONCURRENCY_LEVEL;
+ private long lockAcquistionTimeout = DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+
/**
* Returns number of threads expected to use this class concurrently.
*/
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-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -1,106 +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.CacheStore;
-import org.horizon.loader.StoredEntry;
-import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore;
-import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
-import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
-import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore;
-import org.horizon.marshall.Marshaller;
-
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Set;
-
-/**
- * // TODO: Mircea: Document this!
- *
- * @author
- */
-public class JdbcCacheStore extends AbstractCacheStore {
-
- private JdbcCacheStoreConfig config;
- private JdbcBinaryCacheStore binaryCacheStore = new JdbcBinaryCacheStore();
- private JdbcStringBasedCacheStore stringBasedCacheStore = new JdbcStringBasedCacheStore();
- private ConnectionFactory sharedConnectionFactory;
-
- @Override
- public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
- super.init(config, cache, m);
- this.config = (JdbcCacheStoreConfig) config;
- binaryCacheStore.init(this.config.getBinaryCacheStoreConfig(), cache, m);
- stringBasedCacheStore.init(this.config.getStringCacheStoreConfig(), cache, m);
- }
-
- @Override
- public void start() throws CacheLoaderException {
- super.start();
- ConnectionFactoryConfig factoryConfig = config.getConnectionFactoryConfig();
- sharedConnectionFactory = ConnectionFactory.getConnectionFactory(factoryConfig.getConnectionFactoryClass());
- sharedConnectionFactory.start(factoryConfig);
- binaryCacheStore.start();
- binaryCacheStore.doConnectionFactoryInitialization(sharedConnectionFactory);
- stringBasedCacheStore.start();
- stringBasedCacheStore.doConnectionFactoryInitialization(sharedConnectionFactory);
- }
-
- @Override
- public void stop() throws CacheLoaderException {
- super.stop();
- binaryCacheStore.stop();
- stringBasedCacheStore.stop();
- sharedConnectionFactory.stop();
- }
-
- @Override
- protected void purgeInternal() throws CacheLoaderException {
- binaryCacheStore.purgeExpired();
- stringBasedCacheStore.purgeExpired();
- }
-
- public StoredEntry load(Object key) throws CacheLoaderException {
- return getCacheStore(key).load(key);
- }
-
- public Set<StoredEntry> loadAll() throws CacheLoaderException {
- Set<StoredEntry> fromBuckets = binaryCacheStore.loadAll();
- Set<StoredEntry> fromStrings = stringBasedCacheStore.loadAll();
- fromBuckets.addAll(fromStrings);
- return fromBuckets;
- }
-
- public void store(StoredEntry ed) throws CacheLoaderException {
- getCacheStore(ed.getKey()).store(ed);
- }
-
- public void fromStream(ObjectInput inputStream) throws CacheLoaderException {
- binaryCacheStore.fromStream(inputStream);
- stringBasedCacheStore.fromStream(inputStream);
- }
-
- public void toStream(ObjectOutput outputStream) throws CacheLoaderException {
- binaryCacheStore.toStream(outputStream);
- stringBasedCacheStore.toStream(outputStream);
- }
-
- public boolean remove(Object key) throws CacheLoaderException {
- return getCacheStore(key).remove(key);
- }
-
- public void clear() throws CacheLoaderException {
- binaryCacheStore.clear();
- stringBasedCacheStore.clear();
- }
-
- public Class<? extends CacheLoaderConfig> getConfigurationClass() {
- return JdbcCacheStoreConfig.class;
- }
-
- private CacheStore getCacheStore(Object key) {
- return stringBasedCacheStore.supportsKey(key.getClass()) ? stringBasedCacheStore : binaryCacheStore;
- }
-}
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-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -1,139 +0,0 @@
-package org.horizon.loader.jdbc;
-
-import org.horizon.loader.AbstractCacheStoreConfig;
-import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStoreConfig;
-import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
-import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStoreConfig;
-
-/**
- * // TODO: Mircea: Document this!
- *
- * @author
- */
-public class JdbcCacheStoreConfig extends AbstractCacheStoreConfig {
-
- private ConnectionFactoryConfig connectionFactoryConfig = new ConnectionFactoryConfig();
- private TableManipulation binaryTableManipulation = new TableManipulation();
- private TableManipulation stringsTableManipulation = new TableManipulation();
-
-
- public JdbcCacheStoreConfig() {
- this.className = JdbcCacheStore.class.getName();
- }
-
- public void setConnectionFactoryConfig(ConnectionFactoryConfig connectionFactoryConfig) {
- this.connectionFactoryConfig = connectionFactoryConfig;
- }
-
- public void setBinaryTableManipulation(TableManipulation binaryTableManipulation) {
- this.binaryTableManipulation = binaryTableManipulation;
- }
-
- public void setStringsTableManipulation(TableManipulation stringsTableManipulation) {
- this.stringsTableManipulation = stringsTableManipulation;
- }
-
- JdbcBinaryCacheStoreConfig getBinaryCacheStoreConfig() {
- JdbcBinaryCacheStoreConfig cacheStoreConfig = new JdbcBinaryCacheStoreConfig(false);
- cacheStoreConfig.setTableManipulation(binaryTableManipulation);
- return cacheStoreConfig;
- }
-
- JdbcStringBasedCacheStoreConfig getStringCacheStoreConfig() {
- JdbcStringBasedCacheStoreConfig config = new JdbcStringBasedCacheStoreConfig(false);
- config.setTableManipulation(stringsTableManipulation);
- return config;
- }
-
- public void setIdColumnNameForStrings(String idColumnNameForStrings) {
- this.stringsTableManipulation.setIdColumnName(idColumnNameForStrings);
- }
-
- public void setIdColumnTypeForStrings(String idColumnTypeForStrings) {
- this.stringsTableManipulation.setIdColumnType(idColumnTypeForStrings);
- }
-
- public void setTableNameForStrings(String tableNameForStrings) {
- this.stringsTableManipulation.setTableName(tableNameForStrings);
- }
-
- public void setDataColumnNameForStrings(String dataColumnNameForStrings) {
- this.stringsTableManipulation.setDataColumnName(dataColumnNameForStrings);
- }
-
- public void setDataColumnTypeForStrings(String dataColumnTypeForStrings) {
- this.stringsTableManipulation.setDataColumnType(dataColumnTypeForStrings);
- }
-
- public void setTimestampColumnNameForStrings(String timestampColumnNameForStrings) {
- this.stringsTableManipulation.setTimestampColumnName(timestampColumnNameForStrings);
- }
-
- public void setTimestampColumnTypeForStrings(String timestampColumnTypeForStrings) {
- this.stringsTableManipulation.setTimestampColumnType(timestampColumnTypeForStrings);
- }
-
- public void setCreateTableOnStartForStrings(boolean createTableOnStartForStrings) {
- this.stringsTableManipulation.setCreateTableOnStart(createTableOnStartForStrings);
- }
-
- public void setDropTableOnExitForStrings(boolean dropTableOnExitForStrings) {
- this.stringsTableManipulation.setDropTableOnExit(dropTableOnExitForStrings);
- }
-
- public void setIdColumnNameForBinary(String idColumnNameForBinary) {
- this.binaryTableManipulation.setIdColumnName(idColumnNameForBinary);
- }
-
- public void setIdColumnTypeForBinary(String idColumnTypeForBinary) {
- this.binaryTableManipulation.setIdColumnType(idColumnTypeForBinary);
- }
-
- public void setTableNameForBinary(String tableNameForBinary) {
- this.binaryTableManipulation.setTableName(tableNameForBinary);
- }
-
- public void setDataColumnNameForBinary(String dataColumnNameForBinary) {
- this.binaryTableManipulation.setDataColumnName(dataColumnNameForBinary);
- }
-
- public void setDataColumnTypeForBinary(String dataColumnTypeForBinary) {
- this.binaryTableManipulation.setDataColumnType(dataColumnTypeForBinary);
- }
-
- public void setTimestampColumnNameForBinary(String timestampColumnNameForBinary) {
- this.binaryTableManipulation.setTimestampColumnName(timestampColumnNameForBinary);
- }
-
- public void setTimestampColumnTypeForBinary(String timestampColumnTypeForBinary) {
- this.binaryTableManipulation.setTimestampColumnType(timestampColumnTypeForBinary);
- }
-
- public void setCreateTableOnStartForBinary(boolean createTableOnStartForBinary) {
- this.binaryTableManipulation.setCreateTableOnStart(createTableOnStartForBinary);
- }
-
- public void setDropTableOnExitForBinary(boolean dropTableOnExitForBinary) {
- this.binaryTableManipulation.setDropTableOnExit(dropTableOnExitForBinary);
- }
-
- public void setDriverClass(String driverClass) {
- this.connectionFactoryConfig.setDriverClass(driverClass);
- }
-
- public void setConnectionUrl(String connectionUrl) {
- this.connectionFactoryConfig.setConnectionUrl(connectionUrl);
- }
-
- public void setUserName(String userName) {
- this.connectionFactoryConfig.setUserName(userName);
- }
-
- public void setPassword(String password) {
- this.connectionFactoryConfig.setPassword(password);
- }
-
- public ConnectionFactoryConfig getConnectionFactoryConfig() {
- return connectionFactoryConfig;
- }
-}
Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -44,8 +44,8 @@
private String deleteRowSql;
private String loadAllRowsSql;
private String deleteAllRows;
- private String selectExpiredBucketsSql;
- private String deleteExpiredBucketsSql;
+ private String selectExpiredRowsSql;
+ private String deleteExpiredRowsSql;
public TableManipulation(String idColumnName, String idColumnType, String tableName, String dataColumnName,
String dataColumnType, String timestampColumnName, String timestampColumnType) {
@@ -278,17 +278,17 @@
}
public String getSelectExpiredRowsSql() {
- if (selectExpiredBucketsSql == null) {
- selectExpiredBucketsSql = getLoadAllRowsSql() + " WHERE " + timestampColumnName + "< ?";
+ if (selectExpiredRowsSql == null) {
+ selectExpiredRowsSql = getLoadAllRowsSql() + " WHERE " + timestampColumnName + "< ?";
}
- return selectExpiredBucketsSql;
+ return selectExpiredRowsSql;
}
public String getDeleteExpiredRowsSql() {
- if (deleteExpiredBucketsSql == null) {
- deleteExpiredBucketsSql = "DELETE FROM" + tableName + " WHERE " + timestampColumnName + "< ?";
+ if (deleteExpiredRowsSql == null) {
+ deleteExpiredRowsSql = "DELETE FROM " + tableName + " WHERE " + timestampColumnName + "< ? AND " + timestampColumnName + "> 0";
}
- return deleteExpiredBucketsSql;
+ return deleteExpiredRowsSql;
}
@Override
@@ -307,4 +307,28 @@
public boolean tableExists(Connection connection) throws CacheLoaderException {
return tableExists(connection, tableName);
}
+
+ public String getIdColumnName() {
+ return idColumnName;
+ }
+
+ public String getIdColumnType() {
+ return idColumnType;
+ }
+
+ public String getDataColumnName() {
+ return dataColumnName;
+ }
+
+ public String getDataColumnType() {
+ return dataColumnType;
+ }
+
+ public String getTimestampColumnName() {
+ return timestampColumnName;
+ }
+
+ public String getTimestampColumnType() {
+ return timestampColumnType;
+ }
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -279,7 +279,7 @@
}
}
- protected void purgeInternal() throws CacheLoaderException {
+ public void purgeInternal() throws CacheLoaderException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
@@ -416,7 +416,7 @@
* Keeps a reference to the connection factory for further use. Also initializes the {@link
* org.horizon.loader.jdbc.TableManipulation} that needs connections. This method should be called when you don't
* want the store to manage the connection factory, perhaps because it is using an shared connection factory: see
- * {@link org.horizon.loader.jdbc.JdbcCacheStore} for such an example of this.
+ * {@link org.horizon.loader.jdbc.mixed.JdbcMixedCacheStore} for such an example of this.
*/
public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory) throws CacheLoaderException {
this.connectionFactory = connectionFactory;
Copied: core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java (from rev 7854, core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,130 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.horizon.Cache;
+import org.horizon.loader.AbstractCacheStore;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.CacheLoaderException;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.StoredEntry;
+import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore;
+import org.horizon.marshall.Marshaller;
+
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Set;
+
+/**
+ * Cache store that combines functionality of {@link JdbcBinaryCacheStore} and {@link JdbcStringBasedCacheStore}. It
+ * aggregates an instance of JdbcBinaryCacheStore and JdbcStringBasedCacheStore, delegating work to one of them
+ * (sometimes both, see below) based on the passed in key. In order to determine which store to use it will rely on the
+ * configured {@link org.horizon.loader.jdbc.stringbased.Key2StringMapper} )(see configuration).
+ * <p/>
+ * The advantage it brings is the possibility of effeciently storing string(able) keyd {@link
+ * org.horizon.loader.StoredEntry}s, and at the same time being able to store any other keys, a la {@link
+ * org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore}.
+ * <p/>
+ * There will only be a performance cost for the aggregate operations: loadAll, fromStream, toStream and clear. For
+ * these operations there will be two distinct database call, one for each JdbcStore implementation. Most of application
+ * are only using these operations at lifecycles changes (e.g. fromStram and toStream at cluster join time, loadAll at
+ * startup for warm caches), so performance drawback shouldn't be significant (again, most of the cases).
+ * <p/>
+ * Resource sharing - both aggregated cache loaders have locks and connection pools. The locking is not shared, each
+ * loader keeping its own {@link org.horizon.lock.StripedLock} instace. Also the tables (even though similar as
+ * definition) are different in order to avoid key collision. On the other hand, the connection pooling is a shared
+ * resource.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @see org.horizon.loader.jdbc.mixed.JdbcMixedCacheStoreConfig
+ * @see org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore
+ * @see org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore
+ */
+public class JdbcMixedCacheStore extends AbstractCacheStore {
+
+ private JdbcMixedCacheStoreConfig config;
+ private JdbcBinaryCacheStore binaryCacheStore = new JdbcBinaryCacheStore();
+ private JdbcStringBasedCacheStore stringBasedCacheStore = new JdbcStringBasedCacheStore();
+ private ConnectionFactory sharedConnectionFactory;
+
+ @Override
+ public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+ super.init(config, cache, m);
+ this.config = (JdbcMixedCacheStoreConfig) config;
+ binaryCacheStore.init(this.config.getBinaryCacheStoreConfig(), cache, m);
+ stringBasedCacheStore.init(this.config.getStringCacheStoreConfig(), cache, m);
+ }
+
+ @Override
+ public void start() throws CacheLoaderException {
+ super.start();
+ ConnectionFactoryConfig factoryConfig = config.getConnectionFactoryConfig();
+ sharedConnectionFactory = ConnectionFactory.getConnectionFactory(factoryConfig.getConnectionFactoryClass());
+ sharedConnectionFactory.start(factoryConfig);
+ binaryCacheStore.start();
+ binaryCacheStore.doConnectionFactoryInitialization(sharedConnectionFactory);
+ stringBasedCacheStore.start();
+ stringBasedCacheStore.doConnectionFactoryInitialization(sharedConnectionFactory);
+ }
+
+ @Override
+ public void stop() throws CacheLoaderException {
+ super.stop();
+ binaryCacheStore.stop();
+ stringBasedCacheStore.stop();
+ sharedConnectionFactory.stop();
+ }
+
+ @Override
+ protected void purgeInternal() throws CacheLoaderException {
+ binaryCacheStore.purgeInternal();
+ stringBasedCacheStore.purgeInternal();
+ }
+
+ public StoredEntry load(Object key) throws CacheLoaderException {
+ return getCacheStore(key).load(key);
+ }
+
+ public Set<StoredEntry> loadAll() throws CacheLoaderException {
+ Set<StoredEntry> fromBuckets = binaryCacheStore.loadAll();
+ Set<StoredEntry> fromStrings = stringBasedCacheStore.loadAll();
+ fromBuckets.addAll(fromStrings);
+ return fromBuckets;
+ }
+
+ public void store(StoredEntry ed) throws CacheLoaderException {
+ getCacheStore(ed.getKey()).store(ed);
+ }
+
+ public void fromStream(ObjectInput inputStream) throws CacheLoaderException {
+ binaryCacheStore.fromStream(inputStream);
+ stringBasedCacheStore.fromStream(inputStream);
+ }
+
+ public void toStream(ObjectOutput outputStream) throws CacheLoaderException {
+ binaryCacheStore.toStream(outputStream);
+ stringBasedCacheStore.toStream(outputStream);
+ }
+
+ public boolean remove(Object key) throws CacheLoaderException {
+ return getCacheStore(key).remove(key);
+ }
+
+ public void clear() throws CacheLoaderException {
+ binaryCacheStore.clear();
+ stringBasedCacheStore.clear();
+ }
+
+ public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+ return JdbcMixedCacheStoreConfig.class;
+ }
+
+ private CacheStore getCacheStore(Object key) {
+ return stringBasedCacheStore.supportsKey(key.getClass()) ? stringBasedCacheStore : binaryCacheStore;
+ }
+
+ public ConnectionFactory getConnectionFactory() {
+ return sharedConnectionFactory;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java (from rev 7854, core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,182 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.horizon.loader.AbstractCacheStoreConfig;
+import org.horizon.loader.LockSupportCacheStoreConfig;
+import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStoreConfig;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStoreConfig;
+import org.horizon.loader.jdbc.TableManipulation;
+
+/**
+ * Configureation for {@link org.horizon.loader.jdbc.mixed.JdbcMixedCacheStore}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class JdbcMixedCacheStoreConfig extends AbstractCacheStoreConfig {
+
+ private ConnectionFactoryConfig connectionFactoryConfig = new ConnectionFactoryConfig();
+ private TableManipulation binaryTableManipulation = new TableManipulation();
+ private TableManipulation stringsTableManipulation = new TableManipulation();
+ private String key2StringMapper;
+ private int binaryConcurrencyLevel = LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+ private int stringsConcurrencyLevel = LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+ private int lockAcquistionTimeout = LockSupportCacheStoreConfig.DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+
+
+ public JdbcMixedCacheStoreConfig(ConnectionFactoryConfig connectionFactoryConfig, TableManipulation binaryTableManipulation, TableManipulation stringsTableManipulation) {
+ this.connectionFactoryConfig = connectionFactoryConfig;
+ this.binaryTableManipulation = binaryTableManipulation;
+ this.stringsTableManipulation = stringsTableManipulation;
+ }
+
+ public JdbcMixedCacheStoreConfig() {
+ this.className = JdbcMixedCacheStore.class.getName();
+ }
+
+ public void setConnectionFactoryConfig(ConnectionFactoryConfig connectionFactoryConfig) {
+ this.connectionFactoryConfig = connectionFactoryConfig;
+ }
+
+ public void setBinaryTableManipulation(TableManipulation binaryTableManipulation) {
+ this.binaryTableManipulation = binaryTableManipulation;
+ }
+
+ public void setStringsTableManipulation(TableManipulation stringsTableManipulation) {
+ this.stringsTableManipulation = stringsTableManipulation;
+ }
+
+ JdbcBinaryCacheStoreConfig getBinaryCacheStoreConfig() {
+ JdbcBinaryCacheStoreConfig cacheStoreConfig = new JdbcBinaryCacheStoreConfig(false);
+ cacheStoreConfig.setTableManipulation(binaryTableManipulation);
+ cacheStoreConfig.setPurgeSynchronously(true);//just to make sure we don't create another thread
+ cacheStoreConfig.setLockConcurrencyLevel(binaryConcurrencyLevel);
+ cacheStoreConfig.setLockAcquistionTimeout(lockAcquistionTimeout);
+ return cacheStoreConfig;
+ }
+
+ JdbcStringBasedCacheStoreConfig getStringCacheStoreConfig() {
+ JdbcStringBasedCacheStoreConfig config = new JdbcStringBasedCacheStoreConfig(false);
+ config.setTableManipulation(stringsTableManipulation);
+ config.setPurgeSynchronously(true); //just to make sure we don't create another thread
+ config.setLockConcurrencyLevel(stringsConcurrencyLevel);
+ config.setLockAcquistionTimeout(lockAcquistionTimeout);
+ if (key2StringMapper != null) config.setKey2StringMapperClass(key2StringMapper);
+ return config;
+ }
+
+ public void setIdColumnNameForStrings(String idColumnNameForStrings) {
+ this.stringsTableManipulation.setIdColumnName(idColumnNameForStrings);
+ }
+
+ public void setIdColumnTypeForStrings(String idColumnTypeForStrings) {
+ this.stringsTableManipulation.setIdColumnType(idColumnTypeForStrings);
+ }
+
+ public void setTableNameForStrings(String tableNameForStrings) {
+ if (tableNameForStrings == null) throw new IllegalArgumentException("Null table name not allowed.");
+ if (tableNameForStrings.equals(this.binaryTableManipulation.getTableName())) {
+ throw new IllegalArgumentException("Same table name is used for both cache loaders, this is not allowed!");
+ }
+ this.stringsTableManipulation.setTableName(tableNameForStrings);
+ }
+
+ public void setDataColumnNameForStrings(String dataColumnNameForStrings) {
+ this.stringsTableManipulation.setDataColumnName(dataColumnNameForStrings);
+ }
+
+ public void setDataColumnTypeForStrings(String dataColumnTypeForStrings) {
+ this.stringsTableManipulation.setDataColumnType(dataColumnTypeForStrings);
+ }
+
+ public void setTimestampColumnNameForStrings(String timestampColumnNameForStrings) {
+ this.stringsTableManipulation.setTimestampColumnName(timestampColumnNameForStrings);
+ }
+
+ public void setTimestampColumnTypeForStrings(String timestampColumnTypeForStrings) {
+ this.stringsTableManipulation.setTimestampColumnType(timestampColumnTypeForStrings);
+ }
+
+ public void setCreateTableOnStartForStrings(boolean createTableOnStartForStrings) {
+ this.stringsTableManipulation.setCreateTableOnStart(createTableOnStartForStrings);
+ }
+
+ public void setDropTableOnExitForStrings(boolean dropTableOnExitForStrings) {
+ this.stringsTableManipulation.setDropTableOnExit(dropTableOnExitForStrings);
+ }
+
+ public void setIdColumnNameForBinary(String idColumnNameForBinary) {
+ this.binaryTableManipulation.setIdColumnName(idColumnNameForBinary);
+ }
+
+ public void setIdColumnTypeForBinary(String idColumnTypeForBinary) {
+ this.binaryTableManipulation.setIdColumnType(idColumnTypeForBinary);
+ }
+
+ public void setTableNameForBinary(String tableNameForBinary) {
+ if (tableNameForBinary == null) throw new IllegalArgumentException("Null table name not allowed.");
+ if (tableNameForBinary.equals(this.stringsTableManipulation.getTableName())) {
+ throw new IllegalArgumentException("Same table name is used for both cache loaders, this is not allowed!");
+ }
+ this.binaryTableManipulation.setTableName(tableNameForBinary);
+ }
+
+ public void setDataColumnNameForBinary(String dataColumnNameForBinary) {
+ this.binaryTableManipulation.setDataColumnName(dataColumnNameForBinary);
+ }
+
+ public void setDataColumnTypeForBinary(String dataColumnTypeForBinary) {
+ this.binaryTableManipulation.setDataColumnType(dataColumnTypeForBinary);
+ }
+
+ public void setTimestampColumnNameForBinary(String timestampColumnNameForBinary) {
+ this.binaryTableManipulation.setTimestampColumnName(timestampColumnNameForBinary);
+ }
+
+ public void setTimestampColumnTypeForBinary(String timestampColumnTypeForBinary) {
+ this.binaryTableManipulation.setTimestampColumnType(timestampColumnTypeForBinary);
+ }
+
+ public void setCreateTableOnStartForBinary(boolean createTableOnStartForBinary) {
+ this.binaryTableManipulation.setCreateTableOnStart(createTableOnStartForBinary);
+ }
+
+ public void setDropTableOnExitForBinary(boolean dropTableOnExitForBinary) {
+ this.binaryTableManipulation.setDropTableOnExit(dropTableOnExitForBinary);
+ }
+
+ public void setDriverClass(String driverClass) {
+ this.connectionFactoryConfig.setDriverClass(driverClass);
+ }
+
+ public void setConnectionUrl(String connectionUrl) {
+ this.connectionFactoryConfig.setConnectionUrl(connectionUrl);
+ }
+
+ public void setUserName(String userName) {
+ this.connectionFactoryConfig.setUserName(userName);
+ }
+
+ public void setPassword(String password) {
+ this.connectionFactoryConfig.setPassword(password);
+ }
+
+ public ConnectionFactoryConfig getConnectionFactoryConfig() {
+ return connectionFactoryConfig;
+ }
+
+ public void setKey2StringMapperClass(String name) {
+ this.key2StringMapper = name;
+ }
+
+ public void setLockConcurrencyLevelForStrings(int concurrencyLevel) {
+ this.stringsConcurrencyLevel = concurrencyLevel;
+ }
+
+ public void setLockConcurrencyLevelForBinary(int concurrencyLevel) {
+ this.binaryConcurrencyLevel = concurrencyLevel;
+ }
+
+ public void setLockAcquistionTimeout(int lockAcquistionTimeout) {
+ this.lockAcquistionTimeout = lockAcquistionTimeout;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -223,13 +223,14 @@
}
@Override
- protected void purgeInternal() throws CacheLoaderException {
+ public void purgeInternal() throws CacheLoaderException {
Connection conn = null;
PreparedStatement ps = null;
try {
String sql = tableManipulation.getDeleteExpiredRowsSql();
conn = connectionFactory.getConnection();
ps = conn.prepareStatement(sql);
+ ps.setLong(1, System.currentTimeMillis());
int result = ps.executeUpdate();
if (log.isTraceEnabled())
log.trace("Successfully purged " + result + " rows.");
@@ -319,7 +320,7 @@
* Keeps a reference to the connection factory for further use. Also initializes the {@link
* org.horizon.loader.jdbc.TableManipulation} that needs connections. This method should be called when you don't
* want the store to manage the connection factory, perhaps because it is using an shared connection factory: see
- * {@link org.horizon.loader.jdbc.JdbcCacheStore} for such an example of this.
+ * {@link org.horizon.loader.jdbc.mixed.JdbcMixedCacheStore} for such an example of this.
*/
public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory) throws CacheLoaderException {
this.connectionFactory = connectionFactory;
Deleted: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -1,33 +0,0 @@
-package org.horizon.loader.jdbc;
-
-import org.horizon.loader.BaseCacheStoreTest;
-import org.horizon.loader.CacheStore;
-import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
-import org.testng.annotations.Test;
-
-/**
- * // TODO: Mircea: Document this!
- *
- * @author
- */
-@Test(groups = "functional", testName = "loader.jdbc.JdbcCacheStoreTest")
-public class JdbcCacheStoreTest extends BaseCacheStoreTest {
-
- protected CacheStore createCacheStore() throws Exception {
- JdbcCacheStoreConfig jdbcCacheStoreConfig = new JdbcCacheStoreConfig();
- TableManipulation stringsTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
- stringsTm.setTableName("STRINGS_TABLE");
- TableManipulation binaryTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
- binaryTm.setTableName("BINARY_TABLE");
-
- ConnectionFactoryConfig cfc = UnitTestDatabaseManager.getUniqueConnectionFactoryConfig();
- jdbcCacheStoreConfig.setConnectionFactoryConfig(cfc);
- jdbcCacheStoreConfig.setStringsTableManipulation(stringsTm);
- jdbcCacheStoreConfig.setBinaryTableManipulation(binaryTm);
-
- JdbcCacheStore cacheStore = new JdbcCacheStore();
- cacheStore.init(jdbcCacheStoreConfig, null, getMarshaller());
- cacheStore.start();
- return cacheStore;
- }
-}
Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -2,6 +2,7 @@
import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
import org.horizon.loader.jdbc.connectionfactory.PooledConnectionFactory;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
import org.horizon.test.TestingUtil;
import java.io.File;
@@ -9,6 +10,8 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicInteger;
@@ -118,4 +121,28 @@
return new TableManipulation("ID_COLUMN", "VARCHAR(255)", "HORIZON_JDBC", "DATA_COLUMN",
"BINARY", "TIMESTAMP_COLUMN", "BIGINT");
}
+
+ /**
+ * Counts the number of rows in the given table.
+ */
+ public static int rowCount(ConnectionFactory connectionFactory, String tableName) {
+ Connection conn = null;
+ PreparedStatement statement = null;
+ ResultSet resultSet = null;
+ try {
+ conn = connectionFactory.getConnection();
+ String sql = "SELECT count(*) FROM " + tableName;
+ statement = conn.prepareStatement(sql);
+ resultSet = statement.executeQuery();
+ resultSet.next();
+ return resultSet.getInt(1);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ finally {
+ JdbcUtil.safeClose(resultSet);
+ JdbcUtil.safeClose(statement);
+ connectionFactory.releaseConnection(conn);
+ }
+ }
}
Added: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,90 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.horizon.loader.jdbc.stringbased.PersonKey2StringMapper;
+import org.horizon.loader.LockSupportCacheStoreConfig;
+
+/**
+ * Tester class for {@link JdbcMixedCacheStoreConfig}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+@Test(groups = "unit", testName = "loader.jdbc.mixed.JdbcMixedCacheStoreConfigTest")
+public class JdbcMixedCacheStoreConfigTest {
+ private JdbcMixedCacheStoreConfig config;
+
+ @BeforeMethod
+ public void createConfig() {
+ config = new JdbcMixedCacheStoreConfig();
+ }
+
+ /**
+ * Just take some random props and check their corectness.
+ */
+ public void simpleTest() {
+ config = new JdbcMixedCacheStoreConfig();
+ config.setConnectionUrl("url");
+ config.setCreateTableOnStartForBinary(false);
+ config.setCreateTableOnStartForStrings(true);
+ config.setDataColumnNameForBinary("binary_dc");
+ config.setDataColumnNameForStrings("strings_dc");
+ config.setDataColumnTypeForBinary("binary_dct");
+ config.setDataColumnTypeForStrings("strings_dct");
+ config.setDriverClass("driver");
+
+ //some checks
+ assert !config.getBinaryCacheStoreConfig().getTableManipulation().isCreateTableOnStart();
+ assert config.getStringCacheStoreConfig().getTableManipulation().isCreateTableOnStart();
+ assert config.getConnectionFactoryConfig().getDriverClass().equals("driver");
+ assert config.getBinaryCacheStoreConfig().getTableManipulation().getDataColumnName().equals("binary_dc");
+ assert config.getBinaryCacheStoreConfig().getTableManipulation().getDataColumnType().equals("binary_dct");
+ assert config.getStringCacheStoreConfig().getTableManipulation().getDataColumnName().equals("strings_dc");
+ assert config.getStringCacheStoreConfig().getTableManipulation().getDataColumnType().equals("strings_dct");
+ }
+
+ public void testSameTableName() {
+ config.setTableNameForBinary("table");
+ try {
+ config.setTableNameForStrings("table");
+ assert false: "expection expected as same table name is not allowed for both cache stores";
+ } catch (Exception e) {
+ //expected
+ }
+ //and the other way around
+ config.setTableNameForStrings("table2");
+ try {
+ config.setTableNameForBinary("table2");
+ assert false: "expection expected as same table name is not allowed for both cache stores";
+ } catch (Exception e) {
+ //expected
+ }
+ }
+
+ public void testKey2StringMapper() {
+ config.setKey2StringMapperClass(PersonKey2StringMapper.class.getName());
+ assert config.getStringCacheStoreConfig().getKey2StringMapper().getClass().equals(PersonKey2StringMapper.class);
+ }
+
+ public void testConcurrencyLevel() {
+ assert config.getStringCacheStoreConfig().getLockConcurrencyLevel() == LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+ assert config.getBinaryCacheStoreConfig().getLockConcurrencyLevel() == LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+ config.setLockConcurrencyLevelForStrings(11);
+ config.setLockConcurrencyLevelForBinary(12);
+ assert config.getStringCacheStoreConfig().getLockConcurrencyLevel() == 11;
+ assert config.getBinaryCacheStoreConfig().getLockConcurrencyLevel() == 12;
+ }
+
+ public void testEnforcedSyncPurging() {
+ assert config.getBinaryCacheStoreConfig().isPurgeSynchronously();
+ assert config.getStringCacheStoreConfig().isPurgeSynchronously();
+ }
+
+ public void voidTestLockAquisitionTimeout() {
+ assert config.getStringCacheStoreConfig().getLockAcquistionTimeout() == LockSupportCacheStoreConfig.DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+ assert config.getBinaryCacheStoreConfig().getLockAcquistionTimeout() == LockSupportCacheStoreConfig.DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+ config.setLockAcquistionTimeout(13);
+ assert config.getStringCacheStoreConfig().getLockAcquistionTimeout() == 13;
+ assert config.getBinaryCacheStoreConfig().getLockAcquistionTimeout() == 13;
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,193 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.horizon.loader.CacheLoaderException;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.StoredEntry;
+import org.horizon.loader.jdbc.TableManipulation;
+import org.horizon.loader.jdbc.UnitTestDatabaseManager;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.horizon.loader.jdbc.stringbased.DefaultKey2StringMapper;
+import org.horizon.loader.jdbc.stringbased.Person;
+import org.horizon.marshall.ObjectStreamMarshaller;
+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.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Set;
+
+/**
+ * Tester class for {@link JdbcMixedCacheStore}
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+@Test(groups = "functional", testName = "loader.jdbc.JdbcMixedCacheStoreTest")
+public class JdbcMixedCacheStoreTest {
+
+ private CacheStore cacheStore;
+ private TableManipulation stringsTm;
+ private TableManipulation binaryTm;
+ private ConnectionFactoryConfig cfc;
+
+ private static final Person MIRCEA = new Person("Mircea", "Markus", 28);
+ private static final Person MANIK = new Person("Manik", "Surtani", 18);
+
+
+ @BeforeTest
+ public void createCacheStore() throws CacheLoaderException {
+ stringsTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+ stringsTm.setTableName("STRINGS_TABLE");
+ binaryTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+ binaryTm.setTableName("BINARY_TABLE");
+ cfc = UnitTestDatabaseManager.getUniqueConnectionFactoryConfig();
+ JdbcMixedCacheStoreConfig cacheStoreConfig = new JdbcMixedCacheStoreConfig(cfc, binaryTm, stringsTm);
+ cacheStoreConfig.setPurgeSynchronously(true);
+
+ cacheStoreConfig.setKey2StringMapperClass(DefaultKey2StringMapper.class.getName());
+ cacheStore = new JdbcMixedCacheStore();
+ cacheStore.init(cacheStoreConfig, null, new ObjectStreamMarshaller());
+ cacheStore.start();
+ }
+
+ @AfterMethod
+ public void clearStore() throws Exception {
+ cacheStore.clear();
+ assertBinaryRowCount(0);
+ assertStringsRowCount(0);
+ }
+
+ @AfterTest
+ public void destroyStore() throws CacheLoaderException {
+ cacheStore.stop();
+ UnitTestDatabaseManager.shutdownInMemoryDatabase(cfc);
+ }
+
+ public void testMixedStore() throws Exception {
+ cacheStore.store(new StoredEntry("String", "someValue"));
+ assertStringsRowCount(1);
+ assertBinaryRowCount(0);
+ cacheStore.store(new StoredEntry(MIRCEA, "value"));
+ assertStringsRowCount(1);
+ assertStringsRowCount(1);
+ assert cacheStore.load(MIRCEA).getValue().equals("value");
+ assert cacheStore.load("String").getValue().equals("someValue");
+ }
+
+ public void testMultipleEntriesWithSameHashCode() throws Exception {
+ Person one = new Person("Mircea", "Markus", 28);
+ Person two = new Person("Manik", "Surtani", 28);
+ one.setHashCode(100);
+ two.setHashCode(100);
+ cacheStore.store(new StoredEntry(one, "value"));
+ assertBinaryRowCount(1);
+ assertStringsRowCount(0);
+ cacheStore.store(new StoredEntry(two, "otherValue"));
+ assertBinaryRowCount(1); //both go to same bucket
+ assertStringsRowCount(0);
+ assert cacheStore.load(one).getValue().equals("value");
+ assert cacheStore.load(two).getValue().equals("otherValue");
+ }
+
+ public void testClear() throws Exception {
+ cacheStore.store(new StoredEntry("String", "someValue"));
+ assertRowCounts(0, 1);
+ cacheStore.store(new StoredEntry(MIRCEA, "value"));
+ assertRowCounts(1, 1);
+ cacheStore.clear();
+ assertRowCounts(0,0);
+ }
+
+ public void testMixedFromAndToStream() throws Exception {
+ cacheStore.store(new StoredEntry("String", "someValue"));
+ cacheStore.store(new StoredEntry("String2", "someValue"));
+ cacheStore.store(new StoredEntry(MIRCEA, "value1"));
+ cacheStore.store(new StoredEntry(MANIK, "value2"));
+ assertRowCounts(2,2);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
+ cacheStore.toStream(objectOutputStream);
+ cacheStore.clear();
+ assertRowCounts(0,0);
+ cacheStore.fromStream(new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())));
+ assertRowCounts(2,2);
+ assert cacheStore.load("String").getValue().equals("someValue");
+ assert cacheStore.load("String2").getValue().equals("someValue");
+ assert cacheStore.load(MIRCEA).getValue().equals("value1");
+ assert cacheStore.load(MANIK).getValue().equals("value2");
+ }
+
+ public void testLoadAll() throws Exception {
+ StoredEntry first = new StoredEntry("String", "someValue");
+ StoredEntry second = new StoredEntry("String2", "someValue");
+ StoredEntry third = new StoredEntry(MIRCEA, "value1");
+ StoredEntry forth = new StoredEntry(MANIK, "value2");
+ cacheStore.store(first);
+ cacheStore.store(second);
+ cacheStore.store(third);
+ cacheStore.store(forth);
+ assertRowCounts(2,2);
+ Set<StoredEntry> entries = cacheStore.loadAll();
+ assert entries.size() == 4;
+ assert entries.contains(first);
+ assert entries.contains(second);
+ assert entries.contains(third);
+ assert entries.contains(forth);
+ }
+
+ public void testPurgeExpired() throws Exception {
+ StoredEntry first = new StoredEntry("String", "someValue", 1000);
+ StoredEntry second = new StoredEntry(MIRCEA, "value1", 1000);
+ cacheStore.store(first);
+ cacheStore.store(second);
+ assertRowCounts(1,1);
+ Thread.sleep(1200);
+ cacheStore.purgeExpired();
+ assertRowCounts(0,0);
+ }
+
+ public void testPurgeExpiredWithRemainingEntries() throws Exception {
+ StoredEntry first = new StoredEntry("String", "someValue", 1000);
+ StoredEntry second = new StoredEntry("String2", "someValue");
+ StoredEntry third = new StoredEntry(MIRCEA, "value1", 1000);
+ StoredEntry forth = new StoredEntry(MANIK, "value1");
+ cacheStore.store(first);
+ cacheStore.store(second);
+ cacheStore.store(third);
+ cacheStore.store(forth);
+ assertRowCounts(2,2);
+ Thread.sleep(1200);
+ cacheStore.purgeExpired();
+ assertRowCounts(1,1);
+ }
+
+ public void testTableConflict() {
+
+ }
+
+ private void assertRowCounts(int binary, int strings) {
+ assertBinaryRowCount(binary);
+ assertStringsRowCount(strings);
+ }
+
+ private void assertStringsRowCount(int rowCount) {
+ JdbcMixedCacheStore store = (JdbcMixedCacheStore) cacheStore;
+ ConnectionFactory connectionFactory = store.getConnectionFactory();
+ String tableName = stringsTm.getTableName();
+ int value = UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
+ assert value == rowCount : "Expected " + rowCount + " rows, actual value is " + value;
+ }
+
+ private void assertBinaryRowCount(int rowCount) {
+ JdbcMixedCacheStore store = (JdbcMixedCacheStore) cacheStore;
+ ConnectionFactory connectionFactory = store.getConnectionFactory();
+ String tableName = binaryTm.getTableName();
+ int value = UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
+ assert value == rowCount : "Expected " + rowCount + " rows, actual value is " + value;
+
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java (from rev 7854, core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,35 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.horizon.loader.BaseCacheStoreTest;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.jdbc.TableManipulation;
+import org.horizon.loader.jdbc.UnitTestDatabaseManager;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+@Test(groups = "functional", testName = "loader.jdbc.JdbcMixedCacheStoreTest2")
+public class JdbcMixedCacheStoreTest2 extends BaseCacheStoreTest {
+
+ protected CacheStore createCacheStore() throws Exception {
+ JdbcMixedCacheStoreConfig jdbcCacheStoreConfig = new JdbcMixedCacheStoreConfig();
+ TableManipulation stringsTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+ stringsTm.setTableName("STRINGS_TABLE");
+ TableManipulation binaryTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+ binaryTm.setTableName("BINARY_TABLE");
+
+ ConnectionFactoryConfig cfc = UnitTestDatabaseManager.getUniqueConnectionFactoryConfig();
+ jdbcCacheStoreConfig.setConnectionFactoryConfig(cfc);
+ jdbcCacheStoreConfig.setStringsTableManipulation(stringsTm);
+ jdbcCacheStoreConfig.setBinaryTableManipulation(binaryTm);
+
+ JdbcMixedCacheStore cacheStore = new JdbcMixedCacheStore();
+ cacheStore.init(jdbcCacheStoreConfig, null, getMarshaller());
+ cacheStore.start();
+ return cacheStore;
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -3,9 +3,9 @@
import org.horizon.loader.CacheLoaderException;
import org.horizon.loader.CacheStore;
import org.horizon.loader.StoredEntry;
-import org.horizon.loader.jdbc.JdbcUtil;
import org.horizon.loader.jdbc.TableManipulation;
import org.horizon.loader.jdbc.UnitTestDatabaseManager;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
import org.horizon.marshall.ObjectStreamMarshaller;
import org.testng.annotations.AfterMethod;
@@ -13,12 +13,9 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Set;
-import java.util.HashSet;
/**
* Tester for {@link JdbcStringBasedCacheStore} with an alternative {@link org.horizon.loader.jdbc.stringbased.Key2StringMapper}.
@@ -40,6 +37,7 @@
cfc = UnitTestDatabaseManager.getUniqueConnectionFactoryConfig();
JdbcStringBasedCacheStoreConfig config = new JdbcStringBasedCacheStoreConfig(cfc, tableManipulation);
config.setKey2StringMapperClass(PersonKey2StringMapper.class.getName());
+ config.setPurgeSynchronously(true);
cacheStore = new JdbcStringBasedCacheStore();
cacheStore.init(config, null, new ObjectStreamMarshaller());
cacheStore.start();
@@ -111,27 +109,38 @@
assert rowCount() == 0;
}
+ public void testPurgeExpired() throws Exception {
+ StoredEntry first = new StoredEntry(MIRCEA, "val",1000);
+ StoredEntry second = new StoredEntry(MANIK, "val2");
+ cacheStore.store(first);
+ cacheStore.store(second);
+ assert rowCount() == 2;
+ Thread.sleep(1100);
+// printTableContent();
+ cacheStore.purgeExpired();
+ assert rowCount() == 1;
+ assert cacheStore.load(MANIK).getValue().equals("val2");
+ }
+
+// private void printTableContent() throws Exception {
+// String sql = "SELECT TIMESTAMP_COLUMN FROM HORIZON_JDBC";
+// ConnectionFactory connectionFactory = getConnection();
+// Connection conn = connectionFactory.getConnection();
+// ResultSet rs = conn.createStatement().executeQuery(sql);
+// while (rs.next()) {
+// System.out.println(rs.getLong(1));
+// }
+// }
+
private int rowCount() {
+ ConnectionFactory connectionFactory = getConnection();
+ String tableName = tableManipulation.getTableName();
+ return UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
+ }
+
+ private ConnectionFactory getConnection() {
JdbcStringBasedCacheStore store = (JdbcStringBasedCacheStore) cacheStore;
- Connection conn = null;
- PreparedStatement statement = null;
- ResultSet resultSet = null;
- try {
- conn = store.getConnectionFactory().getConnection();
- String tableName = tableManipulation.getTableName();
- String sql = "SELECT count(*) FROM " + tableName;
- statement = conn.prepareStatement(sql);
- resultSet = statement.executeQuery();
- resultSet.next();
- return resultSet.getInt(1);
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- finally {
- JdbcUtil.safeClose(resultSet);
- JdbcUtil.safeClose(statement);
- store.getConnectionFactory().releaseConnection(conn);
- }
+ return store.getConnectionFactory();
}
private StoredEntry newStoredEntry(Object key, Object value) {
Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java 2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java 2009-03-05 13:47:19 UTC (rev 7857)
@@ -11,6 +11,7 @@
private String name;
private String surname;
private int age;
+ private int hashCode = -1;
public Person(String name, String surname, int age) {
this.name = name;
@@ -30,6 +31,10 @@
return age;
}
+ public void setHashCode(int hashCode) {
+ this.hashCode = hashCode;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -46,6 +51,9 @@
@Override
public int hashCode() {
+ if (hashCode != -1) {
+ return hashCode;
+ }
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (surname != null ? surname.hashCode() : 0);
result = 31 * result + age;
15 years, 9 months
JBoss Cache SVN: r7856 - in benchmarks/benchmark-fwk/trunk: cache-products and 7 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-05 07:24:26 -0500 (Thu, 05 Mar 2009)
New Revision: 7856
Added:
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RC.xml
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RR.xml
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/config.sh
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/commons-logging.jar
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jboss-common-core.jar
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jboss-logging-spi.jar
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jcip-annotations.jar
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jgroups.jar
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jta.jar
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/org/
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/org/cachebench/
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/org/cachebench/cachewrappers/
benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/org/cachebench/cachewrappers/HorizonWrapper.java
Modified:
benchmarks/benchmark-fwk/trunk/build.xml
benchmarks/benchmark-fwk/trunk/runAllLocal.sh
Log:
Added Horizon
Modified: benchmarks/benchmark-fwk/trunk/build.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/build.xml 2009-03-05 11:44:03 UTC (rev 7855)
+++ benchmarks/benchmark-fwk/trunk/build.xml 2009-03-05 12:24:26 UTC (rev 7856)
@@ -248,18 +248,18 @@
</javac>
</target>
- <target name="compile.module.starobrno" depends="fwk"
- description="Compile module starobrno">
- <mkdir dir="./classes/production/starobrno"/>
- <javac destdir="./classes/production/starobrno" debug="${compiler.debug}"
+ <target name="compile.module.horizon" depends="fwk"
+ description="Compile module Horizon">
+ <mkdir dir="./classes/production/horizon"/>
+ <javac destdir="./classes/production/horizon" debug="${compiler.debug}"
nowarn="${compiler.generate.no.warnings}" fork="true">
<classpath>
- <fileset dir="./cache-products/starobrno/lib" includes="*.jar"/>
+ <fileset dir="./cache-products/Horizon-1.0.0/lib" includes="*.jar"/>
<fileset dir="./lib/common" includes="*.jar"/>
<pathelement location="./lib/commons-logging.jar"/>
<pathelement location="${framework.output.dir}"/>
</classpath>
- <src path="./cache-products/starobrno/src"/>
+ <src path="./cache-products/Horizon-1.0.0/src"/>
</javac>
</target>
@@ -268,7 +268,7 @@
</target>
<target name="all"
- depends="clean, fwk, compile.module.jbosscache140, compile.module.jbosscache200, compile.module.pojocache220, compile.module.jbosscache210, compile.module.jbosscache220, compile.module.terracotta250, compile.module.ehcache150, compile.module.ehcache160, compile.module.whirlycache101, compile.module.jbosscache300, compile.module.coherence331, compile.module.starobrno"
+ depends="clean, fwk, compile.module.jbosscache140, compile.module.jbosscache200, compile.module.pojocache220, compile.module.jbosscache210, compile.module.jbosscache220, compile.module.terracotta250, compile.module.ehcache150, compile.module.ehcache160, compile.module.whirlycache101, compile.module.jbosscache300, compile.module.coherence331, compile.module.horizon"
description="build all"/>
<target name="checkClusterAddresses" depends="fwk"
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RC.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RC.xml (rev 0)
+++ benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RC.xml 2009-03-05 12:24:26 UTC (rev 7856)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<horizon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:horizon:config:1.0">
+ <default>
+ <locking concurrencyLevel="5000" isolationLevel="READ_COMMITTED" />
+ </default>
+</horizon>
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RR.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RR.xml (rev 0)
+++ benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/conf/local-RR.xml 2009-03-05 12:24:26 UTC (rev 7856)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<horizon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:horizon:config:1.0">
+ <default>
+ <locking concurrencyLevel="5000" isolationLevel="REPEATABLE_READ" />
+ </default>
+</horizon>
Copied: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/config.sh (from rev 7854, benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/config.sh)
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/config.sh (rev 0)
+++ benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/config.sh 2009-03-05 12:24:26 UTC (rev 7856)
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+#see "$CACHE_ROOT/cache-products/cache.sh" for details
+
+THIS_DIR="./cache-products/Horizon-1.0.0"
+
+#setting up classpath
+for JAR in $THIS_DIR/lib/*
+do
+ CLASSPATH=$CLASSPATH:$JAR
+done
+
+CLASSPATH="$CLASSPATH:./classes/production/horizon"
+CLASSPATH="$CLASSPATH:$THIS_DIR/conf"
+#--classpath was set
+
+#additional JVM options
+JVM_OPTIONS="$JVM_OPTIONS -Djava.net.preferIPv4Stack=true"
+JVM_OPTIONS="$JVM_OPTIONS -DcacheBenchFwk.cacheWrapperClassName=org.cachebench.cachewrappers.HorizonWrapper"
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/commons-logging.jar
===================================================================
(Binary files differ)
Property changes on: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/commons-logging.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
===================================================================
(Binary files differ)
Property changes on: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/horizon.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jboss-common-core.jar
===================================================================
(Binary files differ)
Property changes on: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jboss-common-core.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jboss-logging-spi.jar
===================================================================
(Binary files differ)
Property changes on: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jboss-logging-spi.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jcip-annotations.jar
===================================================================
(Binary files differ)
Property changes on: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jcip-annotations.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jgroups.jar
===================================================================
(Binary files differ)
Property changes on: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jgroups.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jta.jar
===================================================================
(Binary files differ)
Property changes on: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/lib/jta.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/org/cachebench/cachewrappers/HorizonWrapper.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/org/cachebench/cachewrappers/HorizonWrapper.java (rev 0)
+++ benchmarks/benchmark-fwk/trunk/cache-products/Horizon-1.0.0/src/org/cachebench/cachewrappers/HorizonWrapper.java 2009-03-05 12:24:26 UTC (rev 7856)
@@ -0,0 +1,106 @@
+package org.cachebench.cachewrappers;
+
+import org.cachebench.CacheWrapper;
+import org.horizon.Cache;
+import org.horizon.factories.DefaultCacheFactory;
+import org.horizon.manager.CacheManager;
+import org.horizon.manager.DefaultCacheManager;
+
+import javax.transaction.TransactionManager;
+import java.util.Map;
+import java.util.List;
+
+public class HorizonWrapper implements CacheWrapper
+{
+ CacheManager cacheManager;
+ Cache cache;
+ TransactionManager tm;
+ boolean started = false;
+ String config;
+
+ public void init(Map parameters) throws Exception
+ {
+ config = (String) parameters.get("config");
+ setUp();
+ }
+
+ public void setUp() throws Exception
+ {
+ if (!started)
+ {
+ cacheManager = new DefaultCacheManager(config);
+ // use the default cache
+ cache = cacheManager.getCache();
+ started = true;
+ }
+ }
+
+ public void tearDown() throws Exception
+ {
+ if (started)
+ {
+ cacheManager.stop();
+ started = false;
+ }
+ }
+
+ public void put(List<String> path, Object key, Object value) throws Exception
+ {
+ cache.put(key, value);
+ }
+
+ public Object get(List<String> path, Object key) throws Exception
+ {
+ return cache.get(key);
+ }
+
+ public void empty() throws Exception
+ {
+ cache.clear();
+ }
+
+ public int getNumMembers()
+ {
+ return cacheManager.getMembers() == null ? 0 : cacheManager.getMembers().size();
+ }
+
+ public String getInfo()
+ {
+ return cache.getVersion();
+ }
+
+ public Object getReplicatedData(List<String> path, String key) throws Exception
+ {
+ return get(null, key);
+ }
+
+ public Object startTransaction()
+ {
+ if (tm == null) return null;
+ try
+ {
+ tm.begin();
+ return tm.getTransaction();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void endTransaction(boolean successful)
+ {
+ if (tm == null) return;
+ try
+ {
+ if (successful)
+ tm.commit();
+ else
+ tm.rollback();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Modified: benchmarks/benchmark-fwk/trunk/runAllLocal.sh
===================================================================
--- benchmarks/benchmark-fwk/trunk/runAllLocal.sh 2009-03-05 11:44:03 UTC (rev 7855)
+++ benchmarks/benchmark-fwk/trunk/runAllLocal.sh 2009-03-05 12:24:26 UTC (rev 7856)
@@ -7,12 +7,18 @@
export PLAIN_JVM_OPTIONS="${JVM_OPTIONS} -DcacheBenchFwk.fwkCfgFile=cachebench-local.xml -Xms2g -Xmx2g"
unset JVM_OPTIONS && export JVM_OPTIONS="${PLAIN_JVM_OPTIONS} -DcacheBenchFwk.productSuffix=(3.0.3.GA)"
./runLocalNode.sh jbosscache-3.0.0 mvcc-local-RC.xml
+unset JVM_OPTIONS && export JVM_OPTIONS="${PLAIN_JVM_OPTIONS} -DcacheBenchFwk.productSuffix=(3.0.3.GA)"
+./runLocalNode.sh jbosscache-3.0.0 mvcc-local-RR.xml
unset JVM_OPTIONS && export JVM_OPTIONS="${PLAIN_JVM_OPTIONS}"
./runLocalNode.sh ehcache-1.5.0 ehcache-local.xml
unset JVM_OPTIONS && export JVM_OPTIONS="${PLAIN_JVM_OPTIONS} -DcacheBenchFwk.productSuffix=(1.6.0.Beta3)"
./runLocalNode.sh ehcache-1.6.0 ehcache-local.xml
unset JVM_OPTIONS && export JVM_OPTIONS="${PLAIN_JVM_OPTIONS}"
./runLocalNode.sh whirlycache-1.0.1
+unset JVM_OPTIONS && export JVM_OPTIONS="${PLAIN_JVM_OPTIONS} -DcacheBenchFwk.productSuffix=(1.0.0.M1)"
+./runLocalNode.sh Horizon-1.0.0 local-RC.xml
+unset JVM_OPTIONS && export JVM_OPTIONS="${PLAIN_JVM_OPTIONS} -DcacheBenchFwk.productSuffix=(1.0.0.M1)"
+./runLocalNode.sh Horizon-1.0.0 local-RR.xml
mkdir output
mv data* ./output
15 years, 9 months