JBoss Cache SVN: r6759 - benchmarks/benchmark-fwk/trunk.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-19 07:15:40 -0400 (Fri, 19 Sep 2008)
New Revision: 6759
Added:
benchmarks/benchmark-fwk/trunk/compareJBC2and3.sh
Log:
New script
Added: benchmarks/benchmark-fwk/trunk/compareJBC2and3.sh
===================================================================
--- benchmarks/benchmark-fwk/trunk/compareJBC2and3.sh (rev 0)
+++ benchmarks/benchmark-fwk/trunk/compareJBC2and3.sh 2008-09-19 11:15:40 UTC (rev 6759)
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+scaling="2 4 6 8"
+
+
+
+configs="pess-repl-sync.xml pess-repl-sync-br.xml pess-repl-async.xml mvcc-repl-sync.xml mvcc-repl-sync-br.xml mvcc-repl-async.xml"
+#configs="distributed replicated"
+
+
+mkdir output
+
+#### JBoss Cache 3.0.0
+product="jbosscache-3.0.0"
+configs="mvcc-repl-sync.xml mvcc-repl-sync-br.xml mvcc-repl-async.xml"
+
+for config in $configs
+do
+ for size in $scaling
+ do
+ nohup ./cluster.sh start $product $config $size
+
+ outputFileName=data_${product}_${config}_${size}.csv
+ while [ ! -e $outputFileName ]
+ do
+ echo "Waiting for report [ $outputFileName ]"
+ sleep 5
+ done
+ sleep 60
+ mv $outputFileName output/
+ done
+done
+
+#### JBoss Cache 2.2.0
+product="jbosscache-2.2.0"
+configs="pess-repl-sync.xml pess-repl-sync-br.xml pess-repl-async.xml"
+
+for config in $configs
+do
+ for size in $scaling
+ do
+ nohup ./cluster.sh start $product $config $size
+
+ outputFileName=data_${product}_${config}_${size}.csv
+ while [ ! -e $outputFileName ]
+ do
+ echo "Waiting for report [ $outputFileName ]"
+ sleep 5
+ done
+ sleep 60
+ mv $outputFileName output/
+ done
+done
+
+#### EHCache
+product="ehcache-1.5.0"
+configs="ehcache-repl-sync.xml ehcache-repl-async.xml"
+
+for config in $configs
+do
+ for size in $scaling
+ do
+ nohup ./cluster.sh start $product $config $size
+
+ outputFileName=data_${product}_${config}_${size}.csv
+ while [ ! -e $outputFileName ]
+ do
+ echo "Waiting for report [ $outputFileName ]"
+ sleep 5
+ done
+ sleep 60
+ mv $outputFileName output/
+ done
+done
+
+#### Coherence
+product="coherence-3.3.1"
+configs="repl-cache.xml dist-cache.xml"
+
+for config in $configs
+do
+ for size in $scaling
+ do
+ nohup ./cluster.sh start $product $config $size
+
+ outputFileName=data_${product}_${config}_${size}.csv
+ while [ ! -e $outputFileName ]
+ do
+ echo "Waiting for report [ $outputFileName ]"
+ sleep 5
+ done
+ sleep 60
+ mv $outputFileName output/
+ done
+done
+
+
+echo Generating charts ...
+
+./generateChart -reportDir output
15 years, 7 months
JBoss Cache SVN: r6758 - benchmarks/benchmark-fwk/trunk/conf.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-19 07:09:09 -0400 (Fri, 19 Sep 2008)
New Revision: 6758
Modified:
benchmarks/benchmark-fwk/trunk/conf/log4j.xml
Log:
Added JGroups category
Modified: benchmarks/benchmark-fwk/trunk/conf/log4j.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/conf/log4j.xml 2008-09-19 11:08:10 UTC (rev 6757)
+++ benchmarks/benchmark-fwk/trunk/conf/log4j.xml 2008-09-19 11:09:09 UTC (rev 6758)
@@ -48,6 +48,7 @@
<category name="CacheException">
<priority value="INFO"/>
+ <appender-ref ref="CONSOLE"/>
</category>
<category name="org.apache">
@@ -79,6 +80,10 @@
<priority value="ERROR"/>
</category>
+ <category name="org.jgroups">
+ <priority value="ERROR"/>
+ </category>
+
<!-- Here goes the root -->
<root>
<priority value="INFO"/>
15 years, 7 months
JBoss Cache SVN: r6757 - benchmarks/benchmark-fwk/trunk/conf.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-19 07:08:10 -0400 (Fri, 19 Sep 2008)
New Revision: 6757
Modified:
benchmarks/benchmark-fwk/trunk/conf/cachebench.xml
Log:
Updated cfgs
Modified: benchmarks/benchmark-fwk/trunk/conf/cachebench.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/conf/cachebench.xml 2008-09-19 11:07:57 UTC (rev 6756)
+++ benchmarks/benchmark-fwk/trunk/conf/cachebench.xml 2008-09-19 11:08:10 UTC (rev 6757)
@@ -8,7 +8,7 @@
emptyCacheBetweenTests - again, use if you're running out of mem.
numThreads - the number of executor threads to use to perform the required number of operations.
-->
-<cachebench sampleSize="10000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true"
+<cachebench sampleSize="500000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true"
numThreads="10">
@@ -44,7 +44,7 @@
If no warmup is needed use org.cachebench.warmup.NoCacheWarmup
-->
<warmup warmupClass="org.cachebench.warmup.PutGetCacheWarmup">
- <param name="operationCount" value="3000"/>
+ <param name="operationCount" value="10000"/>
</warmup>
<!--
@@ -69,10 +69,10 @@
<test name="SessionSimulator" testClass="org.cachebench.tests.SessionSimulatorTest" weight="2.0">
- <param name="numberOfRequest" value="100000"/>
+ <param name="numberOfRequest" value="500000"/>
<param name="numberOfAttributes" value="100"/>
- <param name="writePercentage" value="20"/>
- <param name="sizeOfAnAttribute" value="1000"/>
+ <param name="writePercentage" value="10"/>
+ <param name="sizeOfAnAttribute" value="10000"/>
</test>
<!--
15 years, 7 months
JBoss Cache SVN: r6756 - benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-19 07:07:57 -0400 (Fri, 19 Sep 2008)
New Revision: 6756
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async-br.xml
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync-br.xml
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync.xml
Log:
Updated cfgs
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async-br.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async-br.xml 2008-09-19 09:38:13 UTC (rev 6755)
+++ benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async-br.xml 2008-09-19 11:07:57 UTC (rev 6756)
@@ -1,29 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.0">
- <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"/>
+ <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"
+ concurrencyLevel="1000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<stateRetrieval timeout="20000" fetchInMemoryState="false"/>
<transport clusterName="JBossCache-Cluster">
<jgroupsConfig>
- <TCP discard_incompatible_packets="true" enable_bundling="true" enable_diagnostics="false"
- enable_unicast_bundling="false" loopback="false" max_bundle_size="64000" max_bundle_timeout="30"
- oob_thread_pool.enabled="true" oob_thread_pool.keep_alive_time="10000" oob_thread_pool.max_threads="4"
- oob_thread_pool.min_threads="2" oob_thread_pool.queue_enabled="false" oob_thread_pool.queue_max_size="10"
- oob_thread_pool.rejection_policy="Run" recv_buf_size="20000000" thread_naming_pattern="pl"
- thread_pool.enabled="true" thread_pool.keep_alive_time="30000" thread_pool.max_threads="4"
- thread_pool.min_threads="1" thread_pool.queue_enabled="true" thread_pool.queue_max_size="50000"
- thread_pool.rejection_policy="discard" use_concurrent_stack="true" use_incoming_packet_handler="true"
- use_send_queues="false"/>
+ <TCP discard_incompatible_packets="true" enable_bundling="false" enable_diagnostics="false"
+ enable_unicast_bundling="false" loopback="false" max_bundle_size="64000" max_bundle_timeout="30"
+ oob_thread_pool.enabled="true" oob_thread_pool.keep_alive_time="10000" oob_thread_pool.max_threads="4"
+ oob_thread_pool.min_threads="2" oob_thread_pool.queue_enabled="false" oob_thread_pool.queue_max_size="10"
+ oob_thread_pool.rejection_policy="Run" recv_buf_size="20000000" thread_naming_pattern="pl"
+ thread_pool.enabled="true" thread_pool.keep_alive_time="30000" thread_pool.max_threads="4"
+ thread_pool.min_threads="1" thread_pool.queue_enabled="true" thread_pool.queue_max_size="50000"
+ thread_pool.rejection_policy="discard" use_concurrent_stack="true" use_incoming_packet_handler="true"
+ use_send_queues="false"/>
<MPING mcast_addr="232.1.2.3" num_initial_members="3" timeout="2000"/>
<MERGE2 max_interval="30000" min_interval="10000"/>
<FD_SOCK/>
<FD max_tries="5" shun="true" timeout="10000"/>
<VERIFY_SUSPECT timeout="1500"/>
<pbcast.NAKACK discard_delivered_msgs="true" gc_lag="0" retransmit_timeout="300,600,1200,2400,4800"
- use_mcast_xmit="false"/>
+ use_mcast_xmit="false"/>
<pbcast.STABLE desired_avg_gossip="50000" max_bytes="400000" stability_delay="1000"/>
<pbcast.GMS join_retry_timeout="2000" join_timeout="5000" print_local_addr="true" shun="false"
- view_ack_collection_timeout="5000" view_bundling="true"/>
+ view_ack_collection_timeout="5000" view_bundling="true"/>
<FC max_credits="5000000" min_threshold="0.20"/>
<FRAG2 frag_size="60000"/>
<pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml 2008-09-19 09:38:13 UTC (rev 6755)
+++ benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml 2008-09-19 11:07:57 UTC (rev 6756)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jbosscache xmlns="urn:jboss:jbosscache-core:config:3.0">
- <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"/>
+ <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"
+ concurrencyLevel="1000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<stateRetrieval timeout="20000" fetchInMemoryState="false"/>
<transport clusterName="JBossCache-Cluster">
@@ -33,6 +34,6 @@
</jgroupsConfig>
</transport>
<replication>
- <async />
+ <async/>
</replication>
</jbosscache>
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync-br.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync-br.xml 2008-09-19 09:38:13 UTC (rev 6755)
+++ benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync-br.xml 2008-09-19 11:07:57 UTC (rev 6756)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.0">
- <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"/>
+ <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"
+ concurrencyLevel="1000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<stateRetrieval timeout="20000" fetchInMemoryState="false"/>
<transport clusterName="JBossCache-Cluster">
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync.xml 2008-09-19 09:38:13 UTC (rev 6755)
+++ benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-sync.xml 2008-09-19 11:07:57 UTC (rev 6756)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.0">
- <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"/>
+ <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"
+ concurrencyLevel="1000"/>
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<stateRetrieval timeout="20000" fetchInMemoryState="false"/>
<transport clusterName="JBossCache-Cluster">
15 years, 7 months
JBoss Cache SVN: r6755 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-09-19 05:38:13 -0400 (Fri, 19 Sep 2008)
New Revision: 6755
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java
Log:
Implemented fetchSize changes in CQI and used the changes in LQRI
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-09-18 17:18:38 UTC (rev 6754)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-09-19 09:38:13 UTC (rev 6755)
@@ -56,14 +56,24 @@
QueryResultIterator iterator();
/**
- * Lazily loads the results from the Query as a {@link org.jboss.cache.search.QueryResultIterator}
+ * Lazily loads the results from the Query as a {@link org.jboss.cache.search.QueryResultIterator} with a given
+ * integer parameter - the fetchSize.
*
+ * @param fetchSize integer to be passed into the lazy implementation of {@link org.jboss.cache.search.QueryResultIterator}
* @return a QueryResultIterator which can be used to <B>lazily</B> iterate through results.
*/
+ QueryResultIterator lazyIterator(int fetchSize);
+
+ /**
+ * Calls the {@link CacheQuery#lazyIterator(int fetchSize)} method but passes in a default 1 as a parameter.
+ *
+ * @return a QueryResultIterator which can be used to <B>lazily</B> iterate through results.
+ */
+
+
QueryResultIterator lazyIterator();
-
/**
* Sets a result with a given index to the first result.
*
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-09-18 17:18:38 UTC (rev 6754)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-09-19 09:38:13 UTC (rev 6755)
@@ -248,6 +248,11 @@
public QueryResultIterator lazyIterator()
{
+ return lazyIterator(1);
+ }
+
+ public QueryResultIterator lazyIterator(int fetchSize)
+ {
IndexSearcher searcher = buildSearcher(searchFactory);
try
@@ -258,7 +263,7 @@
DocumentExtractor extractor = new DocumentExtractor(luceneQuery, searcher, searchFactory, indexProjection);
- return new LazyQueryResultIterator(extractor, entityLoader, hits, searcher, searchFactory, first, max);
+ return new LazyQueryResultIterator(extractor, entityLoader, hits, searcher, searchFactory, first, max, fetchSize);
}
catch (IOException e)
{
@@ -271,14 +276,9 @@
throw new HibernateException( "Unable to query Lucene index", e );
}
+
}
- /**
- * Returns a the results from the query as a List object.
- *
- * @return List of results.
- * @throws HibernateException
- */
public List<Object> list() throws HibernateException
{
IndexSearcher searcher = buildSearcher(searchFactory);
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java 2008-09-18 17:18:38 UTC (rev 6754)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java 2008-09-19 09:38:13 UTC (rev 6755)
@@ -18,7 +18,7 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ */
package org.jboss.cache.search;
@@ -26,8 +26,11 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
+import org.jboss.util.Objects;
import java.util.NoSuchElementException;
+import java.util.List;
+import java.util.ArrayList;
import java.io.IOException;
/**
@@ -40,25 +43,37 @@
public class LazyQueryResultIterator implements QueryResultIterator
{
private int index = 0;
+ private int oldIndex;
private int max = 0;
private int first = 0;
+ private int fetchSize = 0; // difference between fetchsize and index must always be the value for first. fetchSize has to be at least 1.
private CacheEntityLoader entityLoader;
private DocumentExtractor extractor;
private Hits hits;
private IndexSearcher searcher;
private SearchFactoryImplementor searchFactory;
+ private List<Object> bufferObjects;
public LazyQueryResultIterator(DocumentExtractor extractor, CacheEntityLoader entityLoader, Hits hits,
- IndexSearcher searcher, SearchFactoryImplementor searchFactory, int first, int max)
+ IndexSearcher searcher, SearchFactoryImplementor searchFactory, int first, int max, int fetchSize)
{
+ if (fetchSize < 1)
+ {
+ throw new IllegalArgumentException("Incorrect value for fetchsize passed. Your fetchSize is less than 1");
+ }
+
this.extractor = extractor;
this.entityLoader = entityLoader;
index = first;
this.first = first;
this.max = max;
+ this.fetchSize = fetchSize + first;
this.hits = hits;
this.searcher = searcher;
this.searchFactory = searchFactory;
+
+ //Create an ArrayList with size fetchSize - 1 (which is the size of the required buffer.
+ bufferObjects = new ArrayList<Object>(this.fetchSize - 1);
}
public void jumpToResult(int index) throws IndexOutOfBoundsException
@@ -125,11 +140,35 @@
public Object next()
{
Object toReturn = null;
+ int bufferSize = fetchSize - 1;
+
+ if (index <= oldIndex + bufferSize)
+ {
+ oldIndex = index;
+ index++;
+ return bufferObjects.get(oldIndex);
+ }
+
try
{
String documentId = (String) extractor.extract(hits, index).id;
CacheEntityId id = new CacheEntityId(documentId);
toReturn = entityLoader.load(id);
+
+ //now loop through bufferSize times to add the rest of the objects into the list.
+ for (int i = 1; i <= bufferSize; i++)
+ {
+ //Wiping bufferObjects and the oldIndex so that there is no stale data.
+ bufferObjects.clear();
+ oldIndex = 0;
+
+ String bufferDocumentId = (String) extractor.extract(hits, index + i).id;
+ CacheEntityId bufferId = new CacheEntityId(bufferDocumentId);
+ Object toBuffer = entityLoader.load(bufferId);
+ bufferObjects.add(toBuffer);
+
+ }
+ oldIndex = index;
index++;
}
catch (IOException e)
@@ -147,12 +186,37 @@
public Object previous()
{
+ int bufferSize = fetchSize - 1;
Object toReturn = null;
+
+ if (index >= oldIndex - bufferSize)
+ {
+ oldIndex = index;
+ index--;
+ return bufferObjects.get(oldIndex);
+ }
+
try
{
- String documentId = (String) extractor.extract (hits, index).id;
+ String documentId = (String) extractor.extract(hits, index).id;
CacheEntityId id = new CacheEntityId(documentId);
toReturn = entityLoader.load(id);
+
+ //now loop through bufferSize times to add the rest of the objects into the list.
+ for (int i = 1; i <= bufferSize; i++)
+ {
+ //Wiping bufferObjects and oldIndex so that there is no stale data.
+ bufferObjects.clear();
+ oldIndex = 0;
+
+ String bufferDocumentId = (String) extractor.extract(hits, index - i).id; //In this case it has to be index - i because previous() is called.
+ CacheEntityId bufferId = new CacheEntityId(bufferDocumentId);
+ Object toBuffer = entityLoader.load(bufferId);
+ bufferObjects.add(toBuffer);
+
+ }
+
+ oldIndex = index;
index--;
}
catch (IOException e)
@@ -204,4 +268,5 @@
{
throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
}
+
}
15 years, 7 months
JBoss Cache SVN: r6754 - in core/trunk/src: test/java/org/jboss/cache/marshall and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-09-18 13:18:38 -0400 (Thu, 18 Sep 2008)
New Revision: 6754
Added:
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller300.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller300Test.java
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
Log:
JBCACHE-1411 : Marshaller has no special treatment of arrays, even arrays of primitives or known types
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-09-18 16:03:00 UTC (rev 6753)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-09-18 17:18:38 UTC (rev 6754)
@@ -6,6 +6,21 @@
*/
package org.jboss.cache.marshall;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Region;
+import org.jboss.cache.Region.Status;
+import org.jboss.cache.buddyreplication.GravitateResult;
+import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.optimistic.DefaultDataVersion;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.util.FastCopyHashMap;
+import org.jboss.cache.util.Immutables;
+import org.jgroups.Address;
+import org.jgroups.stack.IpAddress;
+
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -22,20 +37,6 @@
import java.util.TreeMap;
import java.util.TreeSet;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
-import org.jboss.cache.Region.Status;
-import org.jboss.cache.buddyreplication.GravitateResult;
-import org.jboss.cache.commands.CommandsFactory;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.util.FastCopyHashMap;
-import org.jboss.cache.util.Immutables;
-import org.jgroups.Address;
-import org.jgroups.stack.IpAddress;
-
/**
* An enhanced marshaller for RPC calls between CacheImpl instances.
*
@@ -67,6 +68,12 @@
protected static final int MAGICNUMBER_IMMUTABLE_MAPCOPY = 21;
protected static final int MAGICNUMBER_MARSHALLEDVALUE = 22;
protected static final int MAGICNUMBER_FASTCOPY_HASHMAP = 23;
+ protected static final int MAGICNUMBER_ARRAY = 24;
+ protected static final int MAGICNUMBER_BYTE = 25;
+ protected static final int MAGICNUMBER_CHAR = 26;
+ protected static final int MAGICNUMBER_FLOAT = 27;
+ protected static final int MAGICNUMBER_DOUBLE = 28;
+ protected static final int MAGICNUMBER_OBJECT = 29;
protected static final int MAGICNUMBER_NULL = 99;
protected static final int MAGICNUMBER_SERIALIZABLE = 100;
protected static final int MAGICNUMBER_REF = 101;
@@ -582,6 +589,8 @@
case MAGICNUMBER_DEFAULT_DATA_VERSION:
retVal = unmarshallDefaultDataVersion(in);
return retVal;
+ case MAGICNUMBER_ARRAY:
+ return unmarshallArray(in, refMap);
case MAGICNUMBER_ARRAY_LIST:
return unmarshallArrayList(in, refMap);
case MAGICNUMBER_LINKED_LIST:
@@ -847,5 +856,150 @@
{
out.writeLong(i);
}
+
+ protected Object unmarshallArray(ObjectInputStream in, UnmarshalledReferences refs) throws Exception
+ {
+ int sz = readUnsignedInt(in);
+ byte type = in.readByte();
+ switch (type)
+ {
+ case MAGICNUMBER_BOOLEAN:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ boolean[] a = new boolean[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readBoolean();
+ return a;
+ }
+ else
+ {
+ Boolean[] a = new Boolean[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readBoolean();
+ return a;
+ }
+ }
+ case MAGICNUMBER_INTEGER:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ int[] a = new int[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readInt();
+ return a;
+ }
+ else
+ {
+ Integer[] a = new Integer[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readInt();
+ return a;
+ }
+ }
+ case MAGICNUMBER_LONG:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ long[] a = new long[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readLong();
+ return a;
+ }
+ else
+ {
+ Long[] a = new Long[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readLong();
+ return a;
+ }
+ }
+ case MAGICNUMBER_CHAR:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ char[] a = new char[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readChar();
+ return a;
+ }
+ else
+ {
+ Character[] a = new Character[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readChar();
+ return a;
+ }
+ }
+ case MAGICNUMBER_BYTE:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ byte[] a = new byte[sz];
+ in.read(a);
+ return a;
+ }
+ else
+ {
+ Byte[] a = new Byte[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readByte();
+ return a;
+ }
+ }
+ case MAGICNUMBER_SHORT:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ short[] a = new short[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readShort();
+ return a;
+ }
+ else
+ {
+ Short[] a = new Short[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readShort();
+ return a;
+ }
+ }
+ case MAGICNUMBER_FLOAT:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ float[] a = new float[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readFloat();
+ return a;
+ }
+ else
+ {
+ Float[] a = new Float[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readFloat();
+ return a;
+ }
+ }
+ case MAGICNUMBER_DOUBLE:
+ {
+ boolean isPrim = in.readBoolean();
+ if (isPrim)
+ {
+ double[] a = new double[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readDouble();
+ return a;
+ }
+ else
+ {
+ Double[] a = new Double[sz];
+ for (int i = 0; i < sz; i++) a[i] = in.readDouble();
+ return a;
+ }
+ }
+ case MAGICNUMBER_OBJECT:
+ {
+ Object[] a = new Object[sz];
+ for (int i = 0; i < sz; i++) a[i] = unmarshallObject(in, refs);
+ return a;
+ }
+ default:
+ throw new CacheException("Unknown array type");
+ }
+ }
}
Added: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller300.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller300.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller300.java 2008-09-18 17:18:38 UTC (rev 6754)
@@ -0,0 +1,126 @@
+package org.jboss.cache.marshall;
+
+import org.jboss.cache.CacheException;
+
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Array;
+import java.util.Map;
+
+/**
+ * Adds special treatment of arrays over and above the superclass.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class CacheMarshaller300 extends CacheMarshaller210
+{
+ @Override
+ protected void marshallObject(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
+ {
+ if (o != null && o.getClass().isArray() && isKnownType(o.getClass().getComponentType()))
+ {
+ marshallArray(o, out, refMap);
+ }
+ else
+ {
+ super.marshallObject(o, out, refMap);
+ }
+ }
+
+ protected boolean isKnownType(Class c)
+ {
+ return (c.equals(Object.class) ||
+ c.isPrimitive() || c.equals(Character.class) || c.equals(Integer.class) || c.equals(Long.class) ||
+ c.equals(Byte.class) || c.equals(Boolean.class) || c.equals(Short.class) || c.equals(Float.class) ||
+ c.equals(Double.class));
+ }
+
+ protected void marshallArray(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
+ {
+ out.writeByte(MAGICNUMBER_ARRAY);
+ Class arrayTypeClass = o.getClass().getComponentType();
+ int sz = Array.getLength(o);
+ writeUnsignedInt(out, sz);
+ boolean isPrim = arrayTypeClass.isPrimitive();
+
+ if (!isPrim && arrayTypeClass.equals(Object.class))
+ {
+ out.writeByte(MAGICNUMBER_OBJECT);
+ for (int i = 0; i < sz; i++) marshallObject(Array.get(o, i), out, refMap);
+ }
+ else if (arrayTypeClass.equals(byte.class) || arrayTypeClass.equals(Byte.class))
+ {
+ out.writeByte(MAGICNUMBER_BYTE);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ out.write((byte[]) o);
+ else
+ for (int i = 0; i < sz; i++) out.writeByte((Byte) Array.get(o, i));
+ }
+ else if (arrayTypeClass.equals(int.class) || arrayTypeClass.equals(Integer.class))
+ {
+ out.writeByte(MAGICNUMBER_INTEGER);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ for (int i = 0; i < sz; i++) out.writeInt(Array.getInt(o, i));
+ else
+ for (int i = 0; i < sz; i++) out.writeInt((Integer) Array.get(o, i));
+ }
+
+ else if (arrayTypeClass.equals(long.class) || arrayTypeClass.equals(Long.class))
+ {
+ out.writeByte(MAGICNUMBER_LONG);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ for (int i = 0; i < sz; i++) out.writeLong(Array.getLong(o, i));
+ else
+ for (int i = 0; i < sz; i++) out.writeLong((Long) Array.get(o, i));
+ }
+ else if (arrayTypeClass.equals(boolean.class) || arrayTypeClass.equals(Boolean.class))
+ {
+ out.writeByte(MAGICNUMBER_BOOLEAN);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ for (int i = 0; i < sz; i++) out.writeBoolean(Array.getBoolean(o, i));
+ else
+ for (int i = 0; i < sz; i++) out.writeBoolean((Boolean) Array.get(o, i));
+ }
+ else if (arrayTypeClass.equals(char.class) || arrayTypeClass.equals(Character.class))
+ {
+ out.writeByte(MAGICNUMBER_CHAR);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ for (int i = 0; i < sz; i++) out.writeChar(Array.getChar(o, i));
+ else
+ for (int i = 0; i < sz; i++) out.writeChar((Character) Array.get(o, i));
+ }
+ else if (arrayTypeClass.equals(short.class) || arrayTypeClass.equals(Short.class))
+ {
+ out.writeByte(MAGICNUMBER_SHORT);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ for (int i = 0; i < sz; i++) out.writeShort(Array.getShort(o, i));
+ else
+ for (int i = 0; i < sz; i++) out.writeShort((Short) Array.get(o, i));
+ }
+ else if (arrayTypeClass.equals(float.class) || arrayTypeClass.equals(Float.class))
+ {
+ out.writeByte(MAGICNUMBER_FLOAT);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ for (int i = 0; i < sz; i++) out.writeFloat(Array.getFloat(o, i));
+ else
+ for (int i = 0; i < sz; i++) out.writeFloat((Float) Array.get(o, i));
+ }
+ else if (arrayTypeClass.equals(double.class) || arrayTypeClass.equals(Double.class))
+ {
+ out.writeByte(MAGICNUMBER_DOUBLE);
+ out.writeBoolean(isPrim);
+ if (isPrim)
+ for (int i = 0; i < sz; i++) out.writeDouble(Array.getDouble(o, i));
+ else
+ for (int i = 0; i < sz; i++) out.writeDouble((Double) Array.get(o, i));
+ }
+ else throw new CacheException("Unknown array type!");
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2008-09-18 16:03:00 UTC (rev 6753)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2008-09-18 17:18:38 UTC (rev 6754)
@@ -283,19 +283,29 @@
break;
case VERSION_220:
case VERSION_210:
+ marshaller = marshallers.get(VERSION_210);
+ if (marshaller == null)
+ {
+ am = new CacheMarshaller210();
+ marshaller = am;
+ componentRegistry.wireDependencies(am);
+ am.init();
+ marshallers.put(VERSION_210, marshaller);
+ }
+ break;
case VERSION_300:
knownVersion = true;
default:
if (!knownVersion && log.isWarnEnabled())
log.warn("Unknown replication version [" + versionId + "]. Falling back to the default marshaller installed.");
- marshaller = marshallers.get(VERSION_210);
+ marshaller = marshallers.get(VERSION_300);
if (marshaller == null)
{
- am = new CacheMarshaller210();
+ am = new CacheMarshaller300();
marshaller = am;
componentRegistry.wireDependencies(am);
am.init();
- marshallers.put(VERSION_210, marshaller);
+ marshallers.put(VERSION_300, marshaller);
}
break;
}
Added: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller300Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller300Test.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller300Test.java 2008-09-18 17:18:38 UTC (rev 6754)
@@ -0,0 +1,89 @@
+package org.jboss.cache.marshall;
+
+import org.jboss.cache.Fqn;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+@Test(groups = {"functional"})
+public class CacheMarshaller300Test
+{
+ public void testArrayTypes() throws Exception
+ {
+ Marshaller m = new CacheMarshaller300();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bout);
+ byte[] s = {1, 2, 3, 4};
+ m.objectToObjectStream(s, out);
+ out.close();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bin);
+
+ Object o = m.objectFromObjectStream(ois);
+
+ ois.close();
+
+ assert o instanceof byte[];
+ byte[] oS = (byte[]) o;
+ assert oS.length == 4;
+ assert oS[0] == 1;
+ assert oS[1] == 2;
+ assert oS[2] == 3;
+ assert oS[3] == 4;
+ }
+
+ public void testBoxedArrayTypes() throws Exception
+ {
+ Marshaller m = new CacheMarshaller300();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bout);
+ Byte[] s = new Byte[]{1, 2, 3, 4};
+ m.objectToObjectStream(s, out);
+ out.close();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bin);
+
+ Object o = m.objectFromObjectStream(ois);
+
+ ois.close();
+
+ assert o instanceof Byte[];
+ Byte[] oS = (Byte[]) o;
+ assert oS.length == 4;
+ assert oS[0] == 1;
+ assert oS[1] == 2;
+ assert oS[2] == 3;
+ assert oS[3] == 4;
+ }
+
+ public void testMixedArrayTypes() throws Exception
+ {
+ Marshaller m = new CacheMarshaller300();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bout);
+ Object[] s = {"Hello", Fqn.fromString("/a"), 1, null};
+ m.objectToObjectStream(s, out);
+ out.close();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bin);
+
+ Object o = m.objectFromObjectStream(ois);
+
+ ois.close();
+
+ assert o instanceof Object[];
+ Object[] oS = (Object[]) o;
+ assert oS.length == 4;
+ assert oS[0].equals("Hello");
+ assert oS[1].equals(Fqn.fromString("/a"));
+ assert oS[2].equals(1);
+ assert oS[3] == null;
+
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-09-18 16:03:00 UTC (rev 6753)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-09-18 17:18:38 UTC (rev 6754)
@@ -29,7 +29,7 @@
{
protected String currentVersion;
protected int currentVersionShort;
- protected Class expectedMarshallerClass, latestMarshallerClass = CacheMarshaller210.class;
+ protected Class expectedMarshallerClass, latestMarshallerClass = CacheMarshaller300.class;
protected VersionAwareMarshaller marshaller;
protected RegionManager regionManager;
protected Configuration c;
@@ -90,7 +90,7 @@
assertEquals(CacheMarshaller200.class, marshaller.getMarshaller(20).getClass());
assertEquals(CacheMarshaller210.class, marshaller.getMarshaller(21).getClass());
- assert marshaller.marshallers.size() == 2 : "Should have 2 marshallers now";
+ assert marshaller.marshallers.size() == 3 : "Should have 3 marshallers now";
}
public void testStringBasedFqn() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-09-18 16:03:00 UTC (rev 6753)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-09-18 17:18:38 UTC (rev 6754)
@@ -51,25 +51,25 @@
assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
marshaller = createVAMandRestartCache("1.4.0.GA");
- assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
+ assertEquals(CacheMarshaller300.class, marshaller.defaultMarshaller.getClass());
marshaller = createVAMandRestartCache("1.5.0.GA");
- assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
+ assertEquals(CacheMarshaller300.class, marshaller.defaultMarshaller.getClass());
marshaller = createVAMandRestartCache("1.3.0.GA");
- assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
+ assertEquals(CacheMarshaller300.class, marshaller.defaultMarshaller.getClass());
marshaller = createVAMandRestartCache("1.3.0.SP2");
- assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
+ assertEquals(CacheMarshaller300.class, marshaller.defaultMarshaller.getClass());
marshaller = createVAMandRestartCache("1.3.1.GA");
- assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
+ assertEquals(CacheMarshaller300.class, marshaller.defaultMarshaller.getClass());
marshaller = createVAMandRestartCache("1.2.4.SP2");
- assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
+ assertEquals(CacheMarshaller300.class, marshaller.defaultMarshaller.getClass());
marshaller = createVAMandRestartCache("1.2.3");
- assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
+ assertEquals(CacheMarshaller300.class, marshaller.defaultMarshaller.getClass());
}
public void testVersionHeaderDefaultCurrent() throws Exception
15 years, 7 months
JBoss Cache SVN: r6753 - benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-09-18 12:03:00 -0400 (Thu, 18 Sep 2008)
New Revision: 6753
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
Log:
updated
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
===================================================================
(Binary files differ)
15 years, 7 months
JBoss Cache SVN: r6752 - benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-09-18 10:20:06 -0400 (Thu, 18 Sep 2008)
New Revision: 6752
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
Log:
updated
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
===================================================================
(Binary files differ)
15 years, 7 months
JBoss Cache SVN: r6751 - 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-09-18 09:27:40 -0400 (Thu, 18 Sep 2008)
New Revision: 6751
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jgroups.jar
Log:
Updated jgroups
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jgroups.jar
===================================================================
(Binary files differ)
15 years, 7 months
JBoss Cache SVN: r6750 - 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-09-18 09:14:33 -0400 (Thu, 18 Sep 2008)
New Revision: 6750
Added:
core/trunk/src/main/java/org/jboss/cache/util/concurrent/ReclosableLatch.java
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
Log:
Better threadgate impl for flush block gate
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-09-18 11:02:45 UTC (rev 6749)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-09-18 13:14:33 UTC (rev 6750)
@@ -32,7 +32,7 @@
import org.jboss.cache.statetransfer.DefaultStateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionTable;
-import org.jboss.cache.util.ThreadGate;
+import org.jboss.cache.util.concurrent.ReclosableLatch;
import org.jboss.cache.util.reflect.ReflectionUtil;
import org.jgroups.Address;
import org.jgroups.Channel;
@@ -58,6 +58,7 @@
import java.util.List;
import java.util.Set;
import java.util.Vector;
+import java.util.concurrent.TimeUnit;
/**
* Manager that handles all RPC calls between JBoss Cache instances
@@ -82,7 +83,7 @@
/**
* Thread gate used to block Dispatcher during JGroups FLUSH protocol
*/
- private final ThreadGate flushBlockGate = new ThreadGate();
+ private final ReclosableLatch flushBlockGate = new ReclosableLatch();
/**
* JGroups RpcDispatcher in use.
*/
@@ -429,7 +430,7 @@
log.trace("callRemoteMethods(): valid members are " + recipients + " methods: " + command + " Using OOB? " + useOutOfBandMessage);
if (channel.flushSupported())
{
- if (!flushBlockGate.await(configuration.getStateRetrievalTimeout()))
+ if (!flushBlockGate.await(configuration.getStateRetrievalTimeout(), TimeUnit.MILLISECONDS))
throw new TimeoutException("State retrieval timed out waiting for flush unblock.");
}
useOutOfBandMessage = false;
Added: core/trunk/src/main/java/org/jboss/cache/util/concurrent/ReclosableLatch.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/concurrent/ReclosableLatch.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/util/concurrent/ReclosableLatch.java 2008-09-18 13:14:33 UTC (rev 6750)
@@ -0,0 +1,66 @@
+package org.jboss.cache.util.concurrent;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.AbstractQueuedSynchronizer;
+
+/**
+ * A better impl of {@link org.jboss.cache.util.ThreadGate}, that uses an {@link java.util.concurrent.locks.AbstractQueuedSynchronizer}.
+ * <p/>
+ * This implementation allows you to create a latch with a default state (open or closed), and repeatedly open or close
+ * the latch.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class ReclosableLatch extends AbstractQueuedSynchronizer
+{
+ // the following states are used in the AQS.
+ private static final int OPEN_STATE = 0, CLOSED_STATE = 1;
+
+ public ReclosableLatch()
+ {
+ setState(CLOSED_STATE);
+ }
+
+ public ReclosableLatch(boolean defaultOpen)
+ {
+ setState(defaultOpen ? OPEN_STATE : CLOSED_STATE);
+ }
+
+ @Override
+ public final int tryAcquireShared(int ignored)
+ {
+ // return 1 if we allow the requestor to proceed, -1 if we want the requestor to block.
+ return getState() == OPEN_STATE ? 1 : -1;
+ }
+
+ @Override
+ public final boolean tryReleaseShared(int state)
+ {
+ // used as a mechanism to set the state of the Sync.
+ setState(state);
+ return true;
+ }
+
+ public final void open()
+ {
+ // do not use setState() directly since this won't notify parked threads.
+ releaseShared(OPEN_STATE);
+ }
+
+ public final void close()
+ {
+ // do not use setState() directly since this won't notify parked threads.
+ releaseShared(CLOSED_STATE);
+ }
+
+ public final void await() throws InterruptedException
+ {
+ acquireSharedInterruptibly(1); // the 1 is a dummy value that is not used.
+ }
+
+ public final boolean await(long time, TimeUnit unit) throws InterruptedException
+ {
+ return tryAcquireSharedNanos(1, unit.toNanos(time)); // the 1 is a dummy value that is not used.
+ }
+}
15 years, 7 months