JBoss Cache SVN: r6388 - benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-07-23 20:53:25 -0400 (Wed, 23 Jul 2008)
New Revision: 6388
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java
Log:
bug fixing
Modified: benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java 2008-07-24 00:48:02 UTC (rev 6387)
+++ benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java 2008-07-24 00:53:25 UTC (rev 6388)
@@ -27,17 +27,17 @@
String trimmedConfig = configuraton.trim();
if (trimmedConfig.indexOf("repl") == 0)
{
- cache = CacheFactory.getCache("replicatedCache");
+ cache = CacheFactory.getCache("repl-CacheBenchmarkFramework");
}
if (trimmedConfig.indexOf("dist") == 0)
{
- cache = CacheFactory.getCache("replicatedCache");
+ cache = CacheFactory.getCache("dist-CacheBenchmarkFramework");
}
throw new RuntimeException("Invalid configuration ('" + trimmedConfig + "'). Configuration name should start with: 'dist' or 'repl'");
}
public void tearDown() throws Exception {
- cache.release();
+ if (cache != null) cache.release();
}
public void put(List<String> path, Object key, Object value) throws Exception {
16 years, 1 month
JBoss Cache SVN: r6387 - benchmarks/benchmark-fwk/trunk/src/org/cachebench.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-07-23 20:48:02 -0400 (Wed, 23 Jul 2008)
New Revision: 6387
Modified:
benchmarks/benchmark-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
Log:
setup shouled be run before warmup
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2008-07-24 00:24:57 UTC (rev 6386)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2008-07-24 00:48:02 UTC (rev 6387)
@@ -155,12 +155,9 @@
cache = newCache(test);
if (cache != null)
{
- if (!localOnly) barrier("BEFORE_WARMUP");
- warmupCache(test, cache);
- if (!localOnly) barrier("AFTER_WARMUP");
-
//now start testing
cache.setUp();
+ warmupCache(test, cache);
List<TestResult> resultsForCache = runTestsOnCache(cache, test);
if (!localOnly) barrier("AFTER_TEST_RUN");
shutdownCache(cache);
@@ -198,6 +195,7 @@
private void warmupCache(TestCase test, CacheWrapper cache) throws Exception
{
+ if (!localOnly) barrier("BEFORE_WARMUP");
log.info("Warming up..");
CacheWarmupConfig warmupConfig = test.getCacheWarmupConfig();
log.trace("Warmup config is: " + warmupConfig);
@@ -205,6 +203,7 @@
warmup.setConfigParams(warmupConfig.getParams());
warmup.warmup(cache);
log.info("Warmup ended!");
+ if (!localOnly) barrier("AFTER_WARMUP");
}
/**
16 years, 1 month
JBoss Cache SVN: r6386 - in benchmarks/benchmark-fwk/trunk: cache-products/coherence-3.3.1 and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-07-23 20:24:57 -0400 (Wed, 23 Jul 2008)
New Revision: 6386
Added:
benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/config.sh
benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java
Removed:
benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/CoherenceWrapper.java
Modified:
benchmarks/benchmark-fwk/trunk/build.xml
benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/conf/cache-config.xml
Log:
updated TC config and added both replicated and distributed tests
Modified: benchmarks/benchmark-fwk/trunk/build.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/build.xml 2008-07-23 20:41:02 UTC (rev 6385)
+++ benchmarks/benchmark-fwk/trunk/build.xml 2008-07-24 00:24:57 UTC (rev 6386)
@@ -94,18 +94,18 @@
</javac>
</target>
- <target name="compile.module.coherence322" depends="compile.module.framework"
- description="Compile module coherence322; production classes">
- <mkdir dir="./classes/production/coherence-3.2.2"/>
- <javac destdir="./classes/production/coherence-3.2.2" debug="${compiler.debug}"
+ <target name="compile.module.coherence331" depends="compile.module.framework"
+ description="Compile module coherence331; production classes">
+ <mkdir dir="./classes/production/coherence-3.3.1"/>
+ <javac destdir="./classes/production/coherence-3.3.1" debug="${compiler.debug}"
nowarn="${compiler.generate.no.warnings}" fork="true">
<classpath>
- <fileset dir="./cache-products/coherence-3.2.2/lib" includes="*.jar"/>
- <pathelement location="./cache-products/coherence-3.2.2/conf"/>
+ <fileset dir="./cache-products/coherence-3.3.1/lib" includes="*.jar"/>
+ <pathelement location="./cache-products/coherence-3.3.1/conf"/>
<pathelement location="${framework.output.dir}"/>
- <pathelement location="./classes/production/coherence-3.2.2"/>
+ <pathelement location="./classes/production/coherence-3.3.1"/>
</classpath>
- <src path="./cache-products/coherence-3.2.2"/>
+ <src path="./cache-products/coherence-3.3.1"/>
</javac>
</target>
@@ -214,7 +214,7 @@
</target>
<target name="all"
- depends="clean, compile.module.framework, compile.module.jbosscache140, compile.module.jbosscache200, compile.module.jbosscache210, compile.module.jbosscache220, compile.module.terracotta250, compile.module.ehcache141, compile.module.whirlycache101, compile.module.jbosscache300"
+ depends="clean, compile.module.framework, compile.module.coherence331, compile.module.jbosscache140, compile.module.jbosscache200, compile.module.jbosscache210, compile.module.jbosscache220, compile.module.terracotta250, compile.module.ehcache141, compile.module.whirlycache101, compile.module.jbosscache300"
description="build all"/>
<target name="checkClusterAddresses" depends="compile.module.framework"
Modified: benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/conf/cache-config.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/conf/cache-config.xml 2008-07-23 20:41:02 UTC (rev 6385)
+++ benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/conf/cache-config.xml 2008-07-24 00:24:57 UTC (rev 6386)
@@ -1,42 +1,53 @@
<?xml version="1.0"?>
+
<!DOCTYPE cache-config SYSTEM "cache-config.dtd">
<cache-config>
- <caching-scheme-mapping>
- <!--
- Caches with any name will be created as default replicated.
- -->
- <cache-mapping>
- <cache-name>*</cache-name>
- <scheme-name>default-replicated</scheme-name>
- </cache-mapping>
- </caching-scheme-mapping>
+ <caching-scheme-mapping>
+ <cache-mapping>
+ <cache-name>repl-*</cache-name>
+ <scheme-name>default-replicated</scheme-name>
+ </cache-mapping>
- <caching-schemes>
- <!--
- Default Replicated caching scheme.
- -->
- <replicated-scheme>
- <scheme-name>default-replicated</scheme-name>
- <service-name>ReplicatedCache</service-name>
+ <cache-mapping>
+ <cache-name>dist-*</cache-name>
+ <scheme-name>default-distributed</scheme-name>
+ </cache-mapping>
+ </caching-scheme-mapping>
- <backing-map-scheme>
- <class-scheme>
- <scheme-ref>default-backing-map</scheme-ref>
- </class-scheme>
- </backing-map-scheme>
- </replicated-scheme>
+ <caching-schemes>
+ <!--
+ Default Replicated caching scheme.
+ -->
+ <replicated-scheme>
+ <scheme-name>default-replicated</scheme-name>
+ <service-name>ReplicatedCache</service-name>
+ <backing-map-scheme>
+ <class-scheme>
+ <scheme-ref>default-backing-map</scheme-ref>
+ </class-scheme>
+ </backing-map-scheme>
+ </replicated-scheme>
- <!--
- Default backing map scheme definition used by all
- The caches that do not require any eviction policies
- -->
- <class-scheme>
- <scheme-name>default-backing-map</scheme-name>
+ <distributed-scheme>
+ <scheme-name>default-distributed</scheme-name>
+ <service-name>DistributedCache</service-name>
- <class-name>com.tangosol.util.SafeHashMap</class-name>
- </class-scheme>
+ <backing-map-scheme>
+ <class-scheme>
+ <scheme-ref>default-backing-map</scheme-ref>
+ </class-scheme>
+ </backing-map-scheme>
+ </distributed-scheme>
- </caching-schemes>
-</cache-config>
+ <!--
+ Default backing map scheme definition used by all
+ The caches that do not require any eviction policies
+ -->
+ <class-scheme>
+ <scheme-name>default-backing-map</scheme-name>
+ <class-name>com.tangosol.util.SafeHashMap</class-name>
+ </class-scheme>
+ </caching-schemes>
+</cache-config>
\ No newline at end of file
Added: benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/config.sh
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/config.sh (rev 0)
+++ benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/config.sh 2008-07-24 00:24:57 UTC (rev 6386)
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+#see "$CACHE_ROOT/cache-products/cache.sh" for details
+
+THIS_DIR="./cache-products/coherence-3.3.1"
+
+#setting up classpath
+for JAR in $THIS_DIR/lib/*
+do
+ CLASSPATH=$CLASSPATH:$JAR
+done
+
+CLASSPATH="$CLASSPATH:./classes/production/coherence-3.3.1"
+CLASSPATH="$THIS_DIR/conf:$CLASSPATH"
+#--classpath was set
+
+#additional JVM options
+JVM_OPTIONS="$JVM_OPTIONS -Xmx2048m -Djava.net.preferIPv4Stack=true -Dtangosol.coherence.localhost=${MYTESTIP_1}"
+JVM_OPTIONS="-Dtangosol.coherence.cacheconfig=cache-config.xml"
+JVM_OPTIONS="$JVM_OPTIONS -DcacheBenchFwk.cacheWrapperClassName=org.cachebench.cachewrappers.Coherence331Wrapper"
\ No newline at end of file
Copied: benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java (from rev 6385, benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/CoherenceWrapper.java)
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java (rev 0)
+++ benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java 2008-07-24 00:24:57 UTC (rev 6386)
@@ -0,0 +1,77 @@
+package org.cachebench.cachewrappers;
+
+import org.cachebench.CacheWrapper;
+
+import java.util.List;
+import java.util.Map;
+
+import com.tangosol.net.NamedCache;
+import com.tangosol.net.CacheFactory;
+
+/**
+ * Pass in a -Dtangosol.coherence.localhost=IP_ADDRESS
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.0.0
+ */
+public class Coherence331Wrapper implements CacheWrapper
+{
+
+ private NamedCache cache;
+
+ public void init(Map parameters) throws Exception {
+ }
+
+ public void setUp() throws Exception {
+ String configuraton = System.getProperty("cacheBenchFwk.cacheConfigFile");
+ String trimmedConfig = configuraton.trim();
+ if (trimmedConfig.indexOf("repl") == 0)
+ {
+ cache = CacheFactory.getCache("replicatedCache");
+ }
+ if (trimmedConfig.indexOf("dist") == 0)
+ {
+ cache = CacheFactory.getCache("replicatedCache");
+ }
+ throw new RuntimeException("Invalid configuration ('" + trimmedConfig + "'). Configuration name should start with: 'dist' or 'repl'");
+ }
+
+ public void tearDown() throws Exception {
+ cache.release();
+ }
+
+ public void put(List<String> path, Object key, Object value) throws Exception {
+ cache.put(pathAsString(path, key), value);
+ }
+
+ public Object get(List<String> path, Object key) throws Exception {
+ return cache.get( pathAsString(path, key));
+ }
+
+ public void empty() throws Exception {
+ cache.clear();
+ }
+
+ public int getNumMembers() {
+ return cache.getCacheService().getCluster().getMemberSet().size();
+ }
+
+ public String getInfo() {
+ return null;
+ }
+
+ public Object getReplicatedData(List<String> path, String key) throws Exception {
+ return get(path, key);
+ }
+
+ private String pathAsString(List<String> path, Object key)
+ {
+ StringBuilder result = new StringBuilder();
+ for (String element : path)
+ {
+ result.append(element);
+ }
+ result.append(key);
+ return result.toString();
+ }
+}
Deleted: benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/CoherenceWrapper.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/CoherenceWrapper.java 2008-07-23 20:41:02 UTC (rev 6385)
+++ benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/CoherenceWrapper.java 2008-07-24 00:24:57 UTC (rev 6386)
@@ -1,63 +0,0 @@
-package org.cachebench.cachewrappers;
-
-import com.tangosol.net.CacheFactory;
-import com.tangosol.net.NamedCache;
-import org.cachebench.CacheWrapper;
-
-import java.util.Map;
-
-/**
- * Pass in a -Dtangosol.coherence.localhost=IP_ADDRESS
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
- * @since 2.0.0
- */
-public class CoherenceWrapper implements CacheWrapper
-{
- NamedCache cache;
-
- public void init(Map parameters) throws Exception
- {
- cache = CacheFactory.getReplicatedCache();
-// cache = CacheFactory.getCache("VirtualCache");
- }
-
- public void setUp() throws Exception
- {
- }
-
- public void tearDown() throws Exception
- {
- cache.release();
- }
-
- 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 cache.getCacheService().getCluster().getMemberSet().size();
- }
-
- public String getInfo()
- {
- return cache.keySet().toString();
- }
-
- public Object getReplicatedData(List<String> path, String key) throws Exception
- {
- return get(path, key);
- }
-}
16 years, 1 month
JBoss Cache SVN: r6385 - in core/trunk/src/main/java/org/jboss/cache: util/concurrent and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-23 16:41:02 -0400 (Wed, 23 Jul 2008)
New Revision: 6385
Added:
core/trunk/src/main/java/org/jboss/cache/util/concurrent/SelfInitializingConcurrentHashMap.java
Modified:
core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
Log:
lazy initialization of child map
Modified: core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java 2008-07-23 16:15:03 UTC (rev 6384)
+++ core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java 2008-07-23 20:41:02 UTC (rev 6385)
@@ -86,6 +86,7 @@
{
PessimisticUnversionedNode<K, V> n = new PessimisticUnversionedNode<K, V>(fqn.getLastElement(), fqn, data, cache);
copyInternals(n);
+ n.children = children;
n.lockStrategyFactory = lockStrategyFactory;
return n;
}
@@ -100,7 +101,7 @@
{
synchronized (this)
{
- children().put(child.getFqn().getLastElement(), child);
+ children.put(child.getFqn().getLastElement(), child);
}
}
else
@@ -116,7 +117,7 @@
throw new IllegalArgumentException("null child name");
}
- child = (NodeSPI<K, V>) children().get(childName);
+ child = (NodeSPI<K, V>) children.get(childName);
InvocationContext ctx = cache.getInvocationContext();
if (createIfNotExists && child == null)
{
@@ -132,7 +133,7 @@
{
// check again to see if the child exists
// after acquiring exclusive lock
- child = (NodeSPI<K, V>) children().get(childName);
+ child = (NodeSPI<K, V>) children.get(childName);
if (child == null)
{
if (notify) cache.getNotifier().notifyNodeCreated(childFqn, true, ctx);
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-23 16:15:03 UTC (rev 6384)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-23 20:41:02 UTC (rev 6385)
@@ -17,6 +17,7 @@
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.util.ImmutableSetCopy;
+import org.jboss.cache.util.concurrent.SelfInitializingConcurrentHashMap;
import java.util.Collections;
import java.util.HashMap;
@@ -24,7 +25,6 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
/**
* Basic data node class. Throws {@link UnsupportedOperationException} for version-specific methods like {@link #getVersion()} and
@@ -82,7 +82,15 @@
setLockForChildInsertRemove(lockForChildInsertRemove);
this.fqn = fqn;
// if this is a root node, create the child map.
- if (fqn.isRoot()) children = new ConcurrentHashMap<Object, Node<K, V>>(64, .5f, 16);
+ if (fqn.isRoot())
+ {
+ children = new ConcurrentHashMap<Object, Node<K, V>>(64, .5f, 16);
+ }
+ else
+ {
+ // this always needs to be initialized. The actual cost of the ConcurrentHashMap, however, is deferred.
+ children = new SelfInitializingConcurrentHashMap<Object, Node<K, V>>();
+ }
}
public UnversionedNode(Fqn fqn, CacheSPI<K, V> cache, boolean lockForChildInsertRemove, Map<K, V> data)
@@ -130,21 +138,6 @@
return cache.peek(fqn.getParent(), true);
}
- protected final ConcurrentMap<Object, Node<K, V>> children()
- {
- if (children == null) initChildMap();
- return children;
- }
-
- private synchronized void initChildMap()
- {
- if (children == null)
- {
- // Fewer segments to save memory
- children = new ConcurrentHashMap<Object, Node<K, V>>(4, .75f, 4);
- }
- }
-
// does not need to be synchronized since this will only be accessed by a single thread in MVCC thanks to the write lock.
private void initDataMap()
{
@@ -202,14 +195,14 @@
throw new IllegalArgumentException("null child name");
}
- child = (NodeSPI<K, V>) children().get(childName);
+ child = (NodeSPI<K, V>) children.get(childName);
InvocationContext ctx = cache.getInvocationContext();
if (createIfNotExists && child == null)
{
Fqn childFqn = Fqn.fromRelativeElements(fqn, childName);
NodeSPI<K, V> newChild = nodeFactory.createNode(childFqn, delegate);
- child = (NodeSPI<K, V>) children().putIfAbsent(childName, newChild);
+ child = (NodeSPI<K, V>) children.putIfAbsent(childName, newChild);
if (child == null)
{
@@ -349,7 +342,7 @@
Fqn childFqn = child.getFqn();
if (childFqn.isDirectChildOf(fqn))
{
- children().put(childFqn.getLastElement(), child);
+ children.put(childFqn.getLastElement(), child);
}
else
{
@@ -449,7 +442,7 @@
this.children = null;
else
{
- this.children().clear();
+ this.children.clear();
this.children.putAll(children);
}
}
@@ -500,7 +493,7 @@
{
if (childName != null)
{
- children().put(childName, n);
+ children.put(childName, n);
}
}
@@ -632,7 +625,7 @@
if (trace) log.trace("Marking node " + getFqn() + " as " + (valid ? "" : "in") + "valid");
if (recursive)
{
- for (Node<K, V> child : children().values())
+ for (Node<K, V> child : children.values())
{
((NodeSPI<K, V>) child).setValid(valid, recursive);
}
@@ -661,7 +654,7 @@
protected void copyInternals(UnversionedNode n)
{
// direct reference to child map
- n.children = children();
+ n.children = children;
n.commandsFactory = commandsFactory;
n.delegate = delegate;
n.nodeFactory = nodeFactory;
Added: core/trunk/src/main/java/org/jboss/cache/util/concurrent/SelfInitializingConcurrentHashMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/concurrent/SelfInitializingConcurrentHashMap.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/util/concurrent/SelfInitializingConcurrentHashMap.java 2008-07-23 20:41:02 UTC (rev 6385)
@@ -0,0 +1,192 @@
+package org.jboss.cache.util.concurrent;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Primarily used to hold child maps for nodes. Underlying CHM is null initially, and once threads start
+ * writing to this map, the CHM is initialized.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class SelfInitializingConcurrentHashMap<K, V> implements ConcurrentMap<K, V>
+{
+ private volatile ConcurrentMap<K, V> delegate;
+// private int initialCapacity = -1, concurrencyLevel = -1;
+// private float loadFactor = -1;
+
+ /**
+ * Creates a new delegate map and will use a default constructor to initialize the {@link java.util.concurrent.ConcurrentMap}
+ * it will eventually delegate to.
+ */
+ public SelfInitializingConcurrentHashMap()
+ {
+
+ }
+
+ /**
+ * Creates a new delegate map and will use the params passed in to initialize the {@link java.util.concurrent.ConcurrentMap}
+ * it will eventually delegate to.
+ *
+ * @param initialCapacity the initial capacity. The implementation
+ * performs internal sizing to accommodate this many elements.
+ * @param loadFactor the load factor threshold, used to control resizing.
+ * Resizing may be performed when the average number of elements per
+ * bin exceeds this threshold.
+ * @param concurrencyLevel the estimated number of concurrently
+ * updating threads. The implementation performs internal sizing
+ * to try to accommodate this many threads.
+ * @throws IllegalArgumentException if the initial capacity is
+ * negative or the load factor or concurrencyLevel are
+ * nonpositive.
+ */
+// public SelfInitializingConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
+// {
+// this.initialCapacity = initialCapacity;
+// this.loadFactor = loadFactor;
+// this.concurrencyLevel = concurrencyLevel;
+// }
+
+ // -------------- initialization methods and helpers ----------------------
+ private ConcurrentMap<K, V> getDelegate()
+ {
+ if (delegate == null) init();
+ return delegate;
+ }
+
+ private synchronized void init()
+ {
+ // Reminiscent of DCL but the delegate here is volatile so construction reordering should not affect.
+ if (delegate == null)
+ {
+ delegate = new ConcurrentHashMap<K, V>(4, 0.75f, 4);
+ // hard-coded for node child maps for now
+
+// if (initialCapacity == -1 || concurrencyLevel == -1 || loadFactor == -1)
+// {
+// delegate = new ConcurrentHashMap<K, V>();
+// }
+// else
+// {
+// delegate = new ConcurrentHashMap<K, V>(initialCapacity, loadFactor, concurrencyLevel);
+// }
+ }
+ }
+
+ // -------------- Public API methods that will trigger initialization ----------------------
+
+ public final V put(K key, V value)
+ {
+ return getDelegate().put(key, value);
+ }
+
+ public final V remove(Object key)
+ {
+ return getDelegate().remove(key);
+ }
+
+ public final void putAll(Map<? extends K, ? extends V> m)
+ {
+ getDelegate().putAll(m);
+ }
+
+ public final V putIfAbsent(K key, V value)
+ {
+ return getDelegate().putIfAbsent(key, value);
+ }
+
+ public final boolean replace(K key, V oldValue, V newValue)
+ {
+ return getDelegate().replace(key, oldValue, newValue);
+ }
+
+ public final V replace(K key, V value)
+ {
+ return getDelegate().replace(key, value);
+ }
+
+ // -------------- Public API methods that won't trigger initialization ----------------------
+
+ public final boolean remove(Object key, Object value)
+ {
+ return delegate != null && delegate.remove(key, value);
+ }
+
+ public final int size()
+ {
+ return delegate == null ? 0 : delegate.size();
+ }
+
+ public final boolean isEmpty()
+ {
+ return delegate == null || delegate.isEmpty();
+ }
+
+ public final boolean containsKey(Object key)
+ {
+ return delegate != null && delegate.containsKey(key);
+ }
+
+ public final boolean containsValue(Object value)
+ {
+ return delegate != null && delegate.containsValue(value);
+ }
+
+ public final V get(Object key)
+ {
+ return delegate == null ? null : delegate.get(key);
+ }
+
+ public final void clear()
+ {
+ if (delegate != null) delegate.clear();
+ }
+
+ public final Set<K> keySet()
+ {
+ if (delegate == null) return Collections.emptySet();
+ return delegate.keySet();
+ }
+
+ public final Collection<V> values()
+ {
+ if (delegate == null) return Collections.emptySet();
+ return delegate.values();
+ }
+
+ public final Set<Entry<K, V>> entrySet()
+ {
+ if (delegate == null) return Collections.emptySet();
+ return delegate.entrySet();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SelfInitializingConcurrentHashMap{" +
+ "delegate=" + delegate +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ SelfInitializingConcurrentHashMap that = (SelfInitializingConcurrentHashMap) o;
+ return !(delegate != null ? !delegate.equals(that.delegate) : that.delegate != null);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (delegate != null ? delegate.hashCode() : 0);
+ return result;
+ }
+}
16 years, 1 month
JBoss Cache SVN: r6384 - core/trunk/src/main/java/org/jboss/cache/util.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-23 12:15:03 -0400 (Wed, 23 Jul 2008)
New Revision: 6384
Modified:
core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java
Log:
Made inner class static
Modified: core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java 2008-07-23 16:06:20 UTC (rev 6383)
+++ core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java 2008-07-23 16:15:03 UTC (rev 6384)
@@ -66,7 +66,7 @@
return new ImmutableSetCopy<Map.Entry<K, V>>(table);
}
- private class ImmutableEntry<K, V> implements Map.Entry<K, V>
+ private static class ImmutableEntry<K, V> implements Map.Entry<K, V>
{
K k;
V v;
16 years, 1 month
JBoss Cache SVN: r6383 - benchmarks/benchmark-fwk/trunk/conf.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-23 12:06:20 -0400 (Wed, 23 Jul 2008)
New Revision: 6383
Modified:
benchmarks/benchmark-fwk/trunk/conf/log4j.xml
Log:
Reduce log level for products being tested
Modified: benchmarks/benchmark-fwk/trunk/conf/log4j.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/conf/log4j.xml 2008-07-23 16:03:13 UTC (rev 6382)
+++ benchmarks/benchmark-fwk/trunk/conf/log4j.xml 2008-07-23 16:06:20 UTC (rev 6383)
@@ -49,19 +49,19 @@
</category>
<category name="net.sf.ehcache">
- <priority value="WARN"/>
+ <priority value="ERROR"/>
</category>
<category name="com.tc">
- <priority value="WARN"/>
+ <priority value="ERROR"/>
</category>
<category name="org.tc">
- <priority value="WARN"/>
+ <priority value="ERROR"/>
</category>
<category name="org.jboss.cache">
- <priority value="INFO"/>
+ <priority value="ERROR"/>
</category>
<!-- Here goes the root -->
16 years, 1 month
JBoss Cache SVN: r6382 - benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-23 12:03:13 -0400 (Wed, 23 Jul 2008)
New Revision: 6382
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
Log:
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
===================================================================
(Binary files differ)
16 years, 1 month
JBoss Cache SVN: r6381 - in benchmarks/benchmark-fwk/trunk/cache-products: jbosscache-3.0.0/src/org/cachebench/cachewrappers and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-23 12:02:31 -0400 (Wed, 23 Jul 2008)
New Revision: 6381
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/ehcache-1.5.0/src/org/cachebench/cachewrappers/EHCacheWrapper.java
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/src/org/cachebench/cachewrappers/JBossCache300Wrapper.java
Log:
Fixed EHCache issues
Modified: benchmarks/benchmark-fwk/trunk/cache-products/ehcache-1.5.0/src/org/cachebench/cachewrappers/EHCacheWrapper.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/ehcache-1.5.0/src/org/cachebench/cachewrappers/EHCacheWrapper.java 2008-07-23 15:25:17 UTC (rev 6380)
+++ benchmarks/benchmark-fwk/trunk/cache-products/ehcache-1.5.0/src/org/cachebench/cachewrappers/EHCacheWrapper.java 2008-07-23 16:02:31 UTC (rev 6381)
@@ -29,12 +29,14 @@
private CacheManager manager;
private Ehcache cache;
private Log logger = LogFactory.getLog("org.cachebench.cachewrappers.EHCacheWrapper");
+ boolean localmode;
/* (non-Javadoc)
* @see org.cachebench.CacheWrapper#init(java.util.Properties)
*/
public void init(Map parameters) throws Exception
{
+ localmode = (Boolean.parseBoolean((String) parameters.get("localOnly")));
logger.debug("Initializing the cache with props " + parameters);
URL url = getClass().getClassLoader().getResource((String) parameters.get("config"));
logger.debug("Config URL = " + url);
@@ -98,8 +100,11 @@
for (String s : manager.getCacheNames()) logger.info(" * " + s);
cache = manager.getCache("cache");
logger.info("Using named cache " + cache);
- logger.info("Bounded peers: " + manager.getCachePeerListener().getBoundCachePeers());
- logger.info("Remote peers: " + manager.getCacheManagerPeerProvider().listRemoteCachePeers(cache));
+ if (!localmode)
+ {
+ logger.info("Bounded peers: " + manager.getCachePeerListener().getBoundCachePeers());
+ logger.info("Remote peers: " + manager.getCacheManagerPeerProvider().listRemoteCachePeers(cache));
+ }
}
/* (non-Javadoc)
@@ -155,12 +160,13 @@
public int getNumMembers()
{
- return manager.getCacheManagerPeerProvider().listRemoteCachePeers(cache).size();
+
+ return localmode ? 0 : manager.getCacheManagerPeerProvider().listRemoteCachePeers(cache).size();
}
public String getInfo()
{
- return cache.getKeys().toString() + " remote peers: " + manager.getCachePeerListener().getBoundCachePeers();
+ return cache.getKeys().toString() + (localmode ? "" : (" remote peers: " + manager.getCachePeerListener().getBoundCachePeers()));
}
public Object getReplicatedData(List<String> path, String key) throws Exception
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/src/org/cachebench/cachewrappers/JBossCache300Wrapper.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/src/org/cachebench/cachewrappers/JBossCache300Wrapper.java 2008-07-23 15:25:17 UTC (rev 6380)
+++ benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/src/org/cachebench/cachewrappers/JBossCache300Wrapper.java 2008-07-23 16:02:31 UTC (rev 6381)
@@ -24,8 +24,8 @@
log.info("Creating cache with the following configuration: " + parameters);
cache = new DefaultCacheFactory().createCache((String) parameters.get("config"));
log.info("Running cache with following config: " + cache.getConfiguration());
- log.info("Running follwing JBossCacheVersion: " + org.jboss.cache.Version.version);
- log.info("Running follwing JBossCacheCodeName: " + org.jboss.cache.Version.codename);
+ log.info("Running following JBossCacheVersion: " + org.jboss.cache.Version.version);
+ log.info("Running following JBossCacheCodeName: " + org.jboss.cache.Version.codename);
}
public void setUp() throws Exception
16 years, 1 month
JBoss Cache SVN: r6380 - in core/branches/2.2.X/src: main/java/org/jboss/cache/buddyreplication and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-23 11:25:17 -0400 (Wed, 23 Jul 2008)
New Revision: 6380
Added:
core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableListCopy.java
core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java
core/branches/2.2.X/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/Fqn.java
core/branches/2.2.X/src/main/java/org/jboss/cache/UnversionedNode.java
core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java
core/branches/2.2.X/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
core/branches/2.2.X/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
Log:
Performance tweaks using custom immutable collections
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/Fqn.java 2008-07-23 15:21:40 UTC (rev 6379)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/Fqn.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -10,6 +10,7 @@
import net.jcip.annotations.Immutable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.util.ImmutableListCopy;
import java.io.Externalizable;
import java.io.IOException;
@@ -124,12 +125,7 @@
if (names != null)
{
// if not safe make a defensive copy
- elements = safe ? names : new ArrayList(names);
- if (elements.size() > 0)
- {
- if (SEPARATOR.equals(elements.get(0))) elements.remove(0);
- if ("".equals(elements.get(0))) elements.remove(0);
- }
+ elements = safe ? names : new ImmutableListCopy(names);
size = elements.size();
}
else
@@ -142,10 +138,7 @@
@SuppressWarnings("unchecked")
protected Fqn(boolean internalMarker, Fqn<?> base, List<?> relative)
{
- List elements = new ArrayList(base.elements.size() + relative.size());
- elements.addAll(base.elements);
- elements.addAll(relative);
- this.elements = elements;
+ elements = new ImmutableListCopy(base.elements, relative);
size = elements.size();
}
@@ -344,12 +337,12 @@
@SuppressWarnings("unchecked")
public static Fqn<String> fromString(String stringRepresentation)
{
- if (stringRepresentation == null || stringRepresentation.equals(SEPARATOR))
- {
- return ROOT;
- }
- List<String> elements = Arrays.asList(stringRepresentation.split("/"));
- return new Fqn(true, elements, false);
+ if (stringRepresentation == null || stringRepresentation.equals(SEPARATOR) || stringRepresentation.equals(""))
+ return root();
+
+ String toMatch = stringRepresentation.startsWith(SEPARATOR) ? stringRepresentation.substring(1) : stringRepresentation;
+ Object[] el = toMatch.split("/");
+ return new Fqn(new ImmutableListCopy(el), true);
}
/**
@@ -554,6 +547,17 @@
}
/**
+ * Returns true if this Fqn is a <i>direct</i> child of a given Fqn.
+ *
+ * @param parentFqn parentFqn to compare with
+ * @return true if this is a direct child, false otherwise.
+ */
+ public boolean isDirectChildOf(Fqn parentFqn)
+ {
+ return size == parentFqn.size() - 1 && isChildOf(parentFqn);
+ }
+
+ /**
* Returns true if this Fqn is equals or the child of parentFqn.
* Example usage:
* <pre>
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-23 15:21:40 UTC (rev 6379)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/UnversionedNode.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -16,7 +16,9 @@
import org.jboss.cache.marshall.MarshalledValue;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.util.ImmutableSetCopy;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -419,11 +421,12 @@
public void addChildDirect(NodeSPI child)
{
- if (child.getFqn().getParent().equals(getFqn()))
+ Fqn childFqn = child.getFqn();
+ if (childFqn.isDirectChildOf(fqn))
{
synchronized (this)
{
- children().put(child.getFqn().getLastElement(), child);
+ children().put(childFqn.getLastElement(), child);
}
}
else
@@ -490,7 +493,7 @@
{
return Collections.emptySet();
}
- return Collections.unmodifiableSet(new HashSet<Object>(data.keySet()));
+ return new ImmutableSetCopy(data.keySet());
}
public boolean removeChildDirect(Object childName)
@@ -643,7 +646,7 @@
{
if (children != null && !children.isEmpty())
{
- return Collections.unmodifiableSet(new HashSet(children.values()));
+ return new ImmutableSetCopy<NodeSPI>((Collection) children.values());
}
else
{
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-07-23 15:21:40 UTC (rev 6379)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -130,7 +130,7 @@
public boolean isDeadBackupRoot(Fqn f)
{
- return f.getParent().equals(BUDDY_BACKUP_SUBTREE_FQN) && f.getLastElementAsString().endsWith(":DEAD");
+ return f.isDirectChildOf(BUDDY_BACKUP_SUBTREE_FQN) && f.getLastElementAsString().endsWith(":DEAD");
}
public String getGroupNameFromAddress(Address address)
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java 2008-07-23 15:21:40 UTC (rev 6379)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -7,12 +7,11 @@
package org.jboss.cache.buddyreplication;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.cache.util.ImmutableListCopy;
import org.jgroups.Address;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Vector;
@@ -66,7 +65,7 @@
public List<Address> getBuddies()
{
// defensive copy and immutable.
- return Collections.unmodifiableList(new ArrayList<Address>(buddies));
+ return new ImmutableListCopy<Address>(buddies);
}
protected void addBuddies(Collection<Address> buddies)
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java 2008-07-23 15:21:40 UTC (rev 6379)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/commands/remote/DataGravitationCleanupCommand.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -84,7 +84,7 @@
// only attempt to clean up the backup if the primary did not exist - a waste of a call otherwise.
Object result = executeRemove(gtx, backup);
if (wasNodeRemoved(result) &&
- buddyFqnTransformer.isDeadBackupFqn(backup) && buddyFqnTransformer.isDeadBackupRoot(backup.getParent().getParent()))
+ buddyFqnTransformer.isDeadBackupFqn(backup) && buddyFqnTransformer.isDeadBackupRoot(backup.getAncestor(backup.size() - 2)))
{
// if this is a DIRECT child of a DEAD buddy backup region, then remove the empty dead region structural node.
NodeSPI deadBackupRoot = dataContainer.peek(backup.getParent(), false);
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-07-23 15:21:40 UTC (rev 6379)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -39,12 +39,12 @@
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.util.ImmutableSetCopy;
import org.jgroups.Address;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -560,7 +560,7 @@
GetChildrenNamesCommand command = commandsFactory.buildGetChildrenNamesCommand(fqn);
Set<E> retval = (Set<E>) invoker.invoke(ctx, command);
if (retval != null)
- retval = Collections.unmodifiableSet(new HashSet<E>(retval));
+ retval = new ImmutableSetCopy<E>(retval);
else
retval = Collections.emptySet();
return retval;
Added: core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableListCopy.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableListCopy.java (rev 0)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableListCopy.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -0,0 +1,426 @@
+package org.jboss.cache.util;
+
+import net.jcip.annotations.Immutable;
+
+import java.lang.reflect.Array;
+import java.util.AbstractList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+/**
+ * A lightweight, read-only copy of a List. Typically used in place of the common idiom:
+ * <code>
+ * return Collections.unmodifiableList(new ArrayList( myInternalList ));
+ * </code>
+ * <p/>
+ * a it is far more efficient than making a defensive copy and then wrapping the defensive copy in a read-only wrapper.
+ * <p/>
+ * Also used whenever a read-only reference List is needed (such as in Fqns).
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ */
+@Immutable
+public class ImmutableListCopy<E> extends AbstractList<E>
+{
+ private final E[] elements;
+ private final int size;
+
+ /**
+ * Only one copy constructor since the list is immutable.
+ *
+ * @param c collection to copy from
+ */
+ @SuppressWarnings("unchecked")
+ public ImmutableListCopy(Collection<? extends E> c)
+ {
+ size = c.size();
+ Object[] el = new Object[size]; // no room for growth;
+ el = c.toArray(el);
+ elements = (E[]) el;
+ }
+
+ /**
+ * Assumes that the array passed in is "safe", i.e., is not referenced from elsewhere. Use with care!
+ *
+ * @param array to reference
+ */
+ public ImmutableListCopy(E[] array)
+ {
+ size = array.length;
+ elements = array;
+ }
+
+ /**
+ * Utility constructors to allow combining collections
+ *
+ * @param collection1 collection to copy from
+ * @param collection2 collection to copy from
+ */
+ @SuppressWarnings("unchecked")
+ public ImmutableListCopy(Collection<? extends E> collection1, Collection<? extends E> collection2)
+ {
+ size = collection1.size() + collection2.size();
+ elements = (E[]) new Object[size]; // no room for growth;
+ Object[] c1 = new Object[collection1.size()];
+ Object[] c2 = new Object[collection2.size()];
+ c1 = collection1.toArray(c1);
+ c2 = collection2.toArray(c2);
+ System.arraycopy(c1, 0, elements, 0, c1.length);
+ System.arraycopy(c2, 0, elements, c1.length, c2.length);
+ }
+
+ @Override
+ public final int size()
+ {
+ return size;
+ }
+
+ @Override
+ public final boolean isEmpty()
+ {
+ return size == 0;
+ }
+
+ @Override
+ public final boolean contains(Object o)
+ {
+ return indexOf(o) >= 0;
+ }
+
+ @Override
+ public final Iterator<E> iterator()
+ {
+ return new ImmutableIterator();
+ }
+
+ @Override
+ public final Object[] toArray()
+ {
+ Object[] result = new Object[size];
+ System.arraycopy(elements, 0, result, 0, size);
+ return result;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <T> T[] toArray(T[] a)
+ {
+ if (a.length < size)
+ {
+ a = (T[]) Array.newInstance(a.getClass().getComponentType(), size);
+ }
+ System.arraycopy(elements, 0, a, 0, size);
+ if (a.length > size) a[size] = null;
+ return a;
+ }
+
+ @Override
+ public final boolean add(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final boolean addAll(Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final boolean addAll(int index, Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public final E get(int index)
+ {
+ assertIndexInRange(index);
+ return elements[index];
+ }
+
+ @Override
+ public final int indexOf(Object o)
+ {
+ if (o == null)
+ {
+ for (int i = 0; i < size; i++)
+ {
+ if (elements[i] == null) return i;
+ }
+ }
+ else
+ {
+ for (int i = 0; i < size; i++)
+ {
+ if (o.equals(elements[i])) return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public final int lastIndexOf(Object o)
+ {
+ if (o == null)
+ {
+ for (int i = size - 1; i >= 0; i--)
+ {
+ if (elements[i] == null) return i;
+ }
+ }
+ else
+ {
+ for (int i = size - 1; i >= 0; i--)
+ {
+ if (o.equals(elements[i])) return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public final ListIterator<E> listIterator()
+ {
+ return new ImmutableIterator();
+ }
+
+ @Override
+ public final ListIterator<E> listIterator(int index)
+ {
+ return new ImmutableIterator(index);
+ }
+
+ @Override
+ public final List<E> subList(int fromIndex, int toIndex)
+ {
+ return new ImmutableSubList<E>(fromIndex, toIndex);
+ }
+
+ private void assertIndexInRange(int index)
+ {
+ if (index >= size || index < 0) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+ }
+
+ private class ImmutableIterator implements ListIterator<E>
+ {
+ int cursor = 0;
+
+ ImmutableIterator(int index)
+ {
+ if (index < 0 || index > size()) throw new IndexOutOfBoundsException("Index: " + index);
+ cursor = index;
+ }
+
+ ImmutableIterator()
+ {
+ }
+
+ public boolean hasNext()
+ {
+ return cursor != size;
+ }
+
+ public E next()
+ {
+ try
+ {
+ return get(cursor++);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean hasPrevious()
+ {
+ return cursor != 0;
+ }
+
+ public E previous()
+ {
+ try
+ {
+ return get(--cursor);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public int nextIndex()
+ {
+ return cursor;
+ }
+
+ public int previousIndex()
+ {
+ return cursor - 1;
+ }
+
+ public void set(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private class ImmutableSubList<E> extends AbstractList<E>
+ {
+ private int offset;
+ private int size;
+
+ ImmutableSubList(int fromIndex, int toIndex)
+ {
+ assertIndexInRange(fromIndex);
+ assertIndexInRange(toIndex - 1);
+ if (fromIndex > toIndex)
+ throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
+ offset = fromIndex;
+ size = toIndex - fromIndex;
+ }
+
+ @SuppressWarnings("unchecked")
+ public final E get(int index)
+ {
+ rangeCheck(index);
+ return (E) ImmutableListCopy.this.get(index + offset);
+ }
+
+ private void rangeCheck(int index)
+ {
+ if (index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ",Size: " + size);
+ }
+
+ public final int size()
+ {
+ return size;
+ }
+
+ @Override
+ protected final void removeRange(int fromIndex, int toIndex)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final boolean addAll(Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final boolean addAll(int index, Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public final Iterator<E> iterator()
+ {
+ return listIterator();
+ }
+
+ @Override
+ public final ListIterator<E> listIterator(final int index)
+ {
+ rangeCheck(index);
+
+ return new ListIterator<E>()
+ {
+ private ListIterator i = ImmutableListCopy.this.listIterator(index + offset);
+
+ public boolean hasNext()
+ {
+ return nextIndex() < size;
+ }
+
+ @SuppressWarnings("unchecked")
+ public E next()
+ {
+ if (hasNext())
+ return (E) i.next();
+ else
+ throw new NoSuchElementException();
+ }
+
+ public boolean hasPrevious()
+ {
+ return previousIndex() >= 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public E previous()
+ {
+ if (hasPrevious())
+ return (E) i.previous();
+ else
+ throw new NoSuchElementException();
+ }
+
+ public int nextIndex()
+ {
+ return i.nextIndex() - offset;
+ }
+
+ public int previousIndex()
+ {
+ return i.previousIndex() - offset;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void set(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ @Override
+ public final List<E> subList(int fromIndex, int toIndex)
+ {
+ return new ImmutableSubList<E>(offset + fromIndex, offset + toIndex);
+ }
+ }
+}
Added: core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java (rev 0)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -0,0 +1,108 @@
+package org.jboss.cache.util;
+
+import net.jcip.annotations.Immutable;
+
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * This is based on an ImmutableListCopy, with the assumption that the set passed in would ensure uniqueness of elements.
+ * <p/>
+ * The constructor takes in a collection so the onus is on the caller to ensure that the collection passed in adheres to
+ * Set semantics.
+ * <p/>
+ * Typically used in place of the common idiom:
+ * <code>
+ * return Collections.unmodifiableSet(new HashSet( myInternalSet ));
+ * </code>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @see org.jboss.cache.util.ImmutableListCopy
+ */
+@Immutable
+public class ImmutableSetCopy<E> extends AbstractSet<E>
+{
+ private final E[] elements;
+ private final int size;
+
+ @SuppressWarnings("unchecked")
+ public ImmutableSetCopy(Collection<E> set)
+ {
+ size = set.size();
+ E[] tempElements = (E[]) new Object[size]; // no room for growth
+ elements = set.toArray(tempElements);
+ }
+
+ /**
+ * Assumes that the array passed in is "safe", i.e., is not referenced from elsewhere. Also assumes the array contains
+ * elements such that the uniqueness required by a set is adhered to. Use with care!
+ *
+ * @param array to reference
+ */
+ public ImmutableSetCopy(E[] array)
+ {
+ elements = array;
+ size = elements.length;
+ }
+
+ @Override
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Iterator<E> iterator()
+ {
+ return new Iterator<E>()
+ {
+ int cursor = 0;
+
+ public boolean hasNext()
+ {
+ return cursor < size;
+ }
+
+ public E next()
+ {
+ if (cursor >= size) throw new NoSuchElementException();
+ return elements[cursor++];
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ public int size()
+ {
+ return size;
+ }
+}
Added: core/branches/2.2.X/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java
===================================================================
--- core/branches/2.2.X/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java (rev 0)
+++ core/branches/2.2.X/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java 2008-07-23 15:25:17 UTC (rev 6380)
@@ -0,0 +1,144 @@
+package org.jboss.cache.util;
+
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.ListIterator;
+
+@Test(groups = "unit")
+public class ImmutableListCopyTest
+{
+ public void testImmutability()
+ {
+ List<String> l = new ImmutableListCopy<String>(Collections.singletonList("one"));
+ try
+ {
+ l.add("two");
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.remove(0);
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.clear();
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.add(0, "x");
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.set(0, "i");
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.addAll(Collections.singletonList("l"));
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.addAll(0, Collections.singletonList("l"));
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.removeAll(Collections.singletonList("l"));
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.retainAll(Collections.singletonList("l"));
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.iterator().remove();
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+
+ try
+ {
+ l.listIterator().set("w");
+ assert false;
+ }
+ catch (UnsupportedOperationException good)
+ {
+
+ }
+ }
+
+ public void testListIterator()
+ {
+ List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+ List<Integer> list = new ImmutableListCopy<Integer>(ints);
+
+ ListIterator<Integer> li = list.listIterator();
+
+ int number = 1;
+ while (li.hasNext()) assert li.next() == number++;
+ assert number == 11;
+
+ number = 10;
+ li = list.listIterator(list.size());
+ while (li.hasPrevious()) assert li.previous() == number--;
+ assert number == 0;
+ }
+}
16 years, 1 month
JBoss Cache SVN: r6379 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-23 11:21:40 -0400 (Wed, 23 Jul 2008)
New Revision: 6379
Modified:
core/trunk/src/main/java/org/jboss/cache/Fqn.java
Log:
removed tmp assertion
Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-07-23 15:00:08 UTC (rev 6378)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-07-23 15:21:40 UTC (rev 6379)
@@ -113,7 +113,6 @@
{
if (names != null)
{
- assertNoWhiteSpace(names);
// if not safe make a defensive copy
elements = safe ? names : new ImmutableListCopy<Object>(names);
size = elements.size();
@@ -125,12 +124,6 @@
}
}
- private void assertNoWhiteSpace(List<Object> l)
- {
- if (l.contains("") || l.contains(SEPARATOR))
- throw new IllegalArgumentException("Fqn list cannot contain whitespace or the [" + SEPARATOR + "] character!");
- }
-
protected Fqn(Fqn base, List<Object> relative)
{
elements = new ImmutableListCopy<Object>(base.elements, relative);
16 years, 1 month