JBoss Cache SVN: r6537 - in searchable/trunk: src/main/java/org/jboss/cache/search and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-08-07 08:04:30 -0400 (Thu, 07 Aug 2008)
New Revision: 6537
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/IndexSearcherCloser.java
searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java
Modified:
searchable/trunk/TODO.txt
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIterator.java
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
Log:
Wrote up lazyIterator() in CacheQueryImpl. Still needs to be tested
Modified: searchable/trunk/TODO.txt
===================================================================
--- searchable/trunk/TODO.txt 2008-08-07 04:21:36 UTC (rev 6536)
+++ searchable/trunk/TODO.txt 2008-08-07 12:04:30 UTC (rev 6537)
@@ -10,4 +10,6 @@
Think.
-5 - Mock objects.
\ No newline at end of file
+5 - Mock objects.
+
+6 - Think about removing the Hibernate Exceptions.
\ No newline at end of file
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-08-07 04:21:36 UTC (rev 6536)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-08-07 12:04:30 UTC (rev 6537)
@@ -14,7 +14,6 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.filter.ChainedFilter;
import org.hibernate.search.filter.FilterKey;
-import org.hibernate.search.impl.SearchFactoryImpl;
import org.hibernate.search.query.FullTextFilterImpl;
import org.hibernate.search.reader.ReaderProvider;
import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
@@ -114,7 +113,7 @@
//searcher cannot be null
try
{
- closeSearcher(searcher, searchFactory.getReaderProvider());
+ IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
//searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
}
catch (SearchException e)
@@ -133,16 +132,6 @@
}
- private void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
- {
- Set<IndexReader> indexReaders = getIndexReaders(searcher);
-
- for (IndexReader indexReader : indexReaders)
- {
- readerProvider.closeReader(indexReader);
- }
- }
-
/**
* Enable a given filter by its name.
*
@@ -232,7 +221,7 @@
finally
{
- closeSearcher(searcher, searchFactory.getReaderProvider());
+ IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
}
@@ -250,14 +239,20 @@
int max = max(first, hits);
DocumentExtractor extractor = new DocumentExtractor(luceneQuery, searcher, searchFactory, indexProjection);
-
+
+ return new LazyQueryResultIterator(extractor, entityLoader, hits, searcher, searchFactory, first, max);
}
catch (IOException e)
{
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
+ try {
+ IndexSearcherCloser.closeSearcher( searcher, searchFactory.getReaderProvider() );
+ }
+ catch (SearchException ee) {
+ //we have the initial issue already
+ }
+ throw new HibernateException( "Unable to query Lucene index", e );
- return null;
+ }
}
/**
@@ -312,7 +307,7 @@
}
finally
{
- closeSearcher(searcher, searchFactory.getReaderProvider());
+ IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/IndexSearcherCloser.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/IndexSearcherCloser.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/IndexSearcherCloser.java 2008-08-07 12:04:30 UTC (rev 6537)
@@ -0,0 +1,25 @@
+package org.jboss.cache.search;
+
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.reader.ReaderProvider;
+import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
+import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader;
+
+import java.util.Set;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
+ */
+public class IndexSearcherCloser
+{
+ static void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
+ {
+ Set<IndexReader> indexReaders = getIndexReaders(searcher);
+
+ for (IndexReader indexReader : indexReaders)
+ {
+ readerProvider.closeReader(indexReader);
+ }
+ }
+}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/LazyQueryResultIterator.java 2008-08-07 12:04:30 UTC (rev 6537)
@@ -0,0 +1,182 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.search.CacheEntityLoader;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+
+import java.util.NoSuchElementException;
+import java.io.IOException;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
+ */
+public class LazyQueryResultIterator implements QueryResultIterator
+{
+ private int index = 0;
+ private int max = 0;
+ private int first = 0;
+ private CacheEntityLoader entityLoader;
+ private DocumentExtractor extractor;
+ private Hits hits;
+ private IndexSearcher searcher;
+ private SearchFactoryImplementor searchFactory;
+
+ public LazyQueryResultIterator(DocumentExtractor extractor, CacheEntityLoader entityLoader, Hits hits,
+ IndexSearcher searcher, SearchFactoryImplementor searchFactory, int first, int max)
+ {
+ this.extractor = extractor;
+ this.entityLoader = entityLoader;
+ index = first;
+ this.first = first;
+ this.max = max;
+ this.hits = hits;
+ this.searcher = searcher;
+ this.searchFactory = searchFactory;
+ }
+
+ public void jumpToResult(int index) throws IndexOutOfBoundsException
+ {
+ if (index < first || index > max)
+ {
+ throw new IndexOutOfBoundsException("The given index is incorrect. Please check and try again.");
+ }
+
+ this.index = first + index;
+
+ }
+
+ public void first()
+ {
+ index = first;
+ }
+
+ public void last()
+ {
+ index = max;
+ }
+
+ public void afterFirst()
+ {
+ index = first + 1;
+ }
+
+ public void beforeLast()
+ {
+ index = max - 1;
+ }
+
+ public boolean isFirst()
+ {
+ return index == first;
+ }
+
+ public boolean isLast()
+ {
+ return index == max;
+ }
+
+ public boolean isAfterFirst()
+ {
+ return index == first + 1;
+ }
+
+ public boolean isBeforeLast()
+ {
+ return index == max - 1;
+ }
+
+ public void close()
+ {
+ IndexSearcherCloser.closeSearcher(searcher, searchFactory.getReaderProvider());
+ }
+
+ public boolean hasNext()
+ {
+ return index <= max;
+ }
+
+ public Object next()
+ {
+ Object toReturn = null;
+ try
+ {
+ String documentId = (String) extractor.extract(hits, index).id;
+ CacheEntityId id = new CacheEntityId(documentId);
+ toReturn = entityLoader.load(id);
+ index++;
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ return toReturn;
+ }
+
+ public boolean hasPrevious()
+ {
+ return index >= first;
+ }
+
+ public Object previous()
+ {
+ Object toReturn = null;
+ try
+ {
+ String documentId = (String) extractor.extract (hits, index).id;
+ CacheEntityId id = new CacheEntityId(documentId);
+ toReturn = entityLoader.load(id);
+ index--;
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ return toReturn;
+ }
+
+ public int nextIndex()
+ {
+ if (!hasNext()) throw new NoSuchElementException("Out of boundaries");
+ return index + 1;
+ }
+
+ public int previousIndex()
+ {
+ if (!hasPrevious()) throw new NoSuchElementException("Out of boundaries.");
+ return index - 1;
+ }
+
+ /**
+ * This method is not supported and should not be used. Use cache.remove() instead.
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+ }
+
+ /**
+ * This method is not supported in and should not be called. Use cache.put() instead.
+ *
+ * @param o
+ * @throws UnsupportedOperationException
+ */
+ public void set(Object o) throws UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+ }
+
+ /**
+ * This method is not supported in and should not be called. Use cache.put() instead.
+ *
+ * @param o
+ * @throws UnsupportedOperationException
+ */
+
+ public void add(Object o)
+ {
+ throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
+ }
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIterator.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIterator.java 2008-08-07 04:21:36 UTC (rev 6536)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIterator.java 2008-08-07 12:04:30 UTC (rev 6537)
@@ -56,4 +56,10 @@
* @return true if the current result is one before the last
*/
boolean isBeforeLast();
+
+ /**
+ * This method must be called on your iterator once you have finished so that Lucene resources can be freed up.
+ */
+
+ void close();
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2008-08-07 04:21:36 UTC (rev 6536)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java 2008-08-07 12:04:30 UTC (rev 6537)
@@ -116,6 +116,12 @@
return idList.get(index) == idList.get(idList.size() - 2);
}
+ public void close()
+ {
+ // This method does not need to do anything for this type of iterator as when an instace of it is
+ // created, the iterator() method in CacheQueryImpl closes everything that needs to be closed.
+ }
+
/**
* Returns true if the list has more elements when traversing the list in the forward direction.
*
@@ -219,4 +225,5 @@
{
throw new UnsupportedOperationException("Not supported as you are trying to change something in the cache");
}
+
}
16 years, 5 months
JBoss Cache SVN: r6536 - in core/trunk/src: main/java/org/jboss/cache/buddyreplication and 8 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-08-07 00:21:36 -0400 (Thu, 07 Aug 2008)
New Revision: 6536
Added:
core/trunk/src/main/java/org/jboss/cache/util/Immutables.java
Removed:
core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java
core/trunk/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java
Modified:
core/trunk/src/main/java/org/jboss/cache/Fqn.java
core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java
core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationContext.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
core/trunk/src/main/java/org/jboss/cache/transaction/AbstractTransactionContext.java
core/trunk/src/main/java/org/jboss/cache/util/ImmutableListCopy.java
core/trunk/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java
Log:
Convert all immutable usage to new Immutables factory.
Drop ImmutableMapCopy and ImmutableSetCopy in favor of map/set wrappers
Add immutable wrappers which are detectable (unlike Collections.unmodifiable*)
Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -7,9 +7,6 @@
package org.jboss.cache;
-import net.jcip.annotations.Immutable;
-import org.jboss.cache.util.ImmutableListCopy;
-
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
@@ -19,6 +16,10 @@
import java.util.Collections;
import java.util.List;
+import net.jcip.annotations.Immutable;
+
+import org.jboss.cache.util.Immutables;
+
/**
* A Fully Qualified Name (Fqn) is a list of names (typically Strings but can be any Object),
* which represent a path to a particular {@link Node} or sometimes a {@link Region} in a {@link Cache}.
@@ -114,7 +115,7 @@
if (names != null)
{
// if not safe make a defensive copy
- elements = safe ? names : new ImmutableListCopy<Object>(names);
+ elements = safe ? names : Immutables.immutableListCopy(names);
size = elements.size();
}
else
@@ -126,7 +127,7 @@
protected Fqn(Fqn base, List<Object> relative)
{
- elements = new ImmutableListCopy<Object>(base.elements, relative);
+ elements = Immutables.immutableListMerge(base.elements, relative);
size = elements.size();
}
@@ -232,8 +233,8 @@
return root();
String toMatch = stringRepresentation.startsWith(SEPARATOR) ? stringRepresentation.substring(1) : stringRepresentation;
- Object[] el = toMatch.split("/");
- return new Fqn(new ImmutableListCopy(el), true);
+ Object[] el = toMatch.split(SEPARATOR);
+ return new Fqn(Immutables.immutableListWrap(el), true);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/PessimisticUnversionedNode.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -1,6 +1,13 @@
package org.jboss.cache;
import static org.jboss.cache.AbstractNode.NodeFlags.VALID;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.legacy.write.CreateNodeCommand;
import org.jboss.cache.invocation.InvocationContext;
@@ -9,14 +16,8 @@
import org.jboss.cache.marshall.MarshalledValue;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.util.FastCopyHashMap;
-import org.jboss.cache.util.ImmutableSetCopy;
+import org.jboss.cache.util.Immutables;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
/**
* UnversionedNode specific to pessimistic locking, with legacy code.
*
@@ -290,7 +291,7 @@
{
if (children != null && !children.isEmpty())
{
- return new ImmutableSetCopy(children.values());
+ return Immutables.immutableSetConvert(children.values());
}
else
{
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -6,13 +6,11 @@
*/
package org.jboss.cache;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import static org.jboss.cache.AbstractNode.NodeFlags.*;
-import org.jboss.cache.marshall.MarshalledValue;
-import org.jboss.cache.util.FastCopyHashMap;
-import org.jboss.cache.util.ImmutableSetCopy;
-import org.jboss.cache.util.concurrent.SelfInitializingConcurrentHashMap;
+import static org.jboss.cache.AbstractNode.NodeFlags.CHILDREN_LOADED;
+import static org.jboss.cache.AbstractNode.NodeFlags.DATA_LOADED;
+import static org.jboss.cache.AbstractNode.NodeFlags.LOCK_FOR_CHILD_INSERT_REMOVE;
+import static org.jboss.cache.AbstractNode.NodeFlags.REMOVED;
+import static org.jboss.cache.AbstractNode.NodeFlags.VALID;
import java.util.Collections;
import java.util.HashMap;
@@ -22,6 +20,13 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.marshall.MarshalledValue;
+import org.jboss.cache.util.FastCopyHashMap;
+import org.jboss.cache.util.Immutables;
+import org.jboss.cache.util.concurrent.SelfInitializingConcurrentHashMap;
+
/**
* Basic data node class. Throws {@link UnsupportedOperationException} for version-specific methods like {@link #getVersion()} and
* {@link #setVersion(org.jboss.cache.optimistic.DataVersion)}, defined in {@link org.jboss.cache.NodeSPI}.
@@ -208,7 +213,7 @@
{
if (!children.isEmpty())
{
- return new ImmutableSetCopy<InternalNode<K, V>>(children().values());
+ return Immutables.immutableSetConvert(children().values());
}
else
{
@@ -370,9 +375,10 @@
if (data != null) data.clear();
}
+ @SuppressWarnings("unchecked")
public Set<Object> getChildrenNames()
{
- return children.isEmpty() ? Collections.emptySet() : new ImmutableSetCopy<Object>(children.keySet());
+ return children.isEmpty() ? Collections.emptySet() : Immutables.immutableSetCopy(children.keySet());
}
public Set<K> getKeys()
@@ -381,7 +387,7 @@
{
return Collections.emptySet();
}
- return new ImmutableSetCopy<K>(data.keySet());
+ return Immutables.immutableSetCopy(data.keySet());
}
public boolean removeChild(Object childName)
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyGroup.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -6,16 +6,17 @@
*/
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.Collection;
import java.util.Date;
import java.util.List;
import java.util.Vector;
+import net.jcip.annotations.ThreadSafe;
+
+import org.jboss.cache.util.Immutables;
+import org.jgroups.Address;
+
/**
* Value object that represents a buddy group
*
@@ -65,7 +66,7 @@
public List<Address> getBuddies()
{
// defensive copy and immutable.
- return new ImmutableListCopy<Address>(buddies);
+ return Immutables.immutableListCopy(buddies);
}
protected void addBuddies(Collection<Address> buddies)
Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -4,7 +4,7 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.commands.Visitor;
import org.jboss.cache.invocation.InvocationContext;
-import org.jboss.cache.util.ImmutableMapCopy;
+import org.jboss.cache.util.Immutables;
/**
* Implements functionality defined by {@link org.jboss.cache.Cache#getData(org.jboss.cache.Fqn)}
@@ -35,9 +35,9 @@
*/
public Object perform(InvocationContext ctx)
{
- NodeSPI n = ctx.lookUpNode(fqn);
+ NodeSPI<?,?> n = ctx.lookUpNode(fqn);
if (n == null || n.isDeleted()) return null;
- return new ImmutableMapCopy(n.getDataDirect());
+ return Immutables.immutableMapCopy(n.getDataDirect());
}
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationContext.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationContext.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -6,6 +6,12 @@
*/
package org.jboss.cache.invocation;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import javax.transaction.Transaction;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.commands.VisitableCommand;
@@ -14,13 +20,8 @@
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionContext;
import org.jboss.cache.transaction.TransactionTable;
-import org.jboss.cache.util.ImmutableListCopy;
+import org.jboss.cache.util.Immutables;
-import javax.transaction.Transaction;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.List;
-
/**
* This context holds information specific to a method invocation. This is used for Optimistic and Pessimisic Node Locking Schemes.
*
@@ -117,7 +118,7 @@
{
// first check transactional scope
if (transactionContext != null) return transactionContext.getLocks();
- return invocationLocks == null || invocationLocks.isEmpty() ? Collections.emptyList() : new ImmutableListCopy(invocationLocks);
+ return invocationLocks == null || invocationLocks.isEmpty() ? Collections.emptyList() : Immutables.immutableListConvert(invocationLocks);
}
@SuppressWarnings("unchecked")
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -1,5 +1,13 @@
package org.jboss.cache.invocation;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
@@ -31,8 +39,8 @@
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Option;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
-import org.jboss.cache.config.Option;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.factories.annotations.Start;
@@ -44,16 +52,9 @@
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.jboss.cache.util.Immutables;
import org.jgroups.Address;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* The delegate that users (and ChainedInterceptor authors) interact with when they create a cache by using a cache factory.
* This wrapper delegates calls down the interceptor chain.
@@ -589,7 +590,7 @@
GetChildrenNamesCommand command = commandsFactory.buildGetChildrenNamesCommand(fqn);
Set<Object> retval = (Set<Object>) invoker.invoke(ctx, command);
if (retval != null)
- retval = new ImmutableSetCopy<Object>(retval);
+ retval = Immutables.immutableSetWrap(retval); // this is already copied in the command
else
retval = Collections.emptySet();
return retval;
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -6,6 +6,14 @@
*/
package org.jboss.cache.loader;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
@@ -20,16 +28,8 @@
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.marshall.NodeDataExceptionMarker;
import org.jboss.cache.marshall.NodeDataMarker;
-import org.jboss.cache.util.ImmutableMapCopy;
+import org.jboss.cache.util.Immutables;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
/**
* A convenience abstract implementation of a {@link CacheLoader}. Specific methods to note are methods like
* {@link #storeState(org.jboss.cache.Fqn,java.io.ObjectInputStream)}, {@link #loadState(org.jboss.cache.Fqn,java.io.ObjectOutputStream)},
@@ -64,7 +64,7 @@
}
// JBCACHE-769 -- make a defensive copy
- Map<Object, Object> attrs = (attributes == null ? null : new ImmutableMapCopy<Object, Object>(attributes));
+ Map<Object, Object> attrs = (attributes == null ? null : Immutables.immutableMapCopy(attributes));
put(fqn, attrs);
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoader.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AsyncCacheLoader.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -3,14 +3,6 @@
*/
package org.jboss.cache.loader;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Modification;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
-import org.jboss.cache.util.ImmutableMapCopy;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,6 +18,14 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.util.Immutables;
+
/**
* The AsyncCacheLoader is a delegating cache loader that extends
* AbstractDelegatingCacheLoader overriding methods to that should not
@@ -191,7 +191,7 @@
if (config.getUseAsyncPut())
{
// JBCACHE-769 -- make a defensive copy
- Map attrs = (attributes == null ? null : new ImmutableMapCopy(attributes));
+ Map attrs = (attributes == null ? null : Immutables.immutableMapCopy(attributes));
Modification mod = new Modification(Modification.ModificationType.PUT_DATA, name, attrs);
enqueue(mod);
}
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -6,20 +6,6 @@
*/
package org.jboss.cache.marshall;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
-import static 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.ImmutableMapCopy;
-import org.jgroups.Address;
-import org.jgroups.stack.IpAddress;
-
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -36,6 +22,20 @@
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.
*
@@ -349,7 +349,7 @@
out.writeByte(MAGICNUMBER_FASTCOPY_HASHMAP);
marshallMap((Map) o, out, refMap);
}
- else if (o.getClass().equals(ImmutableMapCopy.class))
+ else if (o instanceof Map && Immutables.isImmutable(o))
{
out.writeByte(MAGICNUMBER_IMMUTABLE_MAPCOPY);
marshallMap((Map) o, out, refMap);
@@ -748,7 +748,7 @@
{
// read in as a HashMap first
Map m = unmarshallHashMap(in, refMap);
- return new ImmutableMapCopy(m);
+ return Immutables.immutableMapWrap(m);
}
private Map unmarshallTreeMap(ObjectInputStream in, UnmarshalledReferences refMap) throws Exception
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -6,6 +6,43 @@
*/
package org.jboss.cache.notifications;
+import static org.jboss.cache.notifications.event.Event.Type.BUDDY_GROUP_CHANGED;
+import static org.jboss.cache.notifications.event.Event.Type.CACHE_BLOCKED;
+import static org.jboss.cache.notifications.event.Event.Type.CACHE_STARTED;
+import static org.jboss.cache.notifications.event.Event.Type.CACHE_STOPPED;
+import static org.jboss.cache.notifications.event.Event.Type.CACHE_UNBLOCKED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_ACTIVATED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_CREATED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_EVICTED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_INVALIDATED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_LOADED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_MODIFIED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_MOVED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_PASSIVATED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_REMOVED;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_VISITED;
+import static org.jboss.cache.notifications.event.Event.Type.TRANSACTION_COMPLETED;
+import static org.jboss.cache.notifications.event.Event.Type.TRANSACTION_REGISTERED;
+import static org.jboss.cache.notifications.event.Event.Type.VIEW_CHANGED;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.transaction.Transaction;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
@@ -21,30 +58,49 @@
import org.jboss.cache.factories.annotations.Stop;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.marshall.MarshalledValueMap;
-import org.jboss.cache.notifications.annotation.*;
-import org.jboss.cache.notifications.event.*;
-import static org.jboss.cache.notifications.event.Event.Type.*;
-import org.jboss.cache.util.ImmutableMapCopy;
+import org.jboss.cache.notifications.annotation.BuddyGroupChanged;
+import org.jboss.cache.notifications.annotation.CacheBlocked;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.CacheStarted;
+import org.jboss.cache.notifications.annotation.CacheStopped;
+import org.jboss.cache.notifications.annotation.CacheUnblocked;
+import org.jboss.cache.notifications.annotation.NodeActivated;
+import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.notifications.annotation.NodeEvicted;
+import org.jboss.cache.notifications.annotation.NodeInvalidated;
+import org.jboss.cache.notifications.annotation.NodeLoaded;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.annotation.NodeMoved;
+import org.jboss.cache.notifications.annotation.NodePassivated;
+import org.jboss.cache.notifications.annotation.NodeRemoved;
+import org.jboss.cache.notifications.annotation.NodeVisited;
+import org.jboss.cache.notifications.annotation.TransactionCompleted;
+import org.jboss.cache.notifications.annotation.TransactionRegistered;
+import org.jboss.cache.notifications.annotation.ViewChanged;
+import org.jboss.cache.notifications.event.BuddyGroupChangedEvent;
+import org.jboss.cache.notifications.event.CacheBlockedEvent;
+import org.jboss.cache.notifications.event.CacheStartedEvent;
+import org.jboss.cache.notifications.event.CacheStoppedEvent;
+import org.jboss.cache.notifications.event.CacheUnblockedEvent;
+import org.jboss.cache.notifications.event.Event;
+import org.jboss.cache.notifications.event.EventImpl;
+import org.jboss.cache.notifications.event.NodeActivatedEvent;
+import org.jboss.cache.notifications.event.NodeCreatedEvent;
+import org.jboss.cache.notifications.event.NodeEvictedEvent;
+import org.jboss.cache.notifications.event.NodeInvalidatedEvent;
+import org.jboss.cache.notifications.event.NodeLoadedEvent;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.notifications.event.NodeMovedEvent;
+import org.jboss.cache.notifications.event.NodePassivatedEvent;
+import org.jboss.cache.notifications.event.NodeRemovedEvent;
+import org.jboss.cache.notifications.event.NodeVisitedEvent;
+import org.jboss.cache.notifications.event.TransactionCompletedEvent;
+import org.jboss.cache.notifications.event.TransactionRegisteredEvent;
+import org.jboss.cache.notifications.event.ViewChangedEvent;
+import org.jboss.cache.util.Immutables;
import org.jboss.cache.util.concurrent.WithinThreadExecutor;
import org.jgroups.View;
-import javax.transaction.Transaction;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicInteger;
-
/**
* Helper class that handles all notifications to registered listeners.
*
@@ -606,7 +662,7 @@
if (data == null) return null;
if (data.isEmpty()) return Collections.emptyMap();
if (safe(data)) return useMarshalledValueMaps ? new MarshalledValueMap(data) : data;
- Map defensivelyCopiedData = new ImmutableMapCopy(data);
+ Map defensivelyCopiedData = Immutables.immutableMapCopy(data);
return useMarshalledValueMaps ? new MarshalledValueMap(defensivelyCopiedData) : defensivelyCopiedData;
}
@@ -643,7 +699,7 @@
*/
private static boolean safe(Map map)
{
- return map == null || map instanceof ImmutableMapCopy || map.getClass().equals(emptyMap) || map.getClass().equals(singletonMap);
+ return map == null || Immutables.isImmutable(map) || map.getClass().equals(emptyMap) || map.getClass().equals(singletonMap);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/AbstractTransactionContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/AbstractTransactionContext.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/AbstractTransactionContext.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -7,21 +7,22 @@
package org.jboss.cache.transaction;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.config.Option;
-import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
-import org.jboss.cache.util.ImmutableListCopy;
-
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.WriteCommand;
+import org.jboss.cache.config.Option;
+import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
+import org.jboss.cache.util.Immutables;
+
/**
* An abstract transaction context
*/
@@ -159,7 +160,7 @@
@SuppressWarnings("unchecked")
public List getLocks()
{
- return transactionLocks == null || transactionLocks.isEmpty() ? Collections.emptyList() : new ImmutableListCopy(transactionLocks);
+ return transactionLocks == null || transactionLocks.isEmpty() ? Collections.emptyList() : Immutables.immutableListConvert(transactionLocks);
}
Modified: core/trunk/src/main/java/org/jboss/cache/util/ImmutableListCopy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/ImmutableListCopy.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/util/ImmutableListCopy.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -29,7 +29,7 @@
* @since 3.0
*/
@Immutable
-public class ImmutableListCopy<E> extends AbstractList<E> implements Externalizable
+public class ImmutableListCopy<E> extends AbstractList<E> implements Externalizable, Immutables.Immutable
{
private static final long serialVersionUID = 10929568968966L;
private E[] elements;
Deleted: core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/util/ImmutableMapCopy.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -1,149 +0,0 @@
-package org.jboss.cache.util;
-
-import net.jcip.annotations.Immutable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.AbstractMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Along the lines of ImmutableListCopy and ImmutableSetCopy. This lightweight wrapper primarily meant for iteration.
- * performance of get() and containsKey() are not as efficient as that of a {@link java.util.HashMap}, but iteration is
- * fast since the entry table is a fixed size immutable array.
- * <p/>
- * Typically used in place of the common idiom:
- * <code>
- * return Collections.unmodifiableMap(new HashMap( myInternalMap ));
- * </code>
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-@Immutable
-public class ImmutableMapCopy<K, V> extends AbstractMap<K, V> implements Externalizable // externalizable for client code that may serialize this map
-{
- private static final long serialVersionUID = 10929568968766L;
- private Entry<K, V>[] table;
- private int size;
-
- /**
- * For Externalizable
- */
- public ImmutableMapCopy()
- {
- }
-
- @SuppressWarnings("unchecked")
- public ImmutableMapCopy(Map<K, V> map)
- {
- size = map.size();
- table = new ImmutableEntry[size];
- int i = 0;
- for (Map.Entry<K, V> me : map.entrySet())
- {
- table[i++] = new ImmutableEntry<K, V>(me);
- }
- }
-
- @Override
- public int size()
- {
- return size;
- }
-
- @Override
- public final V remove(Object key)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public final void putAll(Map<? extends K, ? extends V> t)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public final void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- public final Set<Entry<K, V>> entrySet()
- {
- return new ImmutableSetCopy<Map.Entry<K, V>>(table);
- }
-
- /**
- * Format:
- * - entry array size (int)
- * - entry key-value pairs (Object, Object)
- *
- * @param out stream to write to
- * @throws IOException
- */
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeInt(size);
- for (Entry e : table)
- {
- out.writeObject(e.getKey());
- out.writeObject(e.getValue());
- }
- }
-
- /**
- * See {@link #writeExternal(java.io.ObjectOutput)} for serialization format
- *
- * @param in stream
- * @throws IOException
- * @throws ClassNotFoundException
- */
- @SuppressWarnings("unchecked")
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- size = in.readInt();
- table = new Entry[size];
- for (int i = 0; i < size; i++)
- {
- table[i] = new ImmutableEntry(in.readObject(), in.readObject());
- }
- }
-
- private static class ImmutableEntry<K, V> implements Map.Entry<K, V>
- {
- K k;
- V v;
-
- private ImmutableEntry(Map.Entry<K, V> entry)
- {
- k = entry.getKey();
- v = entry.getValue();
- }
-
- private ImmutableEntry(K k, V v)
- {
- this.k = k;
- this.v = v;
- }
-
- public K getKey()
- {
- return k;
- }
-
- public V getValue()
- {
- return v;
- }
-
- public V setValue(V value)
- {
- throw new UnsupportedOperationException();
- }
- }
-}
Deleted: core/trunk/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/main/java/org/jboss/cache/util/ImmutableSetCopy.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -1,143 +0,0 @@
-package org.jboss.cache.util;
-
-import net.jcip.annotations.Immutable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-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
- * @since 3.0
- */
-@Immutable
-public class ImmutableSetCopy<E> extends AbstractSet<E> implements Externalizable
-{
- private static final long serialVersionUID = 11929568968766L;
- private E[] elements;
- private 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;
- }
-
- /**
- * Format:
- * - entry array size (int)
- * - elements (Object)
- *
- * @param out stream to write to
- * @throws IOException
- */
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeInt(size);
- for (E e : elements) out.writeObject(e);
- }
-
- /**
- * See {@link #writeExternal(java.io.ObjectOutput)} for serialization format
- *
- * @param in stream
- * @throws IOException
- * @throws ClassNotFoundException
- */
- @SuppressWarnings("unchecked")
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- size = in.readInt();
- elements = (E[]) new Object[size];
- for (int i = 0; i < size; i++) elements[i] = (E) in.readObject();
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/util/Immutables.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/Immutables.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/util/Immutables.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -0,0 +1,541 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* 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.util;
+
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+/**
+ * Factory for generating immutable type wrappers.
+ *
+ * @author Jason T. Greene
+ */
+public class Immutables
+{
+ /**
+ * Whether or not this collection type is immutable
+ *
+ * @param a Collection, Set, List, or Map
+ * @return true if immutable, false if not
+ */
+ public static boolean isImmutable(Object o)
+ {
+ return o instanceof Immutable;
+ }
+
+ /**
+ * Converts a Collection to an immutable List by copying it.
+ *
+ * @param source the collection to convert
+ * @return a copied/converted immutable list
+ */
+ public static <T> List<T> immutableListConvert(Collection<? extends T> source)
+ {
+ return new ImmutableListCopy<T>(source);
+ }
+
+ /**
+ * Creates an immutable copy of the list.
+ *
+ * @param list the list to copy
+ * @return the immutable copy
+ */
+ public static <T> List<T> immutableListCopy(List<? extends T> list)
+ {
+ return new ImmutableListCopy<T>(list);
+ }
+
+ /**
+ * Wraps an array with an immutable list. There is no copying involved.
+ *
+ * @param <T>
+ * @param array the array to wrap
+ * @return a list containing the array
+ */
+ public static <T> List<T> immutableListWrap(T... array)
+ {
+ return new ImmutableListCopy<T>(array);
+ }
+
+ /**
+ * Creates a new immutable list containing the union (combined entries) of both lists.
+ *
+ * @param list1 contains the first elements of the new list
+ * @param list2 contains the successor elements of the new list
+ * @return a new immutable merged copy of list1 and list2
+ */
+ public static <T> List<T> immutableListMerge(List<? extends T> list1, List<? extends T> list2)
+ {
+ return new ImmutableListCopy<T>(list1, list2);
+ }
+
+ /**
+ * Converts a Collections into an immutable Set by copying it.
+ *
+ * @param collection the collection to convert/copy
+ * @return a new immutable set containing the elements in collection
+ */
+ public static <T> Set<T> immutableSetConvert(Collection<? extends T> collection)
+ {
+ return immutableSetWrap(new HashSet<T>(collection));
+ }
+
+ /**
+ * Wraps a set with an immutable set. There is no copying involved.
+ *
+ * @param set the set to wrap
+ * @return an immutable set wrapper that delegates to the original set
+ */
+ public static <T> Set<T> immutableSetWrap(Set<? extends T> set)
+ {
+ return new ImmutableSetWrapper<T>(set);
+ }
+
+ /**
+ * Creates an immutable copy of the specified set.
+ *
+ * @param set the set to copy from
+ * @return an immutable set copy
+ */
+ public static <T> Set<T> immutableSetCopy(Set<? extends T> set)
+ {
+ Set<? extends T> copy = attemptClone(set);
+ if (copy == null)
+ // Set uses Collection copy-ctor
+ copy = attemptCopyConstructor(set, Collection.class);
+
+ if (copy == null)
+ copy = new HashSet<T>(set);
+
+ return new ImmutableSetWrapper<T>(copy);
+ }
+
+
+ /**
+ * Wraps a map with an immutable map. There is no copying involved.
+ *
+ * @param map the map to wrap
+ * @return an immutable map wrapper that delegates to the original map
+ */
+ public static <K,V> Map<K,V> immutableMapWrap(Map<? extends K, ? extends V> map)
+ {
+ return new ImmutableMapWrapper<K,V>(map);
+ }
+
+ /**
+ * Creates an immutable copy of the specified map.
+ *
+ * @param map the map to copy from
+ * @return an immutable map copy
+ */
+ public static <K,V> Map<K,V> immutableMapCopy(Map<? extends K, ? extends V> map)
+ {
+ Map<? extends K, ? extends V> copy = attemptClone(map);
+ if (copy == null)
+ copy = attemptCopyConstructor(map, Map.class);
+ if (copy == null)
+ copy = new HashMap<K,V>(map);
+
+ return new ImmutableMapWrapper<K,V>(map);
+ }
+
+ /**
+ * Creates a new immutable copy of the specified Collection.
+ *
+ * @param collection the collection to copy
+ * @return an immutable copy
+ */
+ public static <T> Collection<T> immutableCollectionCopy(Collection<? extends T> collection)
+ {
+ Collection<? extends T> copy = attemptClone(collection);
+ if (copy == null)
+ copy = attemptCopyConstructor(collection, Collection.class);
+ if (copy == null)
+ copy = new ArrayList<T>(collection);
+
+ return new ImmutableCollectionWrapper<T>(collection);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private static <T> T attemptClone(T source)
+ {
+ if (source instanceof Cloneable)
+ {
+ try
+ {
+ return (T) source.getClass().getMethod("clone").invoke(source);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> T attemptCopyConstructor(T source, Class<? super T> clazz)
+ {
+ try
+ {
+ return (T) source.getClass().getConstructor(clazz).newInstance(source);
+ }
+ catch (Exception e)
+ {
+ }
+
+ return null;
+ }
+
+
+ public interface Immutable
+ {
+ }
+
+ /*
+ * Immutable wrapper types.
+ *
+ * We have to re-implement Collections.unmodifiableXXX, since it is not
+ * simple to detect them (the class names are JDK dependent).
+ */
+
+ private static class ImmutableIteratorWrapper<E> implements Iterator<E>
+ {
+ private Iterator<? extends E> iterator;
+
+ public ImmutableIteratorWrapper(Iterator<? extends E> iterator)
+ {
+ this.iterator = iterator;
+ }
+
+ public boolean hasNext()
+ {
+ return iterator.hasNext();
+ }
+
+ public E next()
+ {
+ return iterator.next();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private static class ImmutableCollectionWrapper<E> implements Collection<E>, Serializable, Immutable
+ {
+ private static final long serialVersionUID = 6777564328198393535L;
+
+ Collection<? extends E> collection;
+
+ public ImmutableCollectionWrapper(Collection<? extends E> collection)
+ {
+ this.collection = collection;
+ }
+
+ public boolean add(E o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection<? extends E> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean contains(Object o)
+ {
+ return collection.contains(o);
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ return collection.containsAll(c);
+ }
+
+ public boolean equals(Object o)
+ {
+ return collection.equals(o);
+ }
+
+ public int hashCode()
+ {
+ return collection.hashCode();
+ }
+
+ public boolean isEmpty()
+ {
+ return collection.isEmpty();
+ }
+
+ public Iterator<E> iterator()
+ {
+ return new ImmutableIteratorWrapper<E>(collection.iterator());
+ }
+
+ public boolean remove(Object o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size()
+ {
+ return collection.size();
+ }
+
+ public Object[] toArray()
+ {
+ return collection.toArray();
+ }
+
+ public <T> T[] toArray(T[] a)
+ {
+ return collection.toArray(a);
+ }
+
+ public String toString()
+ {
+ return collection.toString();
+ }
+ }
+
+
+
+ private static class ImmutableSetWrapper<E> extends ImmutableCollectionWrapper<E> implements Set<E>, Serializable, Immutable
+ {
+ private static final long serialVersionUID = 7991492805176142615L;
+
+ public ImmutableSetWrapper(Set<? extends E> set)
+ {
+ super(set);
+ }
+ }
+
+
+ static class ImmutableEntry<K, V> implements Map.Entry<K, V>
+ {
+ private K key;
+ private V value;
+ private int hash;
+
+ ImmutableEntry(Map.Entry<? extends K, ? extends V> entry)
+ {
+ this.key = entry.getKey();
+ this.value = entry.getValue();
+ this.hash = entry.hashCode();
+ }
+
+ public K getKey()
+ {
+ return key;
+ }
+
+ public V getValue()
+ {
+ return value;
+ }
+
+ public V setValue(V value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ private static boolean eq(Object o1, Object o2)
+ {
+ return o1 == o2 || (o1 != null && o1.equals(o2));
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean equals(Object o)
+ {
+ if (! (o instanceof Map.Entry))
+ return false;
+
+ Map.Entry<K,V> entry = (Map.Entry<K,V>) o;
+ return eq(entry.getKey(), key) && eq(entry.getValue(), value);
+ }
+
+ public int hashCode()
+ {
+ return hash;
+ }
+
+ public String toString()
+ {
+ return getKey() + "=" + getValue();
+ }
+ }
+
+ private static class ImmutableEntrySetWrapper<K,V> extends ImmutableSetWrapper<Map.Entry<K, V>>
+ {
+ private static final long serialVersionUID = 6378667653889667692L;
+
+ @SuppressWarnings("unchecked")
+ public ImmutableEntrySetWrapper(Set<? extends Map.Entry<? extends K, ? extends V>> set)
+ {
+ super((Set<Entry<K, V>>)set);
+ }
+
+ public Object[] toArray()
+ {
+ Object[] array = new Object[collection.size()];
+ int i = 0;
+ for (Map.Entry<K, V> entry : this)
+ array[i++] = entry;
+ return array;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T[] toArray(T[] array)
+ {
+ int size = collection.size();
+ if (array.length < size)
+ array = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
+
+ int i = 0;
+ Object[] result = array;
+ for (Map.Entry<K, V> entry : this)
+ result[i++] = entry;
+
+ return array;
+ }
+
+ public Iterator<Map.Entry<K,V>> iterator()
+ {
+ return new ImmutableIteratorWrapper<Entry<K,V>>(collection.iterator()) {
+ public Entry<K, V> next()
+ {
+ return new ImmutableEntry<K,V>(super.next());
+ }
+ };
+ }
+ }
+
+ private static class ImmutableMapWrapper<K,V> implements Map<K,V>, Serializable, Immutable
+ {
+ private static final long serialVersionUID = 708144227046742221L;
+
+ private Map<? extends K, ? extends V> map;
+
+ public ImmutableMapWrapper(Map<? extends K, ? extends V> map)
+ {
+ this.map = map;
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return map.containsKey(key);
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return map.containsValue(value);
+ }
+
+ public Set<Entry<K, V>> entrySet()
+ {
+ return new ImmutableEntrySetWrapper<K,V>(map.entrySet());
+ }
+
+ public boolean equals(Object o)
+ {
+ return map.equals(o);
+ }
+
+ public V get(Object key)
+ {
+ return map.get(key);
+ }
+
+ public int hashCode()
+ {
+ return map.hashCode();
+ }
+
+ public boolean isEmpty()
+ {
+ return map.isEmpty();
+ }
+
+ public Set<K> keySet()
+ {
+ return new ImmutableSetWrapper<K>(map.keySet());
+ }
+
+ public V put(K key, V value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void putAll(Map<? extends K, ? extends V> t)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public V remove(Object key)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size()
+ {
+ return map.size();
+ }
+
+ public Collection<V> values()
+ {
+ return new ImmutableCollectionWrapper<V>(map.values());
+ }
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java 2008-08-06 16:17:53 UTC (rev 6535)
+++ core/trunk/src/test/java/org/jboss/cache/util/ImmutableListCopyTest.java 2008-08-07 04:21:36 UTC (rev 6536)
@@ -12,7 +12,7 @@
{
public void testImmutability()
{
- List<String> l = new ImmutableListCopy<String>(Collections.singletonList("one"));
+ List<String> l = Immutables.immutableListCopy(Collections.singletonList("one"));
try
{
l.add("two");
@@ -126,10 +126,8 @@
public void testListIterator()
{
- List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ List<Integer> list = Immutables.immutableListWrap(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;
@@ -145,7 +143,7 @@
public void testSubLists()
{
List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
- List<Integer> list = new ImmutableListCopy<Integer>(ints);
+ List<Integer> list = Immutables.immutableListCopy(ints);
assert ints.subList(2, 5).equals(list.subList(2, 5));
assert ints.subList(1, 9).equals(list.subList(1, 9));
16 years, 5 months
JBoss Cache SVN: r6535 - benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-08-06 12:17:53 -0400 (Wed, 06 Aug 2008)
New Revision: 6535
Modified:
benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/SessionSimulatorTest.java
Log:
increased memory size
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/SessionSimulatorTest.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/SessionSimulatorTest.java 2008-08-06 16:14:04 UTC (rev 6534)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/SessionSimulatorTest.java 2008-08-06 16:17:53 UTC (rev 6535)
@@ -15,6 +15,7 @@
/**
* Simulates work with a web session.
*
+ * todo mmarkus - improve the test to support multiple threads. Correlate this with usage of message_bundling in JBC
* @author Mircea.Markus(a)jboss.com
* @since 2.2
*/
16 years, 5 months
JBoss Cache SVN: r6534 - core/trunk/src/main/resources/config-samples.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-08-06 12:14:04 -0400 (Wed, 06 Aug 2008)
New Revision: 6534
Added:
core/trunk/src/main/resources/config-samples/total-replication.xml
Modified:
core/trunk/src/main/resources/config-samples/buddy-replication.xml
core/trunk/src/main/resources/config-samples/invalidation-async.xml
Log:
updated configuration files
Modified: core/trunk/src/main/resources/config-samples/buddy-replication.xml
===================================================================
--- core/trunk/src/main/resources/config-samples/buddy-replication.xml 2008-08-06 16:04:59 UTC (rev 6533)
+++ core/trunk/src/main/resources/config-samples/buddy-replication.xml 2008-08-06 16:14:04 UTC (rev 6534)
@@ -28,7 +28,7 @@
<transport clusterName="JBossCache-Cluster">
<!-- JGroups protocol stack properties. -->
<jgroupsConfig>
- <TCP discard_incompatible_packets="true" enable_bundling="true" enable_diagnostics="true"
+ <TCP discard_incompatible_packets="true" enable_bundling="false" enable_diagnostics="true"
enable_unicast_bundling="true" 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"
Modified: core/trunk/src/main/resources/config-samples/invalidation-async.xml
===================================================================
--- core/trunk/src/main/resources/config-samples/invalidation-async.xml 2008-08-06 16:04:59 UTC (rev 6533)
+++ core/trunk/src/main/resources/config-samples/invalidation-async.xml 2008-08-06 16:14:04 UTC (rev 6534)
@@ -29,7 +29,7 @@
<transport clusterName="JBossCache-Cluster">
<!-- JGroups protocol stack properties. -->
<jgroupsConfig>
- <TCP discard_incompatible_packets="true" enable_bundling="true" enable_diagnostics="true"
+ <TCP discard_incompatible_packets="true" enable_bundling="false" enable_diagnostics="true"
enable_unicast_bundling="true" 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"
Added: core/trunk/src/main/resources/config-samples/total-replication.xml
===================================================================
--- core/trunk/src/main/resources/config-samples/total-replication.xml (rev 0)
+++ core/trunk/src/main/resources/config-samples/total-replication.xml 2008-08-06 16:14:04 UTC (rev 6534)
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://www.jboss.org/jbosscache/jbosscache-config-3.0.xsd">
+
+ <!--
+ isolationLevel : SERIALIZABLE - (not supported in mvcc)
+ REPEATABLE_READ (default)
+ READ_COMMITTED
+ READ_UNCOMMITTED (not supported in mvcc)
+ NONE
+ lockAcquisitionTimeout: max number of milliseconds to wait for a lock acquisition
+ nodeLockingScheme : mvcc (default)
+ optimistic
+ pessimistic
+ -->
+ <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="10000" nodeLockingScheme="mvcc"/>
+
+ <!-- Configure the TransactionManager -->
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
+
+ <!--
+ timeout: The max amount of time (in milliseconds) we wait until the state (i.e. the contents of the cache) is
+ retrieved from existing members in a clustered environment
+ -->
+ <stateRetrieval timeout="20000"/>
+
+ <transport clusterName="JBossCache-Cluster">
+ <!-- JGroups protocol stack properties. -->
+ <jgroupsConfig>
+ <TCP discard_incompatible_packets="true" enable_bundling="false" enable_diagnostics="true"
+ enable_unicast_bundling="true" 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"/>
+ <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"/>
+ <FC max_credits="5000000" min_threshold="0.20"/>
+ <FRAG2 frag_size="60000"/>
+ <pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
+ <pbcast.FLUSH timeout="0"/>
+ </jgroupsConfig>
+ </transport>
+
+
+ <!-- this is a replicated cache-->
+ <replication>
+ <!-- Number of milliseconds to wait until all responses for a synchronous call have been received -->
+ <sync replTimeout="15000"/>
+
+ <!--<async useReplQueue="false" replQueueInterval="1500" replQueueMaxElements="30000"/>-->
+ </replication>
+</jbosscache>
16 years, 5 months
JBoss Cache SVN: r6533 - benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-08-06 12:04:59 -0400 (Wed, 06 Aug 2008)
New Revision: 6533
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
Log:
updated lib
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/lib/jbosscache-core.jar
===================================================================
(Binary files differ)
16 years, 5 months
JBoss Cache SVN: r6532 - benchmarks/benchmark-fwk/trunk.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-08-06 11:52:03 -0400 (Wed, 06 Aug 2008)
New Revision: 6532
Modified:
benchmarks/benchmark-fwk/trunk/runNode.sh
Log:
increased memory size
Modified: benchmarks/benchmark-fwk/trunk/runNode.sh
===================================================================
--- benchmarks/benchmark-fwk/trunk/runNode.sh 2008-08-06 14:58:15 UTC (rev 6531)
+++ benchmarks/benchmark-fwk/trunk/runNode.sh 2008-08-06 15:52:03 UTC (rev 6532)
@@ -2,6 +2,9 @@
# author: Mircea.Markus(a)jboss.com
# cygwin users: add the scripts from :pserver:anoncvs@cygwin.com:/cvs/cygwin-apps/wrappers/java to the $cygwin_home/usr/local/bin
# those would make an automatic conversion from unix CLASSPATH to win classpath, needed when executing java -cp
+# todo mmarkus - add another configuration file to set all the jvm params, which should be called by this one (phps benchmatrk-jvm.sh)
+# todo mmarkus - move the scripts in an bin directory as there are more and more scrips now
+# todo mmarkus - if allJbossCacheTests.sh is launched with nohup it does not work, make that work
preferIPv4Stack=true
DEBUG=debug
16 years, 5 months
JBoss Cache SVN: r6531 - core/trunk/src/main/java/org/jboss/cache/factories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-08-06 10:58:15 -0400 (Wed, 06 Aug 2008)
New Revision: 6531
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
Log:
Cleaned up ugly generic casts in factories
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-08-06 14:57:47 UTC (rev 6530)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-08-06 14:58:15 UTC (rev 6531)
@@ -15,7 +15,6 @@
import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.factories.annotations.Stop;
-import org.jboss.cache.factories.context.ContextMetaFactory;
import org.jboss.cache.util.BeanUtils;
import org.jboss.cache.util.reflect.ReflectionUtil;
16 years, 5 months
JBoss Cache SVN: r6530 - in core/trunk/src/main/java/org/jboss/cache/factories: context and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-08-06 10:57:47 -0400 (Wed, 06 Aug 2008)
New Revision: 6530
Added:
core/trunk/src/main/java/org/jboss/cache/factories/ContextMetaFactory.java
Removed:
core/trunk/src/main/java/org/jboss/cache/factories/context/ContextMetaFactory.java
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/LockManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/StateTransferFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/context/OptimisticContextFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/context/PessimisticContextFactory.java
Log:
Cleaned up ugly generic casts in factories
Modified: core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -16,17 +16,17 @@
@DefaultFactoryFor(classes = CommandsFactory.class)
public class CommandsMetaFactory extends ComponentFactory
{
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("deprecation")
protected <T> T construct(Class<T> componentType)
{
switch (configuration.getNodeLockingScheme())
{
case MVCC:
- return (T) new CommandsFactoryImpl();
+ return componentType.cast(new CommandsFactoryImpl());
case OPTIMISTIC:
- return (T) new OptimisticCommandsFactoryImpl();
+ return componentType.cast(new OptimisticCommandsFactoryImpl());
case PESSIMISTIC:
- return (T) new PessimisticCommandsFactoryImpl();
+ return componentType.cast(new PessimisticCommandsFactoryImpl());
}
throw new ConfigurationException("Unknown locking scheme " + configuration.getNodeLockingScheme());
}
Copied: core/trunk/src/main/java/org/jboss/cache/factories/ContextMetaFactory.java (from rev 6527, core/trunk/src/main/java/org/jboss/cache/factories/context/ContextMetaFactory.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ContextMetaFactory.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ContextMetaFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -0,0 +1,37 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+import org.jboss.cache.factories.context.ContextFactory;
+import org.jboss.cache.factories.context.MVCCContextFactory;
+import org.jboss.cache.factories.context.OptimisticContextFactory;
+import org.jboss.cache.factories.context.PessimisticContextFactory;
+
+/**
+ * Responsible for creating the appropriate {@link org.jboss.cache.factories.context.ContextFactory} based on configuration used.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@DefaultFactoryFor(classes = ContextFactory.class)
+public class ContextMetaFactory extends ComponentFactory
+{
+ @SuppressWarnings("deprecation")
+ protected <T> T construct(Class<T> componentType)
+ {
+ if (log.isTraceEnabled()) log.trace("Cache configuration is " + configuration.getNodeLockingScheme());
+ switch (configuration.getNodeLockingScheme())
+ {
+ case MVCC:
+ if (log.isTraceEnabled()) log.trace("Creating an MVCC context factory");
+ return componentType.cast(new MVCCContextFactory());
+ case OPTIMISTIC:
+ if (log.isTraceEnabled()) log.trace("Creating an optimistic context factory");
+ return componentType.cast(new OptimisticContextFactory());
+ case PESSIMISTIC:
+ if (log.isTraceEnabled()) log.trace("Creating a pessimistic context factory");
+ return componentType.cast(new PessimisticContextFactory());
+ }
+ throw new ConfigurationException("Unknown configuration node locking scheme");
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -29,7 +29,6 @@
public class EmptyConstructorFactory extends ComponentFactory
{
@Override
- @SuppressWarnings("unchecked")
protected <T> T construct(Class<T> componentType)
{
try
@@ -47,7 +46,7 @@
componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
}
- return (T) componentImpl.newInstance();
+ return componentType.cast(componentImpl.newInstance());
}
else
{
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -193,12 +193,11 @@
}
@Override
- @SuppressWarnings("unchecked")
protected <T> T construct(Class<T> componentType)
{
try
{
- return (T) buildInterceptorChain();
+ return componentType.cast(buildInterceptorChain());
}
catch (Exception e)
{
Modified: core/trunk/src/main/java/org/jboss/cache/factories/LockManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/LockManagerFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/LockManagerFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -16,19 +16,19 @@
public class LockManagerFactory extends EmptyConstructorFactory
{
@Override
- @SuppressWarnings({"unchecked", "deprecation"})
+ @SuppressWarnings("deprecation")
protected <T> T construct(Class<T> componentType)
{
if (log.isTraceEnabled()) log.trace("Cache configuration is " + configuration.getNodeLockingScheme());
switch (configuration.getNodeLockingScheme())
{
case MVCC:
- return (T) super.construct(MVCCLockManager.class);
+ return componentType.cast(super.construct(MVCCLockManager.class));
case OPTIMISTIC:
- return (T) super.construct(NodeBasedLockManager.class);
+ return componentType.cast(super.construct(NodeBasedLockManager.class));
case PESSIMISTIC:
default:
- return (T) super.construct(PessimisticNodeBasedLockManager.class);
+ return componentType.cast(super.construct(PessimisticNodeBasedLockManager.class));
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/NodeMetaFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -16,17 +16,17 @@
@DefaultFactoryFor(classes = NodeFactory.class)
public class NodeMetaFactory extends ComponentFactory
{
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("deprecation")
protected <T> T construct(Class<T> componentType)
{
switch (configuration.getNodeLockingScheme())
{
case MVCC:
- return (T) new MVCCNodeFactory();
+ return componentType.cast(new MVCCNodeFactory());
case OPTIMISTIC:
- return (T) new OptimisticNodeFactory();
+ return componentType.cast(new OptimisticNodeFactory());
case PESSIMISTIC:
- return (T) new PessimisticNodeFactory();
+ return componentType.cast(new PessimisticNodeFactory());
default:
throw new ConfigurationException("Unknown locking scheme " + configuration.getNodeLockingScheme());
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/RegionManagerFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -14,15 +14,15 @@
@DefaultFactoryFor(classes = RegionManager.class)
public class RegionManagerFactory extends ComponentFactory
{
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("deprecation")
protected <T> T construct(Class<T> componentType)
{
switch (configuration.getNodeLockingScheme())
{
case MVCC:
- return (T) new RegionManagerImpl();
+ return componentType.cast(new RegionManagerImpl());
default:
- return (T) new LegacyRegionManagerImpl();
+ return componentType.cast(new LegacyRegionManagerImpl());
}
}
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/RuntimeConfigAwareFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -18,7 +18,6 @@
public class RuntimeConfigAwareFactory extends EmptyConstructorFactory
{
@Override
- @SuppressWarnings("unchecked")
protected <T> T construct(Class<T> componentType)
{
T component = super.construct(componentType);
Modified: core/trunk/src/main/java/org/jboss/cache/factories/StateTransferFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/StateTransferFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/StateTransferFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -28,17 +28,17 @@
@DefaultFactoryFor(classes = {StateTransferGenerator.class, StateTransferIntegrator.class})
public class StateTransferFactory extends ComponentFactory
{
+ @SuppressWarnings("deprecation")
protected <T> T construct(Class<T> componentType)
{
-
if (componentType.equals(StateTransferIntegrator.class))
{
switch (configuration.getNodeLockingScheme())
{
case MVCC:
- return (T) new DefaultStateTransferIntegrator();
+ return componentType.cast(new DefaultStateTransferIntegrator());
default:
- return (T) new LegacyStateTransferIntegrator();
+ return componentType.cast(new LegacyStateTransferIntegrator());
}
}
else
@@ -46,9 +46,9 @@
switch (configuration.getNodeLockingScheme())
{
case MVCC:
- return (T) new DefaultStateTransferGenerator();
+ return componentType.cast(new DefaultStateTransferGenerator());
default:
- return (T) new LegacyStateTransferGenerator();
+ return componentType.cast(new LegacyStateTransferGenerator());
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/StateTransferManagerFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -14,15 +14,15 @@
@DefaultFactoryFor(classes = StateTransferManager.class)
public class StateTransferManagerFactory extends ComponentFactory
{
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("deprecation")
protected <T> T construct(Class<T> componentType)
{
switch (configuration.getNodeLockingScheme())
{
case MVCC:
- return (T) new DefaultStateTransferManager();
+ return componentType.cast(new DefaultStateTransferManager());
default:
- return (T) new LegacyStateTransferManager();
+ return componentType.cast(new LegacyStateTransferManager());
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/TransactionManagerFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -15,7 +15,6 @@
@DefaultFactoryFor(classes = {TransactionManager.class})
public class TransactionManagerFactory extends ComponentFactory
{
- @SuppressWarnings("unchecked")
protected <T> T construct(Class<T> componentType)
{
// See if we had a TransactionManager injected into our config
@@ -53,6 +52,6 @@
log.info("failed looking up TransactionManager, will not use transactions", e);
}
}
- return (T) transactionManager;
+ return componentType.cast(transactionManager);
}
}
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/context/ContextMetaFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/context/ContextMetaFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/context/ContextMetaFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -1,34 +0,0 @@
-package org.jboss.cache.factories.context;
-
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.factories.ComponentFactory;
-import org.jboss.cache.factories.annotations.DefaultFactoryFor;
-
-/**
- * Responsible for creating the appropriate {@link ContextFactory} based on configuration used.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-@DefaultFactoryFor(classes = ContextFactory.class)
-public class ContextMetaFactory extends ComponentFactory
-{
- @SuppressWarnings("unchecked")
- protected <T> T construct(Class<T> componentType)
- {
- if (log.isTraceEnabled()) log.trace("Cache configuration is " + configuration.getNodeLockingScheme());
- switch (configuration.getNodeLockingScheme())
- {
- case MVCC:
- if (log.isTraceEnabled()) log.trace("Creating an MVCC context factory");
- return (T) new MVCCContextFactory();
- case OPTIMISTIC:
- if (log.isTraceEnabled()) log.trace("Creating an optimistic context factory");
- return (T) new OptimisticContextFactory();
- case PESSIMISTIC:
- if (log.isTraceEnabled()) log.trace("Creating a pessimistic context factory");
- return (T) new PessimisticContextFactory();
- }
- throw new ConfigurationException("Unknown configuration node locking scheme");
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/context/OptimisticContextFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/context/OptimisticContextFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/context/OptimisticContextFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -12,7 +12,10 @@
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
+ * @deprecated will be removed when optimistic locking is removed.
*/
+@Deprecated
+@SuppressWarnings("deprecation")
public class OptimisticContextFactory extends PessimisticContextFactory
{
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/factories/context/PessimisticContextFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/context/PessimisticContextFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
+++ core/trunk/src/main/java/org/jboss/cache/factories/context/PessimisticContextFactory.java 2008-08-06 14:57:47 UTC (rev 6530)
@@ -16,7 +16,10 @@
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
+ * @deprecated will be removed when pessimistic locking is removed.
*/
+@Deprecated
+@SuppressWarnings("deprecation")
public class PessimisticContextFactory implements ContextFactory
{
DataContainer container;
16 years, 5 months
JBoss Cache SVN: r6529 - in core/trunk/src: main/java/org/jboss/cache/factories and 3 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-08-06 10:42:03 -0400 (Wed, 06 Aug 2008)
New Revision: 6529
Added:
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java
Removed:
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
Log:
Fixed broken data gravitation with MVCC
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-08-06 14:37:50 UTC (rev 6528)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-08-06 14:42:03 UTC (rev 6529)
@@ -219,6 +219,26 @@
public List<NodeData> buildNodeData(List<NodeData> list, NodeSPI node, boolean mapSafe)
{
+ if (usingMvcc)
+ return buildNodeData(list, node.getDelegationTarget(), mapSafe);
+ else
+ return buildNodeDataLegacy(list, node, mapSafe);
+ }
+
+ private List<NodeData> buildNodeData(List<NodeData> list, InternalNode<?, ?> node, boolean mapSafe)
+ {
+ NodeData data = new NodeData(buddyFqnTransformer.getActualFqn(node.getFqn()), node.getData(), mapSafe);
+ list.add(data);
+ for (InternalNode childNode : node.getChildrenMap().values())
+ {
+ buildNodeData(list, childNode, true);
+ }
+ return list;
+ }
+
+ @Deprecated
+ private List<NodeData> buildNodeDataLegacy(List<NodeData> list, NodeSPI node, boolean mapSafe)
+ {
NodeData data = new NodeData(buddyFqnTransformer.getActualFqn(node.getFqn()), node.getDataDirect(), mapSafe);
list.add(data);
for (Object childNode : node.getChildrenDirect())
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-08-06 14:37:50 UTC (rev 6528)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-08-06 14:42:03 UTC (rev 6529)
@@ -132,8 +132,14 @@
}
if (configuration.isUsingBuddyReplication())
- interceptorChain.appendIntereceptor(createInterceptor(DataGravitatorInterceptor.class));
+ {
+ if (configuration.getNodeLockingScheme() == NodeLockingScheme.MVCC)
+ interceptorChain.appendIntereceptor(createInterceptor(DataGravitatorInterceptor.class));
+ else
+ interceptorChain.appendIntereceptor(createInterceptor(LegacyDataGravitatorInterceptor.class));
+ }
+
if (optimistic)
{
interceptorChain.appendIntereceptor(createInterceptor(OptimisticLockingInterceptor.class));
Deleted: core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-08-06 14:37:50 UTC (rev 6528)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-08-06 14:42:03 UTC (rev 6529)
@@ -1,439 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.interceptors;
-
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.buddyreplication.GravitateResult;
-import org.jboss.cache.commands.CommandsFactory;
-import org.jboss.cache.commands.DataCommand;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.read.ExistsCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetKeysCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.read.GravitateDataCommand;
-import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
-import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.invocation.InvocationContext;
-import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jgroups.Address;
-import org.jgroups.blocks.GroupRequest;
-import org.jgroups.blocks.RspFilter;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * The Data Gravitator interceptor intercepts cache misses and attempts to
- * gravitate data from other parts of the cluster.
- * <p/>
- * Only used if Buddy Replication is enabled. Also, the interceptor only kicks
- * in if an {@link org.jboss.cache.config.Option} is passed in to force Data
- * Gravitation for a specific invocation or if <b>autoDataGravitation</b> is
- * set to <b>true</b> when configuring Buddy Replication.
- * <p/>
- * See the JBoss Cache User Guide for more details on configuration options.
- * There is a section dedicated to Buddy Replication in the Replication
- * chapter.
- * <p/>
- * In terms of functionality, if a gravitation call has occured and a cleanup call is needed (based on
- * how BR is configured), a cleanup call will be broadcast immediately after the gravitation call (no txs)
- * or if txs are used, an <i>asynchronous</i> call is made to perform the cleanup <i>outside</i> the scope
- * of the tx that caused the gravitation event.
- * <p/>
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
- */
-public class DataGravitatorInterceptor extends BaseRpcInterceptor
-{
- private BuddyManager buddyManager;
- /**
- * Map that contains commands that need cleaning up. This is keyed on global transaction, and contains a list of
- * cleanup commands corresponding to all gravitate calls made during the course of the transaction in question.
- */
- private Map<GlobalTransaction, List<ReplicableCommand>> cleanupCommands = new ConcurrentHashMap<GlobalTransaction, List<ReplicableCommand>>();
- private DataContainer dataContainer;
- private CommandsFactory commandsFactory;
- private CacheSPI cacheSPI;
- private BuddyFqnTransformer buddyFqnTransformer;
-
- @Inject
- public void injectComponents(BuddyManager buddyManager, DataContainer dataContainer, CommandsFactory commandsFactory, CacheSPI cacheSPI, BuddyFqnTransformer transformer)
- {
- this.buddyManager = buddyManager;
- this.dataContainer = dataContainer;
- this.commandsFactory = commandsFactory;
- this.cacheSPI = cacheSPI;
- buddyFqnTransformer = transformer;
- }
-
- @Override
- public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
- {
- return handleGetMethod(ctx, command);
- }
-
- @Override
- public Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
- {
- return handleGetMethod(ctx, command);
- }
-
- @Override
- public Object visitExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
- {
- return handleGetMethod(ctx, command);
- }
-
- @Override
- public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
- {
- return handleGetMethod(ctx, command);
- }
-
- @Override
- public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
- {
- return handleGetMethod(ctx, command);
- }
-
- @Override
- public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
- {
- return handleGetMethod(ctx, command);
- }
-
- @Override
- public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
- {
- try
- {
- return invokeNextInterceptor(ctx, command);
- }
- finally
- {
- cleanupCommands.remove(ctx.getGlobalTransaction());
- }
- }
-
- @Override
- public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
- {
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- try
- {
- doCommit(gtx);
- return invokeNextInterceptor(ctx, command);
- }
- finally
- {
- cleanupCommands.remove(gtx);
- }
- }
-
- private Object handleGetMethod(InvocationContext ctx, DataCommand command) throws Throwable
- {
- if (isGravitationEnabled(ctx))
- {
- // test that the Fqn being requested exists locally in the cache.
- if (trace) log.trace("Checking local existence of requested fqn " + command.getFqn());
- if (buddyFqnTransformer.isBackupFqn(command.getFqn()))
- {
- log.info("Is call for a backup Fqn, not performing any gravitation. Direct calls on internal backup nodes are *not* supported.");
- }
- else
- {
- if (!dataContainer.exists(command.getFqn()))
- {
- // gravitation is necessary.
-
- if (trace) log.trace("Gravitating from local backup tree");
- BackupData data = localBackupGet(command.getFqn(), ctx);
-
- if (data == null)
- {
- if (trace) log.trace("Gravitating from remote backup tree");
- // gravitate remotely.
- data = remoteBackupGet(command.getFqn());
- }
-
- if (data != null)
- {
- if (trace)
- log.trace("Passing the put call locally to make sure state is persisted and ownership is correctly established.");
- // store the gravitated node locally. This will cause it being backed up in the current instance's buddy.
- createNode(data.backupData);
-
- cleanBackupData(data, ctx);
- }
- }
- else
- {
- if (trace) log.trace("No need to gravitate; have this already.");
- }
- }
- }
- else
- {
- if (trace)
- {
- log.trace("Suppressing data gravitation for this call.");
- }
- }
- return invokeNextInterceptor(ctx, command);
- }
-
- private boolean isGravitationEnabled(InvocationContext ctx)
- {
- boolean enabled = ctx.isOriginLocal();
- if (enabled)
- {
- if (!buddyManager.isAutoDataGravitation())
- {
- enabled = ctx.getOptionOverrides().getForceDataGravitation();
- }
- }
- return enabled;
- }
-
- private void doCommit(GlobalTransaction gtx) throws Throwable
- {
- if (cleanupCommands.containsKey(gtx))
- {
- if (trace) log.trace("Broadcasting cleanup commands for gtx " + gtx);
-
- for (ReplicableCommand command : cleanupCommands.get(gtx))
- {
- try
- {
- doCleanup(command);
- }
- catch (Throwable th)
- {
- log.warn("Problems performing gravitation cleanup. Cleanup command: " + command, th);
- }
- }
- }
- else
- {
- if (trace) log.trace("No cleanups to broadcast in commit phase for gtx " + gtx);
- }
- }
-
- private BackupData remoteBackupGet(Fqn name) throws Exception
- {
- BackupData result = null;
- GravitateResult gr = gravitateData(name);
- if (gr.isDataFound())
- {
- if (trace)
- {
- log.trace("Got response " + gr);
- }
-
- result = new BackupData(name, gr);
- }
- return result;
- }
-
- private void cleanBackupData(BackupData backup, InvocationContext ctx) throws Throwable
- {
-
- DataGravitationCleanupCommand cleanupCommand = commandsFactory.buildDataGravitationCleanupCommand(backup.primaryFqn, backup.backupFqn);
- GlobalTransaction gtx = ctx.getGlobalTransaction();
-
- if (gtx == null)
- {
- // broadcast removes
- // remove main Fqn
- if (trace) log.trace("Performing cleanup on [" + backup.primaryFqn + "]");
- // remove backup Fqn
- doCleanup(cleanupCommand);
- }
- else
- {
- if (trace)
- log.trace("Data gravitation performed under global transaction " + gtx + ". Not broadcasting cleanups until the tx commits. Recording cleanup command for later use.");
- List<ReplicableCommand> commands;
- if (cleanupCommands.containsKey(gtx))
- {
- commands = cleanupCommands.get(gtx);
- }
- else
- {
- commands = new LinkedList<ReplicableCommand>();
- }
-
- commands.add(cleanupCommand);
- cleanupCommands.put(gtx, commands);
- }
- }
-
- private void doCleanup(ReplicableCommand cleanupCommand) throws Throwable
- {
- // cleanup commands are always ASYNCHRONOUS and is broadcast to *everyone* (even members of the current buddy
- // group as they may be members of > 1 buddy group)
- replicateCall(null, cleanupCommand, false, false, false, true, -1);
- }
-
- @SuppressWarnings("deprecation")
- private GravitateResult gravitateData(Fqn fqn) throws Exception
- {
- if (trace) log.trace("Requesting data gravitation for Fqn " + fqn);
-
- List<Address> mbrs = rpcManager.getMembers();
- Boolean searchSubtrees = buddyManager.isDataGravitationSearchBackupTrees() ? Boolean.TRUE : Boolean.FALSE;
- GravitateDataCommand command = commandsFactory.buildGravitateDataCommand(fqn, searchSubtrees);
- // doing a GET_ALL is crappy but necessary since JGroups' GET_FIRST could return null results from nodes that do
- // not have either the primary OR backup, and stop polling other valid nodes.
- List resps = rpcManager.callRemoteMethods(null, command, GroupRequest.GET_ALL, buddyManager.getBuddyCommunicationTimeout(), new ResponseValidityFilter(mbrs, rpcManager.getLocalAddress()), false);
-
- if (trace) log.trace("got responses " + resps);
-
- if (resps == null)
- {
- if (mbrs.size() > 1) log.error("No replies to call " + command);
- return GravitateResult.noDataFound();
- }
-
- // test for and remove exceptions
- GravitateResult result = GravitateResult.noDataFound();
- for (Object o : resps)
- {
- if (o instanceof Throwable)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Found remote Throwable among responses - removing from responses list", (Exception) o);
- }
- }
- else if (o != null)
- {
- result = (GravitateResult) o;
- if (result.isDataFound())
- {
- break;
- }
- }
- else if (!configuration.isUseRegionBasedMarshalling())
- {
- // Null is OK if we are using region based marshalling; it
- // is what is returned if a region is inactive. Otherwise
- // getting a null is an error condition
- log.error("Unexpected null response to call " + command + ".");
- }
-
- }
-
- return result;
- }
-
- @SuppressWarnings("unchecked")
- private void createNode(List<NodeData> nodeData) throws CacheException
- {
- for (NodeData data : nodeData)
- {
- cacheSPI.put(data.getFqn(), data.getAttributes());
- }
- }
-
- private BackupData localBackupGet(Fqn fqn, InvocationContext ctx) throws CacheException
- {
- GravitateResult result = cacheSPI.gravitateData(fqn, true, ctx);// a "local" gravitation
- boolean found = result.isDataFound();
- BackupData data = null;
-
- if (found)
- {
- Fqn backupFqn = result.getBuddyBackupFqn();
- data = new BackupData(fqn, result);
- // now the cleanup
- if (buddyManager.isDataGravitationRemoveOnFind())
- {
- // Remove locally only; the remote call will
- // be broadcast later
- ctx.getOptionOverrides().setCacheModeLocal(true);
- cacheSPI.removeNode(backupFqn);
- }
- else
- {
- cacheSPI.evict(backupFqn, true);
- }
- }
-
- if (trace) log.trace("Retrieved data " + data + " found = " + found);
- return data;
- }
-
- private static class BackupData
- {
- Fqn primaryFqn;
- Fqn backupFqn;
- List<NodeData> backupData;
-
- public BackupData(Fqn primaryFqn, GravitateResult gr)
- {
- this.primaryFqn = primaryFqn;
- this.backupFqn = gr.getBuddyBackupFqn();
- this.backupData = gr.getNodeData();
- }
-
- public String toString()
- {
- return "BackupData{" +
- "primaryFqn=" + primaryFqn +
- ", backupFqn=" + backupFqn +
- ", backupData=" + backupData +
- '}';
- }
- }
-
- public static class ResponseValidityFilter implements RspFilter
- {
- private int numValidResponses = 0;
- private List<Address> pendingResponders;
-
- public ResponseValidityFilter(List<Address> expected, Address localAddress)
- {
- // so for now I used a list to keep it consistent
- this.pendingResponders = new ArrayList<Address>(expected);
- // We'll never get a response from ourself
- this.pendingResponders.remove(localAddress);
- }
-
- public boolean isAcceptable(Object object, Address address)
- {
- pendingResponders.remove(address);
-
- if (object instanceof GravitateResult)
- {
- GravitateResult response = (GravitateResult) object;
- if (response.isDataFound()) numValidResponses++;
- }
- // always return true to make sure a response is logged by the JGroups RpcDispatcher.
- return true;
- }
-
- public boolean needMoreResponses()
- {
- return numValidResponses < 1 && pendingResponders.size() > 0;
- }
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-08-06 14:42:03 UTC (rev 6529)
@@ -0,0 +1,29 @@
+package org.jboss.cache.interceptors;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.invocation.InvocationContext;
+import org.jboss.cache.mvcc.MVCCNodeHelper;
+
+/**
+ * MVCC specific version of the LegacyDataGravitatorInterceptor
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class DataGravitatorInterceptor extends LegacyDataGravitatorInterceptor
+{
+ MVCCNodeHelper helper;
+
+ @Inject
+ public void injectMvccNodeHelper(MVCCNodeHelper helper)
+ {
+ this.helper = helper;
+ }
+
+ @Override
+ protected void wrapIfNeeded(InvocationContext ctx, Fqn fqnToWrap) throws InterruptedException
+ {
+ helper.wrapNodeForReading(ctx, fqnToWrap);
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java (from rev 6527, core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java 2008-08-06 14:42:03 UTC (rev 6529)
@@ -0,0 +1,446 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.interceptors;
+
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.buddyreplication.GravitateResult;
+import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.commands.DataCommand;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.commands.read.ExistsCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.read.GetDataMapCommand;
+import org.jboss.cache.commands.read.GetKeyValueCommand;
+import org.jboss.cache.commands.read.GetKeysCommand;
+import org.jboss.cache.commands.read.GetNodeCommand;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.commands.tx.CommitCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.invocation.InvocationContext;
+import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jgroups.Address;
+import org.jgroups.blocks.GroupRequest;
+import org.jgroups.blocks.RspFilter;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * The Data Gravitator interceptor intercepts cache misses and attempts to
+ * gravitate data from other parts of the cluster.
+ * <p/>
+ * Only used if Buddy Replication is enabled. Also, the interceptor only kicks
+ * in if an {@link org.jboss.cache.config.Option} is passed in to force Data
+ * Gravitation for a specific invocation or if <b>autoDataGravitation</b> is
+ * set to <b>true</b> when configuring Buddy Replication.
+ * <p/>
+ * See the JBoss Cache User Guide for more details on configuration options.
+ * There is a section dedicated to Buddy Replication in the Replication
+ * chapter.
+ * <p/>
+ * In terms of functionality, if a gravitation call has occured and a cleanup call is needed (based on
+ * how BR is configured), a cleanup call will be broadcast immediately after the gravitation call (no txs)
+ * or if txs are used, an <i>asynchronous</i> call is made to perform the cleanup <i>outside</i> the scope
+ * of the tx that caused the gravitation event.
+ * <p/>
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ * @deprecated will be removed with optimistic and pessimistic locking.
+ */
+@Deprecated
+public class LegacyDataGravitatorInterceptor extends BaseRpcInterceptor
+{
+ private BuddyManager buddyManager;
+ /**
+ * Map that contains commands that need cleaning up. This is keyed on global transaction, and contains a list of
+ * cleanup commands corresponding to all gravitate calls made during the course of the transaction in question.
+ */
+ private Map<GlobalTransaction, List<ReplicableCommand>> cleanupCommands = new ConcurrentHashMap<GlobalTransaction, List<ReplicableCommand>>();
+ private DataContainer dataContainer;
+ private CommandsFactory commandsFactory;
+ private CacheSPI cacheSPI;
+ private BuddyFqnTransformer buddyFqnTransformer;
+
+ @Inject
+ public void injectComponents(BuddyManager buddyManager, DataContainer dataContainer, CommandsFactory commandsFactory, CacheSPI cacheSPI, BuddyFqnTransformer transformer)
+ {
+ this.buddyManager = buddyManager;
+ this.dataContainer = dataContainer;
+ this.commandsFactory = commandsFactory;
+ this.cacheSPI = cacheSPI;
+ buddyFqnTransformer = transformer;
+ }
+
+ @Override
+ public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ return handleGetMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ {
+ return handleGetMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
+ {
+ return handleGetMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ return handleGetMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ return handleGetMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ return handleGetMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ try
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ cleanupCommands.remove(ctx.getGlobalTransaction());
+ }
+ }
+
+ @Override
+ public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
+ try
+ {
+ doCommit(gtx);
+ return invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ cleanupCommands.remove(gtx);
+ }
+ }
+
+ private Object handleGetMethod(InvocationContext ctx, DataCommand command) throws Throwable
+ {
+ if (isGravitationEnabled(ctx))
+ {
+ // test that the Fqn being requested exists locally in the cache.
+ if (trace) log.trace("Checking local existence of requested fqn " + command.getFqn());
+ if (buddyFqnTransformer.isBackupFqn(command.getFqn()))
+ {
+ log.info("Is call for a backup Fqn, not performing any gravitation. Direct calls on internal backup nodes are *not* supported.");
+ }
+ else
+ {
+ if (!dataContainer.exists(command.getFqn()))
+ {
+ // gravitation is necessary.
+
+ if (trace) log.trace("Gravitating from local backup tree");
+ BackupData data = localBackupGet(command.getFqn(), ctx);
+
+ if (data == null)
+ {
+ if (trace) log.trace("Gravitating from remote backup tree");
+ // gravitate remotely.
+ data = remoteBackupGet(command.getFqn());
+ }
+
+ if (data != null)
+ {
+ if (trace)
+ log.trace("Passing the put call locally to make sure state is persisted and ownership is correctly established.");
+ // store the gravitated node locally. This will cause it being backed up in the current instance's buddy.
+ createNode(data.backupData);
+ cleanBackupData(data, ctx);
+ wrapIfNeeded(ctx, data.primaryFqn);
+ }
+ }
+ else
+ {
+ if (trace) log.trace("No need to gravitate; have this already.");
+ }
+ }
+ }
+ else
+ {
+ if (trace)
+ {
+ log.trace("Suppressing data gravitation for this call.");
+ }
+ }
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ protected void wrapIfNeeded(InvocationContext ctx, Fqn fqnToWrap) throws InterruptedException
+ {
+ // no op
+ }
+
+ private boolean isGravitationEnabled(InvocationContext ctx)
+ {
+ boolean enabled = ctx.isOriginLocal();
+ if (enabled)
+ {
+ if (!buddyManager.isAutoDataGravitation())
+ {
+ enabled = ctx.getOptionOverrides().getForceDataGravitation();
+ }
+ }
+ return enabled;
+ }
+
+ private void doCommit(GlobalTransaction gtx) throws Throwable
+ {
+ if (cleanupCommands.containsKey(gtx))
+ {
+ if (trace) log.trace("Broadcasting cleanup commands for gtx " + gtx);
+
+ for (ReplicableCommand command : cleanupCommands.get(gtx))
+ {
+ try
+ {
+ doCleanup(command);
+ }
+ catch (Throwable th)
+ {
+ log.warn("Problems performing gravitation cleanup. Cleanup command: " + command, th);
+ }
+ }
+ }
+ else
+ {
+ if (trace) log.trace("No cleanups to broadcast in commit phase for gtx " + gtx);
+ }
+ }
+
+ private BackupData remoteBackupGet(Fqn name) throws Exception
+ {
+ BackupData result = null;
+ GravitateResult gr = gravitateData(name);
+ if (gr.isDataFound())
+ {
+ if (trace)
+ {
+ log.trace("Got response " + gr);
+ }
+
+ result = new BackupData(name, gr);
+ }
+ return result;
+ }
+
+ private void cleanBackupData(BackupData backup, InvocationContext ctx) throws Throwable
+ {
+
+ DataGravitationCleanupCommand cleanupCommand = commandsFactory.buildDataGravitationCleanupCommand(backup.primaryFqn, backup.backupFqn);
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
+
+ if (gtx == null)
+ {
+ // broadcast removes
+ // remove main Fqn
+ if (trace) log.trace("Performing cleanup on [" + backup.primaryFqn + "]");
+ // remove backup Fqn
+ doCleanup(cleanupCommand);
+ }
+ else
+ {
+ if (trace)
+ log.trace("Data gravitation performed under global transaction " + gtx + ". Not broadcasting cleanups until the tx commits. Recording cleanup command for later use.");
+ List<ReplicableCommand> commands;
+ if (cleanupCommands.containsKey(gtx))
+ {
+ commands = cleanupCommands.get(gtx);
+ }
+ else
+ {
+ commands = new LinkedList<ReplicableCommand>();
+ }
+
+ commands.add(cleanupCommand);
+ cleanupCommands.put(gtx, commands);
+ }
+ }
+
+ private void doCleanup(ReplicableCommand cleanupCommand) throws Throwable
+ {
+ // cleanup commands are always ASYNCHRONOUS and is broadcast to *everyone* (even members of the current buddy
+ // group as they may be members of > 1 buddy group)
+ replicateCall(null, cleanupCommand, false, false, false, true, -1);
+ }
+
+ @SuppressWarnings("deprecation")
+ private GravitateResult gravitateData(Fqn fqn) throws Exception
+ {
+ if (trace) log.trace("Requesting data gravitation for Fqn " + fqn);
+
+ List<Address> mbrs = rpcManager.getMembers();
+ Boolean searchSubtrees = buddyManager.isDataGravitationSearchBackupTrees() ? Boolean.TRUE : Boolean.FALSE;
+ GravitateDataCommand command = commandsFactory.buildGravitateDataCommand(fqn, searchSubtrees);
+ // doing a GET_ALL is crappy but necessary since JGroups' GET_FIRST could return null results from nodes that do
+ // not have either the primary OR backup, and stop polling other valid nodes.
+ List resps = rpcManager.callRemoteMethods(null, command, GroupRequest.GET_ALL, buddyManager.getBuddyCommunicationTimeout(), new ResponseValidityFilter(mbrs, rpcManager.getLocalAddress()), false);
+
+ if (trace) log.trace("got responses " + resps);
+
+ if (resps == null)
+ {
+ if (mbrs.size() > 1) log.error("No replies to call " + command);
+ return GravitateResult.noDataFound();
+ }
+
+ // test for and remove exceptions
+ GravitateResult result = GravitateResult.noDataFound();
+ for (Object o : resps)
+ {
+ if (o instanceof Throwable)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Found remote Throwable among responses - removing from responses list", (Exception) o);
+ }
+ }
+ else if (o != null)
+ {
+ result = (GravitateResult) o;
+ if (result.isDataFound())
+ {
+ break;
+ }
+ }
+ else if (!configuration.isUseRegionBasedMarshalling())
+ {
+ // Null is OK if we are using region based marshalling; it
+ // is what is returned if a region is inactive. Otherwise
+ // getting a null is an error condition
+ log.error("Unexpected null response to call " + command + ".");
+ }
+
+ }
+
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void createNode(List<NodeData> nodeData) throws CacheException
+ {
+ for (NodeData data : nodeData)
+ {
+ cacheSPI.put(data.getFqn(), data.getAttributes());
+ }
+ }
+
+ private BackupData localBackupGet(Fqn fqn, InvocationContext ctx) throws CacheException
+ {
+ GravitateResult result = cacheSPI.gravitateData(fqn, true, ctx);// a "local" gravitation
+ boolean found = result.isDataFound();
+ BackupData data = null;
+
+ if (found)
+ {
+ Fqn backupFqn = result.getBuddyBackupFqn();
+ data = new BackupData(fqn, result);
+ // now the cleanup
+ if (buddyManager.isDataGravitationRemoveOnFind())
+ {
+ // Remove locally only; the remote call will
+ // be broadcast later
+ ctx.getOptionOverrides().setCacheModeLocal(true);
+ cacheSPI.removeNode(backupFqn);
+ }
+ else
+ {
+ cacheSPI.evict(backupFqn, true);
+ }
+ }
+
+ if (trace) log.trace("Retrieved data " + data + " found = " + found);
+ return data;
+ }
+
+ private static class BackupData
+ {
+ Fqn primaryFqn;
+ Fqn backupFqn;
+ List<NodeData> backupData;
+
+ public BackupData(Fqn primaryFqn, GravitateResult gr)
+ {
+ this.primaryFqn = primaryFqn;
+ this.backupFqn = gr.getBuddyBackupFqn();
+ this.backupData = gr.getNodeData();
+ }
+
+ public String toString()
+ {
+ return "BackupData{" +
+ "primaryFqn=" + primaryFqn +
+ ", backupFqn=" + backupFqn +
+ ", backupData=" + backupData +
+ '}';
+ }
+ }
+
+ public static class ResponseValidityFilter implements RspFilter
+ {
+ private int numValidResponses = 0;
+ private List<Address> pendingResponders;
+
+ public ResponseValidityFilter(List<Address> expected, Address localAddress)
+ {
+ // so for now I used a list to keep it consistent
+ this.pendingResponders = new ArrayList<Address>(expected);
+ // We'll never get a response from ourself
+ this.pendingResponders.remove(localAddress);
+ }
+
+ public boolean isAcceptable(Object object, Address address)
+ {
+ pendingResponders.remove(address);
+
+ if (object instanceof GravitateResult)
+ {
+ GravitateResult response = (GravitateResult) object;
+ if (response.isDataFound()) numValidResponses++;
+ }
+ // always return true to make sure a response is logged by the JGroups RpcDispatcher.
+ return true;
+ }
+
+ public boolean needMoreResponses()
+ {
+ return numValidResponses < 1 && pendingResponders.size() > 0;
+ }
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-08-06 14:37:50 UTC (rev 6528)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-08-06 14:42:03 UTC (rev 6529)
@@ -14,7 +14,7 @@
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.XmlConfigurationParser;
import org.jboss.cache.config.parsing.element.BuddyElementParser;
-import org.jboss.cache.interceptors.DataGravitatorInterceptor;
+import org.jboss.cache.interceptors.LegacyDataGravitatorInterceptor;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -102,7 +102,7 @@
boolean hasDG = false;
for (CommandInterceptor interceptor : cache.getInterceptorChain())
{
- hasDG = hasDG || (interceptor instanceof DataGravitatorInterceptor);
+ hasDG = hasDG || (interceptor instanceof LegacyDataGravitatorInterceptor);
}
System.out.println(cache.getInterceptorChain());
Modified: core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-08-06 14:37:50 UTC (rev 6528)
+++ core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-08-06 14:42:03 UTC (rev 6529)
@@ -503,7 +503,7 @@
assertEquals(OptimisticTxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticReplicationInterceptor.class, interceptors.next().getClass());
- assertEquals(DataGravitatorInterceptor.class, interceptors.next().getClass());
+ assertEquals(LegacyDataGravitatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticLockingInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticValidatorInterceptor.class, interceptors.next().getClass());
assertEquals(OptimisticCreateIfNotExistsInterceptor.class, interceptors.next().getClass());
@@ -534,7 +534,7 @@
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(DataGravitatorInterceptor.class, interceptors.next().getClass());
+ assertEquals(LegacyDataGravitatorInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
16 years, 5 months
JBoss Cache SVN: r6528 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-08-06 10:37:50 -0400 (Wed, 06 Aug 2008)
New Revision: 6528
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/MvccBuddyReplicationTest.java
Log:
Improved test
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/MvccBuddyReplicationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/MvccBuddyReplicationTest.java 2008-08-06 09:23:41 UTC (rev 6527)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/MvccBuddyReplicationTest.java 2008-08-06 14:37:50 UTC (rev 6528)
@@ -21,57 +21,50 @@
*/
package org.jboss.cache.buddyreplication;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Cache;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.config.Option;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Option;
import org.jboss.cache.config.parsing.XmlConfigurationParser;
+import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.Test;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.AfterMethod;
-import java.util.Properties;
-import java.util.List;
-import java.util.ArrayList;
-
/**
* @author Mircea.Markus(a)jboss.com
* @since 3.0
*/
-@Test(groups = "functionl")
+@Test(groups = "functional")
public class MvccBuddyReplicationTest
{
private static final String FILE = "configs/mvcc-repl-sync-br.xml";
- Configuration configuration;
-
- public void testSimpleFailure() throws InterruptedException
+ public void testSimpleFailure()
{
- Cache cache1 = createCache();
- Thread.sleep(1000);
- Cache cache2 = createCache();
-
- cache1.put("/test", "key", "value");
- cache1.stop();
-
- Option option = cache2.getInvocationContext().getOptionOverrides();
- option.setForceDataGravitation(true);
+ Cache<String, String> cache1 = null, cache2 = null;
try
{
+ cache1 = createCache();
+ TestingUtil.sleepThread(1000);
+ cache2 = createCache();
+
+ cache1.put("/test", "key", "value");
+ cache1.stop();
+
+ Option option = cache2.getInvocationContext().getOptionOverrides();
+ option.setForceDataGravitation(true);
assert cache2.get("/test", "key").equals("value");
- } finally
+ }
+ finally
{
- cache2.stop();
+ TestingUtil.killCaches(cache1, cache2);
+
}
}
- private Cache createCache()
+ private Cache<String, String> createCache()
{
Configuration fileConfig = new XmlConfigurationParser().parseFile(FILE);
- DefaultCacheFactory dcf = new DefaultCacheFactory();
+ DefaultCacheFactory<String, String> dcf = new DefaultCacheFactory<String, String>();
return dcf.createCache(fileConfig);
}
}
16 years, 5 months