JBoss Cache SVN: r6049 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-26 07:02:27 -0400 (Thu, 26 Jun 2008)
New Revision: 6049
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
Log:
Created QueryResultIteratorImpl and fixed CacheQueryImpl
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-26 02:21:26 UTC (rev 6048)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-26 11:02:27 UTC (rev 6049)
@@ -82,35 +82,41 @@
return null;
}
-
-
/**
* @return The result size of the query.
*/
public int getResultSize()
{
- if (resultSize == null) {
+ if (resultSize == null)
+ {
//get result size without object initialization
IndexSearcher searcher = buildSearcher(searchFactory);
- if (searcher == null) {
+ if (searcher == null)
+ {
resultSize = 0;
}
- else {
+ else
+ {
Hits hits;
- try {
+ try
+ {
hits = getHits(searcher);
resultSize = hits.length();
}
- catch (IOException e) {
+ catch (IOException e)
+ {
throw new HibernateException("Unable to query Lucene index", e);
}
- finally {
+ finally
+ {
//searcher cannot be null
- try {
+ try
+ {
closeSearcher(searcher, searchFactory.getReaderProvider());
//searchFactoryImplementor.getReaderProvider().closeReader( searcher.getIndexReader() );
}
- catch (SearchException e) {
+ catch (SearchException e)
+ {
log.warn("Unable to properly close searcher during lucene query: " + e);
}
}
@@ -150,7 +156,8 @@
{
Set<IndexReader> indexReaders = getIndexReaders(searcher);
- for (IndexReader indexReader : indexReaders) {
+ for (IndexReader indexReader : indexReaders)
+ {
readerProvider.closeReader(indexReader);
}
}
@@ -163,7 +170,8 @@
*/
public FullTextFilter enableFullTextFilter(String name)
{
- if (filterDefinitions == null) {
+ if (filterDefinitions == null)
+ {
filterDefinitions = new HashMap<String, FullTextFilterImpl>();
}
FullTextFilterImpl filterDefinition = filterDefinitions.get(name);
@@ -172,7 +180,8 @@
filterDefinition = new FullTextFilterImpl();
filterDefinition.setName(name);
FilterDef filterDef = searchFactory.getFilterDefinition(name);
- if (filterDef == null) {
+ if (filterDef == null)
+ {
throw new SearchException("Unkown @FullTextFilter: " + name);
}
filterDefinitions.put(name, filterDefinition);
@@ -197,7 +206,8 @@
*/
public void setFirstResult(int firstResult)
{
- if (firstResult < 0) {
+ if (firstResult < 0)
+ {
throw new IllegalArgumentException("'first' pagination parameter less than 0");
}
this.firstResult = firstResult;
@@ -207,11 +217,13 @@
{
List list;
IndexSearcher searcher = buildSearcher(searchFactory);
- if (searcher == null) {
+ if (searcher == null)
+ {
throw new NullPointerException("IndexSearcher instance is null.");
}
- try {
+ try
+ {
Hits hits = getHits(searcher);
int first = first();
int max = max(first, hits);
@@ -219,7 +231,8 @@
List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
DocumentExtractor extractor = new DocumentExtractor(searchFactory, indexProjection);
- for (int index = first; index <= max; index++) {
+ for (int index = first; index <= max; index++)
+ {
String documentId = (String) extractor.extract(hits, index).id;
CacheEntityId id = new CacheEntityId(documentId);
ids.add(id);
@@ -227,14 +240,16 @@
list = entityLoader.load(ids);
}
- catch (IOException e) {
+ catch (IOException e)
+ {
throw new HibernateException("Unable to query Lucene index", e);
}
- finally {
+ finally
+ {
- closeSearcher(searcher, searchFactory.getReaderProvider());
+ closeSearcher(searcher, searchFactory.getReaderProvider());
}
@@ -247,7 +262,8 @@
Hits hits;
- try {
+ try
+ {
hits = getHits(searcher);
int first = first();
int max = max(first, hits);
@@ -257,7 +273,8 @@
List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
- for (int index = first; index <= max; index++) {
+ for (int index = first; index <= max; index++)
+ {
String documentId = (String) extractor.extract(hits, index).id;
CacheEntityId id = new CacheEntityId(documentId);
@@ -265,18 +282,17 @@
}
List<Object> list = entityLoader.load(ids);
-
+
}
- catch (IOException e) {
+ catch (IOException e)
+ {
throw new HibernateException("Unable to query Lucene index", e);
}
return null;
}
-
-
/**
* Returns a the results from the query as a List object.
*
@@ -291,7 +307,8 @@
Hits hits;
- try {
+ try
+ {
hits = getHits(searcher);
int first = first();
int max = max(first, hits);
@@ -300,30 +317,34 @@
List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
DocumentExtractor extractor = new DocumentExtractor(searchFactory, indexProjection);
- for (int index = first; index <= max; index++) {
+ for (int index = first; index <= max; index++)
+ {
String documentId = (String) extractor.extract(hits, index).id;
CacheEntityId id = new CacheEntityId(documentId);
ids.add(id);
}
List<Object> list = entityLoader.load(ids);
- if (resultTransformer == null) {
+ if (resultTransformer == null)
+ {
return list;
}
- else {
+ else
+ {
return resultTransformer.transformList(list);
}
}
- catch (IOException e) {
+ catch (IOException e)
+ {
throw new HibernateException("Unable to query Lucene index", e);
}
- finally {
- closeSearcher(searcher, searchFactory.getReaderProvider());
+ finally
+ {
+ closeSearcher(searcher, searchFactory.getReaderProvider());
-
}
}
@@ -371,24 +392,22 @@
// }
// }
-
private int max(int first, Hits hits)
{
return maxResults == null ?
- hits.length() - 1 :
- maxResults + first < hits.length() ?
- first + maxResults - 1 :
- hits.length() - 1;
+ hits.length() - 1 :
+ maxResults + first < hits.length() ?
+ first + maxResults - 1 :
+ hits.length() - 1;
}
private int first()
{
return firstResult != null ?
- firstResult :
- 0;
+ firstResult :
+ 0;
}
-
public int executeUpdate() throws HibernateException
{
throw new UnsupportedOperationException(" This method is not supported in JBossCache Searchable");
@@ -396,7 +415,8 @@
public void setMaxResults(int maxResults)
{
- if (maxResults < 0) {
+ if (maxResults < 0)
+ {
throw new IllegalArgumentException("'max' pagination parameter less than 0");
}
this.maxResults = maxResults;
@@ -404,7 +424,8 @@
public void setFetchSize(int fetchSize)
{
- if (fetchSize <= 0) {
+ if (fetchSize <= 0)
+ {
throw new IllegalArgumentException("'fetch size' parameter less than or equals to 0");
}
this.fetchSize = fetchSize;
@@ -427,24 +448,29 @@
Similarity searcherSimilarity = null;
- if (classes == null || classes.length == 0) {
+ if (classes == null || classes.length == 0)
+ {
//no class means all classes
- for (DocumentBuilder builder : builders.values()) {
+ for (DocumentBuilder builder : builders.values())
+ {
searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy().getDirectoryProvidersForAllShards();
populateDirectories(directories, directoryProviders, searchFactoryImplementor);
}
classesAndSubclasses = null;
}
- else {
+ else
+ {
Set<Class> involvedClasses = new HashSet<Class>(classes.length);
Collections.addAll(involvedClasses, classes);
- for (Class clazz : classes) {
+ for (Class clazz : classes)
+ {
DocumentBuilder builder = builders.get(clazz);
if (builder != null) involvedClasses.addAll(builder.getMappedSubclasses());
}
- for (Class clazz : involvedClasses) {
+ for (Class clazz : involvedClasses)
+ {
DocumentBuilder builder = builders.get(clazz);
if (builder == null)
throw new HibernateException("Not a mapped entity (don't forget to add @Indexed): " + clazz);
@@ -458,14 +484,19 @@
//compute optimization needClassFilterClause
//if at least one DP contains one class that is not part of the targeted classesAndSubclasses we can't optimize
- if (classesAndSubclasses != null) {
- for (DirectoryProvider dp : directories) {
+ if (classesAndSubclasses != null)
+ {
+ for (DirectoryProvider dp : directories)
+ {
final Set<Class> classesInDirectoryProvider = searchFactoryImplementor.getClassesInDirectoryProvider(dp);
// if a DP contains only one class, we know for sure it's part of classesAndSubclasses
- if (classesInDirectoryProvider.size() > 1) {
+ if (classesInDirectoryProvider.size() > 1)
+ {
//risk of needClassFilterClause
- for (Class clazz : classesInDirectoryProvider) {
- if (!classesAndSubclasses.contains(clazz)) {
+ for (Class clazz : classesInDirectoryProvider)
+ {
+ if (!classesAndSubclasses.contains(clazz))
+ {
this.needClassFilterClause = true;
break;
}
@@ -484,10 +515,12 @@
private Similarity checkSimilarity(Similarity similarity, DocumentBuilder builder)
{
- if (similarity == null) {
+ if (similarity == null)
+ {
similarity = builder.getSimilarity();
}
- else if (!similarity.getClass().equals(builder.getSimilarity().getClass())) {
+ else if (!similarity.getClass().equals(builder.getSimilarity().getClass()))
+ {
throw new HibernateException("Cannot perform search on two entities with differing Similarity implementations (" + similarity.getClass().getName() + " & " + builder.getSimilarity().getClass().getName() + ")");
}
@@ -497,8 +530,10 @@
private void populateDirectories(List<DirectoryProvider> directories, DirectoryProvider[] directoryProviders,
SearchFactoryImplementor searchFactoryImplementor)
{
- for (DirectoryProvider provider : directoryProviders) {
- if (!directories.contains(provider)) {
+ for (DirectoryProvider provider : directoryProviders)
+ {
+ if (!directories.contains(provider))
+ {
directories.add(provider);
}
}
@@ -521,16 +556,19 @@
private org.apache.lucene.search.Query filterQueryByClasses(org.apache.lucene.search.Query luceneQuery)
{
- if (!needClassFilterClause) {
+ if (!needClassFilterClause)
+ {
return luceneQuery;
}
- else {
+ else
+ {
//A query filter is more practical than a manual class filtering post query (esp on scrollable resultsets)
//it also probably minimise the memory footprint
BooleanQuery classFilter = new BooleanQuery();
//annihilate the scoring impact of DocumentBuilder.CLASS_FIELDNAME
classFilter.setBoost(0);
- for (Class clazz : classesAndSubclasses) {
+ for (Class clazz : classesAndSubclasses)
+ {
Term t = new Term(DocumentBuilder.CLASS_FIELDNAME, clazz.getName());
TermQuery termQuery = new TermQuery(t);
classFilter.add(termQuery, BooleanClause.Occur.SHOULD);
@@ -544,27 +582,35 @@
private void buildFilters()
{
- if (filterDefinitions != null && filterDefinitions.size() > 0) {
+ if (filterDefinitions != null && filterDefinitions.size() > 0)
+ {
ChainedFilter chainedFilter = new ChainedFilter();
- for (FullTextFilterImpl filterDefinition : filterDefinitions.values()) {
+ for (FullTextFilterImpl filterDefinition : filterDefinitions.values())
+ {
FilterDef def = searchFactory.getFilterDefinition(filterDefinition.getName());
Class implClass = def.getImpl();
Object instance;
- try {
+ try
+ {
instance = implClass.newInstance();
}
- catch (Exception e) {
+ catch (Exception e)
+ {
throw new SearchException("Unable to create @FullTextFilterDef: " + def.getImpl(), e);
}
- for (Map.Entry<String, Object> entry : filterDefinition.getParameters().entrySet()) {
+ for (Map.Entry<String, Object> entry : filterDefinition.getParameters().entrySet())
+ {
def.invoke(entry.getKey(), instance, entry.getValue());
}
- if (def.isCache() && def.getKeyMethod() == null && filterDefinition.getParameters().size() > 0) {
+ if (def.isCache() && def.getKeyMethod() == null && filterDefinition.getParameters().size() > 0)
+ {
throw new SearchException("Filter with parameters and no @Key method: " + filterDefinition.getName());
}
FilterKey key = null;
- if (def.isCache()) {
- if (def.getKeyMethod() == null) {
+ if (def.isCache())
+ {
+ if (def.getKeyMethod() == null)
+ {
key = new FilterKey()
{
public int hashCode()
@@ -580,54 +626,68 @@
}
};
}
- else {
- try {
+ else
+ {
+ try
+ {
key = (FilterKey) def.getKeyMethod().invoke(instance);
}
- catch (IllegalAccessException e) {
+ catch (IllegalAccessException e)
+ {
throw new SearchException("Unable to access @Key method: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
}
- catch (InvocationTargetException e) {
+ catch (InvocationTargetException e)
+ {
throw new SearchException("Unable to access @Key method: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
}
- catch (ClassCastException e) {
+ catch (ClassCastException e)
+ {
throw new SearchException("@Key method does not return FilterKey: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
}
}
key.setImpl(def.getImpl());
}
Filter filter = def.isCache() ?
- searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
- null;
- if (filter == null) {
- if (def.getFactoryMethod() != null) {
- try {
+ searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
+ null;
+ if (filter == null)
+ {
+ if (def.getFactoryMethod() != null)
+ {
+ try
+ {
filter = (Filter) def.getFactoryMethod().invoke(instance);
}
- catch (IllegalAccessException e) {
+ catch (IllegalAccessException e)
+ {
throw new SearchException("Unable to access @Factory method: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
- catch (InvocationTargetException e) {
+ catch (InvocationTargetException e)
+ {
throw new SearchException("Unable to access @Factory method: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
- catch (ClassCastException e) {
+ catch (ClassCastException e)
+ {
throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
}
- else {
- try {
+ else
+ {
+ try
+ {
filter = (Filter) instance;
}
- catch (ClassCastException e) {
+ catch (ClassCastException e)
+ {
throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
}
if (def.isCache())
16 years, 6 months
JBoss Cache SVN: r6048 - in pojo/trunk: src/main/java/org/jboss/cache/pojo/annotation and 8 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-25 22:21:26 -0400 (Wed, 25 Jun 2008)
New Revision: 6048
Removed:
pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Attach.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/CheckIdValidity.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Detach.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Find.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Reentrant.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Tx.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/TxUndo.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckIdInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckNonSerializableInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/MethodReentrancyStopperInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoBeginInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoEventInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoFailedTxMockupInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxLockInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoSynchronizationInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/StaticFieldInterceptor.java
Modified:
pojo/trunk/pom.xml
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListAbstract.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListImpl.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedMapImpl.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedSetImpl.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalConstant.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoUtil.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/util/CacheApiUtil.java
pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml
pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListImplTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ListUndoTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/LocalUndoTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/MapUndoTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/SetUndoTest.java
Log:
PCACHE-68 Remove self-weaved interceptor stack
Modified: pojo/trunk/pom.xml
===================================================================
--- pojo/trunk/pom.xml 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/pom.xml 2008-06-26 02:21:26 UTC (rev 6048)
@@ -122,44 +122,6 @@
<redirectTestOutputToFile>false</redirectTestOutputToFile>
</configuration>
</plugin>
- <plugin>
- <groupId>org.jboss.maven.plugins</groupId>
- <artifactId>maven-jbossaop-plugin</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <!-- HACK: AOP project and plugin has broken deps -->
- <dependencies>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.0.4</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <version>${jbosscache-core-version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.aop</groupId>
- <artifactId>jboss-aop</artifactId>
- <version>${jboss.aop.version}</version>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <id>aopc</id>
- <phase>compile</phase>
- <goals>
- <goal>compile</goal>
- </goals>
- <configuration>
- <verbose>false</verbose>
- <aoppaths>
- <aoppath>${basedir}/src/main/resources/META-INF/pojocache-aop.xml</aoppath>
- </aoppaths>
- </configuration>
- </execution>
- </executions>
- </plugin>
<!-- the docbook generation plugin for the user guide -->
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Attach.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Attach.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Attach.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,25 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation for PojoCache interceptor stack. This one checks for tx.
- *
- * @author Ben Wang
- * @version $Id$
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.METHOD)
-public @interface Attach
-{
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/CheckIdValidity.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/CheckIdValidity.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/CheckIdValidity.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,25 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation for PojoCache interceptor stack. This one to check id validity.
- *
- * @author Ben Wang
- * @version $Id$
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.METHOD)
-public @interface CheckIdValidity
-{
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Detach.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Detach.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Detach.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,25 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation for PojoCache interceptor stack. This one checks for tx.
- *
- * @author Ben Wang
- * @version $Id$
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.METHOD)
-public @interface Detach
-{
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Find.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Find.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Find.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,25 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation for PojoCache interceptor stack. This one checks for tx.
- *
- * @author Ben Wang
- * @version $Id$
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.METHOD)
-public @interface Find
-{
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Reentrant.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Reentrant.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Reentrant.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,26 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annoataion that wraps the Prepare annotation of JBossAop.
- *
- * @author Ben Wang
- * Date: Jan 22, 2006
- * @version $Id$
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.TYPE)
-public @interface Reentrant
-{
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Tx.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Tx.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/Tx.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,25 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation for PojoCache interceptor stack. This one checks for tx.
- *
- * @author Ben Wang
- * @version $Id$
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.METHOD)
-public @interface Tx
-{
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/TxUndo.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/TxUndo.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/annotation/TxUndo.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,25 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation for PojoCache interceptor stack. This one annotates method to provide rollback operation.
- *
- * @author Ben Wang
- * @version $Id$
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.METHOD)
-public @interface TxUndo
-{
-}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListAbstract.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListAbstract.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListAbstract.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -6,8 +6,6 @@
*/
package org.jboss.cache.pojo.collection;
-import org.jboss.cache.pojo.annotation.Reentrant;
-
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -17,8 +15,6 @@
*
* @author Scott Marlow
*/
-
-@Reentrant
abstract class CachedListAbstract implements List
{
public void clear()
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListImpl.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListImpl.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedListImpl.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -76,7 +76,7 @@
public Object get(int index)
{
checkIndex();
- return Null.toNullValue(pojoCache.getObject(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index))));
+ return Null.toNullValue(pojoCache.find(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index))));
}
private static void checkIndex()
@@ -229,7 +229,7 @@
throw new NoSuchElementException("CachedSetImpl.iterator.next(). " +
" Cursor position " + current + " is greater than the size " + size());
- return Null.toNullValue(pojoCache.getObject(AopUtil.constructFqn(getFqn(), IntegerCache.toString(++current))));
+ return Null.toNullValue(pojoCache.find(AopUtil.constructFqn(getFqn(), IntegerCache.toString(++current))));
}
public void remove()
@@ -282,6 +282,22 @@
return new MyListIterator(this, index);
}
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ int size = size();
+ for (int i = 0; i < size; i++)
+ {
+ Object key = get(i);
+ if (key == interceptor.getBoundProxy())
+ key = "(this list)";
+ buf.append("[").append(key).append("]");
+ if (i <= size) buf.append(", ");
+ }
+
+ return buf.toString();
+ }
+
static class MyListIterator implements ListIterator
{
int index = 0;
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedMapImpl.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedMapImpl.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedMapImpl.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -20,11 +20,9 @@
import org.jboss.aop.Advised;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.annotation.Reentrant;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
import org.jboss.cache.pojo.util.CacheApiUtil;
@@ -36,7 +34,6 @@
* @author Ben Wang
* @author Scott Marlow
*/
-@Reentrant
public class CachedMapImpl implements Map
{
private PojoCacheImpl pojoCache;
@@ -91,7 +88,7 @@
public Object get(Object key)
{
- return Null.toNullValue(pojoCache.getObject(constructFqn(getFqn(), Null.toNullKeyObject(key))));
+ return Null.toNullValue(pojoCache.find(constructFqn(getFqn(), Null.toNullKeyObject(key))));
}
public Object put(Object key, Object value)
@@ -233,7 +230,7 @@
{
Fqn f = ((Node) i.next()).getFqn();
lastKey = f.getLastElement();
- return Null.toNullValue(pojoCache.getObject(f));
+ return Null.toNullValue(pojoCache.find(f));
}
public void remove()
@@ -344,7 +341,13 @@
for (Iterator it = set.iterator(); it.hasNext();)
{
Object key = it.next();
- buf.append("[").append(key).append(", ").append(get(key)).append("]");
+ Object value = get(key);
+ if (key == interceptor.getBoundProxy())
+ key = "(this map)";
+ if (value == interceptor.getBoundProxy())
+ value = "(this map)";
+
+ buf.append("[").append(key).append(", ").append(value).append("]");
if (it.hasNext()) buf.append(", ");
}
@@ -368,7 +371,7 @@
public Object getValue()
{
- return Null.toNullValue(pojoCache.getObject(constructFqn(getFqn(), key)));
+ return Null.toNullValue(pojoCache.find(constructFqn(getFqn(), key)));
}
public Object setValue(Object value)
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -57,7 +57,7 @@
{
Fqn<?> fqn = AopUtil.constructFqn(this.fqn, IntegerCache.toString(index));
- return Null.toNullValue(cache.getObject(fqn, null, arraySource));
+ return Null.toNullValue(cache.find(fqn, null, arraySource));
}
public void destroy()
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedSetImpl.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedSetImpl.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedSetImpl.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -17,11 +17,9 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.pojo.annotation.Reentrant;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
import org.jboss.cache.pojo.util.AopUtil;
@@ -39,7 +37,6 @@
* @author Scott Marlow
* @author Jussi Pyorre
*/
-@Reentrant
public class CachedSetImpl extends AbstractSet
{
private PojoCacheImpl pojoCache;
@@ -172,6 +169,8 @@
for (Iterator it = iterator(); it.hasNext();)
{
Object key = it.next();
+ if (key == interceptor.getBoundProxy())
+ key = "(this set)";
buf.append("[").append(key).append("]");
if (it.hasNext()) buf.append(", ");
}
@@ -222,7 +221,7 @@
private Object getNoUnmask(Object key)
{
- return pojoCache.getObject(AopUtil.constructFqn(getFqn(), key));
+ return pojoCache.find(AopUtil.constructFqn(getFqn(), key));
}
public int hashCode()
@@ -275,7 +274,7 @@
public Object next()
{
node = iterator.next();
- o = Null.toNullValue(pojoCache.getObject(node.getFqn()));
+ o = Null.toNullValue(pojoCache.find(node.getFqn()));
return o;
}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -50,6 +50,7 @@
ClassProxy result = ClassProxyFactory.newInstance(clazz, null, true);
InstanceAdvisor advisor = result._getInstanceAdvisor();
advisor.appendInterceptor(interceptor);
+ interceptor.setBoundProxy(result);
return result;
}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -102,7 +102,7 @@
if (CachedType.isSimpleAttribute(field))
result = cache_.get(fqn, field.getName());
else
- result = pCache_.getObject(fqn, field.getName(), obj);
+ result = pCache_.find(fqn, field.getName(), obj);
field.set(obj, result);
}
@@ -192,7 +192,7 @@
// But we will have to ignore it if value is null
if (value instanceof Map || value instanceof List || value instanceof Set)
{
- Object newValue = pCache_.getObject(fqn, field.getName(), obj);
+ Object newValue = pCache_.find(fqn, field.getName(), obj);
util_.inMemorySubstitution(obj, field, newValue);
}
}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -26,6 +26,7 @@
import static org.jboss.cache.notifications.event.Event.Type.TRANSACTION_REGISTERED;
import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_OPERATION;
import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_STATUS;
+import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_LOCK;
import java.lang.reflect.Field;
import java.util.Collection;
@@ -48,7 +49,6 @@
import org.jboss.cache.notifications.event.TransactionalEvent;
import org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType;
import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.interceptors.PojoTxLockInterceptor;
import org.jboss.cache.pojo.notification.NotificationContext;
import org.jboss.cache.pojo.notification.event.ArrayModifiedEvent;
import org.jboss.cache.pojo.notification.event.AttachedEvent;
@@ -80,7 +80,7 @@
internalKeys.add(POJOCACHE_OPERATION);
internalKeys.add(PojoInstance.KEY);
internalKeys.add(PojoReference.KEY);
- internalKeys.add(PojoTxLockInterceptor.LOCK_KEY);
+ internalKeys.add(POJOCACHE_LOCK);
}
private PojoCacheImpl cache;
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalConstant.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalConstant.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalConstant.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -28,4 +28,5 @@
public static final String POJOCACHE_KEY_PREFIX = "POJOCache.";
public static final String POJOCACHE_STATUS = POJOCACHE_KEY_PREFIX + "Status";
public static final String POJOCACHE_OPERATION = POJOCACHE_KEY_PREFIX + "Operation";
+ public static final String POJOCACHE_LOCK = POJOCACHE_KEY_PREFIX + "LOCK";
}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -13,6 +13,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
+import org.jboss.cache.lock.UpgradeException;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.util.ObjectUtil;
@@ -374,4 +375,42 @@
return false;
}
-}
+
+ public boolean lockPojo(Fqn id) throws CacheException
+ {
+ final int RETRY = 5;
+
+ if (log.isDebugEnabled())
+ log.debug("lockPojo(): id:" + id);
+
+ boolean isNeeded = true;
+ int retry = 0;
+
+ while (isNeeded)
+ {
+ try
+ {
+ cache.put(id, InternalConstant.POJOCACHE_LOCK, "LOCK");
+ isNeeded = false;
+ }
+ catch (UpgradeException upe)
+ {
+ log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will re-try. id: " + id
+ + " retry times: " + retry);
+ if (retry++ > RETRY)
+ return false;
+
+ // try to sleep a little as well.
+ try
+ {
+ Thread.sleep(10);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -48,7 +48,7 @@
// Note this is actually the aliasFqn, not the real fqn!
Object obj;
- obj = cache.getObject(fqn);
+ obj = cache.find(fqn);
if (obj == null)
throw new PojoCacheException("ObjectGraphHandler.get(): null object from internal ref node." +
" Internal ref node: " + fqn);
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -51,8 +51,6 @@
private ArrayHandler arrayHandler;
private SerializableObjectHandler serializableHandler_;
// Use ThreadLocal to hold a boolean isBulkRemove
- private ThreadLocal<Boolean> bulkRemove_ = new ThreadLocal<Boolean>();
- private final String DETACH = "DETACH";
private PojoUtil util_ = new PojoUtil();
public PojoCacheDelegate(PojoCacheImpl cache)
@@ -67,16 +65,6 @@
arrayHandler = new ArrayHandler(pojoCache);
}
- public void setBulkRemove(boolean bulk)
- {
- bulkRemove_.set(bulk);
- }
-
- private boolean getBulkRemove()
- {
- return bulkRemove_.get();
- }
-
public Object getObject(Fqn fqn, String field, Object source) throws CacheException
{
// TODO Must we really to couple with BR? JBCACHE-669
@@ -114,6 +102,8 @@
*/
public Object putObject(Fqn fqn, Object obj, String field, Object source) throws CacheException
{
+ internal_.lockPojo(fqn);
+
// Skip some un-necessary update if obj is the same class as the old one
Object oldValue = internal_.getPojo(fqn, field);
boolean allowArray = source instanceof ArrayInterceptable;
@@ -229,6 +219,8 @@
*/
public Object removeObject(Fqn fqn, String field, Object source) throws CacheException
{
+ internal_.lockPojo(fqn);
+
// the class attribute is implicitly stored as an immutable read-only attribute
PojoReference pojoReference = internal_.getPojoReference(fqn, field);
if (pojoReference == null)
@@ -249,7 +241,7 @@
+ " with the corresponding internal id: " + internalFqn);
}
- Object result = pojoCache.getObject(internalFqn);
+ Object result = pojoCache.find(internalFqn);
if (result == null)
return null;
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -12,6 +12,10 @@
import java.util.WeakHashMap;
import java.util.regex.Pattern;
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
@@ -25,9 +29,8 @@
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.PojoCacheThreadContext;
-import org.jboss.cache.pojo.annotation.Attach;
-import org.jboss.cache.pojo.annotation.Detach;
-import org.jboss.cache.pojo.annotation.Find;
+import org.jboss.cache.pojo.interceptors.PojoTxSynchronizationHandler;
+import org.jboss.cache.transaction.BatchModeTransactionManager;
/**
* Implementation class for PojoCache interface
@@ -94,75 +97,134 @@
return attach(Fqn.fromString(id), pojo);
}
- @Attach
public Object attach(Fqn<?> id, Object pojo) throws PojoCacheException
{
+ return attach(id, pojo, null, null);
+ }
+
+ public Object attach(Fqn<?> id, Object pojo, String field, Object source) throws PojoCacheException
+ {
+ TransactionManager tm = getTransactionManager();
+ boolean createdTransaction = setupTransaction(tm);
try
{
- Object obj = putObject(id, pojo, null, null);
+ Object obj = delegate_.putObject(id, pojo, field, source);
return obj;
}
- catch (CacheException e)
+ catch (Throwable t)
{
- throw new PojoCacheException("putObject failed " + id, e);
+ setRollbackOnly(tm);
+ throw new PojoCacheException("attach failed " + id, t);
}
+ finally
+ {
+ if (createdTransaction)
+ endTransaction(tm, id);
+ }
}
- @Attach
- public Object attach(Fqn<?> id, Object pojo, String field, Object source) throws PojoCacheException
+ public Object detach(Fqn<?> id, String field, Object source) throws PojoCacheException
{
+ TransactionManager tm = getTransactionManager();
+ boolean createdTransaction = setupTransaction(tm);
try
{
- Object obj = putObject(id, pojo, field, source);
+ Object obj = delegate_.removeObject(id, field, source);
return obj;
}
- catch (CacheException e)
+ catch (Throwable t)
{
- throw new PojoCacheException("putObject failed " + id, e);
+ setRollbackOnly(tm);
+ throw new PojoCacheException("detach failed " + id, t);
}
+ finally
+ {
+ if (createdTransaction)
+ endTransaction(tm, id);
+ }
}
- /**
- * This public API is called from internal package only.
- */
- public Object putObject(Fqn<?> id, Object pojo, String field, Object source) throws CacheException
+ private void endTransaction(TransactionManager tm, Fqn<?> id)
{
- return delegate_.putObject(id, pojo, field, source);
+ try
+ {
+ switch (tm.getStatus())
+ {
+ case Status.STATUS_PREPARING:
+ case Status.STATUS_PREPARED:
+ case Status.STATUS_ACTIVE:
+ tm.commit();
+ break;
+ case Status.STATUS_MARKED_ROLLBACK:
+ tm.rollback();
+ break;
+ }
+ }
+ catch (Throwable t)
+ {
+ if (log_.isWarnEnabled())
+ log_.warn("Could not end transaction for operation on: " + id, t);
+ }
}
- public Object detach(String id) throws PojoCacheException
+ private void setRollbackOnly(TransactionManager tm)
{
- return detach(Fqn.fromString(id));
+ try
+ {
+ if (tm.getStatus() != Status.STATUS_MARKED_ROLLBACK)
+ tm.setRollbackOnly();
+ }
+ catch (Throwable t)
+ {
+ if (log_.isWarnEnabled())
+ log_.warn("Could not rollback transaction!", t);
+ }
}
- @Detach
- public Object detach(Fqn<?> id, String field, Object source) throws PojoCacheException
+ private boolean setupTransaction(TransactionManager tm)
{
+ boolean created = false;
try
{
- Object pojo = getObject(id, field, source);// TODO need optimization here since it will be redundant here
- if (pojo == null) return pojo;
+ Transaction transaction = tm.getTransaction();
+ if (transaction == null)
+ {
+ tm.begin();
+ transaction = tm.getTransaction();
+ created = true;
+ }
- Object obj = removeObject(id, field, source);
- return obj;
+ transaction.registerSynchronization(PojoTxSynchronizationHandler.create());
}
- catch (CacheException e)
+ catch (Exception e)
{
- throw new PojoCacheException("detach " + id + " failed", e);
+ throw new PojoCacheException("Error creating transaction", e);
}
+
+ return created;
}
- public Object detach(Fqn<?> id) throws PojoCacheException
+ private TransactionManager getTransactionManager()
{
- return detach(id, null, null);
+ TransactionManager tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ if (tm == null)
+ tm = BatchModeTransactionManager.getInstance();
+
+ return tm;
}
- public Object removeObject(Fqn<?> id, String field, Object source) throws CacheException
+ public Object detach(String id) throws PojoCacheException
{
- delegate_.setBulkRemove(false);
- return delegate_.removeObject(id, field, source);
+ return detach(Fqn.fromString(id));
}
+
+
+ public Object detach(Fqn<?> id) throws PojoCacheException
+ {
+ return detach(id, null, null);
+ }
+
public String getPojoID(Object pojo)
{
throw new PojoCacheException("getPojoID not yet implemented");
@@ -178,12 +240,11 @@
return find(Fqn.fromString(id));
}
- @Find
public Object find(Fqn<?> id) throws PojoCacheException
{
try
{
- return getObject(id);
+ return find(id, null, null);
}
catch (CacheException e)
{
@@ -191,13 +252,8 @@
}
}
- public Object getObject(Fqn<?> id) throws CacheException
+ public Object find(Fqn<?> id, String field, Object source) throws CacheException
{
- return getObject(id, null, null);
- }
-
- public Object getObject(Fqn<?> id, String field, Object source) throws CacheException
- {
return delegate_.getObject(id, field, source);
}
@@ -207,7 +263,6 @@
return findAll(Fqn.fromString(id));
}
- @Find
public Map<Fqn<?>, Object> findAll(Fqn<?> id) throws PojoCacheException
{
// Should produce "/"
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoUtil.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoUtil.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoUtil.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -8,19 +8,19 @@
package org.jboss.cache.pojo.impl;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.List;
-import org.jboss.aop.Advised;
-import org.jboss.aop.Domain;
import org.jboss.aop.InstanceAdvisor;
import org.jboss.aop.advice.Interceptor;
import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.annotation.TxUndo;
import org.jboss.cache.pojo.collection.CachedArray;
import org.jboss.cache.pojo.collection.CachedArrayRegistry;
+import org.jboss.cache.pojo.interceptors.PojoTxSynchronizationHandler;
import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
+import org.jboss.cache.pojo.util.MethodCall;
/**
* Utility class for method wrappers that we are interested to rollback (i.e., rollback).
@@ -30,33 +30,48 @@
*/
public class PojoUtil
{
- private static final String BindingName = "ReentrancyStopperInterceptor.";
-
- @TxUndo
public void attachInterceptor(Object pojo, InstanceAdvisor advisor, Interceptor interceptor)
{
_attachInterceptor(pojo, advisor, interceptor);
+ Method method = MethodDeclarations.undoAttachInterceptor;
+ MethodCall mc = new MethodCall(method, new Object[] {pojo, advisor, interceptor}, this);
+ addUndo(mc);
}
- @TxUndo
public void detachInterceptor(InstanceAdvisor advisor, Interceptor interceptor)
{
_detachInterceptor(advisor, interceptor);
+ Method method = MethodDeclarations.undoDetachInterceptor;
+ MethodCall mc = new MethodCall(method, new Object[] {advisor, interceptor}, this);
+ addUndo(mc);
}
- @TxUndo
+ private void addUndo(MethodCall mc)
+ {
+ PojoTxSynchronizationHandler handler = PojoTxSynchronizationHandler.current();
+ if (handler != null)
+ handler.addToList(mc);
+ }
+
public void detachCollectionInterceptor(AbstractCollectionInterceptor interceptor) {
interceptor.detach(true);
+ Method method = MethodDeclarations.undoDetachCollectionInterceptor;
+ MethodCall mc = new MethodCall(method, new Object[] {interceptor}, this);
+ addUndo(mc);
}
- @TxUndo
public void attachArray(Object array, CachedArray cached) {
CachedArrayRegistry.register(array, cached);
+ Method method = MethodDeclarations.undoAttachArray;
+ MethodCall mc = new MethodCall(method, new Object[] {array, cached}, this);
+ addUndo(mc);
}
- @TxUndo
public void detachArray(Object array, CachedArray cached) {
CachedArrayRegistry.unregister(array);
+ Method method = MethodDeclarations.undoDetachArray;
+ MethodCall mc = new MethodCall(method, new Object[] {array, cached}, this);
+ addUndo(mc);
}
public void undoAttachInterceptor(Object pojo, InstanceAdvisor advisor, Interceptor interceptor)
@@ -87,11 +102,23 @@
CachedArrayRegistry.register(array, cached);
}
-
- @TxUndo
public void inMemorySubstitution(Object obj, Field field, Object newValue)
{
+ Method method = MethodDeclarations.undoInMemorySubstitution;
+ Object[] args;
+ try
+ {
+ args = new Object[]{obj, field, field.get(obj)};
+ }
+ catch (Throwable t)
+ {
+ throw new PojoCacheException("Severe error building undo list", t);
+ }
+
_inMemorySubstitution(obj, field, newValue);
+
+ MethodCall mc = new MethodCall(method, args, this);
+ addUndo(mc);
}
public void undoInMemorySubstitution(Object obj, Field field, Object oldValue)
@@ -104,13 +131,6 @@
advisor.appendInterceptor(interceptor);
}
- private Domain getInstanceDomain(Object obj)
- {
- Advised advised = ((Advised) obj);
- InstanceAdvisor advisor = advised._getInstanceAdvisor();
- return advisor.getDomain();
- }
-
private void _inMemorySubstitution(Object obj, Field field, Object newValue)
{
try
@@ -137,10 +157,14 @@
}
}
- @TxUndo
- public int incrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ public int incrementReferenceCount(Fqn<?> sourceFqn, int count, List<?> refList)
{
- return _incrementReferenceCount(sourceFqn, count, refList);
+ int ret = _incrementReferenceCount(sourceFqn, count, refList);
+ Method method = MethodDeclarations.undoIncrementReferenceCount;
+ Object[] args = new Object[]{sourceFqn, count, refList};
+ MethodCall mc = new MethodCall(method, args, this);
+ addUndo(mc);
+ return ret;
}
public int undoIncrementReferenceCount(Fqn sourceFqn, int count, List refList)
@@ -154,10 +178,14 @@
return count + 1;
}
- @TxUndo
- public int decrementReferenceCount(Fqn sourceFqn, int count, List refList)
+ public int decrementReferenceCount(Fqn<?> sourceFqn, int count, List<?> refList)
{
- return _decrementReferenceCount(sourceFqn, count, refList);
+ int ret = _decrementReferenceCount(sourceFqn, count, refList);
+ Method method = MethodDeclarations.undoDecrementReferenceCount;
+ Object[] args = new Object[]{sourceFqn, count, refList};
+ MethodCall mc = new MethodCall(method, args, this);
+ addUndo(mc);
+ return ret;
}
public int undoDecrementReferenceCount(Fqn sourceFqn, int count, List refList)
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckIdInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckIdInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckIdInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.Fqn;
-
-/**
- * Interceptor (done via aop advice) to check the validity of the id specified by the user.
- *
- * @version $Id$
- */
-public class CheckIdInterceptor extends AbstractInterceptor
-{
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException("CheckIdInterceptor.invoke(): invocation not MethodInvocation");
- }
-
- MethodInvocation invocation = (MethodInvocation) in;
- invocation.getAdvisor();
- try
- {
- checkFqnValidity((Fqn) invocation.getArguments()[0]);
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- finally
- {
- }
- }
-
-
- private static void checkFqnValidity(Fqn id)
- {
- // throws exception is fqn is JBossInternal
-// if (id.hasElement(InternalConstant.JBOSS_INTERNAL_STRING))
-// {
-// throw new IllegalArgumentException("CheckIdIntercepto.checkFqnValidity(): fqn is not valid: " + id);
-// }
- }
-}
-
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckNonSerializableInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckNonSerializableInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/CheckNonSerializableInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.util.AopUtil;
-
-/**
- * Interceptor (done via aop advice) to check the validity of the id specified by the user.
- *
- * @version $Id$
- */
-public class CheckNonSerializableInterceptor extends AbstractInterceptor
-{
- private boolean marshallNonSerializable_ = false;
-
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException("CheckIdInterceptor.invoke(): invocation not MethodInvocation");
- }
-
- MethodInvocation invocation = (MethodInvocation) in;
- Fqn id = (Fqn) invocation.getArguments()[0];
- Object obj = invocation.getArguments()[1];
- if (!marshallNonSerializable_)
- {
- AopUtil.checkObjectType(obj);
- }
- else
- {
- log.debug("invoke(): marshallNonSerializable is set to true. We will skip object type checking for id:"
- + id.toString());
- }
-
- try
- {
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- finally
- {
- }
- }
-
- public void setMarshallNonSerializable(boolean isTrue)
- {
- marshallNonSerializable_ = isTrue;
- }
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/MethodReentrancyStopperInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/MethodReentrancyStopperInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/MethodReentrancyStopperInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,88 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.pojo.PojoCacheException;
-
-import java.lang.reflect.Method;
-
-/**
- * @author Ben Wang
- */
-
-public class MethodReentrancyStopperInterceptor implements Interceptor
-{
- private final Log log_ = LogFactory.getLog(MethodReentrancyStopperInterceptor.class);
- private ThreadLocal<Boolean> done;
- private String methodName;
-
- public MethodReentrancyStopperInterceptor()
- {
- done = new ThreadLocal<Boolean>();
- done.set(false);
- }
-
- public void setMethodName(String mname)
- {
- methodName = mname;
- }
-
- public String getName()
- {
- return MethodReentrancyStopperInterceptor.class.getName() + "-" + methodName;
- }
-
- public Object invoke(Invocation invocation) throws Throwable
- {
- boolean wasDone = done.get();
-
- try
- {
- if (!wasDone)
- {
- done.set(true);
- return invocation.invokeNext();
- }
- else
- {
- //Needs adding, and will invoke target joinpoint skipping the rest of the chain
- if (log_.isDebugEnabled())
- {
- Method method = ((MethodInvocation) invocation).getMethod();
- log_.debug("Detect recursive interception. Will call the target directly: " + method.getName());
- }
-
- if (methodName.equals("toString"))
- {
- return invocation.getTargetObject().getClass().getName();
- }
- else if (methodName.equals("hashCode"))
- {
- return 0;
- }
- else
- {
- throw new PojoCacheException("MethodReentrancyStopperInterceptor.invoke(): unknown method name"
- + methodName);
- }
- }
- }
- finally
- {
- if (!wasDone)
- {
- done.set(false);
- }
- }
- }
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoBeginInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoBeginInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoBeginInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.aop.metadata.SimpleMetaData;
-
-/**
- * The first interceptor that deals initialization.
- *
- * @author Ben Wang
- * @version $Id$
- */
-public class PojoBeginInterceptor extends AbstractInterceptor
-{
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException("BeginInterceptor.invoke(): invocation not MethodInvocation");
- }
- MethodInvocation invocation = (MethodInvocation) in;
- // Let's initialize the metadata
- SimpleMetaData simple = new SimpleMetaData();
- invocation.setMetaData(simple);
-
- try
- {
- log.debug("**** Entering method: **** " + invocation.getMethod());
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- finally
- {
-// reset(); // reset
- log.debug("Leaving method: " + invocation.getMethod());
- }
- }
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoEventInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoEventInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoEventInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-
-/**
- * Handles the POJO event notification.
- *
- * @author Ben Wang
- * @version $Id$
- */
-public class PojoEventInterceptor extends AbstractInterceptor
-{
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException("PojoEventInterceptor.invoke(): invocation not MethodInvocation");
- }
- MethodInvocation invocation = (MethodInvocation) in;
- try
- {
- System.out.println("**** Entering method: **** " + invocation.getMethod());
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- finally
- {
- System.out.println("Leaving method: " + invocation.getMethod());
- }
- }
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoFailedTxMockupInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoFailedTxMockupInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoFailedTxMockupInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,65 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.impl.InternalConstant;
-
-import javax.transaction.Transaction;
-
-/**
- * Interceptor to mockup tx failure that resulting in rollback. User can simulate a rollback
- * by setting the static method <code>setRollback</code>. Note that you will need to use
- * setRollback for every method call, that is, it will reset itself after a rollback
- * has been performed.
- *
- * @author Ben Wang
- * @version $Id$
- */
-public class PojoFailedTxMockupInterceptor extends AbstractInterceptor
-{
- public static boolean TX_ROLLBACK = false;
-
- public static void setTxRollback(boolean isTrue)
- {
- TX_ROLLBACK = isTrue;
- }
-
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException(
- "PojoFailedTxMockupInterceptor.invoke(): invocation not MethodInvocation");
- }
- MethodInvocation invocation = (MethodInvocation) in;
- try
- {
- Object obj = null;
- obj = invocation.invokeNext(); // proceed to next advice or actual call
- if(TX_ROLLBACK)
- {
- Transaction tx = (Transaction)
- invocation.getMetaData().getMetaData(PojoTxInterceptor.TAG, PojoTxInterceptor.TX);
-
- Fqn id = (Fqn) invocation.getArguments()[0];
-
- if(!id.isChildOrEquals(InternalConstant.JBOSS_INTERNAL))
- {
- tx.setRollbackOnly();
- TX_ROLLBACK = false;
- }
- }
- return obj;
- } finally
- {
- }
- }
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,145 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.transaction.BatchModeTransactionManager;
-
-import javax.transaction.RollbackException;
-import javax.transaction.Status;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-/**
- * Interceptor (done via aop advice) for transaction
- *
- * @author Ben Wang
- * @version $Id$
- */
-public class PojoTxInterceptor extends AbstractInterceptor
-{
- private TransactionManager localTm_ = null;
- private TransactionManager txManager_;
- public static final String TAG = "PC";
- public static final String TX = "TX";
-
-
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException("TxInterceptor.invoke(): invocation not MethodInvocation");
- }
- MethodInvocation invocation = (MethodInvocation) in;
-
- if (txManager_ == null)
- {
- txManager_ = getCache(invocation).getTransactionManager();
- }
-
- Transaction tx = null;
- if (txManager_ != null)
- {
- // Use the configured one if so setup.
- localTm_ = txManager_;
- }
- else
- {
- localTm_ = BatchModeTransactionManager.getInstance();
- }
-
- tx = localTm_.getTransaction();
-
- boolean needTx = false;
- if (tx == null) needTx = true;
- Fqn id = null;
- try
- {
- if (needTx)
- {
- id = (Fqn) invocation.getArguments()[0];
- log.debug("Initiating a local transaction for batch processing with id: " + id.toString());
- // Start one of our own as batch processing.
- try
- {
- localTm_.begin();
- tx = localTm_.getTransaction();
- // Stuff tx context into the metadata
- invocation.getMetaData().addMetaData(TAG, TX, tx);
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- catch (Exception e)
- {
- log.warn(invocation.getMethod().getName() + ": exception occurred: " + e);
- try
- {
- localTm_.setRollbackOnly();
- }
- catch (Exception e2)
- {
- log.error("setRollbackOnly", e2);
- }
-
- throw new PojoCacheException("PojoCache operation will be rollback. id: " + id
- + ". Operation: " + invocation.getMethod().getName(), e);
- }
- }
- else
- {
- invocation.getMetaData().addMetaData(TAG, TX, tx);
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- }
- finally
- {
- if (needTx)
- {
- endTransaction(id);
- }
- }
- }
-
- private void endTransaction(Fqn id)
- {
- if (localTm_ == null)
- {
- log.warn("endTransaction(): tm is null for id: " + id);
- return;
- }
-
-
- try
- {
- if (localTm_.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK)
- {
- localTm_.commit();
- }
- else if (localTm_.getTransaction().getStatus() == Status.STATUS_ROLLEDBACK)
- {
- log.info("endTransaction(): has been rolled back for id: " + id);
- }
- else
- {
- log.info("endTransaction(): rolling back tx for id: " + id);
- localTm_.rollback();
- }
- }
- catch (RollbackException re)
- {
- // Do nothing here since cache may rollback automatically.
- log.warn("endTransaction(): rolling back transaction with exception: " + re);
- }
- catch (Exception e)
- {
- log.warn("endTransaction(): Failed with exception: " + e);
- }
- }
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxLockInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxLockInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxLockInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,96 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.lock.UpgradeException;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.impl.InternalConstant;
-
-/**
- * Interceptor that handles the parent node lock associated with transaction.
- *
- * @author Ben Wang
- * @version $Id$
- */
-public class PojoTxLockInterceptor extends AbstractInterceptor
-{
- public static final String LOCK_KEY = InternalConstant.POJOCACHE_KEY_PREFIX + "LOCK";
- // retry times for lockPojo just in case there is upgrade exception during concurrent access.
- private final int RETRY = 5;
-
- public Object invoke(Invocation in) throws Throwable
- {
- MethodInvocation invocation = (MethodInvocation) in;
- try
- {
- handleLock(invocation);
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- finally
- {
-// handleUnLock(invocation);
- }
- }
-
- private void handleLock(MethodInvocation invocation) throws Throwable
- {
- Fqn id = (Fqn) invocation.getArguments()[0];
- Cache<Object, Object> cache = getCache(invocation);
-// Object owner = cache.getLockOwner();
- Object owner = null;
- if (!lockPojo(owner, id, cache))
- {
- throw new PojoCacheException("PojoCache.removeObject(): Can't obtain the pojo lock under id: " + id);
- }
- }
-
- private boolean lockPojo(Object owner, Fqn id, Cache<Object, Object> cache) throws CacheException
- {
- if (log.isDebugEnabled())
- {
- log.debug("lockPojo(): id:" + id + " Owner: " + owner);
- }
-
- boolean isNeeded = true;
- int retry = 0;
-
- while (isNeeded)
- {
- try
- {
- cache.put(id, LOCK_KEY, "LOCK");
- isNeeded = false;
- }
- catch (UpgradeException upe)
- {
- log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will re-try. id: " + id
- + " retry times: " + retry);
- if (retry++ > RETRY)
- {
- return false;
- }
- // try to sleep a little as well.
- try
- {
- Thread.sleep(10);
- }
- catch (InterruptedException e)
- {
- }
- }
- }
-
- return true;
- }
-}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxSynchronizationHandler.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -24,15 +24,34 @@
* @version $Id$
*/
-class PojoTxSynchronizationHandler implements Synchronization
+public class PojoTxSynchronizationHandler implements Synchronization
{
private static Log log = LogFactory.getLog(PojoTxSynchronizationHandler.class.getName());
private List undoList_ = new ArrayList();
+ private static ThreadLocal<PojoTxSynchronizationHandler> handler = new ThreadLocal<PojoTxSynchronizationHandler>();
+
PojoTxSynchronizationHandler()
{
}
+ public static PojoTxSynchronizationHandler current()
+ {
+ return handler.get();
+ }
+
+ public static PojoTxSynchronizationHandler create()
+ {
+ PojoTxSynchronizationHandler current = handler.get();
+ if (current == null)
+ {
+ current = new PojoTxSynchronizationHandler();
+ handler.set(current);
+ }
+
+ return current;
+ }
+
public void beforeCompletion()
{
// Not interested
@@ -89,7 +108,8 @@
public void resetUndoOp()
{
undoList_.clear();
- PojoTxUndoSynchronizationInterceptor.reset();
+ handler.set(null);
+ //PojoTxUndoSynchronizationInterceptor.reset();
}
}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.PojoCacheException;
-import org.jboss.cache.pojo.impl.MethodDeclarations;
-import org.jboss.cache.pojo.util.MethodCall;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.List;
-
-/**
- * Interceptor (done via aop advice) for transaction rollback. This is is attached to the
- * operation that needs a corresponding rollback, e.g., attachInterceptor.
- *
- * @author Ben Wang
- * @version $Id$
- */
-public class PojoTxUndoInterceptor extends AbstractInterceptor
-{
- /// Just that AOP requires an extra key.
- public static final String TAG = "PojoCache";
-
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException("TxUndoInterceptor.invoke(): invocation not MethodInvocation");
- }
- MethodInvocation invocation = (MethodInvocation) in;
-
- PojoTxSynchronizationHandler handler =
- PojoTxUndoSynchronizationInterceptor.getSynchronizationHandler();
-
- if (handler == null)
- {
- return invocation.invokeNext();
-// TODO handler is null can mean we are not calling the right interceptor stack. Need to revisit.
-// E.g., a fresh getObject or find will trigger this.
-// throw new IllegalStateException("PojoTxUndoInterceptor.invoke(): PojoTxSynchronizationHandler is null");
- }
-
- // Add to the rollback list
- String methodName = invocation.getMethod().getName();
- // TODO Needs to handle Collection interceptor as well.
- if (methodName.equals(MethodDeclarations.attachInterceptor.getName()))
- {
- Method method = MethodDeclarations.undoAttachInterceptor;
- MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
- handler.addToList(mc);
- }
- else if (methodName.equals(MethodDeclarations.detachInterceptor.getName()))
- {
- Method method = MethodDeclarations.undoDetachInterceptor;
- MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
- handler.addToList(mc);
- }
- else if (methodName.equals(MethodDeclarations.detachCollectionInterceptor.getName()))
- {
- Method method = MethodDeclarations.undoDetachCollectionInterceptor;
- MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
- handler.addToList(mc);
- }
- else if (methodName.equals(MethodDeclarations.attachArray.getName()))
- {
- Method method = MethodDeclarations.undoAttachArray;
- MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
- handler.addToList(mc);
- }
- else if (methodName.equals(MethodDeclarations.detachArray.getName()))
- {
- Method method = MethodDeclarations.undoDetachArray;
- MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
- handler.addToList(mc);
- }
- else if (methodName.equals(MethodDeclarations.inMemorySubstitution.getName()))
- {
- Method method = MethodDeclarations.undoInMemorySubstitution;
- Object obj = invocation.getArguments()[0];
- Field field = (Field) invocation.getArguments()[1];
- Object oldValue = field.get(obj);
- Object[] args = new Object[]{obj, field, oldValue};
- MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
- handler.addToList(mc);
- }
- else if (methodName.equals(MethodDeclarations.incrementReferenceCount.getName()))
- {
- Method method = MethodDeclarations.undoIncrementReferenceCount;
- Fqn fqn = (Fqn) invocation.getArguments()[0];
- int count = (Integer) invocation.getArguments()[1];
- List referenceList = (List) invocation.getArguments()[2];
- Object[] args = new Object[]{fqn, count, referenceList};
- MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
- handler.addToList(mc);
- }
- else if (methodName.equals(MethodDeclarations.decrementReferenceCount.getName()))
- {
- Method method = MethodDeclarations.undoDecrementReferenceCount;
- Fqn fqn = (Fqn) invocation.getArguments()[0];
- int count = (Integer) invocation.getArguments()[1];
- List referenceList = (List) invocation.getArguments()[2];
- Object[] args = new Object[]{fqn, count, referenceList};
- MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
- handler.addToList(mc);
- }
- else
- {
- throw new PojoCacheException("PojoTxUndoInterceptor: invalid invocation name: " + methodName);
- }
-
- return invocation.invokeNext();
- }
-
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoSynchronizationInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoSynchronizationInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/PojoTxUndoSynchronizationInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,92 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.cache.pojo.interceptors;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.cache.pojo.PojoCacheException;
-
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-
-/**
- * Interceptor that handles registration of tx synchronization for rollback
- * operations.
- *
- * @author Ben Wang
- * @version $Id$
- */
-public class PojoTxUndoSynchronizationInterceptor extends AbstractInterceptor
-{
- // We stores the handler in thread local since the afterCompletion won't be
- // called untill tx.commit(). Note that this is static since it can be
- // recursive call to attach/detach.
- private static ThreadLocal synchronizationHandler_ = new ThreadLocal();
-
- public Object invoke(Invocation in) throws Throwable
- {
- if (!(in instanceof MethodInvocation))
- {
- throw new IllegalArgumentException("TxSyncrhonizationInterceptor.invoke(): invocation not MethodInvocation");
- }
- MethodInvocation invocation = (MethodInvocation) in;
- try
- {
- registerTxHandler(invocation);
- return invocation.invokeNext(); // proceed to next advice or actual call
- }
- finally
- {
- }
- }
-
- private void registerTxHandler(MethodInvocation invocation) throws PojoCacheException
- {
- try
- {
- // Need to have this in case of rollback
- PojoTxSynchronizationHandler handler = (PojoTxSynchronizationHandler) synchronizationHandler_.get();
- if (handler == null)
- {
- // First entry point for this transaction scope.
- Transaction tx = (Transaction) invocation.getMetaData(PojoTxInterceptor.TAG, PojoTxInterceptor.TX);
- if (tx == null)
- {
- throw new IllegalStateException("PojoCache.registerTxHanlder(). Can't have null tx handle.");
- }
-
- handler = new PojoTxSynchronizationHandler();
-
- log.debug("Registering PojoTxSynchronizationHandler for rollback if ncessary " + handler);
- // Register so we can rollback if necessary
- tx.registerSynchronization(handler);
-
- synchronizationHandler_.set(handler);
- }
- }
- catch (RollbackException e)
- {
- throw new PojoCacheException("PojoTxUndoSynchronizationInterceptor.registerTxHandler(): Exception: " + e);
- }
- catch (SystemException e)
- {
- throw new PojoCacheException("PojoTxUndoSynchronizationInterceptor.registerTxHandler(): Exception: " + e);
- }
- }
-
- public static PojoTxSynchronizationHandler getSynchronizationHandler()
- {
- return (PojoTxSynchronizationHandler) synchronizationHandler_.get();
- }
-
- public static void reset()
- {
- synchronizationHandler_.set(null);
- }
-}
Deleted: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/StaticFieldInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/StaticFieldInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/StaticFieldInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,110 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.pojo.interceptors;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.pojo.impl.InternalConstant;
-import org.jboss.cache.pojo.impl.PojoCacheImpl;
-
-import java.lang.reflect.Field;
-
-/**
- * interceptor to intercept for static field replication.
- *
- * @author Ben Wang
- */
-
-public class StaticFieldInterceptor implements Interceptor
-{
- private final Log log_ = LogFactory.getLog(StaticFieldInterceptor.class);
- private PojoCacheImpl pCache_;
- private Fqn fqn_;
- private String name_;
- private String key_;
-
- public StaticFieldInterceptor()
- {
- }
-
- public String getName()
- {
- if (name_ == null)
- {
- this.name_ = "StaticFieldInterceptor on [" + fqn_ + "]";
- }
- return name_;
- }
-
- public Object invoke(Invocation invocation) throws Throwable
- {
- /*
- // Kind of ad hoc now. MethodInvocation should not invoke this.
- if(invocation instanceof MethodInvocation)
- return invocation.invokeNext();
-
- needInit(((FieldInvocation)invocation).getField());
- if (invocation instanceof FieldWriteInvocation)
- {
- FieldInvocation fieldInvocation =
- (FieldInvocation) invocation;
-
- Advisor advisor = fieldInvocation.getAdvisor();
- Field field = fieldInvocation.getField();
- if(log_.isTraceEnabled())
- {
- log_.trace("invoke(): field write interception for fqn: " +fqn_ + " and field: " +field);
- }
-
- // Only if this field is replicatable. static, transient and final are not.
- Object value = ((FieldWriteInvocation) fieldInvocation).getValue();
-
- cache_.put(fqn_, key_, value);
- Object obj = fieldInvocation.getTargetObject();
- } else if (invocation instanceof FieldReadInvocation)
- {
- FieldInvocation fieldInvocation =
- (FieldInvocation) invocation;
- Field field = fieldInvocation.getField();
- Advisor advisor = fieldInvocation.getAdvisor();
- return cache_.get(fqn_, key_);
- }
- */
- return invocation.invokeNext();
-
- }
-
- private void needInit(Field field)
- {
- if (pCache_ == null)
- {
- String cn = field.getDeclaringClass().getName();
- fqn_ = Fqn.fromString(InternalConstant.JBOSS_INTERNAL_STATIC + "/" + cn);
- key_ = field.getName();
- }
- }
-
- boolean isChildOf(Fqn parentFqn)
- {
- return fqn_.isChildOf(parentFqn);
- }
-
- public Fqn getFqn()
- {
- return fqn_;
- }
-
- public void setFqn(Fqn fqn)
- {
- this.fqn_ = fqn;
- }
-
-}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/AbstractCollectionInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -7,7 +7,7 @@
package org.jboss.cache.pojo.interceptors.dynamic;
-import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.proxy.ClassProxy;
import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.PojoCacheAlreadyDetachedException;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
@@ -25,6 +25,7 @@
{
Fqn fqn;
PojoCacheImpl cache;
+ ClassProxy boundProxy;
private boolean attached_ = true;
private PojoInstance pojoInstance_;
@@ -127,4 +128,14 @@
abstract Object getCacheCopy();
abstract void setCurrentCopy(Object obj);
public abstract Object getCurrentCopy();
+
+ public ClassProxy getBoundProxy()
+ {
+ return boundProxy;
+ }
+
+ public void setBoundProxy(ClassProxy boundProxy)
+ {
+ this.boundProxy = boundProxy;
+ }
}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -148,7 +148,7 @@
}
else
{
- result = pCache_.getObject(fqn_, field.getName(), target);
+ result = pCache_.find(fqn_, field.getName(), target);
// Work around AOP issue with field reads
if (result != null && result.getClass().isArray())
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CachedMapInterceptor.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -7,6 +7,7 @@
package org.jboss.cache.pojo.interceptors.dynamic;
import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.proxy.ClassProxy;
import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.collection.CachedMapImpl;
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/util/CacheApiUtil.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/util/CacheApiUtil.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/util/CacheApiUtil.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -26,4 +26,6 @@
Node n = cache.getRoot().getChild(fqn);
return n != null ? n.getChildren() : null;
}
+
+
}
Modified: pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml
===================================================================
--- pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml 2008-06-26 02:21:26 UTC (rev 6048)
@@ -1,152 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- This is the PojoCache configuration file that specifies:
- 1. Interceptor stack for API
- 2. Annotation binding for POJO (via "prepare" element)
-
- Basically, this is a variant of jboss-aop.xml. Note that
- except for the customization of interceptor stack, you should
- not need to modify this file.
-
- To run PojoCache, you will need to define a system property:
- jboss.aop.path that contains the path to this file such that JBoss Aop
- can locate it.
+ This is a variant of jboss-aop.xml.
-->
<aop>
-
- <!--
- This defines the PojoCache 2.0 interceptor stack. Unless necessary, don't modify the stack here!
- -->
-
- <!-- Check id range validity -->
- <interceptor name="CheckId" class="org.jboss.cache.pojo.interceptors.CheckIdInterceptor"
- scope="PER_INSTANCE"/>
-
- <!-- Track Tx undo operation -->
- <interceptor name="Undo" class="org.jboss.cache.pojo.interceptors.PojoTxUndoInterceptor"
- scope="PER_INSTANCE"/>
-
- <!-- Begining of interceptor chain -->
- <interceptor name="Start" class="org.jboss.cache.pojo.interceptors.PojoBeginInterceptor"
- scope="PER_INSTANCE">
- </interceptor>
-
- <!-- Check if we need a local tx for batch processing -->
- <interceptor name="Tx" class="org.jboss.cache.pojo.interceptors.PojoTxInterceptor"
- scope="PER_INSTANCE"/>
-
- <!--
- Mockup failed tx for testing. You will need to set PojoFailedTxMockupInterceptor.setRollback(true)
- to activate it.
- -->
- <interceptor name="MockupTx" class="org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor"
- scope="PER_INSTANCE"/>
-
- <!-- Perform parent level node locking -->
- <interceptor name="TxLock" class="org.jboss.cache.pojo.interceptors.PojoTxLockInterceptor"
- scope="PER_INSTANCE"/>
-
- <!-- Interceptor to perform Pojo level rollback -->
- <interceptor name="TxUndo" class="org.jboss.cache.pojo.interceptors.PojoTxUndoSynchronizationInterceptor"
- scope="PER_INSTANCE"/>
-
- <!-- Interceptor to used to check recursive field interception. -->
- <interceptor name="ReentrantToString" class="org.jboss.cache.pojo.interceptors.MethodReentrancyStopperInterceptor"
- scope="PER_INSTANCE">
- <attribute name="MethodName">toString</attribute>
- </interceptor>
-
- <interceptor name="ReentrantHashCode" class="org.jboss.cache.pojo.interceptors.MethodReentrancyStopperInterceptor"
- scope="PER_INSTANCE">
- <attribute name="MethodName">hashCode</attribute>
- </interceptor>
-
- <!-- Whether to allow non-serializable pojo. Default is false. -->
- <interceptor name="MarshallNonSerializable"
- class="org.jboss.cache.pojo.interceptors.CheckNonSerializableInterceptor"
- scope="PER_INSTANCE">
- <attribute name="marshallNonSerializable">false</attribute>
- </interceptor>
-
- <!-- This defines the stack macro -->
- <stack name="Attach">
- <interceptor-ref name="Start"/>
- <interceptor-ref name="CheckId"/>
- <interceptor-ref name="MarshallNonSerializable"/>
- <interceptor-ref name="Tx"/>
- <!-- NOTE: You can comment this out during production although leaving it here is OK. -->
- <interceptor-ref name="MockupTx"/>
- <interceptor-ref name="TxLock"/>
- <interceptor-ref name="TxUndo"/>
- </stack>
-
- <stack name="Detach">
- <interceptor-ref name="Start"/>
- <interceptor-ref name="CheckId"/>
- <interceptor-ref name="Tx"/>
- <!-- NOTE: You can comment this out during production although leaving it here is OK. -->
- <interceptor-ref name="MockupTx"/>
- <interceptor-ref name="TxLock"/>
- <interceptor-ref name="TxUndo"/>
- </stack>
-
- <stack name="Find">
- <interceptor-ref name="Start"/>
- <interceptor-ref name="CheckId"/>
- </stack>
-
- <!--
- The following section should be READ-ONLY!! It defines the annotation binding to the stack.
- -->
-
- <!-- This binds the jointpoint to specific in-memory operations. Currently in PojoUtil. -->
- <bind pointcut="execution(*
- @org.jboss.cache.pojo.annotation.Reentrant->toString())">
- <interceptor-ref name="ReentrantToString"/>
- </bind>
-
- <bind pointcut="execution(*
- @org.jboss.cache.pojo.annotation.Reentrant->hashCode())">
- <interceptor-ref name="ReentrantHashCode"/>
- </bind>
-
- <bind pointcut="execution(*
- org.jboss.cache.pojo.impl.PojoUtil->@org.jboss.cache.pojo.annotation.TxUndo(..))">
- <interceptor-ref name="Undo"/>
- </bind>
-
- <bind pointcut="execution(* org.jboss.cache.pojo.impl.PojoCacheImpl->@org.jboss.cache.pojo.annotation.Attach(..))">
- <stack-ref name="Attach"/>
- </bind>
-
- <bind pointcut="execution(* org.jboss.cache.pojo.impl.PojoCacheImpl->@org.jboss.cache.pojo.annotation.Detach(..))">
- <stack-ref name="Detach"/>
- </bind>
-
- <bind pointcut="execution(* org.jboss.cache.pojo.impl.PojoCacheImpl->@org.jboss.cache.pojo.annotation.Find(..))">
- <stack-ref name="Find"/>
- </bind>
-
-
- <!--
- Following is declaration for JDK50 annotation. You use the specific annotation on your
- POJO such that it can be instrumented. Idea is user will then need only to annotate like:
- @org.jboss.cache.pojo.annotation.Replicable
- in his POJO. There will be no need of jboss-aop.xml from user's side.
- Note that this annotation is inheritant, meaning the subclass will be
- instrumented as well.
- -->
-
- <!-- If a POJO has Replicable annotation, it will be asepectized. -->
- <!--
+ <!-- If a POJO has a Replicable annotation, it will be asepectized. -->
+
+ <!--
Supports inheritance and polymorphism. It can either be a concrete class
or an interface. All sub-classes or interface implementors will be instrumeneted.
-->
<prepare expr="field(* $instanceof{(a)org.jboss.cache.pojo.annotation.Replicable}->*)" />
<!-- Work around that ensures annotated classes which do not access fields are instrumented -->
+ <introduction expr="class($instanceof{(a)org.jboss.cache.pojo.annotation.Replicable})"/>
-
<!-- Array support -->
<!-- Comment entire section to disable -->
<arrayreplacement expr="class($instanceof{(a)org.jboss.cache.pojo.annotation.Replicable})"/>
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListImplTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListImplTest.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/collection/CachedListImplTest.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -23,7 +23,7 @@
*/
@Test(groups = {"functional"})
-public class CachedListImplTest
+public class CachedListImplTest
{
Log log = LogFactory.getLog(CachedListImplTest.class);
PojoCache cache_, cache1_;
@@ -60,15 +60,6 @@
// proxy now
list = (List<String>) cache_.find("list");
- // test repl
- try {
- cache_.getCache().put(Fqn.fromString("test"), "1", list);
- fail("Should have a non-serializable exception on list: " +list);
- } catch (Exception ex)
- {
- // OK. It works
- }
-
// JBCACHE-975
list = (List<String>) cache_.detach("list");
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ListUndoTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ListUndoTest.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ListUndoTest.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -19,7 +19,6 @@
import org.jboss.aop.proxy.ClassProxy;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.testng.annotations.AfterMethod;
@@ -60,20 +59,16 @@
// public void testDummy() {}
- private void setTxRollback(boolean isTrue)
- {
- PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
- }
-
public void testSimple() throws Exception
{
ArrayList<String> list = new ArrayList<String>();
list.add("test1");
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.attach("/a", list);
+ tx_mgr.rollback();
}
catch (Exception e)
{
@@ -93,10 +88,11 @@
list.add("English");
test.setLanguages(list);
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.attach("/a", test);
+ tx_mgr.rollback();
}
catch (Exception e)
{
@@ -124,10 +120,11 @@
cache_.attach("/a", test);
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.detach("/a");
+ tx_mgr.rollback();
}
catch (Exception e)
{
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/LocalUndoTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/LocalUndoTest.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/LocalUndoTest.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -18,7 +18,6 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
@@ -60,11 +59,6 @@
// public void testDummy() {}
- private void setTxRollback(boolean isTrue)
- {
- PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
- }
-
public void testSimpleTxWithRollback1() throws Exception
{
log_.info("testSimpleTxWithRollback1() ....");
@@ -72,10 +66,11 @@
test.setName("Ben");
test.setAge(10);
- setTxRollback(true);
try
{
- cache_.attach("/a", test);
+ tx_mgr.begin();
+ cache_.attach("/a", test);
+ tx_mgr.rollback();
}
catch (Exception e)
{
@@ -102,10 +97,11 @@
test.setAge(10);
cache_.attach("/a", test);
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.detach("/a");
+ tx_mgr.rollback();
}
catch (Exception e)
{
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/MapUndoTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/MapUndoTest.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/MapUndoTest.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -19,7 +19,6 @@
import org.jboss.aop.proxy.ClassProxy;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.testng.annotations.AfterMethod;
@@ -60,20 +59,16 @@
// public void testDummy() {}
- private void setTxRollback(boolean isTrue)
- {
- PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
- }
-
public void testSimple() throws Exception
{
HashMap<String, String> map = new HashMap<String, String>();
map.put("1", "test1");
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.attach("/a", map);
+ tx_mgr.rollback();
}
catch (Exception e)
{
@@ -93,10 +88,11 @@
map.put("1", "English");
test.setHobbies(map);
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.attach("/a", test);
+ tx_mgr.rollback();
}
catch (Exception e)
{
@@ -124,10 +120,11 @@
cache_.attach("/a", test);
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.detach("/a");
+ tx_mgr.rollback();
}
catch (Exception e)
{
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -242,17 +242,19 @@
{
TestingUtil.sleepThread(1000); // give Thread1 time to createPerson
List<String> lang = ((Person) cache1.find("/person/test6")).getLanguages();
+ System.out.println(lang == null);
tx = getTransaction();
tx.begin();
lang.add("English");
tx.commit();
+ System.out.println("Successful!");
}
catch (RollbackException rollback)
{
- ;
}
catch (Exception ex)
{
+ ex.printStackTrace();
try
{
tx.rollback();
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/SetUndoTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/SetUndoTest.java 2008-06-25 18:35:22 UTC (rev 6047)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/SetUndoTest.java 2008-06-26 02:21:26 UTC (rev 6048)
@@ -19,7 +19,6 @@
import org.jboss.aop.proxy.ClassProxy;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.pojo.interceptors.PojoFailedTxMockupInterceptor;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.testng.annotations.AfterMethod;
@@ -58,22 +57,16 @@
cache_.stop();
}
-// public void testDummy() {}
-
- private void setTxRollback(boolean isTrue)
- {
- PojoFailedTxMockupInterceptor.TX_ROLLBACK = isTrue;
- }
-
public void testSimple() throws Exception
{
HashSet<String> set = new HashSet<String>();
set.add("test1");
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.attach("/a", set);
+ tx_mgr.rollback();
}
catch (Exception e)
{
@@ -93,10 +86,11 @@
set.add("English");
test.setSkills(set);
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.attach("/a", test);
+ tx_mgr.rollback();
} catch (Exception e)
{
}
@@ -123,10 +117,11 @@
cache_.attach("/a", test);
- setTxRollback(true);
try
{
+ tx_mgr.begin();
cache_.detach("/a");
+ tx_mgr.rollback();
} catch (Exception e)
{
}
16 years, 6 months
JBoss Cache SVN: r6047 - core/trunk/src/main/java/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-25 14:35:22 -0400 (Wed, 25 Jun 2008)
New Revision: 6047
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
Log:
Added comments and TODOs
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-06-25 18:31:09 UTC (rev 6046)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-06-25 18:35:22 UTC (rev 6047)
@@ -93,30 +93,35 @@
@Override
public Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
{
+ // TODO : Handle this properly
return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
}
@Override
public Object handleClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
{
+ // TODO : Handle this properly
return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
}
@Override
public Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
+ // TODO : Handle this properly
return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
}
@Override
public Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
{
+ // TODO : Handle this properly
return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
}
@Override
public Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
{
+ // TODO : Handle this properly
return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
}
@@ -159,6 +164,7 @@
@Override
public Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
{
+ // TODO : Handle this properly
List<Fqn> list = new ArrayList<Fqn>();
list.add(command.getFqn());
list.add(command.getTo());
@@ -213,6 +219,7 @@
// for non-transactional stuff.
if (ctx.getTransaction() == null)
{
+ if (trace) log.trace("Releasing locks for thread " + Thread.currentThread());
List<Fqn> locks;
if (!(locks = ctx.getLocks()).isEmpty())
{
@@ -239,6 +246,7 @@
{
if (ctx.getTransaction() != null)
{
+ if (trace) log.trace("Releasing locks for transaction " + ctx.getGlobalTransaction());
List<Fqn> locks;
if (!(locks = ctx.getTransactionContext().getLocks()).isEmpty())
{
@@ -289,6 +297,7 @@
return invokeNextInterceptor(ctx, command);
}
+ // TODO : this method is probably unnecessary
protected Object handleWriteCommand(InvocationContext ctx, VisitableCommand command, List<Fqn> fqnsToRead, List<Fqn> fqnsToWrite) throws Throwable
{
for (Fqn f : fqnsToRead)
16 years, 6 months
JBoss Cache SVN: r6046 - in core/trunk/src: main/java/org/jboss/cache/config and 7 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-25 14:31:09 -0400 (Wed, 25 Jun 2008)
New Revision: 6046
Added:
core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/
core/trunk/src/test/java/org/jboss/cache/api/mvcc/CacheAPIMVCCTest.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChildInsertRemoveTest.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/NodeAPIMVCCTest.java
core/trunk/src/test/java/org/jboss/cache/mvcc/MVCCFullStackTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
core/trunk/src/main/java/org/jboss/cache/DataContainer.java
core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
core/trunk/src/main/java/org/jboss/cache/config/Configuration.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/invocation/NodeInvocationDelegate.java
core/trunk/src/test/java/org/jboss/cache/api/CacheAPIOptimisticTest.java
core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
Log:
Partially complete MVCC implementation. Still WIP.
Modified: core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -14,7 +14,7 @@
*
* @author manik
*/
-public abstract class AbstractNode<K, V>// implements Node<K, V>
+public abstract class AbstractNode<K, V>
{
protected Map<Object, Node<K, V>> children;
protected Fqn<?> fqn;
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainer.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainer.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -1,6 +1,7 @@
package org.jboss.cache;
import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.mvcc.InternalNode;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -208,4 +209,19 @@
* @return see above.
*/
Object[] createNodes(Fqn fqn);
+
+ /**
+ * Similar to {@link #peek(Fqn)} except that the underlying node is NOT wrapped as a {@link org.jboss.cache.NodeSPI}.
+ *
+ * @param f fqn to peek
+ * @return internal node
+ */
+ InternalNode peekInternalNode(Fqn f);
+
+ /**
+ * Sets a new root node
+ *
+ * @param nodeInvocationDelegate
+ */
+ void setRoot(NodeSPI nodeInvocationDelegate);
}
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -11,6 +11,7 @@
import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.lock.LockManager;
import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.mvcc.InternalNode;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -527,6 +528,14 @@
return new Object[]{result, n};
}
+ public InternalNode peekInternalNode(Fqn f)
+ {
+ // Yuck!
+ NodeSPI nodeSPI = peek(f);
+ if (nodeSPI == null) return null;
+ return (InternalNode) ((NodeInvocationDelegate) nodeSPI).getDelegationTarget();
+ }
+
public void setBuddyFqnTransformer(BuddyFqnTransformer buddyFqnTransformer)
{
this.buddyFqnTransformer = buddyFqnTransformer;
Modified: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -7,6 +7,7 @@
package org.jboss.cache;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.ComponentFactory;
import org.jboss.cache.factories.annotations.Inject;
@@ -15,6 +16,7 @@
import org.jboss.cache.invocation.InvocationContextContainer;
import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.lock.LockStrategyFactory;
+import org.jboss.cache.mvcc.InternalNode;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.optimistic.WorkspaceNode;
import org.jboss.cache.optimistic.WorkspaceNodeImpl;
@@ -29,7 +31,7 @@
public class NodeFactory<K, V> extends ComponentFactory
{
private CacheSPI<K, V> cache;
- private boolean optimistic;
+ private boolean useVersionedNode;
private Configuration configuration;
private InvocationContextContainer invocationContextContainer;
private InterceptorChain interceptorChain;
@@ -62,8 +64,8 @@
@Inject
public void injectDependencies(CacheSPI<K, V> cache, Configuration configuration,
- InvocationContextContainer invocationContextContainer,
- InterceptorChain interceptorChain, CommandsFactory commandsFactory, LockStrategyFactory lockStrategyFactory)
+ InvocationContextContainer invocationContextContainer,
+ InterceptorChain interceptorChain, CommandsFactory commandsFactory, LockStrategyFactory lockStrategyFactory)
{
this.cache = cache;
this.configuration = configuration;
@@ -79,7 +81,7 @@
@Start
public void init()
{
- optimistic = configuration.isNodeLockingOptimistic();
+ useVersionedNode = configuration.getNodeLockingScheme() != NodeLockingScheme.PESSIMISTIC;
}
@@ -98,7 +100,7 @@
*/
public NodeSPI<K, V> createDataNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
{
- UnversionedNode un = optimistic ? new VersionedNode<K, V>(fqn, parent, data, cache) : new UnversionedNode<K, V>(childName, fqn, data, cache);
+ UnversionedNode un = useVersionedNode ? new VersionedNode<K, V>(fqn, parent, data, cache) : new UnversionedNode<K, V>(childName, fqn, data, cache);
// always assume that new nodes do not have data loaded
un.setDataLoaded(false);
NodeInvocationDelegate<K, V> nid = new NodeInvocationDelegate(un);
@@ -136,4 +138,11 @@
return createDataNode(null, Fqn.ROOT, null, null, false);
}
+ public NodeSPI createNodeInvocationDelegate(InternalNode internalNode)
+ {
+ NodeInvocationDelegate nid = new NodeInvocationDelegate(internalNode);
+ nid.initialize(configuration, invocationContextContainer, componentRegistry, interceptorChain);
+ nid.injectDependencies(cache);
+ return nid;
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -50,15 +50,15 @@
/**
* A reference of the CacheImpl instance.
*/
- private transient CacheSPI cache;
+ transient CacheSPI cache;
/**
* Map of general data keys to values.
*/
- private final Map data = new HashMap();
+ final Map data = new HashMap();
protected NodeSPI delegate;
- private CommandsFactory commandsFactory;
+ CommandsFactory commandsFactory;
protected LockStrategyFactory lockStrategyFactory;
/**
Modified: core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -28,6 +28,7 @@
{
private static final String DATA_VERSION_INTERNAL_KEY = "_JBOSS_INTERNAL_OPTIMISTIC_DATA_VERSION";
private DataVersion version; // make sure this is NOT initialized to anything, even a null! Since the UnversionedNode constructor may set this value based on a data version passed along in the data map.
+
static
{
log = LogFactory.getLog(VersionedNode.class);
@@ -106,4 +107,18 @@
}
super.setInternalState(state);
}
+
+ @Override
+ public VersionedNode copy()
+ {
+ VersionedNode n = new VersionedNode(fqn, getParent(), data, cache);
+ n.children = children;
+ n.commandsFactory = commandsFactory;
+ n.delegate = delegate;
+ n.flags.clear();
+ n.flags.addAll(flags);
+ n.lockStrategyFactory = lockStrategyFactory;
+ n.version = version;
+ return n;
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -7,7 +7,6 @@
package org.jboss.cache.config;
import org.jboss.cache.Version;
-import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.JGroupsStackParser;
import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.lock.IsolationLevel;
@@ -15,9 +14,9 @@
import org.w3c.dom.Element;
import java.net.URL;
+import java.util.Collections;
+import java.util.List;
import java.util.Locale;
-import java.util.List;
-import java.util.Collections;
/**
* Encapsulates the configuration of a Cache.
@@ -133,12 +132,17 @@
public enum NodeLockingScheme
{
/**
+ * Data is locked using the MVCC locking scheme. This is the default locking scheme in JBoss Cache 3.0.0.
+ *
+ * @see <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">http://wiki.jboss.org/wiki/JBossCacheMVCC</a>
+ */
+ MVCC,
+ /**
* Data is exclusively locked during modification.
*
* @see <a href="http://en.wikipedia.org/wiki/Concurrency_control">http://en.wikipedia.org/wiki/Concurrency_control (pessimistic)</a>
*/
PESSIMISTIC,
-
/**
* Data is unlocked during modification, modifications merged at commit.
*
@@ -189,7 +193,7 @@
private boolean syncRollbackPhase = false;
private BuddyReplicationConfig buddyReplicationConfig;
private boolean nodeLockingOptimistic = false;
- private NodeLockingScheme nodeLockingScheme = NodeLockingScheme.PESSIMISTIC;
+ private NodeLockingScheme nodeLockingScheme = NodeLockingScheme.PESSIMISTIC; // TODO: Make this default MVCC once MVCC is completely implemented.
private String muxStackName = null;
private boolean usingMultiplexer = false;
private transient RuntimeConfig runtimeConfig;
@@ -198,7 +202,7 @@
private boolean useLazyDeserialization = false;
private int objectInputStreamPoolSize = 50;
private int objectOutputStreamPoolSize = 50;
- private List<CustomInterceptorConfig> customInterceptors = Collections.EMPTY_LIST;
+ private List<CustomInterceptorConfig> customInterceptors = Collections.emptyList();
// ------------------------------------------------------------------------------------------------------------
// SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
@@ -537,6 +541,7 @@
return this.shutdownHookBehavior;
}
+ @Deprecated
public boolean isNodeLockingOptimistic()
{
return nodeLockingOptimistic;
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -7,6 +7,7 @@
package org.jboss.cache.factories;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.jboss.cache.interceptors.*;
@@ -84,8 +85,12 @@
//Nothing...
}
- if (!optimistic)
+ if (configuration.getNodeLockingScheme() == NodeLockingScheme.MVCC)
{
+ interceptorChain.appendIntereceptor(createInterceptor(MVCCLockingInterceptor.class));
+ }
+ else if (configuration.getNodeLockingScheme() == NodeLockingScheme.PESSIMISTIC)
+ {
interceptorChain.appendIntereceptor(createInterceptor(PessimisticLockInterceptor.class));
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/LockManagerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/LockManagerFactory.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/factories/LockManagerFactory.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -2,6 +2,7 @@
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.lock.MVCCLockManager;
import org.jboss.cache.lock.NodeBasedLockManager;
import org.jboss.cache.lock.PessimisticNodeBasedLockManager;
@@ -18,13 +19,15 @@
@SuppressWarnings({"unchecked", "deprecation"})
protected <T> T construct(Class<T> componentType)
{
- if (configuration.isNodeLockingOptimistic())
+ switch (configuration.getNodeLockingScheme())
{
- return (T) super.construct(NodeBasedLockManager.class);
+ case MVCC:
+ return (T) super.construct(MVCCLockManager.class);
+ case OPTIMISTIC:
+ return (T) super.construct(NodeBasedLockManager.class);
+ case PESSIMISTIC:
+ default:
+ return (T) super.construct(PessimisticNodeBasedLockManager.class);
}
- else
- {
- return (T) super.construct(PessimisticNodeBasedLockManager.class);
- }
}
}
Added: core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,392 @@
+package org.jboss.cache.interceptors;
+
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.NodeFactory;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.commands.VisitableCommand;
+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.tx.CommitCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.write.*;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.interceptors.base.PostProcessingCommandInterceptor;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.LockManager;
+import static org.jboss.cache.lock.LockType.WRITE;
+import org.jboss.cache.mvcc.InternalNode;
+import org.jboss.cache.mvcc.ReadCommittedNode;
+import org.jboss.cache.mvcc.RepeatableReadNode;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Interceptor to implement <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">MVCC</a> functionality.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @see <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">MVCC designs</a>
+ * @since 3.0
+ */
+public class MVCCLockingInterceptor extends PostProcessingCommandInterceptor
+{
+ // TODO: Implement me.
+
+ // Need to think about how this will behave with 1. LockParentForChildInsertRemove and 2. CacheLoading.
+
+ // Need to think further about cached node lookups. Walking the tree sucks ass.
+
+ // How will wrapper nodes unwrap?
+
+ boolean isUsingRepeatableRead, ignoreWriteSkew, lockParentForChildInsertRemove;
+ LockManager lockManager;
+ DataContainer dataContainer;
+ NodeFactory nodeFactory;
+
+ @Inject
+ public void setDependencies(LockManager lockManager, DataContainer dataContainer, NodeFactory nodeFactory)
+ {
+ this.lockManager = lockManager;
+ this.dataContainer = dataContainer;
+ this.nodeFactory = nodeFactory;
+ }
+
+ @Start
+ public void start()
+ {
+ isUsingRepeatableRead = configuration.getIsolationLevel() == IsolationLevel.REPEATABLE_READ; // otherwise default to READ_COMMITTED
+ ignoreWriteSkew = true; // todo this should come from a cfg variable
+ lockParentForChildInsertRemove = configuration.isLockParentForChildInsertRemove();
+ }
+
+ @Override
+ public Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ {
+ getWrappedNode(ctx, command.getFqn(), true, true); // get the node and stick it in the context.
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ getWrappedNode(ctx, command.getFqn(), true, true); // get the node and stick it in the context.
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handlePutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
+ {
+ getWrappedNode(ctx, command.getFqn(), true, true); // get the node and stick it in the context.
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ {
+ return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ {
+ return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ {
+ return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
+ {
+ return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ {
+ return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
+ {
+ return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+ {
+ List<Fqn> list = new ArrayList<Fqn>();
+ list.add(command.getFqn());
+ list.add(command.getTo());
+ return handleWriteCommand(ctx, command, new ArrayList<Fqn>(1), list);
+ }
+
+ @Override
+ public Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
+ {
+ return handleReadCommand(ctx, command, Collections.singletonList(command.getFqn()));
+ }
+
+ @Override
+ public Object handleCreateNodeCommand(InvocationContext ctx, CreateNodeCommand command) throws Throwable
+ {
+ getWrappedNode(ctx, command.getFqn(), true, true); // get the node and stick it in the context.
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ Object retval = null;
+ try
+ {
+ retval = invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ transactionalCleanup(false, ctx);
+ }
+ return retval;
+ }
+
+ @Override
+ public Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ Object retval = null;
+ try
+ {
+ retval = invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ transactionalCleanup(true, ctx);
+ }
+ return retval;
+ }
+
+ protected void doAfterCall(InvocationContext ctx, VisitableCommand command)
+ {
+ // for non-transactional stuff.
+ if (ctx.getTransaction() == null)
+ {
+ List<Fqn> locks;
+ if (!(locks = ctx.getLocks()).isEmpty())
+ {
+ // clean up.
+ Fqn[] fqnsToUnlock = new Fqn[locks.size()];
+ fqnsToUnlock = locks.toArray(fqnsToUnlock);
+ Object owner = Thread.currentThread();
+
+ for (int i = fqnsToUnlock.length - 1; i > -1; i--)
+ {
+ // for each of these, swap refs
+ ReadCommittedNode rcn = (ReadCommittedNode) ctx.lookUpNode(fqnsToUnlock[i]);
+ rcn.copyNodeForUpdate(dataContainer, ignoreWriteSkew);
+ rcn.commitUpdate(dataContainer, nodeFactory);
+ // and then unlock
+ lockManager.unlock(fqnsToUnlock[i], owner);
+ }
+ ctx.clearLocks();
+ }
+ }
+ }
+
+ protected void transactionalCleanup(boolean commit, InvocationContext ctx)
+ {
+ if (ctx.getTransaction() != null)
+ {
+ List<Fqn> locks;
+ if (!(locks = ctx.getTransactionContext().getLocks()).isEmpty())
+ {
+ // clean up.
+ Fqn[] fqnsToUnlock = new Fqn[locks.size()];
+ fqnsToUnlock = locks.toArray(fqnsToUnlock);
+ Object owner = ctx.getGlobalTransaction();
+
+ for (int i = fqnsToUnlock.length - 1; i > -1; i--)
+ {
+ ReadCommittedNode rcn = (ReadCommittedNode) ctx.lookUpNode(fqnsToUnlock[i]);
+ if (commit)
+ {
+ // for each of these, swap refs
+ rcn.copyNodeForUpdate(dataContainer, ignoreWriteSkew);
+ rcn.commitUpdate(dataContainer, nodeFactory);
+ }
+ else
+ {
+ rcn.rollbackUpdate();
+ }
+ // and then unlock
+ lockManager.unlock(fqnsToUnlock[i], owner);
+ }
+ ctx.clearLocks();
+ }
+ }
+ }
+
+ // ----------------- actual implementation details ----------------------------
+
+ protected Object handleReadCommand(InvocationContext ctx, VisitableCommand command, List<Fqn> fqns) throws Throwable
+ {
+ // does the node exist in the context?
+ for (Fqn f : fqns)
+ {
+ if (ctx.lookUpNode(f) == null)
+ {
+ // simple implementation. Peek the node, wrap it, put wrapped node in the context.
+ InternalNode node = dataContainer.peekInternalNode(f);
+ if (node != null)
+ {
+ NodeSPI wrapped = isUsingRepeatableRead ? new RepeatableReadNode(node) : new ReadCommittedNode(node);
+ ctx.putLookedUpNode(f, wrapped);
+ }
+ }
+ }
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ protected Object handleWriteCommand(InvocationContext ctx, VisitableCommand command, List<Fqn> fqnsToRead, List<Fqn> fqnsToWrite) throws Throwable
+ {
+ for (Fqn f : fqnsToRead)
+ {
+ if (ctx.lookUpNode(f) == null)
+ {
+ // simple implementation. Peek the node, wrap it, put wrapped node in the context.
+ InternalNode node = dataContainer.peekInternalNode(f);
+ if (node != null)
+ {
+ NodeSPI wrapped = isUsingRepeatableRead ? new RepeatableReadNode(node) : new ReadCommittedNode(node);
+ ctx.putLookedUpNode(f, wrapped);
+ }
+ }
+ }
+
+ for (Fqn f : fqnsToWrite)
+ {
+ if (ctx.lookUpNode(f) == null)
+ {
+ // simple implementation. Peek the node, wrap it, put wrapped node in the context.
+ InternalNode node = dataContainer.peekInternalNode(f);
+ if (node != null)
+ {
+ lockManager.lock(f, WRITE, ctx);
+ NodeSPI wrapped = isUsingRepeatableRead ? new RepeatableReadNode(node) : new ReadCommittedNode(node);
+ ctx.putLookedUpNode(f, wrapped);
+ }
+ }
+ }
+
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ /**
+ * First checks in contexts for the existence of the node. If it does exist, it will return it, acquiring a lock if
+ * necessary. Otherwise, it will peek in the dataContainer, wrap the node, lock if necessary, and add it to the context.
+ * If it doesn't even exist in the dataContainer and createIfAbsent is true, it will create a new node and add it to the
+ * data structure. It will lock the node, and potentially the parent as well, if necessary. If the parent is locked,
+ * it too will be added to the context if it wasn't there already.
+ *
+ * @param fqn to retrieve
+ * @param lock if true, a lock will be acquired.
+ * @param createIfAbsent if true, will be created if absent.
+ * @return a NodeSPI or null.
+ */
+ protected NodeSPI getWrappedNode(InvocationContext context, Fqn fqn, boolean lock, boolean createIfAbsent) throws InterruptedException
+ {
+ NodeSPI n = context.lookUpNode(fqn);
+ if (n != null)
+ {
+ // acquire lock if needed
+ if (lock && !isLocked(context, fqn)) lockManager.lockAndRecord(fqn, WRITE, context);
+ if (trace) log.trace("Retrieving wrapped node " + fqn);
+ return n;
+ }
+
+ // else, fetch from dataContainer.
+ InternalNode in = dataContainer.peekInternalNode(fqn);
+ if (in != null)
+ {
+ // do we need a lock?
+ if (lock && !isLocked(context, fqn)) lockManager.lockAndRecord(fqn, WRITE, context);
+ NodeSPI wrapped = isUsingRepeatableRead ? new RepeatableReadNode(in) : new ReadCommittedNode(in);
+ context.putLookedUpNode(fqn, wrapped);
+ return wrapped;
+ }
+
+ // else, do we need to create one?
+ if (createIfAbsent)
+ {
+ Fqn parentFqn = fqn.getParent();
+ NodeSPI parent = getWrappedNode(context, parentFqn, false, createIfAbsent);
+ // do we need to lock the parent to create children?
+ if (lockParentForChildInsertRemove || parent.isLockForChildInsertRemove())
+ {
+ // get a lock on the parent.
+ if (!isLocked(context, parentFqn)) lockManager.lockAndRecord(parentFqn, WRITE, context);
+ }
+
+ // now to lock and create the node.
+ if (!isLocked(context, fqn)) lockManager.lockAndRecord(fqn, WRITE, context);
+ NodeSPI temp = parent.getOrCreateChild(fqn.getLastElement(), context.getGlobalTransaction());
+ in = (InternalNode) ((NodeInvocationDelegate) temp).getDelegationTarget();
+ NodeSPI wrapped = isUsingRepeatableRead ? new RepeatableReadNode(in) : new ReadCommittedNode(in);
+ context.putLookedUpNode(fqn, wrapped);
+ return wrapped;
+ }
+
+ return null;
+ }
+
+ protected boolean isLocked(InvocationContext ctx, Fqn fqn)
+ {
+ // don't EVER use lockManager.isLocked() since with lock striping it may be the case that we hold the relevant
+ // lock which may be shared with another Fqn that we have a lock for already.
+ // nothing wrong, just means that we fail to record the lock. And that is a problem.
+ // Better to check our records and lock again if necessary.
+ return ctx.getLocks().contains(fqn);
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -283,16 +283,7 @@
if (child == null)
{
- Option o2;
- try
- {
- o2 = o1.clone();
- }
- catch (CloneNotSupportedException e)
- {
- // should never happen
- throw new RuntimeException(e);
- }
+ Option o2 = o1.copy();
spi.getInvocationContext().setOptionOverrides(o1);
spi.put(nf, null);
Added: core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,284 @@
+package org.jboss.cache.mvcc;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.lock.NodeLock;
+import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.transaction.GlobalTransaction;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * // TODO Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class NodeReference implements InternalNode
+{
+ transient volatile InternalNode delegate;
+
+ public NodeReference(InternalNode delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public InternalNode getDelegate()
+ {
+ return delegate;
+ }
+
+ public void setDelegate(InternalNode delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public NodeSPI getParent()
+ {
+ return delegate.getParent();
+ }
+
+ public CacheSPI getCache()
+ {
+ return delegate.getCache();
+ }
+
+ public boolean isChildrenLoaded()
+ {
+ return delegate.isChildrenLoaded();
+ }
+
+ public void setChildrenLoaded(boolean flag)
+ {
+ delegate.setChildrenLoaded(flag);
+ }
+
+ public Object getDirect(Object key)
+ {
+ return delegate.getDirect(key);
+ }
+
+ public Map getDataDirect()
+ {
+ return delegate.getDataDirect();
+ }
+
+ public Object putDirect(Object key, Object value)
+ {
+ return delegate.putDirect(key, value);
+ }
+
+ public NodeSPI getOrCreateChild(Object child_name, GlobalTransaction gtx, boolean notify)
+ {
+ return delegate.getOrCreateChild(child_name, gtx, notify);
+ }
+
+ public Object removeDirect(Object key)
+ {
+ return delegate.removeDirect(key);
+ }
+
+ public void addChildDirect(NodeSPI child)
+ {
+ delegate.addChildDirect(child);
+ }
+
+ public NodeSPI addChildDirect(Fqn f)
+ {
+ return delegate.addChildDirect(f);
+ }
+
+ public NodeSPI addChildDirect(Fqn f, boolean notify)
+ {
+ return delegate.addChildDirect(f, notify);
+ }
+
+ public NodeSPI addChildDirect(Object o, boolean notify)
+ {
+ return delegate.addChildDirect(o, notify);
+ }
+
+ public void clearDataDirect()
+ {
+ delegate.clearDataDirect();
+ }
+
+ public NodeSPI getChildDirect(Fqn fqn)
+ {
+ return delegate.getChildDirect(fqn);
+ }
+
+ public Set getChildrenNamesDirect()
+ {
+ return delegate.getChildrenNamesDirect();
+ }
+
+ public Set getKeysDirect()
+ {
+ return delegate.getKeysDirect();
+ }
+
+ public boolean removeChildDirect(Object childName)
+ {
+ return delegate.removeChildDirect(childName);
+ }
+
+ public boolean removeChildDirect(Fqn f)
+ {
+ return delegate.removeChildDirect(f);
+ }
+
+ public Map getChildrenMapDirect()
+ {
+ return delegate.getChildrenMapDirect();
+ }
+
+ public void setChildrenMapDirect(Map children)
+ {
+ delegate.setChildrenMapDirect(children);
+ }
+
+ public void putAllDirect(Map data)
+ {
+ delegate.putAllDirect(data);
+ }
+
+ public void removeChildrenDirect()
+ {
+ delegate.removeChildrenDirect();
+ }
+
+ public void setVersion(DataVersion version)
+ {
+ delegate.setVersion(version);
+ }
+
+ public DataVersion getVersion()
+ {
+ return delegate.getVersion();
+ }
+
+ public Fqn getFqn()
+ {
+ return delegate.getFqn();
+ }
+
+ public void setFqn(Fqn fqn)
+ {
+ delegate.setFqn(fqn);
+ }
+
+ public NodeSPI getChildDirect(Object childName)
+ {
+ return delegate.getChildDirect(childName);
+ }
+
+ public Set getChildrenDirect()
+ {
+ return delegate.getChildrenDirect();
+ }
+
+ public boolean hasChildrenDirect()
+ {
+ return delegate.hasChildrenDirect();
+ }
+
+ public Set getChildrenDirect(boolean includeMarkedForRemoval)
+ {
+ return delegate.getChildrenDirect(includeMarkedForRemoval);
+ }
+
+ public boolean isDataLoaded()
+ {
+ return delegate.isDataLoaded();
+ }
+
+ public void setDataLoaded(boolean dataLoaded)
+ {
+ delegate.setDataLoaded(dataLoaded);
+ }
+
+ public boolean isValid()
+ {
+ return delegate.isValid();
+ }
+
+ public void setValid(boolean valid, boolean recursive)
+ {
+ delegate.setValid(valid, recursive);
+ }
+
+ public boolean isLockForChildInsertRemove()
+ {
+ return delegate.isLockForChildInsertRemove();
+ }
+
+ public void setLockForChildInsertRemove(boolean lockForChildInsertRemove)
+ {
+ delegate.setLockForChildInsertRemove(lockForChildInsertRemove);
+ }
+
+ public void setInternalState(Map state)
+ {
+ delegate.setInternalState(state);
+ }
+
+ public Map getInternalState(boolean onlyInternalState)
+ {
+ return delegate.getInternalState(onlyInternalState);
+ }
+
+ public void releaseObjectReferences(boolean recursive)
+ {
+ delegate.releaseObjectReferences(recursive);
+ }
+
+ public boolean isDeleted()
+ {
+ return delegate.isDeleted();
+ }
+
+ public void markAsDeleted(boolean marker)
+ {
+ delegate.markAsDeleted(marker);
+ }
+
+ public void markAsDeleted(boolean marker, boolean recursive)
+ {
+ delegate.markAsDeleted(marker, recursive);
+ }
+
+ public void setResident(boolean resident)
+ {
+ delegate.setResident(resident);
+ }
+
+ public boolean isResident()
+ {
+ return delegate.isResident();
+ }
+
+ public InternalNode copy()
+ {
+ InternalNode cloneDelegate = delegate.copy();
+ return new NodeReference(cloneDelegate);
+ }
+
+ public NodeLock getLock()
+ {
+ return delegate.getLock();
+ }
+
+ public void addChild(Object nodeName, Node nodeToAdd)
+ {
+ delegate.addChild(nodeName, nodeToAdd);
+ }
+
+ public void printDetails(StringBuffer sb, int indent)
+ {
+ delegate.printDetails(sb, indent);
+ }
+}
Added: core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,63 @@
+package org.jboss.cache.mvcc;
+
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.NodeFactory;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
+import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.optimistic.DefaultDataVersion;
+
+/**
+ * Repeatable read would do a simple delegation to the underlying node.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class ReadCommittedNode extends NodeInvocationDelegate
+{
+ protected volatile InternalNode backup;
+ protected boolean changed;
+
+ public ReadCommittedNode(InternalNode node)
+ {
+ super(node);
+ }
+
+ public void copyNodeForUpdate(DataContainer container, boolean ignoreWriteSkew)
+ {
+ changed = true;
+ backup = node;
+ node = backup.copy();
+ // TODO: Make sure this works with custom versions as well!
+ DataVersion newVersion = ((DefaultDataVersion) node.getVersion()).increment();
+ node.setVersion(newVersion);
+ }
+
+ public void commitUpdate(DataContainer container, NodeFactory nf)
+ {
+ if (changed)
+ {
+ updateNode(container, nf);
+ changed = false;
+ backup = null;
+ }
+ }
+
+ protected void updateNode(DataContainer container, NodeFactory nf)
+ {
+ // TODO: Deal with removes and moves
+ // TODO: Deal with creating - what if children is null?
+
+ ((NodeReference) backup).setDelegate(((NodeReference) node).getDelegate());
+ node = backup;
+ }
+
+ public void rollbackUpdate()
+ {
+ if (changed)
+ {
+ node = backup;
+ backup = null;
+ changed = false;
+ }
+ }
+}
Added: core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,57 @@
+package org.jboss.cache.mvcc;
+
+import org.jboss.cache.CacheException;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.NodeFactory;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.optimistic.DefaultDataVersion;
+
+/**
+ * // TODO Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class RepeatableReadNode extends ReadCommittedNode
+{
+ public RepeatableReadNode(InternalNode node)
+ {
+ super(node);
+ }
+
+ @Override
+ public void copyNodeForUpdate(DataContainer container, boolean ignoreWriteSkew)
+ {
+ changed = true;
+ backup = node;
+ // write skew check
+ DataVersion underlyingNodeVersion = container.peek(getFqn()).getVersion();
+ if (ignoreWriteSkew || backup.getVersion().equals(underlyingNodeVersion))
+ {
+ node = backup.copy();
+ // TODO: Make sure this works with custom versions as well!
+ DataVersion newVersion = ((DefaultDataVersion) node.getVersion()).increment();
+ node.setVersion(newVersion);
+ }
+ else
+ {
+ throw new CacheException("Detected write skew. Attempting to overwrite version " + backup.getVersion() + " but current version has progressed to " + underlyingNodeVersion);
+ }
+ }
+
+ @Override
+ protected void updateNode(DataContainer dataContainer, NodeFactory nf)
+ {
+ // TODO: Deal with removes and moves
+ if (getFqn().isRoot())
+ {
+ dataContainer.setRoot(nf.createNodeInvocationDelegate(node));
+ }
+ else
+ {
+ NodeSPI parent = dataContainer.peek(getFqn().getParent());
+ parent.addChildDirect(nf.createNodeInvocationDelegate(node));
+ }
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/api/CacheAPIOptimisticTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/CacheAPIOptimisticTest.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/test/java/org/jboss/cache/api/CacheAPIOptimisticTest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -1,5 +1,6 @@
package org.jboss.cache.api;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.testng.annotations.Test;
@@ -9,8 +10,10 @@
@Test(groups = "functional")
public class CacheAPIOptimisticTest extends CacheAPITest
{
- public CacheAPIOptimisticTest()
+ @Override
+ protected NodeLockingScheme getNodeLockingScheme()
{
- optimistic = true;
+ return NodeLockingScheme.OPTIMISTIC;
}
+
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -8,6 +8,7 @@
import org.jboss.cache.Node;
import org.jboss.cache.Region;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeCreated;
@@ -35,16 +36,15 @@
public class CacheAPITest
{
private Cache<String, String> cache;
- protected boolean optimistic;
final List<String> events = new ArrayList<String>();
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
// start a single cache instance
- CacheFactory<String, String> cf = new DefaultCacheFactory();
+ CacheFactory<String, String> cf = new DefaultCacheFactory<String, String>();
cache = cf.createCache("META-INF/conf-test/local-tx-service.xml", false);
- cache.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
+ cache.getConfiguration().setNodeLockingScheme(getNodeLockingScheme());
cache.start();
events.clear();
}
@@ -55,6 +55,10 @@
if (cache != null) cache.stop();
}
+ protected NodeLockingScheme getNodeLockingScheme()
+ {
+ return NodeLockingScheme.PESSIMISTIC;
+ }
/**
* Tests that the configuration contains the values expected, as well as immutability of certain elements
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -1,5 +1,9 @@
package org.jboss.cache.api;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
+import org.jboss.cache.interceptors.PessimisticLockInterceptor;
+import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.testng.annotations.Test;
/**
@@ -8,8 +12,22 @@
@Test(groups = "functional")
public class NodeAPIOptimisticTest extends NodeAPITest
{
- public NodeAPIOptimisticTest()
+ protected NodeLockingScheme getNodeLockingScheme()
{
- optimistic = true;
+ return NodeLockingScheme.OPTIMISTIC;
}
+
+ protected void assertNodeLockingScheme()
+ {
+ assert cache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC;
+ boolean interceptorChainOK = false;
+
+ for (CommandInterceptor i : cache.getInterceptorChain())
+ {
+ if (i instanceof PessimisticLockInterceptor) assert false : "Not an optimistic locking chain!!";
+ if (i instanceof OptimisticNodeInterceptor) interceptorChainOK = true;
+ }
+
+ assert interceptorChainOK : "Not an optimistic locking chain!!";
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-06-25 18:29:49 UTC (rev 6045)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -4,7 +4,9 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import static org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
+import org.jboss.cache.interceptors.MVCCLockingInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.interceptors.PessimisticLockInterceptor;
import org.jboss.cache.interceptors.base.CommandInterceptor;
@@ -33,21 +35,19 @@
{
private Node<Object, Object> rootNode;
- private CacheSPI<Object, Object> cache;
+ protected CacheSPI<Object, Object> cache;
private TransactionManager tm;
private static final Fqn<String> A = Fqn.fromString("/a"), B = Fqn.fromString("/b"), C = Fqn.fromString("/c"), D = Fqn
.fromString("/d");
- protected boolean optimistic = false;
-
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
// start a single cache instance
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache("META-INF/conf-test/local-tx-service.xml", false);
- cache.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
+ cache.getConfiguration().setNodeLockingScheme(getNodeLockingScheme());
cache.start();
rootNode = cache.getRoot();
tm = cache.getTransactionManager();
@@ -77,23 +77,29 @@
}
}
- private void assertOptimistic()
+ protected NodeLockingScheme getNodeLockingScheme()
{
- assert cache.getConfiguration().isNodeLockingOptimistic();
+ return NodeLockingScheme.PESSIMISTIC;
+ }
+
+ protected void assertNodeLockingScheme()
+ {
+ assert cache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.PESSIMISTIC;
boolean interceptorChainOK = false;
for (CommandInterceptor i : cache.getInterceptorChain())
{
- if (i instanceof PessimisticLockInterceptor) assert false : "Not an optimistic locking chain!!";
- if (i instanceof OptimisticNodeInterceptor) interceptorChainOK = true;
+ if (i instanceof PessimisticLockInterceptor) interceptorChainOK = true;
+ if (i instanceof OptimisticNodeInterceptor) assert false : "Not a pessimistic locking chain!!";
+ if (i instanceof MVCCLockingInterceptor) assert false : "Not a pessimistic locking chain!!";
}
- assert interceptorChainOK : "Not an optimistic locking chain!!";
+ assert interceptorChainOK : "Not a pessimistic locking chain!!";
}
public void testAddingData()
{
- if (optimistic) assertOptimistic();
+ assertNodeLockingScheme();
Node<Object, Object> nodeA = rootNode.addChild(A);
nodeA.put("key", "value");
@@ -177,7 +183,7 @@
Node<Object, Object> nodeB = nodeA.addChild(B);
Node<Object, Object> nodeC = nodeB.addChild(C);
- if (!optimistic)
+ if (getNodeLockingScheme() != OPTIMISTIC)
{
assertEquals(3, cache.getNumberOfNodes());
assertEquals(4, cache.getNumberOfLocksHeld());
@@ -187,7 +193,7 @@
tm.begin();
assertEquals(0, cache.getNumberOfLocksHeld());
nodeC.put("key", "value");
- if (!optimistic) assertEquals(4, cache.getNumberOfLocksHeld());
+ if (getNodeLockingScheme() != OPTIMISTIC) assertEquals(4, cache.getNumberOfLocksHeld());
tm.commit();
}
@@ -289,7 +295,7 @@
cache.put(A_B, "1", "1");
cache.put(A_C, "2", "2");
- if (!optimistic)
+ if (getNodeLockingScheme() != OPTIMISTIC)
{
assertEquals(3, cache.getNumberOfNodes());
assertEquals(4, cache.getNumberOfLocksHeld());
@@ -329,7 +335,8 @@
public void testGetChildAPI()
{
// creates a Node<Object, Object> with fqn /a/b/c
- rootNode.addChild(A).addChild(B).addChild(C);
+ Node childA = rootNode.addChild(A);
+ childA.addChild(B).addChild(C);
rootNode.getChild(A).put("key", "value");
rootNode.getChild(A).getChild(B).put("key", "value");
Copied: core/trunk/src/test/java/org/jboss/cache/api/mvcc/CacheAPIMVCCTest.java (from rev 6034, core/trunk/src/test/java/org/jboss/cache/api/CacheAPIOptimisticTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/CacheAPIMVCCTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/CacheAPIMVCCTest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,20 @@
+package org.jboss.cache.api.mvcc;
+
+import org.jboss.cache.api.CacheAPITest;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.testng.annotations.Test;
+
+
+/**
+ * MVCC version of {@link org.jboss.cache.api.CacheAPITest}
+ */
+@Test(groups = "functional")
+public class CacheAPIMVCCTest extends CacheAPITest
+{
+ @Override
+ protected NodeLockingScheme getNodeLockingScheme()
+ {
+ return NodeLockingScheme.MVCC;
+ }
+
+}
\ No newline at end of file
Property changes on: core/trunk/src/test/java/org/jboss/cache/api/mvcc/CacheAPIMVCCTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChildInsertRemoveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChildInsertRemoveTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockParentForChildInsertRemoveTest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,12 @@
+package org.jboss.cache.api.mvcc;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional")
+public class LockParentForChildInsertRemoveTest extends LockTest
+{
+ public LockParentForChildInsertRemoveTest()
+ {
+ lockParentForInsertRemove = true;
+ }
+}
Added: core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,153 @@
+package org.jboss.cache.api.mvcc;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.lock.MVCCLockManager.LockContainer;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+import java.util.Collections;
+
+/**
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@Test(groups = "functional")
+public class LockTest
+{
+ Cache<String, String> cache;
+ TransactionManager tm;
+ Fqn A = Fqn.fromString("/a");
+ Fqn AB = Fqn.fromString("/a/b");
+ Fqn ABC = Fqn.fromString("/a/b/c");
+ LockManager lockManager;
+ InvocationContextContainer icc;
+ boolean lockParentForInsertRemove = false;
+
+ @BeforeMethod
+ public void setUp()
+ {
+ cache = new DefaultCacheFactory<String, String>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL), false);
+ cache.getConfiguration().setNodeLockingScheme(NodeLockingScheme.MVCC);
+ cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.getConfiguration().setLockParentForChildInsertRemove(lockParentForInsertRemove);
+ cache.start();
+ lockManager = TestingUtil.extractComponentRegistry(cache).getComponent(LockManager.class);
+ icc = TestingUtil.extractComponentRegistry(cache).getComponent(InvocationContextContainer.class);
+ tm = TestingUtil.extractComponentRegistry(cache).getComponent(TransactionManager.class);
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ private void assertLocked(Fqn fqn)
+ {
+ assert lockManager.isLocked(fqn) : fqn + " not locked!";
+ assert icc.get().getLocks().contains(fqn) : "Lock not recorded for " + fqn;
+ }
+
+ private void assertNotLocked(Fqn fqn)
+ {
+ // can't rely on the negative test since other nodes may share the same lock with lock striping.
+// assert !lockManager.isLocked(fqn) : fqn + " is locked!";
+ assert !icc.get().getLocks().contains(fqn) : fqn + " lock recorded!";
+ }
+
+ private void assertNoLocks()
+ {
+ LockContainer lc = (LockContainer) TestingUtil.extractField(lockManager, "lockContainer");
+ assert lc.getNumLocksHeld() == 0 : "Stale locks exist!" + lockManager.printLockInfo();
+ assert icc.get().getLocks().isEmpty() : "Stale (?) locks recorded! " + icc.get().getLocks();
+ }
+
+ public void testLocksOnPutKeyVal() throws Exception
+ {
+ tm.begin();
+ cache.put(AB, "k", "v");
+ if (lockParentForInsertRemove)
+ assertLocked(Fqn.ROOT);
+ else
+ assertNotLocked(Fqn.ROOT);
+ assertLocked(A);
+ assertLocked(AB);
+ assertNotLocked(ABC);
+ tm.commit();
+
+ assertNoLocks();
+
+ tm.begin();
+ assert cache.get(AB, "k").equals("v");
+ assertNotLocked(Fqn.ROOT);
+ assertNotLocked(A);
+ assertNotLocked(AB);
+ assertNotLocked(ABC);
+ tm.commit();
+
+ assertNoLocks();
+
+ tm.begin();
+ cache.put(ABC, "k", "v");
+ assertNotLocked(Fqn.ROOT);
+ assertNotLocked(A);
+ if (lockParentForInsertRemove)
+ assertLocked(AB);
+ else
+ assertNotLocked(AB);
+ assertLocked(ABC);
+ tm.commit();
+
+ assertNoLocks();
+ }
+
+ public void testLocksOnPutData() throws Exception
+ {
+ tm.begin();
+ cache.put(AB, Collections.singletonMap("k", "v"));
+ if (lockParentForInsertRemove)
+ assertLocked(Fqn.ROOT);
+ else
+ assertNotLocked(Fqn.ROOT);
+ assertLocked(A);
+ assertLocked(AB);
+ assertNotLocked(ABC);
+ tm.commit();
+
+ assertNoLocks();
+
+ tm.begin();
+ assert cache.get(AB, "k").equals("v");
+ assertNotLocked(Fqn.ROOT);
+ assertNotLocked(A);
+ assertNotLocked(AB);
+ assertNotLocked(ABC);
+ tm.commit();
+
+ assertNoLocks();
+
+ tm.begin();
+ cache.put(ABC, Collections.singletonMap("k", "v"));
+ assertNotLocked(Fqn.ROOT);
+ assertNotLocked(A);
+ if (lockParentForInsertRemove)
+ assertLocked(AB);
+ else
+ assertNotLocked(AB);
+ assertLocked(ABC);
+ tm.commit();
+
+ assertNoLocks();
+ }
+}
Copied: core/trunk/src/test/java/org/jboss/cache/api/mvcc/NodeAPIMVCCTest.java (from rev 6034, core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/NodeAPIMVCCTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/NodeAPIMVCCTest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,37 @@
+package org.jboss.cache.api.mvcc;
+
+import org.jboss.cache.api.NodeAPITest;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.interceptors.MVCCLockingInterceptor;
+import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
+import org.jboss.cache.interceptors.PessimisticLockInterceptor;
+import org.jboss.cache.interceptors.base.CommandInterceptor;
+import org.testng.annotations.Test;
+
+/**
+ * An MVCC version of {@link org.jboss.cache.api.NodeAPITest}
+ */
+@Test(groups = "functional")
+public class NodeAPIMVCCTest extends NodeAPITest
+{
+ protected NodeLockingScheme getNodeLockingScheme()
+ {
+ return NodeLockingScheme.MVCC;
+ }
+
+ protected void assertNodeLockingScheme()
+ {
+ assert cache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.MVCC;
+ boolean interceptorChainOK = false;
+
+ for (CommandInterceptor i : cache.getInterceptorChain())
+ {
+ if (i instanceof PessimisticLockInterceptor) assert false : "Not an MVCC locking chain!!";
+ if (i instanceof OptimisticNodeInterceptor) assert false : "Not an MVCC locking chain!!";
+ if (i instanceof MVCCLockingInterceptor) interceptorChainOK = true;
+
+ }
+
+ assert interceptorChainOK : "Not an MVCC locking chain!!";
+ }
+}
\ No newline at end of file
Added: core/trunk/src/test/java/org/jboss/cache/mvcc/MVCCFullStackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mvcc/MVCCFullStackTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/mvcc/MVCCFullStackTest.java 2008-06-25 18:31:09 UTC (rev 6046)
@@ -0,0 +1,33 @@
+package org.jboss.cache.mvcc;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.interceptors.MVCCLockingInterceptor;
+import org.jboss.cache.util.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@Test(groups = "functional")
+public class MVCCFullStackTest
+{
+ CacheSPI<Object, Object> cache;
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testDefaultConfiguration()
+ {
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache();
+
+ assert TestingUtil.findInterceptor(cache, MVCCLockingInterceptor.class) != null : "MVCC interceptor should be in stack";
+ assert cache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.MVCC;
+ }
+}
16 years, 6 months
JBoss Cache SVN: r6045 - core/trunk/src/main/java/org/jboss/cache/lock.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-25 14:29:49 -0400 (Wed, 25 Jun 2008)
New Revision: 6045
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java
core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java
core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
Log:
Added extra methods to interface
Modified: core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java 2008-06-25 18:28:12 UTC (rev 6044)
+++ core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java 2008-06-25 18:29:49 UTC (rev 6045)
@@ -47,4 +47,9 @@
{
return getReadOwners(node.getFqn());
}
+
+ public boolean isLocked(NodeSPI node)
+ {
+ return isLocked(node.getFqn());
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java 2008-06-25 18:28:12 UTC (rev 6044)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java 2008-06-25 18:29:49 UTC (rev 6045)
@@ -258,6 +258,14 @@
/**
* Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.
*
+ * @param fqn node to inspect
+ * @return true of locked; false if not.
+ */
+ boolean isLocked(Fqn fqn);
+
+ /**
+ * Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.
+ *
* @param n node to inspect
* @param lockType lockType to test for
* @return true of locked; false if not.
@@ -302,4 +310,11 @@
* @param node node to inspect
*/
String printLockInfo(NodeSPI node);
+
+ /**
+ * Prints lock information for all locks.
+ *
+ * @return
+ */
+ String printLockInfo();
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-06-25 18:28:12 UTC (rev 6044)
+++ core/trunk/src/main/java/org/jboss/cache/lock/MVCCLockManager.java 2008-06-25 18:29:49 UTC (rev 6045)
@@ -1,6 +1,8 @@
package org.jboss.cache.lock;
import net.jcip.annotations.ThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
@@ -13,6 +15,7 @@
import org.jboss.cache.util.concurrent.locks.OwnableReentrantLock;
import javax.transaction.TransactionManager;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -47,6 +50,8 @@
private TransactionManager transactionManager;
private InvocationContextContainer invocationContextContainer;
private static final int DEFAULT_CONCURRENCY = 20;
+ private static final Log log = LogFactory.getLog(MVCCLockManager.class);
+ private static final boolean trace = log.isTraceEnabled();
@Inject
public void injectDataContainer(DataContainer dataContainer, CacheSPI cache, TransactionManager transactionManager, InvocationContextContainer invocationContextContainer)
@@ -80,6 +85,7 @@
public boolean lock(Fqn fqn, LockType lockType, Object owner) throws InterruptedException
{
assertIsWriteLock(lockType);
+ if (trace) log.trace("Attempting to lock " + fqn);
Lock lock = lockContainer.getLock(fqn);
return lock.tryLock(lockAcquisitionTimeout, MILLISECONDS);
}
@@ -87,6 +93,7 @@
public boolean lock(Fqn fqn, LockType lockType, Object owner, long timeoutMillis) throws InterruptedException
{
assertIsWriteLock(lockType);
+ if (trace) log.trace("Attempting to lock " + fqn);
Lock lock = lockContainer.getLock(fqn);
return lock.tryLock(timeoutMillis, MILLISECONDS);
}
@@ -94,6 +101,7 @@
public boolean lockAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx) throws InterruptedException
{
assertIsWriteLock(lockType);
+ if (trace) log.trace("Attempting to lock " + fqn);
Lock lock = lockContainer.getLock(fqn);
if (lock.tryLock(ctx.getContextLockAcquisitionTimeout(lockAcquisitionTimeout), MILLISECONDS))
{
@@ -107,6 +115,7 @@
public void unlock(Fqn fqn, Object owner)
{
+ if (trace) log.trace("Attempting to unlock " + fqn);
Lock lock = lockContainer.getLock(fqn);
lock.unlock();
}
@@ -119,7 +128,11 @@
// unlocking needs to be done in reverse order.
Fqn[] fqns = new Fqn[locks.size()];
fqns = locks.toArray(fqns);
- for (int i = fqns.length - 1; i > -1; i--) lockContainer.getLock(fqns[i]).unlock();
+ for (int i = fqns.length - 1; i > -1; i--)
+ {
+ if (trace) log.trace("Attempting to unlock " + fqns[i]);
+ lockContainer.getLock(fqns[i]).unlock();
+ }
}
}
@@ -228,9 +241,9 @@
return lockContainer.ownsLock(fqn, owner);
}
- public boolean isLocked(NodeSPI n)
+ public boolean isLocked(Fqn fqn)
{
- return lockContainer.isLocked(n.getFqn());
+ return lockContainer.isLocked(fqn);
}
public boolean isLocked(NodeSPI n, LockType lockType)
@@ -251,11 +264,16 @@
public String printLockInfo(NodeSPI node)
{
- return "Not supported in this impl.";
+ return printLockInfo();
}
+ public String printLockInfo()
+ {
+ return lockContainer.toString();
+ }
+
@ThreadSafe
- abstract class LockContainer
+ public abstract class LockContainer
{
private final int lockSegmentMask;
private final int lockSegmentShift;
@@ -318,9 +336,11 @@
abstract boolean isLocked(Fqn fqn);
abstract Lock getLock(Fqn fqn);
+
+ public abstract int getNumLocksHeld();
}
- class ReentrantLockContainer extends LockContainer
+ public class ReentrantLockContainer extends LockContainer
{
ReentrantLock[] sharedLocks;
@@ -332,9 +352,18 @@
ReentrantLock getLock(Fqn fqn)
{
- return sharedLocks[hashToIndex(fqn)];
+ ReentrantLock l = sharedLocks[hashToIndex(fqn)];
+ if (trace) log.trace("Found lock " + l + " for fqn " + fqn);
+ return l;
}
+ public int getNumLocksHeld()
+ {
+ int i = 0;
+ for (ReentrantLock l : sharedLocks) if (l.isLocked()) i++;
+ return i;
+ }
+
boolean ownsLock(Fqn fqn, Object owner)
{
ReentrantLock lock = getLock(fqn);
@@ -346,9 +375,16 @@
ReentrantLock lock = getLock(fqn);
return lock.isLocked();
}
+
+ public String toString()
+ {
+ return "ReentrantLockContainer{" +
+ "sharedLocks=" + (sharedLocks == null ? null : Arrays.asList(sharedLocks)) +
+ '}';
+ }
}
- class OwnableReentrantLockContainer extends LockContainer
+ public class OwnableReentrantLockContainer extends LockContainer
{
OwnableReentrantLock[] sharedLocks;
@@ -360,7 +396,9 @@
OwnableReentrantLock getLock(Fqn fqn)
{
- return sharedLocks[hashToIndex(fqn)];
+ OwnableReentrantLock l = sharedLocks[hashToIndex(fqn)];
+ if (trace) log.trace("Found lock " + l + " for fqn " + fqn);
+ return l;
}
boolean ownsLock(Fqn fqn, Object owner)
@@ -374,5 +412,19 @@
OwnableReentrantLock lock = getLock(fqn);
return lock.isLocked();
}
+
+ public int getNumLocksHeld()
+ {
+ int i = 0;
+ for (OwnableReentrantLock l : sharedLocks) if (l.isLocked()) i++;
+ return i;
+ }
+
+ public String toString()
+ {
+ return "OwnableReentrantLockContainer{" +
+ "sharedLocks=" + (sharedLocks == null ? null : Arrays.asList(sharedLocks)) +
+ '}';
+ }
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java 2008-06-25 18:28:12 UTC (rev 6044)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java 2008-06-25 18:29:49 UTC (rev 6045)
@@ -251,6 +251,11 @@
return n.getLock().isLocked();
}
+ public boolean isLocked(Fqn fqn)
+ {
+ return isLocked(dataContainer.peek(fqn));
+ }
+
public boolean isLocked(NodeSPI n, LockType type)
{
switch (type)
@@ -299,4 +304,9 @@
return sb.toString();
}
+
+ public String printLockInfo()
+ {
+ return printLockInfo(dataContainer.getRoot());
+ }
}
16 years, 6 months
JBoss Cache SVN: r6044 - in core/trunk/src/main/java/org/jboss/cache: transaction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-25 14:28:12 -0400 (Wed, 25 Jun 2008)
New Revision: 6044
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java
Log:
Added caching of looked up nodes
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-06-25 18:27:24 UTC (rev 6043)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-06-25 18:28:12 UTC (rev 6044)
@@ -59,24 +59,68 @@
private final Map<Fqn, NodeSPI> lookedUpNodes = new HashMap<Fqn, NodeSPI>();
+ /**
+ * Retrieves a node from the registry of looked up nodes in the current scope.
+ * <p/>
+ * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#lookUpNode(Fqn)}
+ * <p/>
+ *
+ * @param fqn fqn to look up
+ * @return a node, or null if it cannot be found.
+ * @since 3.0.
+ */
public NodeSPI lookUpNode(Fqn fqn)
{
- // TODO: should delegate to TransactionEntry if one is in scope
+ if (transactionContext != null) return transactionContext.lookUpNode(fqn);
return lookedUpNodes.get(fqn);
}
+ /**
+ * Puts an entry in the registry of looked up nodes in the current scope.
+ * <p/>
+ * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#putLookedUpNode(Fqn, NodeSPI)}
+ * <p/>
+ *
+ * @param f fqn to add
+ * @param n node to add
+ * @since 3.0.
+ */
public void putLookedUpNode(Fqn f, NodeSPI n)
{
- lookedUpNodes.put(f, n);
+ if (transactionContext != null)
+ transactionContext.putLookedUpNode(f, n);
+ else
+ lookedUpNodes.put(f, n);
}
+ /**
+ * Clears the registry of looked up nodes.
+ * <p/>
+ * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#clearLookedUpNodes()}.
+ * <p/>
+ *
+ * @since 3.0.
+ */
public void clearLookedUpNodes()
{
- lookedUpNodes.clear();
+ if (transactionContext != null)
+ transactionContext.clearLookedUpNodes();
+ else
+ lookedUpNodes.clear();
}
+ /**
+ * Retrieves a map of nodes looked up within the current invocation's scope.
+ * <p/>
+ * If a transaction is in progress, this method will delegate to {@link org.jboss.cache.transaction.TransactionContext#getLookedUpNodes()}.
+ * <p/>
+ *
+ * @return a map of looked up nodes.
+ * @since 3.0
+ */
public Map<Fqn, NodeSPI> getLookedUpNodes()
{
+ if (transactionContext != null) return transactionContext.getLookedUpNodes();
return lookedUpNodes;
}
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java 2008-06-25 18:27:24 UTC (rev 6043)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java 2008-06-25 18:28:12 UTC (rev 6044)
@@ -425,27 +425,67 @@
return localModifications != null && !localModifications.isEmpty();
}
+ /**
+ * Retrieves a node from the registry of looked up nodes in the current scope.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#lookUpNode(org.jboss.cache.Fqn)}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ *
+ * @param fqn fqn to look up
+ * @return a node, or null if it cannot be found.
+ * @since 3.0.
+ */
public NodeSPI lookUpNode(Fqn fqn)
{
return lookedUpNodes.get(fqn);
}
+ /**
+ * Puts an entry in the registry of looked up nodes in the current scope.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#putLookedUpNode(org.jboss.cache.Fqn, org.jboss.cache.NodeSPI)}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ *
+ * @param f fqn to add
+ * @param n node to add
+ * @since 3.0.
+ */
public void putLookedUpNode(Fqn f, NodeSPI n)
{
lookedUpNodes.put(f, n);
}
+ /**
+ * Clears the registry of looked up nodes.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#clearLookedUpNodes()}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ *
+ * @since 3.0.
+ */
public void clearLookedUpNodes()
{
lookedUpNodes.clear();
}
+ /**
+ * Retrieves a map of nodes looked up within the current invocation's scope.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#getLookedUpNodes()}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ *
+ * @return a map of looked up nodes.
+ * @since 3.0
+ */
public Map<Fqn, NodeSPI> getLookedUpNodes()
{
return lookedUpNodes;
}
-
/**
* Cleans up internal state
*/
16 years, 6 months
JBoss Cache SVN: r6043 - core/trunk/src/main/java/org/jboss/cache/optimistic.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-25 14:27:24 -0400 (Wed, 25 Jun 2008)
New Revision: 6043
Modified:
core/trunk/src/main/java/org/jboss/cache/optimistic/DefaultDataVersion.java
Log:
Should be marked as immutable
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/DefaultDataVersion.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/DefaultDataVersion.java 2008-06-25 17:04:10 UTC (rev 6042)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/DefaultDataVersion.java 2008-06-25 18:27:24 UTC (rev 6043)
@@ -6,6 +6,8 @@
*/
package org.jboss.cache.optimistic;
+import net.jcip.annotations.Immutable;
+
/**
* The default implementation of a DataVersion, uses a <code>long</code> to
* compare versions.
@@ -17,6 +19,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
+@Immutable
public class DefaultDataVersion implements DataVersion
{
private static final long serialVersionUID = -6896315742831861046L;
16 years, 6 months
JBoss Cache SVN: r6042 - in core/trunk/src: main/java/org/jboss/cache and 19 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-06-25 13:04:10 -0400 (Wed, 25 Jun 2008)
New Revision: 6042
Added:
core/trunk/src/main/etc/META-INF/config2to3.xslt
core/trunk/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/BuddyElementParserTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/JGroupsStackParserTest.java
Removed:
core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/MissingPolicyException.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java
core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/CacheLoadersElementParserTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java
core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java
core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java
core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java
core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java
core/trunk/src/test/java/org/jboss/cache/mgmt/PassivationTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java
core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml
core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml
core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml
Log:
porting existing code to use the new XML parser
Added: core/trunk/src/main/etc/META-INF/config2to3.xslt
===================================================================
--- core/trunk/src/main/etc/META-INF/config2to3.xslt (rev 0)
+++ core/trunk/src/main/etc/META-INF/config2to3.xslt 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,420 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <xsl:element name="jbosscache">
+ <xsl:call-template name="locking"/>
+ <xsl:call-template name="transaction"/>
+ <xsl:call-template name="serialization"/>
+ <xsl:call-template name="startup"/>
+ <xsl:call-template name="transport"/>
+ <xsl:apply-templates select="//attribute"/>
+ <!--<xsl:call-template name="invalidation"/> -->
+ </xsl:element>
+ </xsl:template>
+
+ <xsl:template match="//attribute"/>
+
+ <xsl:template name="locking">
+ <xsl:if
+ test="//attribute[@name='IsolationLevel'] | //attribute[@name='LockAcquisitionTimeout'] | //attribute[@name='LockParentForChildInsertRemove']">
+ <xsl:element name="locking">
+ <xsl:if test="//attribute[@name='IsolationLevel']">
+ <xsl:attribute name="isolationLevel">
+ <xsl:value-of select="normalize-space(//attribute[@name='IsolationLevel'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='LockAcquisitionTimeout']">
+ <xsl:attribute name="lockAcquisitionTimeout">
+ <xsl:value-of select="normalize-space(//attribute[@name='LockAcquisitionTimeout'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='LockParentForChildInsertRemove']">
+ <xsl:attribute name="lockParentForChildInsertRemove">
+ <xsl:value-of select="normalize-space(//attribute[@name='LockParentForChildInsertRemove'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ </xsl:element>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="transaction">
+ <xsl:if
+ test="//attribute[@name='TransactionManagerLookupClass'] | //attribute[@name='SyncRollbackPhase'] | //attribute[@name='SyncCommitPhase']">
+ <xsl:element name="transaction">
+ <xsl:if test="//attribute[@name='TransactionManagerLookupClass']">
+ <xsl:attribute name="transactionManagerLookupClass">
+ <xsl:value-of select="normalize-space(//attribute[@name='TransactionManagerLookupClass'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='SyncCommitPhase']">
+ <xsl:attribute name="syncCommitPhase">
+ <xsl:value-of select="normalize-space(//attribute[@name='SyncCommitPhase'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='SyncRollbackPhase']">
+ <xsl:attribute name="syncRollbackPhase">
+ <xsl:value-of select="normalize-space(//attribute[@name='SyncRollbackPhase'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ </xsl:element>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="serialization">
+ <xsl:if
+ test="//attribute[@name='ObjectInputStreamPoolSize'] | //attribute[@name='ObjectOutputStreamPoolSize'] | //attribute[@name='ReplicationVersion'] | //attribute[@name='MarshallerClass'] | //attribute[@name='UseLazyDeserialization'] | //attribute[@name='UseRegionBasedMarshalling']">
+ <serialization>
+ <xsl:if test="//attribute[@name='ObjectInputStreamPoolSize']">
+ <xsl:attribute name="objectInputStreamPoolSize">
+ <xsl:value-of select="normalize-space(//attribute[@name='ObjectInputStreamPoolSize'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='ObjectOutputStreamPoolSize']">
+ <xsl:attribute name="objectOutputStreamPoolSize">
+ <xsl:value-of select="normalize-space(//attribute[@name='ObjectOutputStreamPoolSize'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='ReplicationVersion']">
+ <xsl:attribute name="version">
+ <xsl:value-of select="normalize-space(//attribute[@name='ReplicationVersion'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='MarshallerClass']">
+ <xsl:attribute name="marshallerClass">
+ <xsl:value-of select="normalize-space(//attribute[@name='MarshallerClass'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='UseLazyDeserialization']">
+ <xsl:attribute name="useLazyDeserialization">
+ <xsl:value-of select="normalize-space(//attribute[@name='UseLazyDeserialization'])"/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:if test="//attribute[@name='UseRegionBasedMarshalling']">
+ <xsl:attribute name="useRegionBasedMarshalling">
+ <xsl:value-of select="normalize-space(//attribute[@name='UseRegionBasedMarshalling'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ </serialization>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="//attribute[@name='CacheMode']">
+ <xsl:if test="(normalize-space(.) = 'INVALIDATION_ASYNC') or (normalize-space(.) = 'INVALIDATION_SYNC')">
+ <invalidation>
+ <xsl:if test="(normalize-space(.) = 'INVALIDATION_ASYNC')">
+ <xsl:element name="async">
+ <xsl:call-template name="asyncAttributes"/>
+ </xsl:element>
+ </xsl:if>
+ <xsl:if test="(normalize-space(.) = 'INVALIDATION_SYNC')">
+ <xsl:element name="sync">
+ <xsl:call-template name="syncAttributes"/>
+ </xsl:element>
+ </xsl:if>
+ </invalidation>
+ </xsl:if>
+ <xsl:if test="(normalize-space(.) = 'REPL_ASYNC') or (normalize-space(.) = 'REPL_SYNC')">
+ <replication>
+ <xsl:if test="(normalize-space(.) = 'REPL_ASYNC')">
+ <xsl:element name="async">
+ <xsl:call-template name="asyncAttributes"/>
+ </xsl:element>
+ </xsl:if>
+ <xsl:if test="(normalize-space(.) = 'REPL_SYNC')">
+ <xsl:element name="sync">
+ <xsl:call-template name="syncAttributes"/>
+ </xsl:element>
+ </xsl:if>
+ <xsl:call-template name="buddy"/>
+ </replication>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="buddy">
+ <xsl:if test="//attribute[@name='BuddyReplicationConfig']">
+ <buddy>
+ <xsl:if test="//buddyReplicationEnabled">
+ <xsl:attribute name="enabled">
+ <xsl:value-of select="//buddyReplicationEnabled"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//buddyPoolName">
+ <xsl:attribute name="poolName">
+ <xsl:value-of select="//buddyPoolName"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//buddyCommunicationTimeout">
+ <xsl:attribute name="communicationTimeout">
+ <xsl:value-of select="//buddyCommunicationTimeout"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//autoDataGravitation | //dataGravitationRemoveOnFind | //dataGravitationSearchBackupTrees">
+ <dataGravitation>
+ <xsl:if test="//autoDataGravitation">
+ <xsl:attribute name="auto">
+ <xsl:value-of select="//autoDataGravitation"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//dataGravitationRemoveOnFind">
+ <xsl:attribute name="removeOnFind">
+ <xsl:value-of select="//dataGravitationRemoveOnFind"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//dataGravitationSearchBackupTrees">
+ <xsl:attribute name="searchBackupTrees">
+ <xsl:value-of select="//dataGravitationSearchBackupTrees"/>
+ </xsl:attribute>
+ </xsl:if>
+ </dataGravitation>
+ </xsl:if>
+ <xsl:if test="//buddyLocatorProperties">
+ <locator>
+ <xsl:if test="//buddyLocatorClass">
+ <xsl:attribute name="class">
+ <xsl:value-of select="//buddyLocatorClass"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//buddyLocatorProperties">
+ <properties>
+ <xsl:value-of select="//buddyLocatorProperties"/>
+ </properties>
+ </xsl:if>
+ </locator>
+ </xsl:if>
+ </buddy>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="asyncAttributes">
+ <xsl:if test="//attribute[@name='UseReplQueue']">
+ <xsl:attribute name="useReplQueue">
+ <xsl:value-of select="//attribute[@name='UseReplQueue']"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='ReplQueueInterval']">
+ <xsl:attribute name="replQueueInterval">
+ <xsl:value-of select="//attribute[@name='ReplQueueInterval']"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='ReplQueueMaxElements']">
+ <xsl:attribute name="replQueueMaxElements">
+ <xsl:value-of select="//attribute[@name='ReplQueueMaxElements']"/>
+ </xsl:attribute>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="syncAttributes">
+ <xsl:if test="//attribute[@name='SyncReplTimeout']">
+ <xsl:attribute name="replTimeout">
+ <xsl:value-of select="//attribute[@name='SyncReplTimeout']"/>
+ </xsl:attribute>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="startup">
+ <xsl:if
+ test="//attribute[@name='FetchInMemoryState'] | //attribute[@name='StateRetrievalTimeout'] | //attribute[@name='InactiveOnStartup']">
+ <xsl:element name="startup">
+ <xsl:if test="//attribute[@name='FetchInMemoryState']">
+ <xsl:attribute name="fetchInMemoryState">
+ <xsl:value-of select="normalize-space(//attribute[@name='FetchInMemoryState'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='StateRetrievalTimeout']">
+ <xsl:attribute name="stateRetrievalTimeout">
+ <xsl:value-of select="normalize-space(//attribute[@name='StateRetrievalTimeout'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='InactiveOnStartup']">
+ <xsl:attribute name="inactiveOnStartup">
+ <xsl:value-of select="normalize-space(//attribute[@name='InactiveOnStartup'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ </xsl:element>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="//attribute[@name='ShutdownHookBehavior']">
+ <shutdown>
+ <xsl:attribute name="hookBehavior">
+ <xsl:value-of select="normalize-space(.)"/>
+ </xsl:attribute>
+ </shutdown>
+ </xsl:template>
+
+ <xsl:template match="//attribute[@name='ExposeManagementStatistics']">
+ <jmxStatistics>
+ <xsl:attribute name="enabled">
+ <xsl:value-of select="normalize-space(.)"/>
+ </xsl:attribute>
+ </jmxStatistics>
+ </xsl:template>
+
+ <xsl:template match="//attribute[@name='EvictionPolicyConfig']">
+ <eviction>
+ <xsl:if test="./config/attribute[@name='wakeUpIntervalSeconds']">
+ <xsl:attribute name="wakeUpIntervalSeconds">
+ <xsl:value-of select="normalize-space(./config/attribute[@name='wakeUpIntervalSeconds'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./config/attribute[@name='policyClass'] | ./config/attribute[@name='policyClass']">
+ <defaults>
+ <xsl:if test="./config/attribute[@name='policyClass']">
+ <xsl:attribute name="policyClass">
+ <xsl:value-of select="normalize-space(./config/attribute[@name='policyClass'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./config/attribute[@name='eventQueueSize']">
+ <xsl:attribute name="eventQueueSize">
+ <xsl:value-of select="normalize-space(./config/attribute[@name='eventQueueSize'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ </defaults>
+ </xsl:if>
+ <xsl:if test="./config/region[@name='/_default_']">
+ <root>
+ <xsl:copy-of select="./config/region[@name='/_default_']/*"/>
+ </root>
+ </xsl:if>
+ <xsl:for-each select="./config/region[@name!='/_default_']">
+ <region>
+ <xsl:if test="@name">
+ <xsl:attribute name="name">
+ <xsl:value-of select="@name"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:copy-of select="./*"/>
+ </region>
+ </xsl:for-each>
+ </eviction>
+ </xsl:template>
+
+ <xsl:template match="//attribute[@name='CacheLoaderConfiguration']">
+ <loaders>
+ <xsl:if test="./config/passivation">
+ <xsl:attribute name="passivation">
+ <xsl:value-of select="./config/passivation"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./config/shared">
+ <xsl:attribute name="shared">
+ <xsl:value-of select="./config/shared"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./config/preload">
+ <preload>
+ <xsl:call-template name="preloadTokenizer">
+ <xsl:with-param name="string" select="./config/preload"/>
+ <xsl:with-param name="delimiter" select="','"/>
+ </xsl:call-template>
+ </preload>
+ </xsl:if>
+ <xsl:for-each select="./config/cacheloader">
+ <loader>
+ <xsl:if test="./class">
+ <xsl:attribute name="class">
+ <xsl:value-of select="./class"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./async">
+ <xsl:attribute name="async">
+ <xsl:value-of select="./async"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./fetchPersistentState">
+ <xsl:attribute name="fetchPersistentState">
+ <xsl:value-of select="./fetchPersistentState"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./ignoreModifications">
+ <xsl:attribute name="ignoreModifications">
+ <xsl:value-of select="./ignoreModifications"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./purgeOnStartup">
+ <xsl:attribute name="purgeOnStartup">
+ <xsl:value-of select="./purgeOnStartup"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./properties">
+ <xsl:copy-of select="./properties"/>
+ </xsl:if>
+ <xsl:if test="./singletonStore">
+ <singletonStore>
+ <xsl:if test="./singletonStore/enabled">
+ <xsl:attribute name="enabled">
+ <xsl:value-of select="./singletonStore/enabled"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./singletonStore/enabled">
+ <xsl:attribute name="enabled">
+ <xsl:value-of select="./singletonStore/enabled"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="./singletonStore/class">
+ <xsl:attribute name="class">
+ <xsl:value-of select="./singletonStore/class"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:copy-of select="./singletonStore/properties"/>
+ </singletonStore>
+ </xsl:if>
+ </loader>
+ </xsl:for-each>
+ </loaders>
+ </xsl:template>
+
+ <xsl:template name="preloadTokenizer">
+ <xsl:param name="string"/>
+ <xsl:param name="delimiter" select="' '"/>
+ <xsl:choose>
+ <xsl:when test="$delimiter and contains($string, $delimiter)">
+ <node>
+ <xsl:attribute name="fqn">
+ <xsl:value-of select="substring-before($string,$delimiter)"/>
+ </xsl:attribute>
+ </node>
+ <xsl:call-template name="preloadTokenizer">
+ <xsl:with-param name="string" select="substring-after($string,$delimiter)"/>
+ <xsl:with-param name="delimiter" select="$delimiter"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <node>
+ <xsl:attribute name="fqn">
+ <xsl:value-of select="$string"/>
+ </xsl:attribute>
+ </node>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+
+ <xsl:template name="transport">
+ <xsl:if
+ test="//attribute[@name='ClusterName'] | //attribute[@name='MultiplexerStack'] | //attribute[@name='ClusterConfig']">
+ <transport>
+ <xsl:if test="//attribute[@name='ClusterName']">
+ <xsl:attribute name="clusterName">
+ <xsl:value-of select="normalize-space(//attribute[@name='ClusterName'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='MultiplexerStack']">
+ <xsl:attribute name="multiplexerStack">
+ <xsl:value-of select="normalize-space(//attribute[@name='MultiplexerStack'])"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="//attribute[@name='ClusterConfig']">
+ <jgroupsConfig>
+ <xsl:copy-of select="//attribute[@name='ClusterConfig']/config/*"/>
+ </jgroupsConfig>
+ </xsl:if>
+ </transport>
+ </xsl:if>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -8,7 +8,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.factories.ComponentFactory;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.invocation.CacheInvocationDelegate;
@@ -62,7 +62,7 @@
public Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
{
- XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+ XmlConfigurationParser2x parser = new XmlConfigurationParser2x();
Configuration c = parser.parseFile(configFileName);
return createCache(c, start);
}
@@ -141,14 +141,14 @@
public Cache<K, V> createCache(InputStream is) throws ConfigurationException
{
- XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+ XmlConfigurationParser2x parser = new XmlConfigurationParser2x();
Configuration c = parser.parseStream(is);
return createCache(c);
}
public Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
{
- XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+ XmlConfigurationParser2x parser = new XmlConfigurationParser2x();
Configuration c = parser.parseStream(is);
return createCache(c, start);
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -7,7 +7,8 @@
package org.jboss.cache.config;
import org.jboss.cache.Version;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
+import org.jboss.cache.config.parsing.JGroupsStackParser;
import org.jboss.cache.factories.annotations.NonVolatile;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.marshall.Marshaller;
@@ -30,6 +31,7 @@
private Marshaller marshaller;
+ private JGroupsStackParser jGroupsStackParser = new JGroupsStackParser();
public void setCacheMarshaller(Marshaller instance)
{
@@ -207,7 +209,7 @@
*/
public void setClusterConfig(Element config)
{
- setClusterConfig(XmlConfigurationParserOld.parseClusterConfigXml(config));
+ setClusterConfig(jGroupsStackParser.parseClusterConfigXml(config));
}
public void setClusterName(String clusterName)
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -36,14 +36,8 @@
*/
private static final long serialVersionUID = -7979639000026975201L;
- public static final String WAKEUP_INTERVAL_SECONDS = "wakeUpIntervalSeconds";
-
public static final int WAKEUP_DEFAULT = 5;
- public static final String EVENT_QUEUE_SIZE = "eventQueueSize";
-
- public static final String EVICTION_POLICY_CLASS = "policyClass";
-
public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000;
private String defaultEvictionPolicyClass;
@@ -132,7 +126,7 @@
{
if (evictionRegionConfigs == null)
{
- return new ArrayList<EvictionRegionConfig>(1);
+ evictionRegionConfigs = new ArrayList<EvictionRegionConfig>(1);
}
return evictionRegionConfigs;
}
@@ -174,6 +168,7 @@
{
testImmutability("WakeupInterval");
this.wakeupInterval = wakeupInterval;
+ this.wakeupIntervalSeconds = (int)wakeupInterval/1000;
}
/**
@@ -193,7 +188,7 @@
{
testImmutability("wakeupIntervalSeconds");
this.wakeupIntervalSeconds = wakeupIntervalSeconds;
- setWakeupInterval(wakeupIntervalSeconds * 1000);
+ this.wakeupInterval = wakeupIntervalSeconds * 1000;
}
public boolean equals(Object o)
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -36,8 +36,6 @@
public static final String NAME = "name";
public static final String REGION = "region";
- public static final String REGION_POLICY_CLASS = "policyClass";
- public static final String EVENT_QUEUE_SIZE = "eventQueueSize";
private Fqn regionFqn;
@Dynamic
@@ -131,7 +129,10 @@
if (obj instanceof EvictionRegionConfig)
{
EvictionRegionConfig other = (EvictionRegionConfig) obj;
- return Util.safeEquals(this.regionFqn, other.regionFqn);
+ boolean equalRegions = Util.safeEquals(this.regionFqn, other.regionFqn);
+ boolean equalConfigurations = Util.safeEquals(this.evictionPolicyConfig, other.evictionPolicyConfig);
+ boolean equalEventQueuSizes = this.getEventQueueSize() == other.getEventQueueSize();
+ return equalRegions && equalConfigurations && equalConfigurations;
}
return false;
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/MissingPolicyException.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/MissingPolicyException.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/MissingPolicyException.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -21,7 +21,7 @@
*/
package org.jboss.cache.config;
-public class MissingPolicyException extends RuntimeException
+public class MissingPolicyException extends ConfigurationException
{
/** The serialVersionUID */
Deleted: core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -1,56 +0,0 @@
-package org.jboss.cache.config.parsing;
-
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.w3c.dom.Element;
-
-import java.util.Properties;
-
-/**
- * Utility class for parsing 'buddyReplication' element in the .xml configuration file.
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 3.0
- */
-public class BuddyReplicationElementParser extends XmlParserBase
-{
- public BuddyReplicationConfig parseBuddyReplicationElement(Element element)
- {
- BuddyReplicationConfig brc = new BuddyReplicationConfig();
- String enabled = element.getAttribute("enabled");
- if (existsAttribute(enabled)) brc.setEnabled(getBoolean(enabled));
- String buddyPoolName = element.getAttribute("buddyPoolName");
- if (existsAttribute(buddyPoolName)) brc.setBuddyPoolName(buddyPoolName);
- String buddyCommunicationTimeout = element.getAttribute("buddyCommunicationTimeout");
- if (existsAttribute(buddyCommunicationTimeout))
- brc.setBuddyCommunicationTimeout(getInt(buddyCommunicationTimeout));
-
- parseDataGravitationElement(getSingleElement("dataGravitation", element), brc);
- BuddyReplicationConfig.BuddyLocatorConfig blc = parseBuddyLocatorConfig(getSingleElement("buddyLocator", element));
- brc.setBuddyLocatorConfig(blc);
- return brc;
- }
-
- private BuddyReplicationConfig.BuddyLocatorConfig parseBuddyLocatorConfig(Element element)
- {
- if (element == null) return null;
- BuddyReplicationConfig.BuddyLocatorConfig result = new BuddyReplicationConfig.BuddyLocatorConfig();
- String buddyLocatorClass = element.getAttribute("class");
- if (existsAttribute(buddyLocatorClass)) result.setBuddyLocatorClass(buddyLocatorClass);
- Properties props = null;
- props = XmlConfigHelper.readPropertiesContents(element, "properties");
- result.setBuddyLocatorClass(buddyLocatorClass);
- result.setBuddyLocatorProperties(props);
- return result;
- }
-
- private void parseDataGravitationElement(Element element, BuddyReplicationConfig brc)
- {
- if (element == null) return;
- String auto = element.getAttribute("auto");
- if (existsAttribute(auto)) brc.setAutoDataGravitation(getBoolean(auto));
- String removeOnFind = element.getAttribute("removeOnFind");
- if (existsAttribute(removeOnFind)) brc.setDataGravitationRemoveOnFind(getBoolean(removeOnFind));
- String searchBackupTrees = element.getAttribute("searchBackupTrees");
- if (existsAttribute(searchBackupTrees)) brc.setDataGravitationSearchBackupTrees(getBoolean(searchBackupTrees));
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -73,7 +73,7 @@
private static final Log log = LogFactory.getLog(CacheConfigsXmlParser.class);
- private final XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+ private final XmlConfigurationParser2x parser = new XmlConfigurationParser2x();
public Map<String, Configuration> parseConfigs(String fileName) throws CloneNotSupportedException
{
Deleted: core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -1,108 +0,0 @@
-package org.jboss.cache.config.parsing;
-
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.ConfigurationException;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.util.Properties;
-
-/**
- * Utility class for parsing the 'caceheloaders' element in the .xml configuration file.
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 3.0
- */
-public class CacheLoadersElementParser extends XmlParserBase
-{
-
- public CacheLoaderConfig parseCacheLoadersElement(Element element)
- {
- CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
- String passivation = element.getAttribute("passivation");
- if (existsAttribute(passivation)) cacheLoaderConfig.setPassivation(getBoolean(passivation));
- String shared = element.getAttribute("shared");
- if (existsAttribute(shared)) cacheLoaderConfig.setShared(getBoolean(shared));
- String preload = getPreloadString(getSingleElement("preload", element));
- if (preload != null) cacheLoaderConfig.setPreload(preload);
-
- NodeList cacheLoaderNodes = element.getElementsByTagName("cacheLoader");
- for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
- {
- Element indivElement = (Element) cacheLoaderNodes.item(i);
- CacheLoaderConfig.IndividualCacheLoaderConfig iclc = parseIndividualCacheLoaderConfig(indivElement);
- cacheLoaderConfig.addIndividualCacheLoaderConfig(iclc);
- }
-
- return cacheLoaderConfig;
- }
-
- private CacheLoaderConfig.IndividualCacheLoaderConfig parseIndividualCacheLoaderConfig(Element indivElement)
- {
- CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
-
- String async = indivElement.getAttribute("async");
- if (existsAttribute(async)) iclc.setAsync(getBoolean(async));
- String fetchPersistentState = indivElement.getAttribute("fetchPersistentState");
- if (existsAttribute(fetchPersistentState)) iclc.setFetchPersistentState(getBoolean(fetchPersistentState));
- String ignoreModifications = indivElement.getAttribute("ignoreModifications");
- if (existsAttribute(ignoreModifications)) iclc.setIgnoreModifications(getBoolean(ignoreModifications));
- String purgeOnStartup = indivElement.getAttribute("purgeOnStartup");
- if (existsAttribute(purgeOnStartup)) iclc.setPurgeOnStartup(getBoolean(purgeOnStartup));
- String clClass = indivElement.getAttribute("class");
- if (!existsAttribute(clClass)) throw new ConfigurationException("Missing 'class' attribute for cache loader configuration");
- iclc.setClassName(clClass);
- iclc.setProperties(XmlConfigHelper.readPropertiesContents(indivElement, "properties"));
- CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = parseSingletonStoreConfig(indivElement);
- if (ssc != null)
- {
- iclc.setSingletonStoreConfig(ssc);
- }
- return iclc;
- }
-
- private String getPreloadString(Element preloadElement)
- {
- if (preloadElement == null) return null; //might be no preload
- NodeList nodesToPreload = preloadElement.getElementsByTagName("node");
- StringBuffer result = new StringBuffer();
- for (int i = 0; i < nodesToPreload.getLength(); i++)
- {
- Element node = (Element) nodesToPreload.item(i);
- String fqn2preload = node.getAttribute("fqn");
- if (!existsAttribute(fqn2preload)) throw new ConfigurationException("Missing 'fqn' attribute in 'preload\\norde' tag");
- if (i > 0) result.append(",");
- result.append(fqn2preload);
- }
- //no elements defined for preload so by default load the root
- if (nodesToPreload.getLength() == 0)
- {
- result.append("");
- }
- return result.toString();
- }
-
- static CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig parseSingletonStoreConfig(Element cacheLoaderelement)
- {
- /* singletonStore element can only appear once in a cacheloader, so we just take the first one ignoring any
- subsequent definitions in cacheloader element*/
- Node singletonStoreNode = cacheLoaderelement.getElementsByTagName("singletonStore").item(0);
- if (singletonStoreNode != null && singletonStoreNode.getNodeType() == Node.ELEMENT_NODE)
- {
- Element singletonStoreElement = (Element) singletonStoreNode;
- boolean singletonStoreEnabled = XmlConfigHelper.readBooleanContents(singletonStoreElement, "enabled");
- String singletonStoreClass = XmlConfigHelper.readStringContents(singletonStoreElement, "class");
- Properties singletonStoreproperties;
- singletonStoreproperties = XmlConfigHelper.readPropertiesContents(singletonStoreElement, "properties");
- CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = new CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig();
- ssc.setSingletonStoreEnabled(singletonStoreEnabled);
- ssc.setSingletonStoreClass(singletonStoreClass);
- ssc.setSingletonStoreproperties(singletonStoreproperties);
-
- return ssc;
- }
-
- return null;
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,53 @@
+package org.jboss.cache.config.parsing;
+
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.File;
+
+/**
+ * Class used for converting a config file from from 2.x version to 3.x verison.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class ConfigFilesConvertor
+{
+ static Document document;
+
+
+ public static void main(String[] argv) throws Exception
+ {
+ if (argv.length != 2)
+ {
+ System.err.println("Usage: java Stylizer stylesheet xmlfile");
+ System.exit(1);
+ }
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+ //factory.setNamespaceAware(true);
+ //factory.setValidating(true);
+ File stylesheet = new File(argv[0]);
+ File datafile = new File(argv[1]);
+
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ document = builder.parse(datafile);
+
+ // Use a Transformer for output
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ StreamSource stylesource = new StreamSource(stylesheet);
+ Transformer transformer = tFactory.newTransformer(stylesource);
+
+ DOMSource source = new DOMSource(document);
+ StreamResult result = new StreamResult(System.out);
+ transformer.transform(source, result);
+ }
+}
\ No newline at end of file
Deleted: core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -1,110 +0,0 @@
-package org.jboss.cache.config.parsing;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.util.Util;
-import org.jboss.cache.RegionManager;
-
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * Knows how to parse the <b>eviction</b> element uder a parser.
- *
- * @author Mircea.Markus(a)jboss.com
- * @since 3.0
- */
-public class EvictionElementParser extends XmlParserBase
-{
- public EvictionConfig getEvictionConfig(Element evictionElement)
- {
- EvictionConfig evictionConfig = new EvictionConfig();
- String wakeUpInterval = evictionElement.getAttribute("wakeUpInterval");
- if (existsAttribute(wakeUpInterval)) evictionConfig.setWakeupInterval(getInt(wakeUpInterval));
- String defaultPolicyClass = evictionElement.getAttribute("defaultPolicyClass");
- if (existsAttribute(defaultPolicyClass)) evictionConfig.setDefaultEvictionPolicyClass(defaultPolicyClass);
- String defaultEventQueueSize = evictionElement.getAttribute("defaultEventQueueSize");
- if (existsAttribute(defaultEventQueueSize)) evictionConfig.setDefaultEventQueueSize(getInt(defaultEventQueueSize));
- List<EvictionRegionConfig> evictionRegionConfigs = new ArrayList<EvictionRegionConfig>(3);
- Element defaultRegion = getSingleElement("default", evictionElement);
- if (defaultRegion != null)
- {
- EvictionRegionConfig erc = getEvictionRegionConfig(defaultRegion, defaultPolicyClass, getInt(defaultEventQueueSize));
- erc.setRegionName(RegionManager.DEFAULT_REGION.toString());
- evictionRegionConfigs.add(erc);
- }
- NodeList regions = evictionElement.getElementsByTagName("region");
- for (int i = 0; i < regions.getLength(); i++)
- {
- Element regionConfig = (Element) regions.item(i);
- EvictionRegionConfig erc = getEvictionRegionConfig(regionConfig, defaultPolicyClass, getInt(defaultEventQueueSize));
- evictionRegionConfigs.add(erc);
- }
- evictionConfig.setEvictionRegionConfigs(evictionRegionConfigs);
- return evictionConfig;
- }
-
- private EvictionRegionConfig getEvictionRegionConfig(Element element, String defaultPolicyClass, int defaultEventQueueSize)
- {
- EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionName(element.getAttribute("name"));
- String queueSize = element.getAttribute("eventQueueSize");
- if (existsAttribute(queueSize))
- {
- erc.setEventQueueSize(getInt(queueSize));
- }
- else
- {
- erc.setEventQueueSize(defaultEventQueueSize);
- }
- String policyClass = element.getAttribute("policyClass");
- if (!existsAttribute(policyClass))
- {
- if (defaultPolicyClass == null)
- {
- throw new MissingPolicyException("There is no Eviction Policy Class specified on the region or for the entire cache!");
- }
- else
- {
- policyClass = defaultPolicyClass;
- }
- }
- EvictionPolicy policy;
- try
- {
- policy = (EvictionPolicy) Util.loadClass(policyClass).newInstance();
- }
- catch (Exception e)
- {
- throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
- }
-
- EvictionPolicyConfig epc;
- try
- {
- epc = policy.getEvictionConfigurationClass().newInstance();
- }
- catch (Exception e)
- {
- throw new RuntimeException("Failed to instantiate eviction configuration of class " +
- policy.getEvictionConfigurationClass(), e);
- }
- parseEvictionPolicyConfig(element, epc);
- erc.setEvictionPolicyConfig(epc);
- return erc;
- }
-
- public static void parseEvictionPolicyConfig(Element element, EvictionPolicyConfig target)
- {
- target.reset();
- ParsedAttributes attributes = XmlConfigHelper.extractAttributes(element);
- XmlConfigHelper.setValues(target, attributes.stringAttribs, false);
- XmlConfigHelper.setValues(target, attributes.xmlAttribs, true);
- target.validate();
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -14,14 +14,12 @@
*/
public class JGroupsStackParser
{
-
- //todo - further refine in smaller methods and make not-static
/**
* Parses the cluster config which is used to start a JGroups channel
*
* @param config an old-style JGroups protocol config String
*/
- public static String parseClusterConfigXml(Element config)
+ public String parseClusterConfigXml(Element config)
{
StringBuffer buffer = new StringBuffer();
NodeList stack = config.getChildNodes();
@@ -38,33 +36,43 @@
Element tag = (Element) node;
String protocol = tag.getTagName();
buffer.append(protocol);
- NamedNodeMap attrs = tag.getAttributes();
- int attrLength = attrs.getLength();
- if (attrLength > 0)
- {
- buffer.append('(');
- }
- for (int a = 0; a < attrLength; a++)
- {
- Attr attr = (Attr) attrs.item(a);
- String name = attr.getName();
- String value = attr.getValue();
- buffer.append(name);
- buffer.append('=');
- buffer.append(value);
- if (a < attrLength - 1)
- {
- buffer.append(';');
- }
- }
- if (attrLength > 0)
- {
- buffer.append(')');
- }
+ processAttributes(buffer, tag);
buffer.append(':');
}
// Remove the trailing ':'
buffer.setLength(buffer.length() - 1);
return buffer.toString();
}
+
+ private void processAttributes(StringBuffer buffer, Element tag)
+ {
+ NamedNodeMap attrs = tag.getAttributes();
+ int attrLength = attrs.getLength();
+ if (attrLength > 0)
+ {
+ buffer.append('(');
+ }
+ for (int a = 0; a < attrLength; a++)
+ {
+ Attr attr = (Attr) attrs.item(a);
+ processSingleAttribute(buffer, attr);
+ if (a < attrLength - 1)
+ {
+ buffer.append(';');
+ }
+ }
+ if (attrLength > 0)
+ {
+ buffer.append(')');
+ }
+ }
+
+ private void processSingleAttribute(StringBuffer buffer, Attr attr)
+ {
+ String name = attr.getName();
+ String value = attr.getValue();
+ buffer.append(name);
+ buffer.append('=');
+ buffer.append(value);
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -3,6 +3,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.*;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.lock.IsolationLevel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -79,8 +82,7 @@
configureShutdown(getSingleElement("shutdown"));
configureJmxStatistics(getSingleElement("jmxStatistics"));
configureEviction(getSingleElement("eviction"));
- configureCacheLoaders(getSingleElement("cacheLoaders"));
- configureBuddyReplication(getSingleElement("buddyReplication"));
+ configureCacheLoaders(getSingleElement("loaders"));
configureCustomInterceptors(getSingleElement("customInterceptors"));
return config;
}
@@ -144,16 +146,16 @@
private void configureBuddyReplication(Element element)
{
if (element == null) return;//buddy config might not exist, expect that
- BuddyReplicationElementParser buddyElementParser = new BuddyReplicationElementParser();
- BuddyReplicationConfig brConfig = buddyElementParser.parseBuddyReplicationElement(element);
+ BuddyElementParser buddyElementParser = new BuddyElementParser();
+ BuddyReplicationConfig brConfig = buddyElementParser.parseBuddyElement(element);
config.setBuddyReplicationConfig(brConfig);
}
private void configureCacheLoaders(Element element)
{
if (element == null) return; //null cache loaders are allowed
- CacheLoadersElementParser clElementParser = new CacheLoadersElementParser();
- CacheLoaderConfig cacheLoaderConfig = clElementParser.parseCacheLoadersElement(element);
+ LoadersElementParser clElementParser = new LoadersElementParser();
+ CacheLoaderConfig cacheLoaderConfig = clElementParser.parseLoadersElement(element);
config.setCacheLoaderConfig(cacheLoaderConfig);
}
@@ -161,10 +163,9 @@
{
if (evictionElement == null) return; //no eviction might be configured
EvictionElementParser evictionElementParser = new EvictionElementParser();
- config.setEvictionConfig(evictionElementParser.getEvictionConfig(evictionElement));
+ config.setEvictionConfig(evictionElementParser.parseEvictionElement(evictionElement));
}
-
private void configureJmxStatistics(Element element)
{
if (element == null) return; //might not be specified
@@ -183,15 +184,13 @@
{
String clusterName = element.getAttribute("clusterName");
config.setClusterName(clusterName);
- Element multiplexer = getSingleElement("multiplexer", element);
- if (multiplexer != null)
- {
- config.setMultiplexerStack(multiplexer.getAttribute("stack"));
- }
+ String multiplexerStack = element.getAttribute("multiplexerStack");
+ if (existsAttribute(multiplexerStack)) config.setMultiplexerStack(multiplexerStack);
Element clusterConfig = getSingleElement("jgroupsConfig", element);
if (clusterConfig != null)
{
- String clusterConfigStr = JGroupsStackParser.parseClusterConfigXml(clusterConfig);
+ JGroupsStackParser stackParser = new JGroupsStackParser();
+ String clusterConfigStr = stackParser.parseClusterConfigXml(clusterConfig);
config.setClusterConfig(clusterConfigStr);
}
}
@@ -239,6 +238,7 @@
config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
configureSyncMode(getSingleElement("sync", element));
}
+ configureBuddyReplication(getSingleElement("buddy", element));
}
private void configureSyncMode(Element element)
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java (from rev 5995, core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,560 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.config.parsing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.MissingPolicyException;
+import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.util.Util;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+/**
+ * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object. When deployed as a
+ * JBoss MBean, this role is performed by the JBoss Microcontainer. This class is only used internally in unit tests
+ * or within {@link org.jboss.cache.CacheFactory} implementations for standalone JBoss Cache usage.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
+ * @since 2.00.
+ * @deprecated
+ */
+public class XmlConfigurationParser2x
+{
+ private static final Log log = LogFactory.getLog(XmlConfigurationParser2x.class);
+
+ public static final String ATTR = "attribute";
+ public static final String NAME = "name";
+
+ /**
+ * Parses an XML file and returns a new configuration. This method attempts to look for the file name passed in on
+ * the classpath. If not found, it will search for the file on the file system instead, treating the name as an
+ * absolute path.
+ *
+ * @param filename the name of the XML file to parse.
+ * @return a configured Configuration object representing the configuration in the file
+ */
+ public Configuration parseFile(String filename)
+ {
+ InputStream is = getAsInputStreamFromClassLoader(filename);
+ if (is == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Unable to find configuration file " + filename + " in classpath; searching for this file on the filesystem instead.");
+ try
+ {
+ is = new FileInputStream(filename);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!", e);
+ }
+ }
+
+ return parseStream(is);
+ }
+
+ /**
+ * Parses an input stream containing XML text and returns a new configuration.
+ *
+ * @param stream input stream to parse. SHould not be null.
+ * @return a configured Configuration object representing the configuration in the stream
+ * @since 2.1.0
+ */
+ public Configuration parseStream(InputStream stream)
+ {
+ // loop through all elements in XML.
+ Element root = XmlConfigHelper.getDocumentRoot(stream);
+ Element mbeanElement = getMBeanElement(root);
+
+ return parseConfiguration(mbeanElement);
+ }
+
+ public Configuration parseConfiguration(Element configurationRoot)
+ {
+ ParsedAttributes attributes = XmlConfigHelper.extractAttributes(configurationRoot);
+
+ // Deal with legacy attributes we no longer support
+ handleRemovedAttributes(attributes);
+
+ // Deal with legacy attributes that we renamed or otherwise altered
+ handleRenamedAttributes(attributes);
+
+ Configuration c = new Configuration();
+ XmlConfigHelper.setValues(c, attributes.stringAttribs, false);
+ // Special handling for XML elements -- we hard code the parsing
+ setXmlValues(c, attributes.xmlAttribs);
+
+ return c;
+ }
+
+ /**
+ * Check for and remove any attributes that were supported in the
+ * 1.x releases and no longer are. Log a WARN or throw a
+ * {@link ConfigurationException} if any are found. Which is done depends
+ * on the attribute:
+ * <p/>
+ * <ul>
+ * <li><i>MultiplexerService</i> -- throws an Exception</li>
+ * <li><i>ServiceName</i> -- logs a WARN</li>
+ * </ul>
+ *
+ * @param attributes
+ */
+ protected void handleRemovedAttributes(ParsedAttributes attributes)
+ {
+ String evictionPolicy = attributes.stringAttribs.remove("EvictionPolicyClass");
+ if (evictionPolicy != null)
+ {
+ throw new ConfigurationException("XmlConfigurationParser does not " +
+ "support the JBC 1.x attribute EvictionPolicyClass. Set the default " +
+ "eviction policy via the policyClass element in the EvictionConfig section");
+ }
+ String multiplexerService = attributes.stringAttribs.remove("MultiplexerService");
+ if (multiplexerService != null)
+ {
+ throw new ConfigurationException("XmlConfigurationParser does not " +
+ "support the JBC 1.x attribute MultiplexerService. Inject the " +
+ "multiplexer directly using Configuration.getRuntimeConfig().setMuxChannelFactory()");
+ }
+ String serviceName = attributes.stringAttribs.remove("ServiceName");
+ if (serviceName != null)
+ {
+ log.warn("XmlConfigurationParser does not support the deprecated " +
+ "attribute ServiceName. If JMX registration is needed, " +
+ "register a CacheJmxWrapper or PojoCacheJmxWrapper in " +
+ "JMX with the desired name");
+ }
+ }
+
+ /**
+ * Check for any attributes that were supported in the
+ * 1.x releases but whose name has changed. Log a WARN if any are found, but
+ * convert the attribute to the new name.
+ * <p/>
+ * <ul>
+ * <li><i>UseMbean</i> becomes <i>ExposeManagementStatistics</i></li>
+ * </ul>
+ *
+ * @param attributes
+ */
+ private void handleRenamedAttributes(ParsedAttributes attributes)
+ {
+ String keepStats = attributes.stringAttribs.remove("UseInterceptorMbeans");
+ if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
+ {
+ log.warn("Found non-existent JBC 1.x attribute 'UseInterceptorMbeans' and replaced " +
+ "with 'ExposeManagementStatistics'. Please update your config " +
+ "to use the new attribute name");
+ attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
+ }
+ Element clc = attributes.xmlAttribs.remove("CacheLoaderConfiguration");
+ if (clc != null && attributes.xmlAttribs.get("CacheLoaderConfig") == null)
+ {
+ log.warn("Found non-existent JBC 1.x attribute 'CacheLoaderConfiguration' and replaced " +
+ "with 'CacheLoaderConfig'. Please update your config " +
+ "to use the new attribute name");
+ attributes.xmlAttribs.put("CacheLoaderConfig", clc);
+ }
+ }
+
+ protected InputStream getAsInputStreamFromClassLoader(String filename)
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ InputStream is = cl == null ? null : cl.getResourceAsStream(filename);
+ if (is == null)
+ {
+ // check system class loader
+ is = getClass().getClassLoader().getResourceAsStream(filename);
+ }
+ return is;
+ }
+
+ protected Element getMBeanElement(Element root)
+ {
+ // This is following JBoss convention.
+ NodeList list = root.getElementsByTagName(XmlConfigHelper.ROOT);
+ if (list == null) throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " tag");
+
+ if (list.getLength() > 1) throw new ConfigurationException("Has multiple " + XmlConfigHelper.ROOT + " tag");
+
+ Node node = list.item(0);
+ Element element;
+ if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
+ {
+ element = (Element) node;
+ }
+ else
+ {
+ throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " element");
+ }
+ return element;
+ }
+
+ protected void setXmlValues(Configuration conf, Map<String, Element> attribs)
+ {
+ for (Entry<String, Element> entry : attribs.entrySet())
+ {
+ String propname = entry.getKey();
+ if ("BuddyReplicationConfiguration".equals(propname)
+ || "BuddyReplicationConfig".equals(propname))
+ {
+ BuddyReplicationConfig brc = parseBuddyReplicationConfig(entry.getValue());
+ conf.setBuddyReplicationConfig(brc);
+ }
+ else if ("CacheLoaderConfiguration".equals(propname)
+ || "CacheLoaderConfig".equals(propname))
+ {
+ CacheLoaderConfig clc = parseCacheLoaderConfig(entry.getValue());
+ conf.setCacheLoaderConfig(clc);
+ }
+ else if ("EvictionPolicyConfiguration".equals(propname)
+ || "EvictionPolicyConfig".equals(propname))
+ {
+ EvictionConfig ec = parseEvictionConfig(entry.getValue());
+ conf.setEvictionConfig(ec);
+ }
+ else if ("ClusterConfig".equals(propname))
+ {
+ String jgc = parseClusterConfigXml(entry.getValue());
+ conf.setClusterConfig(jgc);
+ }
+ else
+ {
+ throw new ConfigurationException("Unknown configuration element " + propname);
+ }
+ }
+ }
+
+ private static BuddyReplicationConfig parseBuddyReplicationConfig(Element element)
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setEnabled(XmlConfigHelper.readBooleanContents(element, "buddyReplicationEnabled"));
+ brc.setDataGravitationRemoveOnFind(XmlConfigHelper.readBooleanContents(element, "dataGravitationRemoveOnFind", true));
+ brc.setDataGravitationSearchBackupTrees(XmlConfigHelper.readBooleanContents(element, "dataGravitationSearchBackupTrees", true));
+ brc.setAutoDataGravitation(brc.isEnabled() && XmlConfigHelper.readBooleanContents(element, "autoDataGravitation", false));
+
+ String strBuddyCommunicationTimeout = XmlConfigHelper.readStringContents(element, "buddyCommunicationTimeout");
+ try
+ {
+ brc.setBuddyCommunicationTimeout(Integer.parseInt(strBuddyCommunicationTimeout));
+ }
+ catch (Exception e)
+ {
+ }
+ finally
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Using buddy communication timeout of " + brc.getBuddyCommunicationTimeout() + " millis");
+ }
+ }
+ String buddyPoolName = XmlConfigHelper.readStringContents(element, "buddyPoolName");
+ if ("".equals(buddyPoolName))
+ {
+ buddyPoolName = null;
+ }
+
+ brc.setBuddyPoolName(buddyPoolName);
+
+ // now read the buddy locator details
+
+ String buddyLocatorClass = XmlConfigHelper.readStringContents(element, "buddyLocatorClass");
+ if (buddyLocatorClass == null || buddyLocatorClass.length() == 0)
+ {
+ buddyLocatorClass = NextMemberBuddyLocator.class.getName();
+ }
+ Properties props = null;
+ props = XmlConfigHelper.readPropertiesContents(element, "buddyLocatorProperties");
+ BuddyLocatorConfig blc = new BuddyLocatorConfig();
+ blc.setBuddyLocatorClass(buddyLocatorClass);
+ blc.setBuddyLocatorProperties(props);
+ brc.setBuddyLocatorConfig(blc);
+
+ return brc;
+ }
+
+ private static CacheLoaderConfig parseCacheLoaderConfig(Element element)
+ {
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ clc.setPassivation(XmlConfigHelper.readBooleanContents(element, "passivation"));
+ String s = XmlConfigHelper.readStringContents(element, "preload");
+ if (s != null && s.length() > 0) clc.setPreload(s);
+ clc.setShared(XmlConfigHelper.readBooleanContents(element, "shared"));
+
+ NodeList cacheLoaderNodes = element.getElementsByTagName("cacheloader");
+ for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
+ {
+ Node node = cacheLoaderNodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element indivElement = (Element) node;
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
+ iclc.setAsync(XmlConfigHelper.readBooleanContents(indivElement, "async", false));
+ iclc.setIgnoreModifications(XmlConfigHelper.readBooleanContents(indivElement, "ignoreModifications", false));
+ iclc.setFetchPersistentState(XmlConfigHelper.readBooleanContents(indivElement, "fetchPersistentState", false));
+ iclc.setPurgeOnStartup(XmlConfigHelper.readBooleanContents(indivElement, "purgeOnStartup", false));
+ iclc.setClassName(XmlConfigHelper.readStringContents(indivElement, "class"));
+ iclc.setProperties(XmlConfigHelper.readPropertiesContents(indivElement, "properties"));
+
+ SingletonStoreConfig ssc = parseSingletonStoreConfig(indivElement);
+ if (ssc != null)
+ {
+ iclc.setSingletonStoreConfig(ssc);
+ }
+
+ clc.addIndividualCacheLoaderConfig(iclc);
+ }
+ }
+ return clc;
+ }
+
+ private static CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig parseSingletonStoreConfig(Element cacheLoaderelement)
+ {
+ /* singletonStore element can only appear once in a cacheloader, so we just take the first one ignoring any
+ subsequent definitions in cacheloader element*/
+ Node singletonStoreNode = cacheLoaderelement.getElementsByTagName("singletonStore").item(0);
+ if (singletonStoreNode != null && singletonStoreNode.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element singletonStoreElement = (Element) singletonStoreNode;
+ boolean singletonStoreEnabled = XmlConfigHelper.readBooleanContents(singletonStoreElement, "enabled");
+ String singletonStoreClass = XmlConfigHelper.readStringContents(singletonStoreElement, "class");
+ Properties singletonStoreproperties;
+ singletonStoreproperties = XmlConfigHelper.readPropertiesContents(singletonStoreElement, "properties");
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = new CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig();
+ ssc.setSingletonStoreEnabled(singletonStoreEnabled);
+ ssc.setSingletonStoreClass(singletonStoreClass);
+ ssc.setSingletonStoreproperties(singletonStoreproperties);
+
+ return ssc;
+ }
+
+ return null;
+ }
+
+
+ private static EvictionConfig parseEvictionConfig(Element element)
+ {
+ EvictionConfig ec = new EvictionConfig();
+
+ if (element != null)
+ {
+ // If they set the default eviction policy in the element, use that
+ // in preference to the external attribute
+ String temp = XmlConfigHelper.getTagContents(element,
+ "policyClass", ATTR, NAME);
+ if (temp != null && temp.length() > 0)
+ {
+ ec.setDefaultEvictionPolicyClass(temp);
+ }
+
+ temp = XmlConfigHelper.getTagContents(element,
+ "wakeUpIntervalSeconds", ATTR, NAME);
+
+ int wakeupIntervalSeconds = 0;
+ if (temp != null)
+ {
+ wakeupIntervalSeconds = Integer.parseInt(temp);
+ }
+
+ if (wakeupIntervalSeconds <= 0)
+ {
+ wakeupIntervalSeconds = EvictionConfig.WAKEUP_DEFAULT;
+ }
+
+ ec.setWakeupIntervalSeconds(wakeupIntervalSeconds);
+
+ int eventQueueSize = 0;
+ temp = XmlConfigHelper.getTagContents(element,
+ "eventQueueSize", ATTR, NAME);
+
+ if (temp != null)
+ {
+ eventQueueSize = Integer.parseInt(temp);
+ }
+
+ if (eventQueueSize <= 0)
+ {
+ eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ }
+
+ ec.setDefaultEventQueueSize(eventQueueSize);
+
+ NodeList list = element.getElementsByTagName(EvictionRegionConfig.REGION);
+ if (list != null && list.getLength() > 0)
+ {
+ List regionConfigs = new ArrayList(list.getLength());
+ for (int i = 0; i < list.getLength(); i++)
+ {
+ org.w3c.dom.Node node = list.item(i);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+ try
+ {
+ regionConfigs.add(parseEvictionRegionConfig((Element) node, ec.getDefaultEvictionPolicyClass(), eventQueueSize));
+ }
+ catch (MissingPolicyException missingPolicy)
+ {
+ LogFactory.getLog(EvictionConfig.class).warn(missingPolicy.getLocalizedMessage());
+ throw missingPolicy;
+ }
+ }
+
+ ec.setEvictionRegionConfigs(regionConfigs);
+ }
+ }
+
+ return ec;
+
+ }
+
+ private static EvictionRegionConfig parseEvictionRegionConfig(Element element,
+ String defaultEvictionClass,
+ int defaultQueueCapacity)
+ {
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+
+ erc.setRegionName(element.getAttribute(EvictionRegionConfig.NAME));
+
+ String temp = element.getAttribute("eventQueueSize");
+ if (temp != null && temp.length() > 0)
+ {
+ erc.setEventQueueSize(Integer.parseInt(temp));
+ }
+ else
+ {
+ erc.setEventQueueSize(defaultQueueCapacity);
+ }
+ String evictionClass = element.getAttribute("policyClass");
+
+ if (evictionClass == null || evictionClass.length() == 0)
+ {
+ evictionClass = defaultEvictionClass;
+ // if it's still null... what do we setCache?
+ if (evictionClass == null || evictionClass.length() == 0)
+ {
+ throw new MissingPolicyException(
+ "There is no Eviction Policy Class specified on the region or for the entire cache!");
+ }
+ }
+
+ EvictionPolicy policy;
+ try
+ {
+ policy = (EvictionPolicy) Util.loadClass(evictionClass).newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
+ }
+
+ EvictionPolicyConfig epc;
+ try
+ {
+ epc = policy.getEvictionConfigurationClass().newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to instantiate eviction configuration of class " +
+ policy.getEvictionConfigurationClass(), e);
+ }
+
+ EvictionElementParser.parseEvictionPolicyConfig(element, epc);
+
+ erc.setEvictionPolicyConfig(epc);
+ return erc;
+
+ }
+
+ /**
+ * Parses the cluster config which is used to start a JGroups channel
+ *
+ * @param config an old-style JGroups protocol config String
+ */
+ public static String parseClusterConfigXml(Element config)
+ {
+ StringBuffer buffer = new StringBuffer();
+ NodeList stack = config.getChildNodes();
+ int length = stack.getLength();
+
+ for (int s = 0; s < length; s++)
+ {
+ org.w3c.dom.Node node = stack.item(s);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+
+ Element tag = (Element) node;
+ String protocol = tag.getTagName();
+ buffer.append(protocol);
+ NamedNodeMap attrs = tag.getAttributes();
+ int attrLength = attrs.getLength();
+ if (attrLength > 0)
+ {
+ buffer.append('(');
+ }
+ for (int a = 0; a < attrLength; a++)
+ {
+ Attr attr = (Attr) attrs.item(a);
+ String name = attr.getName();
+ String value = attr.getValue();
+ buffer.append(name);
+ buffer.append('=');
+ buffer.append(value);
+ if (a < attrLength - 1)
+ {
+ buffer.append(';');
+ }
+ }
+ if (attrLength > 0)
+ {
+ buffer.append(')');
+ }
+ buffer.append(':');
+ }
+ // Remove the trailing ':'
+ buffer.setLength(buffer.length() - 1);
+ return buffer.toString();
+ }
+
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Deleted: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParserOld.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -1,536 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.config.parsing;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.util.Util;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-/**
- * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object. When deployed as a
- * JBoss MBean, this role is performed by the JBoss Microcontainer. This class is only used internally in unit tests
- * or within {@link org.jboss.cache.CacheFactory} implementations for standalone JBoss Cache usage.
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
- * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
- * @since 2.00.
- * @deprecated
- */
-public class XmlConfigurationParserOld
-{
- private static final Log log = LogFactory.getLog(XmlConfigurationParserOld.class);
-
- public static final String ATTR = "attribute";
- public static final String NAME = "name";
-
- /**
- * Parses an XML file and returns a new configuration. This method attempts to look for the file name passed in on
- * the classpath. If not found, it will search for the file on the file system instead, treating the name as an
- * absolute path.
- *
- * @param filename the name of the XML file to parse.
- * @return a configured Configuration object representing the configuration in the file
- */
- public Configuration parseFile(String filename)
- {
- InputStream is = getAsInputStreamFromClassLoader(filename);
- if (is == null)
- {
- if (log.isDebugEnabled())
- log.debug("Unable to find configuration file " + filename + " in classpath; searching for this file on the filesystem instead.");
- try
- {
- is = new FileInputStream(filename);
- }
- catch (FileNotFoundException e)
- {
- throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!", e);
- }
- }
-
- return parseStream(is);
- }
-
- /**
- * Parses an input stream containing XML text and returns a new configuration.
- *
- * @param stream input stream to parse. SHould not be null.
- * @return a configured Configuration object representing the configuration in the stream
- * @since 2.1.0
- */
- public Configuration parseStream(InputStream stream)
- {
- // loop through all elements in XML.
- Element root = XmlConfigHelper.getDocumentRoot(stream);
- Element mbeanElement = getMBeanElement(root);
-
- return parseConfiguration(mbeanElement);
- }
-
- public Configuration parseConfiguration(Element configurationRoot)
- {
- ParsedAttributes attributes = XmlConfigHelper.extractAttributes(configurationRoot);
-
- // Deal with legacy attributes we no longer support
- handleRemovedAttributes(attributes);
-
- // Deal with legacy attributes that we renamed or otherwise altered
- handleRenamedAttributes(attributes);
-
- Configuration c = new Configuration();
- XmlConfigHelper.setValues(c, attributes.stringAttribs, false);
- // Special handling for XML elements -- we hard code the parsing
- setXmlValues(c, attributes.xmlAttribs);
-
- return c;
- }
-
- /**
- * Check for and remove any attributes that were supported in the
- * 1.x releases and no longer are. Log a WARN or throw a
- * {@link ConfigurationException} if any are found. Which is done depends
- * on the attribute:
- * <p/>
- * <ul>
- * <li><i>MultiplexerService</i> -- throws an Exception</li>
- * <li><i>ServiceName</i> -- logs a WARN</li>
- * </ul>
- *
- * @param attributes
- */
- protected void handleRemovedAttributes(ParsedAttributes attributes)
- {
- String evictionPolicy = attributes.stringAttribs.remove("EvictionPolicyClass");
- if (evictionPolicy != null)
- {
- throw new ConfigurationException("XmlConfigurationParser does not " +
- "support the JBC 1.x attribute EvictionPolicyClass. Set the default " +
- "eviction policy via the policyClass element in the EvictionConfig section");
- }
- String multiplexerService = attributes.stringAttribs.remove("MultiplexerService");
- if (multiplexerService != null)
- {
- throw new ConfigurationException("XmlConfigurationParser does not " +
- "support the JBC 1.x attribute MultiplexerService. Inject the " +
- "multiplexer directly using Configuration.getRuntimeConfig().setMuxChannelFactory()");
- }
- String serviceName = attributes.stringAttribs.remove("ServiceName");
- if (serviceName != null)
- {
- log.warn("XmlConfigurationParser does not support the deprecated " +
- "attribute ServiceName. If JMX registration is needed, " +
- "register a CacheJmxWrapper or PojoCacheJmxWrapper in " +
- "JMX with the desired name");
- }
- }
-
- /**
- * Check for any attributes that were supported in the
- * 1.x releases but whose name has changed. Log a WARN if any are found, but
- * convert the attribute to the new name.
- * <p/>
- * <ul>
- * <li><i>UseMbean</i> becomes <i>ExposeManagementStatistics</i></li>
- * </ul>
- *
- * @param attributes
- */
- private void handleRenamedAttributes(ParsedAttributes attributes)
- {
- String keepStats = attributes.stringAttribs.remove("UseInterceptorMbeans");
- if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
- {
- log.warn("Found non-existent JBC 1.x attribute 'UseInterceptorMbeans' and replaced " +
- "with 'ExposeManagementStatistics'. Please update your config " +
- "to use the new attribute name");
- attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
- }
- Element clc = attributes.xmlAttribs.remove("CacheLoaderConfiguration");
- if (clc != null && attributes.xmlAttribs.get("CacheLoaderConfig") == null)
- {
- log.warn("Found non-existent JBC 1.x attribute 'CacheLoaderConfiguration' and replaced " +
- "with 'CacheLoaderConfig'. Please update your config " +
- "to use the new attribute name");
- attributes.xmlAttribs.put("CacheLoaderConfig", clc);
- }
- }
-
- protected InputStream getAsInputStreamFromClassLoader(String filename)
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- InputStream is = cl == null ? null : cl.getResourceAsStream(filename);
- if (is == null)
- {
- // check system class loader
- is = getClass().getClassLoader().getResourceAsStream(filename);
- }
- return is;
- }
-
- protected Element getMBeanElement(Element root)
- {
- // This is following JBoss convention.
- NodeList list = root.getElementsByTagName(XmlConfigHelper.ROOT);
- if (list == null) throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " tag");
-
- if (list.getLength() > 1) throw new ConfigurationException("Has multiple " + XmlConfigHelper.ROOT + " tag");
-
- Node node = list.item(0);
- Element element;
- if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
- {
- element = (Element) node;
- }
- else
- {
- throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " element");
- }
- return element;
- }
-
- protected void setXmlValues(Configuration conf, Map<String, Element> attribs)
- {
- for (Entry<String, Element> entry : attribs.entrySet())
- {
- String propname = entry.getKey();
- if ("BuddyReplicationConfiguration".equals(propname)
- || "BuddyReplicationConfig".equals(propname))
- {
- BuddyReplicationConfig brc = parseBuddyReplicationConfig(entry.getValue());
- conf.setBuddyReplicationConfig(brc);
- }
- else if ("CacheLoaderConfiguration".equals(propname)
- || "CacheLoaderConfig".equals(propname))
- {
- CacheLoaderConfig clc = parseCacheLoaderConfig(entry.getValue());
- conf.setCacheLoaderConfig(clc);
- }
- else if ("EvictionPolicyConfiguration".equals(propname)
- || "EvictionPolicyConfig".equals(propname))
- {
- EvictionConfig ec = parseEvictionConfig(entry.getValue());
- conf.setEvictionConfig(ec);
- }
- else if ("ClusterConfig".equals(propname))
- {
- String jgc = parseClusterConfigXml(entry.getValue());
- conf.setClusterConfig(jgc);
- }
- else
- {
- throw new ConfigurationException("Unknown configuration element " + propname);
- }
- }
- }
-
- public static BuddyReplicationConfig parseBuddyReplicationConfig(Element element)
- {
- BuddyReplicationConfig brc = new BuddyReplicationConfig();
- brc.setEnabled(XmlConfigHelper.readBooleanContents(element, "buddyReplicationEnabled"));
- brc.setDataGravitationRemoveOnFind(XmlConfigHelper.readBooleanContents(element, "dataGravitationRemoveOnFind", true));
- brc.setDataGravitationSearchBackupTrees(XmlConfigHelper.readBooleanContents(element, "dataGravitationSearchBackupTrees", true));
- brc.setAutoDataGravitation(brc.isEnabled() && XmlConfigHelper.readBooleanContents(element, "autoDataGravitation", false));
-
- String strBuddyCommunicationTimeout = XmlConfigHelper.readStringContents(element, "buddyCommunicationTimeout");
- try
- {
- brc.setBuddyCommunicationTimeout(Integer.parseInt(strBuddyCommunicationTimeout));
- }
- catch (Exception e)
- {
- }
- finally
- {
- if (log.isDebugEnabled())
- {
- log.debug("Using buddy communication timeout of " + brc.getBuddyCommunicationTimeout() + " millis");
- }
- }
- String buddyPoolName = XmlConfigHelper.readStringContents(element, "buddyPoolName");
- if ("".equals(buddyPoolName))
- {
- buddyPoolName = null;
- }
-
- brc.setBuddyPoolName(buddyPoolName);
-
- // now read the buddy locator details
-
- String buddyLocatorClass = XmlConfigHelper.readStringContents(element, "buddyLocatorClass");
- if (buddyLocatorClass == null || buddyLocatorClass.length() == 0)
- {
- buddyLocatorClass = NextMemberBuddyLocator.class.getName();
- }
- Properties props = null;
- props = XmlConfigHelper.readPropertiesContents(element, "buddyLocatorProperties");
- BuddyLocatorConfig blc = new BuddyLocatorConfig();
- blc.setBuddyLocatorClass(buddyLocatorClass);
- blc.setBuddyLocatorProperties(props);
- brc.setBuddyLocatorConfig(blc);
-
- return brc;
- }
-
- public static CacheLoaderConfig parseCacheLoaderConfig(Element element)
- {
- CacheLoaderConfig clc = new CacheLoaderConfig();
- clc.setPassivation(XmlConfigHelper.readBooleanContents(element, "passivation"));
- clc.setPreload(XmlConfigHelper.readStringContents(element, "preload"));
- clc.setShared(XmlConfigHelper.readBooleanContents(element, "shared"));
-
- NodeList cacheLoaderNodes = element.getElementsByTagName("cacheloader");
- for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
- {
- Node node = cacheLoaderNodes.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- Element indivElement = (Element) node;
- CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
- iclc.setAsync(XmlConfigHelper.readBooleanContents(indivElement, "async", false));
- iclc.setIgnoreModifications(XmlConfigHelper.readBooleanContents(indivElement, "ignoreModifications", false));
- iclc.setFetchPersistentState(XmlConfigHelper.readBooleanContents(indivElement, "fetchPersistentState", false));
- iclc.setPurgeOnStartup(XmlConfigHelper.readBooleanContents(indivElement, "purgeOnStartup", false));
- iclc.setClassName(XmlConfigHelper.readStringContents(indivElement, "class"));
- iclc.setProperties(XmlConfigHelper.readPropertiesContents(indivElement, "properties"));
-
- SingletonStoreConfig ssc = CacheLoadersElementParser.parseSingletonStoreConfig(indivElement);
- if (ssc != null)
- {
- iclc.setSingletonStoreConfig(ssc);
- }
-
- clc.addIndividualCacheLoaderConfig(iclc);
- }
- }
-
- return clc;
- }
-
- public static EvictionConfig parseEvictionConfig(Element element)
- {
- EvictionConfig ec = new EvictionConfig();
-
- if (element != null)
- {
- // If they set the default eviction policy in the element, use that
- // in preference to the external attribute
- String temp = XmlConfigHelper.getTagContents(element,
- EvictionConfig.EVICTION_POLICY_CLASS, ATTR, NAME);
- if (temp != null && temp.length() > 0)
- {
- ec.setDefaultEvictionPolicyClass(temp);
- }
-
- temp = XmlConfigHelper.getTagContents(element,
- EvictionConfig.WAKEUP_INTERVAL_SECONDS, ATTR, NAME);
-
- int wakeupIntervalSeconds = 0;
- if (temp != null)
- {
- wakeupIntervalSeconds = Integer.parseInt(temp);
- }
-
- if (wakeupIntervalSeconds <= 0)
- {
- wakeupIntervalSeconds = EvictionConfig.WAKEUP_DEFAULT;
- }
-
- ec.setWakeupIntervalSeconds(wakeupIntervalSeconds);
-
- int eventQueueSize = 0;
- temp = XmlConfigHelper.getTagContents(element,
- EvictionConfig.EVENT_QUEUE_SIZE, ATTR, NAME);
-
- if (temp != null)
- {
- eventQueueSize = Integer.parseInt(temp);
- }
-
- if (eventQueueSize <= 0)
- {
- eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
- }
-
- ec.setDefaultEventQueueSize(eventQueueSize);
-
- NodeList list = element.getElementsByTagName(EvictionRegionConfig.REGION);
- if (list != null && list.getLength() > 0)
- {
- List regionConfigs = new ArrayList(list.getLength());
- for (int i = 0; i < list.getLength(); i++)
- {
- org.w3c.dom.Node node = list.item(i);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- {
- continue;
- }
- try
- {
- regionConfigs.add(parseEvictionRegionConfig((Element) node, ec.getDefaultEvictionPolicyClass(), eventQueueSize));
- }
- catch (MissingPolicyException missingPolicy)
- {
- LogFactory.getLog(EvictionConfig.class).warn(missingPolicy.getLocalizedMessage());
- throw missingPolicy;
- }
- }
-
- ec.setEvictionRegionConfigs(regionConfigs);
- }
- }
-
- return ec;
-
- }
-
- public static EvictionRegionConfig parseEvictionRegionConfig(Element element,
- String defaultEvictionClass,
- int defaultQueueCapacity)
- {
- EvictionRegionConfig erc = new EvictionRegionConfig();
-
- erc.setRegionName(element.getAttribute(EvictionRegionConfig.NAME));
-
- String temp = element.getAttribute(EvictionRegionConfig.EVENT_QUEUE_SIZE);
- if (temp != null && temp.length() > 0)
- {
- erc.setEventQueueSize(Integer.parseInt(temp));
- }
- else
- {
- erc.setEventQueueSize(defaultQueueCapacity);
- }
- String evictionClass = element.getAttribute(EvictionRegionConfig.REGION_POLICY_CLASS);
-
- if (evictionClass == null || evictionClass.length() == 0)
- {
- evictionClass = defaultEvictionClass;
- // if it's still null... what do we setCache?
- if (evictionClass == null || evictionClass.length() == 0)
- {
- throw new MissingPolicyException(
- "There is no Eviction Policy Class specified on the region or for the entire cache!");
- }
- }
-
- EvictionPolicy policy;
- try
- {
- policy = (EvictionPolicy) Util.loadClass(evictionClass).newInstance();
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
- }
-
- EvictionPolicyConfig epc;
- try
- {
- epc = policy.getEvictionConfigurationClass().newInstance();
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Failed to instantiate eviction configuration of class " +
- policy.getEvictionConfigurationClass(), e);
- }
-
- EvictionElementParser.parseEvictionPolicyConfig(element, epc);
-
- erc.setEvictionPolicyConfig(epc);
- return erc;
-
- }
-
- /**
- * Parses the cluster config which is used to start a JGroups channel
- *
- * @param config an old-style JGroups protocol config String
- */
- public static String parseClusterConfigXml(Element config)
- {
- StringBuffer buffer = new StringBuffer();
- NodeList stack = config.getChildNodes();
- int length = stack.getLength();
-
- for (int s = 0; s < length; s++)
- {
- org.w3c.dom.Node node = stack.item(s);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- {
- continue;
- }
-
- Element tag = (Element) node;
- String protocol = tag.getTagName();
- buffer.append(protocol);
- NamedNodeMap attrs = tag.getAttributes();
- int attrLength = attrs.getLength();
- if (attrLength > 0)
- {
- buffer.append('(');
- }
- for (int a = 0; a < attrLength; a++)
- {
- Attr attr = (Attr) attrs.item(a);
- String name = attr.getName();
- String value = attr.getValue();
- buffer.append(name);
- buffer.append('=');
- buffer.append(value);
- if (a < attrLength - 1)
- {
- buffer.append(';');
- }
- }
- if (attrLength > 0)
- {
- buffer.append(')');
- }
- buffer.append(':');
- }
- // Remove the trailing ':'
- buffer.setLength(buffer.length() - 1);
- return buffer.toString();
- }
-
-}
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java (from rev 5995, core/trunk/src/main/java/org/jboss/cache/config/parsing/BuddyReplicationElementParser.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,73 @@
+package org.jboss.cache.config.parsing.element;
+
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.parsing.XmlParserBase;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
+import org.w3c.dom.Element;
+
+import java.util.Properties;
+
+/**
+ * Utility class for parsing 'buddy' element in the .xml configuration file.
+ * <pre>
+ * Note: class does not rely on element position in the configuration file.
+ * It does not rely on element's name either.
+ * </pre>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class BuddyElementParser extends XmlParserBase
+{
+ public BuddyReplicationConfig parseBuddyElement(Element element)
+ {
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ String enabled = element.getAttribute("enabled");
+ if (existsAttribute(enabled)) brc.setEnabled(getBoolean(enabled));
+ String buddyPoolName = element.getAttribute("poolName");
+ if (existsAttribute(buddyPoolName)) brc.setBuddyPoolName(buddyPoolName);
+ String buddyCommunicationTimeout = element.getAttribute("communicationTimeout");
+ if (existsAttribute(buddyCommunicationTimeout))
+ brc.setBuddyCommunicationTimeout(getInt(buddyCommunicationTimeout));
+
+ parseDataGravitationElement(getSingleElement("dataGravitation", element), brc);
+ BuddyReplicationConfig.BuddyLocatorConfig blc = parseBuddyLocatorConfig(getSingleElement("locator", element));
+ brc.setBuddyLocatorConfig(blc);
+ return brc;
+ }
+
+ private BuddyReplicationConfig.BuddyLocatorConfig parseBuddyLocatorConfig(Element element)
+ {
+ if (element == null) return defaultBuddyLocatorConfig();
+ BuddyReplicationConfig.BuddyLocatorConfig result = new BuddyReplicationConfig.BuddyLocatorConfig();
+ String buddyLocatorClass = element.getAttribute("class");
+ if (existsAttribute(buddyLocatorClass)) result.setBuddyLocatorClass(buddyLocatorClass);
+ Properties existing = new Properties();
+ Properties configured = XmlConfigHelper.readPropertiesContents(element, "properties");
+ existing.putAll(configured);
+ result.setBuddyLocatorClass(buddyLocatorClass);
+ result.setBuddyLocatorProperties(existing);
+ return result;
+ }
+
+ private BuddyReplicationConfig.BuddyLocatorConfig defaultBuddyLocatorConfig()
+ {
+ BuddyReplicationConfig.BuddyLocatorConfig result = new BuddyReplicationConfig.BuddyLocatorConfig();
+ result.setBuddyLocatorClass(NextMemberBuddyLocator.class.getName());
+ Properties props = new Properties();
+ result.setBuddyLocatorProperties(props);
+ return result;
+ }
+
+ private void parseDataGravitationElement(Element element, BuddyReplicationConfig brc)
+ {
+ if (element == null) return;
+ String auto = element.getAttribute("auto");
+ if (existsAttribute(auto)) brc.setAutoDataGravitation(getBoolean(auto));
+ String removeOnFind = element.getAttribute("removeOnFind");
+ if (existsAttribute(removeOnFind)) brc.setDataGravitationRemoveOnFind(getBoolean(removeOnFind));
+ String searchBackupTrees = element.getAttribute("searchBackupTrees");
+ if (existsAttribute(searchBackupTrees)) brc.setDataGravitationSearchBackupTrees(getBoolean(searchBackupTrees));
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java (from rev 5995, core/trunk/src/main/java/org/jboss/cache/config/parsing/EvictionElementParser.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,129 @@
+package org.jboss.cache.config.parsing.element;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.MissingPolicyException;
+import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.parsing.XmlParserBase;
+import org.jboss.cache.config.parsing.ParsedAttributes;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.util.Util;
+import org.jboss.cache.RegionManager;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Knows how to parse the <b>eviction</b> xml element.
+ * <pre>
+ * Note: class does not rely on element position in the configuration file.
+ * It does not rely on element's name either.
+ * </pre>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class EvictionElementParser extends XmlParserBase
+{
+ public EvictionConfig parseEvictionElement(Element evictionElement)
+ {
+ EvictionConfig evictionConfig = new EvictionConfig();
+ String wakeUpInterval = evictionElement.getAttribute("wakeUpInterval");
+ if (existsAttribute(wakeUpInterval)) evictionConfig.setWakeupInterval(getInt(wakeUpInterval));
+
+ Element element = getSingleElement("defaults", evictionElement);
+ processDefaults(evictionConfig, element);
+
+ List<EvictionRegionConfig> evictionRegionConfigs = new ArrayList<EvictionRegionConfig>(3);
+ Element rootRegion = getSingleElement("root", evictionElement);
+ String defaultPolicyClass = evictionConfig.getDefaultEvictionPolicyClass();
+ int defaultEvQueueSize = evictionConfig.getDefaultEventQueueSize();
+ if (rootRegion != null)
+ {
+ EvictionRegionConfig erc = getEvictionRegionConfig(rootRegion, defaultPolicyClass, defaultEvQueueSize);
+ erc.setRegionName(RegionManager.DEFAULT_REGION.toString());
+ evictionRegionConfigs.add(erc);
+ }
+
+ NodeList regions = evictionElement.getElementsByTagName("region");
+ for (int i = 0; i < regions.getLength(); i++)
+ {
+ Element regionConfig = (Element) regions.item(i);
+ EvictionRegionConfig erc = getEvictionRegionConfig(regionConfig, defaultPolicyClass, defaultEvQueueSize);
+ evictionRegionConfigs.add(erc);
+ }
+ evictionConfig.setEvictionRegionConfigs(evictionRegionConfigs);
+ return evictionConfig;
+ }
+
+ private void processDefaults(EvictionConfig evictionConfig, Element element)
+ {
+ if (element == null) return;
+ String policyClass = element.getAttribute("policyClass");
+ if (existsAttribute(policyClass)) evictionConfig.setDefaultEvictionPolicyClass(policyClass);
+ String eventQueueSize = element.getAttribute("eventQueueSize");
+ if (existsAttribute(eventQueueSize)) evictionConfig.setDefaultEventQueueSize(getInt(eventQueueSize));
+ }
+
+ private EvictionRegionConfig getEvictionRegionConfig(Element element, String defaultPolicyClass, int defaultEventQueueSize)
+ {
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+ erc.setRegionName(element.getAttribute("name"));
+ String queueSize = element.getAttribute("eventQueueSize");
+ if (existsAttribute(queueSize))
+ {
+ erc.setEventQueueSize(getInt(queueSize));
+ }
+ else
+ {
+ erc.setEventQueueSize(defaultEventQueueSize);
+ }
+ String policyClass = element.getAttribute("policyClass");
+ if (!existsAttribute(policyClass))
+ {
+ if (defaultPolicyClass == null)
+ {
+ throw new MissingPolicyException("There is no Eviction Policy Class specified on the region or for the entire cache!");
+ }
+ else
+ {
+ policyClass = defaultPolicyClass;
+ }
+ }
+ EvictionPolicy policy;
+ try
+ {
+ policy = (EvictionPolicy) Util.loadClass(policyClass).newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
+ }
+
+ EvictionPolicyConfig epc;
+ try
+ {
+ epc = policy.getEvictionConfigurationClass().newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to instantiate eviction configuration of class " +
+ policy.getEvictionConfigurationClass(), e);
+ }
+ parseEvictionPolicyConfig(element, epc);
+ erc.setEvictionPolicyConfig(epc);
+ return erc;
+ }
+
+ public static void parseEvictionPolicyConfig(Element element, EvictionPolicyConfig target)
+ {
+ target.reset();
+ ParsedAttributes attributes = XmlConfigHelper.extractAttributes(element);
+ XmlConfigHelper.setValues(target, attributes.stringAttribs, false);
+ XmlConfigHelper.setValues(target, attributes.xmlAttribs, true);
+ target.validate();
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java (from rev 5997, core/trunk/src/main/java/org/jboss/cache/config/parsing/CacheLoadersElementParser.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,106 @@
+package org.jboss.cache.config.parsing.element;
+
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.parsing.XmlParserBase;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.Properties;
+
+/**
+ * Utility class for parsing the 'loaders' element in the .xml configuration file.
+ * <pre>
+ * Note: class does not rely on element position in the configuration file.
+ * It does not rely on element's name either.
+ * </pre>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+public class LoadersElementParser extends XmlParserBase
+{
+ public CacheLoaderConfig parseLoadersElement(Element element)
+ {
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ String passivation = element.getAttribute("passivation");
+ if (existsAttribute(passivation)) cacheLoaderConfig.setPassivation(getBoolean(passivation));
+ String shared = element.getAttribute("shared");
+ if (existsAttribute(shared)) cacheLoaderConfig.setShared(getBoolean(shared));
+ String preload = getPreloadString(getSingleElement("preload", element));
+ if (preload != null) cacheLoaderConfig.setPreload(preload);
+
+ NodeList cacheLoaderNodes = element.getElementsByTagName("loader");
+ for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
+ {
+ Element indivElement = (Element) cacheLoaderNodes.item(i);
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = parseIndividualCacheLoaderConfig(indivElement);
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(iclc);
+ }
+ return cacheLoaderConfig;
+ }
+
+ private CacheLoaderConfig.IndividualCacheLoaderConfig parseIndividualCacheLoaderConfig(Element indivElement)
+ {
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
+
+ String async = indivElement.getAttribute("async");
+ if (existsAttribute(async)) iclc.setAsync(getBoolean(async));
+ String fetchPersistentState = indivElement.getAttribute("fetchPersistentState");
+ if (existsAttribute(fetchPersistentState)) iclc.setFetchPersistentState(getBoolean(fetchPersistentState));
+ String ignoreModifications = indivElement.getAttribute("ignoreModifications");
+ if (existsAttribute(ignoreModifications)) iclc.setIgnoreModifications(getBoolean(ignoreModifications));
+ String purgeOnStartup = indivElement.getAttribute("purgeOnStartup");
+ if (existsAttribute(purgeOnStartup)) iclc.setPurgeOnStartup(getBoolean(purgeOnStartup));
+ String clClass = indivElement.getAttribute("class");
+ if (!existsAttribute(clClass))
+ throw new ConfigurationException("Missing 'class' attribute for cache loader configuration");
+ iclc.setClassName(clClass);
+ iclc.setProperties(XmlConfigHelper.readPropertiesContents(indivElement, "properties"));
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = parseSingletonStoreConfig(getSingleElement("singletonStore", indivElement));
+ if (ssc != null)
+ {
+ iclc.setSingletonStoreConfig(ssc);
+ }
+ return iclc;
+ }
+
+ private String getPreloadString(Element preloadElement)
+ {
+ if (preloadElement == null) return null; //might be no preload
+ NodeList nodesToPreload = preloadElement.getElementsByTagName("node");
+ StringBuffer result = new StringBuffer();
+ for (int i = 0; i < nodesToPreload.getLength(); i++)
+ {
+ Element node = (Element) nodesToPreload.item(i);
+ String fqn2preload = node.getAttribute("fqn");
+ if (!existsAttribute(fqn2preload))
+ throw new ConfigurationException("Missing 'fqn' attribute in 'preload\\norde' tag");
+ if (i > 0) result.append(",");
+ result.append(fqn2preload);
+ }
+ //no elements defined for preload so by default load the root
+ if (nodesToPreload.getLength() == 0)
+ {
+ result.append("/");
+ }
+ return result.toString();
+ }
+
+ public CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig parseSingletonStoreConfig(Element element)
+ {
+ if (element == null) return null; //might happen, this config option is not mandatory
+ String enabled = element.getAttribute("enabled");
+ boolean singletonStoreEnabled = getBoolean(element.getAttribute("enabled"));
+ String singletonStoreClass = element.getAttribute("class");
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = new CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig();
+ if (existsAttribute(singletonStoreClass)) ssc.setSingletonStoreClass(singletonStoreClass);
+ Properties singletonStoreproperties = XmlConfigHelper.readPropertiesContents(element, "properties");
+ ssc.setSingletonStoreEnabled(singletonStoreEnabled);
+ ssc.setSingletonStoreClass(singletonStoreClass);
+ ssc.setSingletonStoreproperties(singletonStoreproperties);
+ return ssc;
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -76,6 +76,7 @@
public void setMinTimeToLive(long minTimeToLive)
{
this.minTimeToLive = minTimeToLive;
+ this.minTimeToLiveSeconds = (int)(minTimeToLive / 1000);
}
/**
@@ -94,7 +95,7 @@
public void setMinTimeToLiveSeconds(int minTimeToLiveSeconds)
{
this.minTimeToLiveSeconds = minTimeToLiveSeconds;
- setMinTimeToLive(minTimeToLive * 1000);
+ minTimeToLive = minTimeToLiveSeconds * 1000;
}
public void validate() throws ConfigurationException
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -80,6 +80,7 @@
public void setTimeToLive(long timeToLive)
{
this.timeToLive = timeToLive;
+ this.timeToLiveSeconds = (int) (timeToLive * 1000);
}
/**
@@ -98,7 +99,7 @@
public void setTimeToLiveSeconds(int timeToLiveSeconds)
{
this.timeToLiveSeconds = timeToLiveSeconds;
- setTimeToLive(timeToLiveSeconds * 1000);
+ timeToLive = timeToLiveSeconds * 1000;
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -55,6 +55,13 @@
setTimeToLive(-1);
}
+ public LRUConfiguration(long timeToLive, long maxAge)
+ {
+ super();
+ setTimeToLive(timeToLive);
+ setMaxAge(maxAge);
+ }
+
@Override
protected void setEvictionPolicyClassName()
{
@@ -72,6 +79,7 @@
{
testImmutability("timeToLive");
this.timeToLive = timeToLive;
+ this.timeToLiveSeconds = (int)(timeToLive/1000);
}
/** value expressed in millis*/
@@ -85,6 +93,7 @@
{
testImmutability("maxAge");
this.maxAge = maxAge;
+ this.maxAgeSeconds = (int) (maxAge/1000);
}
/**
@@ -105,7 +114,7 @@
{
testImmutability("timeToLiveSeconds");
this.timeToLiveSeconds = timeToLiveSeconds;
- setTimeToLive(timeToLiveSeconds * 1000);
+ timeToLive = timeToLiveSeconds * 1000;
}
/**
@@ -126,7 +135,7 @@
{
testImmutability("maxAgeSeconds");
this.maxAgeSeconds = maxAgeSeconds;
- setMaxAge(maxAgeSeconds * 1000);
+ this.maxAge = maxAgeSeconds * 1000;
}
/**
@@ -162,7 +171,9 @@
LRUConfiguration that = (LRUConfiguration) o;
if (maxAge != that.maxAge) return false;
+ if (maxAgeSeconds != that.maxAgeSeconds) return false;
if (timeToLive != that.timeToLive) return false;
+ if (timeToLiveSeconds != that.timeToLiveSeconds) return false;
return true;
}
@@ -170,6 +181,8 @@
public int hashCode()
{
int result = super.hashCode();
+ result = 31 * result + timeToLiveSeconds;
+ result = 31 * result + maxAgeSeconds;
result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
result = 31 * result + (int) (maxAge ^ (maxAge >>> 32));
return result;
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -23,19 +23,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.CacheStatus;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.RuntimeConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.*;
+import org.jboss.cache.config.*;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
+import org.jboss.cache.config.parsing.JGroupsStackParser;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.util.CachePrinter;
import org.jgroups.Address;
@@ -61,6 +55,7 @@
extends NotificationBroadcasterSupport
implements CacheJmxWrapperMBean<K, V>, MBeanRegistration, CacheNotificationBroadcaster
{
+
private Log log = LogFactory.getLog(getClass().getName());
private MBeanServer server;
@@ -85,6 +80,11 @@
private Element clusterConfig;
private JChannelFactoryMBean multiplexerService;
+ private BuddyElementParser buddyElementParser = new BuddyElementParser();
+ private LoadersElementParser loadersElementParser = new LoadersElementParser();
+ private EvictionElementParser evictionElementParser = new EvictionElementParser();
+ private JGroupsStackParser stackParser = new JGroupsStackParser();
+
// ----------------------------------------------------------- Constructors
public CacheJmxWrapper()
@@ -374,21 +374,21 @@
BuddyReplicationConfig brc = null;
if (config != null)
{
- brc = XmlConfigurationParserOld.parseBuddyReplicationConfig(config);
+ brc = buddyElementParser.parseBuddyElement(config);
}
getConfiguration().setBuddyReplicationConfig(brc);
this.buddyReplConfig = config;
}
- public void setCacheLoaderConfig(Element cache_loader_config)
+ public void setCacheLoaderConfig(Element cacheLoaderConfig)
{
CacheLoaderConfig clc = null;
- if (cache_loader_config != null)
+ if (cacheLoaderConfig != null)
{
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(cache_loader_config);
+ clc = loadersElementParser.parseLoadersElement(cacheLoaderConfig);
}
getConfiguration().setCacheLoaderConfig(clc);
- this.cacheLoaderConfig = cache_loader_config;
+ this.cacheLoaderConfig = cacheLoaderConfig;
}
public void setCacheLoaderConfiguration(Element config)
@@ -408,7 +408,7 @@
String props = null;
if (config != null)
{
- props = XmlConfigurationParserOld.parseClusterConfigXml(config);
+ stackParser.parseClusterConfigXml(config);
}
getConfiguration().setClusterConfig(props);
this.clusterConfig = config;
@@ -435,7 +435,7 @@
EvictionConfig ec = null;
if (config != null)
{
- ec = XmlConfigurationParserOld.parseEvictionConfig(config);
+ ec = evictionElementParser.parseEvictionElement(config);
}
getConfiguration().setEvictionConfig(ec);
this.evictionConfig = config;
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -105,7 +105,7 @@
*/
Element getCacheLoaderConfig();
- void setCacheLoaderConfig(Element cache_loader_config);
+ void setCacheLoaderConfig(Element cacheLoaderConfig);
/**
* @deprecated use {@link #getCacheLoaderConfig()}
Modified: core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -7,7 +7,7 @@
package org.jboss.cache;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
@@ -31,7 +31,7 @@
@BeforeMethod(alwaysRun = true)
public void setUp()
{
- XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+ XmlConfigurationParser2x parser = new XmlConfigurationParser2x();
expected = parser.parseFile(configFile);
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -9,7 +9,7 @@
import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.CacheLoadersElementParser;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
@@ -533,19 +533,19 @@
protected CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
{
String xml =
- " <cacheLoaders passivation=\"" + passivation + "\" shared=\"" + shared + "\">\n" +
+ " <loaders passivation=\"" + passivation + "\" shared=\"" + shared + "\">\n" +
" <preload>\n" +
" <node fqn=\"" + preload + "\"/>\n" +
" </preload>\n" +
- " <cacheLoader class=\"" + cacheloaderClass + "\" async=\"" + async + "\" fetchPersistentState=\"" + fetchPersistentState + "\"\n" +
+ " <loader class=\"" + cacheloaderClass + "\" async=\"" + async + "\" fetchPersistentState=\"" + fetchPersistentState + "\"\n" +
" purgeOnStartup=\"" + purgeOnStartup + "\">\n" +
" <properties>\n" +
- properties +
+ properties +
" </properties>\n" +
- " </cacheLoader>\n" +
- " </cacheLoaders>";
+ " </loader>\n" +
+ " </loaders>";
Element element = XmlConfigHelper.stringToElement(xml);
- CacheLoadersElementParser elementParser = new CacheLoadersElementParser();
- return elementParser.parseCacheLoadersElement(element);
+ LoadersElementParser elementParser = new LoadersElementParser();
+ return elementParser.parseLoadersElement(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -12,9 +12,9 @@
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.factories.CommandsFactory;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -31,7 +31,6 @@
public class BuddyManagerTest
{
private static final String DUMMY_LOCAL_ADDRESS = "myLocalAddress:12345";
- private BuddyFqnTransformer fqnTransformer;
/**
* Constructs a buddy manager using the default buddy locator but with some specific properties.
@@ -40,11 +39,15 @@
*/
public void testConstruction1() throws Exception
{
- String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- " <buddyLocatorProperties>numBuddies = 3</buddyLocatorProperties>\n" +
- " <buddyPoolName>groupOne</buddyPoolName></config>";
- Element element = XmlConfigHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlConfig =
+ " <buddyReplication enabled=\"true\" buddyPoolName=\"groupOne\">\n" +
+ " <buddyLocator>\n" +
+ " <properties>\n" +
+ " numBuddies = 3\n" +
+ " </properties>\n" +
+ " </buddyLocator>\n" +
+ " </buddyReplication>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
assertTrue(mgr.isEnabled());
@@ -55,6 +58,14 @@
assertTrue(blc.isIgnoreColocatedBuddies());
}
+ private BuddyReplicationConfig getBuddyReplicationConfig(String xmlConfig)
+ throws Exception
+ {
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyElementParser replicationElementParser = new BuddyElementParser();
+ return replicationElementParser.parseBuddyElement(element);
+ }
+
/**
* Constructs a buddy manager using a nonexistent buddy locator but with some specific properties.
*
@@ -62,12 +73,15 @@
*/
public void testConstruction2() throws Exception
{
- String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- " <buddyLocatorClass>org.i.dont.exist.PhantomBuddyLocator</buddyLocatorClass>\n" +
- " <buddyLocatorProperties>numBuddies = 3</buddyLocatorProperties>\n" +
- " <buddyPoolName>groupOne</buddyPoolName></config>";
- Element element = XmlConfigHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlConfig =
+ " <buddyReplication enabled=\"true\" buddyPoolName=\"groupOne\">\n" +
+ " <buddyLocator class=\"org.i.dont.exist.PhantomBuddyLocator\">\n" +
+ " <properties>\n" +
+ " numBuddies = 3\n" +
+ " </properties>\n" +
+ " </buddyLocator>\n" +
+ " </buddyReplication>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
assertTrue(mgr.isEnabled());
@@ -87,12 +101,9 @@
*/
public void testConstruction3() throws Exception
{
- String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
-
- Element element = XmlConfigHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlConfig = "<buddyReplication enabled=\"false\"/>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
-
assertTrue(!mgr.isEnabled());
}
@@ -103,10 +114,9 @@
*/
public void testConstruction4() throws Exception
{
- String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
+ String xmlConfig = "<buddyReplication enabled=\"true\"/>";
- Element element = XmlConfigHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
assertTrue(mgr.isEnabled());
@@ -122,9 +132,9 @@
BuddyManager bm = null;
try
{
- Element element = XmlConfigHelper.stringToElement("<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>");
- BuddyReplicationConfig cfg = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
- bm = new BuddyManager(cfg);
+ String xmlConfig = "<buddyReplication enabled=\"false\"/>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
+ bm = new BuddyManager(config);
bm.injectDependencies(null, null, null, null, null, null, null, null, new BuddyFqnTransformer());
CommandsFactory commandsFactory = new CommandsFactory();
commandsFactory.initialize(null, null, null, null, null, null, null, new Configuration(), null, new BuddyFqnTransformer());
@@ -208,7 +218,7 @@
public void testGetActualFqn()
{
- fqnTransformer = new BuddyFqnTransformer();
+ BuddyFqnTransformer fqnTransformer = new BuddyFqnTransformer();
Fqn<String> x = Fqn.fromString("/x");
Fqn backup = fqnTransformer.getBackupFqn("y", x);
assertEquals(x, fqnTransformer.getActualFqn(backup));
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,10 +11,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.interceptors.DataGravitatorInterceptor;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -46,9 +47,8 @@
public void testDisabledConfig() throws Exception
{
- String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
- Element element = XmlConfigHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlConfig = "<buddyReplication enabled=\"false\"/>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setBuddyReplicationConfig(config);
assertNull(cache.getBuddyManager());
@@ -56,9 +56,8 @@
public void testBasicConfig() throws Exception
{
- String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
- Element element = XmlConfigHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlConfig = "<buddyReplication enabled=\"true\"/>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache.getConfiguration().setBuddyReplicationConfig(config);
@@ -74,9 +73,18 @@
assertTrue(blc.isIgnoreColocatedBuddies());
}
+ private BuddyReplicationConfig getBuddyReplicationConfig(String xmlConfig)
+ throws Exception
+ {
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyElementParser elementParser = new BuddyElementParser();
+ BuddyReplicationConfig config = elementParser.parseBuddyElement(element);
+ return config;
+ }
+
public void testXmlConfig() throws Exception
{
- cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(new XmlConfigurationParserOld().parseFile("META-INF/buddy-replication-cache-service.xml"), false);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(new XmlConfigurationParser2x().parseFile("META-INF/buddy-replication-cache-service.xml"), false);
cache.create();
cache.start();
BuddyManager bm = cache.getBuddyManager();
@@ -104,9 +112,8 @@
public void testLocalModeConfig() throws Exception
{
- String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
- Element element = XmlConfigHelper.stringToElement(xmlConfig);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlConfig = "<buddyReplication enabled=\"true\"/>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setBuddyReplicationConfig(config);
cache.create();
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -20,8 +20,8 @@
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.config.parsing.CacheLoadersElementParser;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
import org.jgroups.Address;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -130,18 +130,30 @@
{
CacheSPI<Object, Object> c = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC, false, false, true), false);
c.getConfiguration().setClusterName("BuddyReplicationTest");
- // basic config
- String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- "<buddyCommunicationTimeout>500000</buddyCommunicationTimeout>\n" +
- " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
- " <autoDataGravitation>" + useDataGravitation + "</autoDataGravitation>\n" +
- " <dataGravitationRemoveOnFind>" + removeOnFind + "</dataGravitationRemoveOnFind>\n" +
- " <buddyLocatorProperties>numBuddies = " + numBuddies + "</buddyLocatorProperties>\n";
-
- if (buddyPoolName != null) xmlString += "<buddyPoolName>" + buddyPoolName + "</buddyPoolName>";
- xmlString += "</config>";
- Element element = XmlConfigHelper.stringToElement(xmlString);
- BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String buddyPoolNameStr = buddyPoolName != null ? "buddyPoolName=\"" + buddyPoolName + "\"" : "";
+ String xmlStr =
+ " <buddyReplication enabled=\"true\" " + buddyPoolNameStr + " buddyCommunicationTimeout=\"500000\">\n" +
+ " <dataGravitation auto=\"" + useDataGravitation + "\" removeOnFind=\""+ removeOnFind + "\" searchBackupTrees=\"true\"/>\n" +
+ " <buddyLocator class=\"org.jboss.cache.buddyreplication.NextMemberBuddyLocator\">\n" +
+ " <properties>\n" +
+ " numBuddies = " + numBuddies +"\n" +
+ " </properties>\n" +
+ " </buddyLocator>\n" +
+ " </buddyReplication>";
+// // basic config
+// String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
+// "<buddyCommunicationTimeout>500000</buddyCommunicationTimeout>\n" +
+// " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
+// " <autoDataGravitation>" + useDataGravitation + "</autoDataGravitation>\n" +
+// " <dataGravitationRemoveOnFind>" + removeOnFind + "</dataGravitationRemoveOnFind>\n" +
+// " <buddyLocatorProperties>numBuddies = " + numBuddies + "</buddyLocatorProperties>\n";
+//
+// if (buddyPoolName != null) xmlString += "<buddyPoolName>" + buddyPoolName + "</buddyPoolName>";
+// xmlString += "</config>";
+ BuddyElementParser parser = new BuddyElementParser();
+ Element element = XmlConfigHelper.stringToElement(xmlStr);
+ BuddyReplicationConfig config = parser.parseBuddyElement(element);
+// BuddyReplicationConfig config = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
c.getConfiguration().setBuddyReplicationConfig(config);
c.getConfiguration().setFetchInMemoryState(true);
@@ -226,14 +238,14 @@
CacheSPI cache = createCache(1, null, useDataGravitation, removeOnFind, false);
String xmlStr = " " +
- " <cacheLoaders passivation=\"" + passivation + "\" shared=\"false\">\n" +
+ " <loaders passivation=\"" + passivation + "\" shared=\"false\">\n" +
" <preload/>\n" +
- " <cacheLoader class=\"" + DummyInMemoryCacheLoader.class.getName() + "\" async=\"false\" fetchPersistentState=\""+ fetchPersistent + "\"/>\n" +
- " </cacheLoaders>";
+ " <loader class=\"" + DummyInMemoryCacheLoader.class.getName() + "\" async=\"false\" fetchPersistentState=\""+ fetchPersistent + "\"/>\n" +
+ " </loaders>";
System.out.println("xmlStr = +\n" + xmlStr);
Element xmlEl = XmlConfigHelper.stringToElement(xmlStr);
- CacheLoadersElementParser parser = new CacheLoadersElementParser();
- CacheLoaderConfig config = parser.parseCacheLoadersElement(xmlEl);
+ LoadersElementParser parser = new LoadersElementParser();
+ CacheLoaderConfig config = parser.parseLoadersElement(xmlEl);
cache.getConfiguration().setCacheLoaderConfig(config);
if (start)
{
Modified: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -22,7 +22,7 @@
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.eviction.LRUPolicy;
import org.testng.annotations.Test;
@@ -42,7 +42,7 @@
public void testClone() throws Exception
{
- XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+ XmlConfigurationParser2x parser = new XmlConfigurationParser2x();
Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE);
try {
Modified: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/config/ConfigurationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -12,7 +12,7 @@
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.TransactionSetup;
import org.testng.annotations.Test;
@@ -47,7 +47,7 @@
public void testMultiplexerStack() throws Exception
{
- XmlConfigurationParserOld parser = new XmlConfigurationParserOld();
+ XmlConfigurationParser2x parser = new XmlConfigurationParser2x();
Configuration conf = parser.parseFile("META-INF/conf-test/mux-service.xml");
// test that multiplexer settings have been read in properly.
Modified: core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/config/StringPropertyReplacementTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -17,7 +17,7 @@
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.eviction.LRUPolicy;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -93,7 +93,7 @@
System.setProperty(MAX_NODES_PROP, "1000");
System.setProperty(BUDDY_POOL_PROP, "replaced");
- Configuration cfg = new XmlConfigurationParserOld().parseFile(STRING_REPLACED_FILE);
+ Configuration cfg = new XmlConfigurationParser2x().parseFile(STRING_REPLACED_FILE);
assertEquals(NodeLockingScheme.OPTIMISTIC, cfg.getNodeLockingScheme());
assertEquals(CacheMode.REPL_SYNC, cfg.getCacheMode());
Added: core/trunk/src/test/java/org/jboss/cache/config/parsing/BuddyElementParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/BuddyElementParserTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/BuddyElementParserTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,75 @@
+package org.jboss.cache.config.parsing;
+
+import org.testng.annotations.Test;
+import org.w3c.dom.Element;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
+
+/**
+ * Tester class for {@link org.jboss.cache.config.parsing.element.BuddyElementParser}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+@Test(groups = "unit")
+public class BuddyElementParserTest
+{
+
+ /** one instance per all tests as it is stateless */
+ BuddyElementParser parser = new BuddyElementParser();
+
+
+ /**
+ * Test default values for unspecified elements.
+ */
+ public void testDefaultValues() throws Exception
+ {
+ String xmlConfig = "<buddyReplication enabled=\"true\"/>";
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig brConfig = parser.parseBuddyElement(element);
+ assert brConfig.getBuddyLocatorConfig().getClassName().equals(NextMemberBuddyLocator.class.getName()) : "default buddy locator class is NextMemberBuddyLocator";
+ assert brConfig.getBuddyLocatorConfig().getBuddyLocatorProperties().isEmpty();
+ assert brConfig.isDataGravitationRemoveOnFind() : "default to true";
+ assert brConfig.isDataGravitationSearchBackupTrees() : "default to true";
+ assert brConfig.isAutoDataGravitation() : "default to false";
+ }
+
+ /**
+ * If NextMemberBuddyLocator is set as buddy locator, but no params are being specified for it, make sure that
+ * default values for numBudies and ignoreColocatedBuddies are present.
+ */
+ public void testDefaultParamsForNextMemberBuddyLocator() throws Exception
+ {
+ String xmlConfig =
+ " <buddyReplication enabled=\"true\" buddyPoolName=\"groupOne\">\n" +
+ " <buddyLocator>\n" +
+ " <properties>\n" +
+ " numBuddies = 3\n" +
+ " </properties>\n" +
+ " </buddyLocator>\n" +
+ " </buddyReplication>";
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig brConfig = parser.parseBuddyElement(element);
+ assert brConfig.getBuddyLocatorConfig().getClassName().equals(NextMemberBuddyLocator.class.getName()) : "default buddy locator class is NextMemberBuddyLocator";
+ assert brConfig.getBuddyLocatorConfig().getBuddyLocatorProperties().get("numBuddies").equals("3");
+ assert brConfig.getBuddyLocatorConfig().getBuddyLocatorProperties().size() == 1;
+ }
+
+ public void testNormalConfig() throws Exception
+ {
+ String xmlConfig =
+ " <buddyReplication enabled=\"true\" buddyPoolName=\"groupOne\">\n" +
+ " <buddyLocator>\n" +
+ " <properties>\n" +
+ " numBuddies = 3\n" +
+ " </properties>\n" +
+ " </buddyLocator>\n" +
+ " </buddyReplication>";
+ Element element = XmlConfigHelper.stringToElement(xmlConfig);
+ BuddyReplicationConfig brConfig = parser.parseBuddyElement(element);
+ assert brConfig.isEnabled();
+ assert brConfig.getBuddyPoolName().equals("groupOne");
+ assert brConfig.getBuddyLocatorConfig().getBuddyLocatorProperties().get("numBuddies").equals("3");
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/config/parsing/CacheLoadersElementParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/CacheLoadersElementParserTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/CacheLoadersElementParserTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -3,9 +3,12 @@
import org.testng.annotations.Test;
import org.w3c.dom.Element;
import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
+import java.util.List;
+
/**
- * Tester class for {@link CacheLoadersElementParser}
+ * Tester class for {@link org.jboss.cache.config.parsing.element.LoadersElementParser}
*
* @author Mircea.Markus(a)jboss.com
* @since 3.0
@@ -13,28 +16,26 @@
@Test(groups = "unit")
public class CacheLoadersElementParserTest
{
- CacheLoadersElementParser parser = new CacheLoadersElementParser();
+ LoadersElementParser parser = new LoadersElementParser();
public void simpleParse() throws Exception
{
-
String xmlStr = " " +
- " <cacheLoaders passivation=\"false\" shared=\"false\">\n" +
+ " <loaders passivation=\"false\" shared=\"false\">\n" +
" <preload>\n" +
" <node fqn=\"/\"/>\n" +
" </preload>\n" +
- " <cacheLoader class=\"org.jboss.cache.loader.JDBCCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
+ " <loader class=\"org.jboss.cache.loader.JDBCCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
" ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
" <properties>\n" +
" cache.jdbc.table.name=jbosscache\n" +
" cache.jdbc.table.create=true\n" +
" cache.jdbc.table.drop=true\n" +
" </properties>\n" +
- " </cacheLoader>\n" +
- " </cacheLoaders>";
- Element element = XmlConfigHelper.stringToElement(xmlStr);
- CacheLoaderConfig config = parser.parseCacheLoadersElement(element);
+ " </loader>\n" +
+ " </loaders>";
+ CacheLoaderConfig config = getCacheLoaderConfig(xmlStr);
assert !config.isPassivation();
assert !config.isShared();
assert config.getPreload().equals("/");
@@ -45,20 +46,100 @@
assert !config.getFirstCacheLoaderConfig().isPurgeOnStartup();
}
+
/**
- * If so an empty preload string should apear.
+ * Tests that if no values are specified the parser sets default config values.
*/
- public void testMissingPreloadNodes() throws Exception
+ public void testDefaultValues() throws Exception
{
+ String xmlStr =
+ " <loaders passivation=\"false\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.JDBCCacheLoader\">" +
+ " <singletonStore/>\n" +
+ " </loader>"+
+ " </loaders>";
+ CacheLoaderConfig config = getCacheLoaderConfig(xmlStr);
+ assert config.getPreload().equals("/") : "the default value for preload is root";
+ assert !config.getFirstCacheLoaderConfig().isAsync() : "by default CL are sync";
+ assert !config.isShared() : "by default the cl are not sared";
+ assert !config.getFirstCacheLoaderConfig().isIgnoreModifications();
+ assert !config.getFirstCacheLoaderConfig().isPurgeOnStartup();
+ assert !config.getFirstCacheLoaderConfig().getSingletonStoreConfig().isSingletonStoreEnabled();
+ assert config.getFirstCacheLoaderConfig().getSingletonStoreConfig().getSingletonStoreClass().equals("org.jboss.cache.loader.SingletonStoreCacheLoader");
+ assert config.getFirstCacheLoaderConfig().getSingletonStoreConfig().getSingletonStoreClass().equals("org.jboss.cache.loader.SingletonStoreCacheLoader");
+ }
+
+ public void testMultiplePreloadNodes() throws Exception
+ {
String xmlStr = " " +
- " <cacheLoaders passivation=\"false\" shared=\"false\">\n" +
- " <preload/>\n" +
- " <cacheLoader class=\"org.jboss.cache.loader.JDBCCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
- " ignoreModifications=\"false\" purgeOnStartup=\"false\"/>\n" +
- " </cacheLoaders>";
+ " <loaders passivation=\"false\" shared=\"false\">\n" +
+ " <preload>\n" +
+ " <node fqn=\"/\"/>\n" +
+ " <node fqn=\"/a\"/>\n" +
+ " <node fqn=\"/a/b\"/>\n" +
+ " </preload>\n" +
+ " <loader class=\"org.jboss.cache.loader.JDBCCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
+ " ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
+ " </loader>" +
+ "</loaders>";
+ CacheLoaderConfig config = getCacheLoaderConfig(xmlStr);
+ assert config.getPreload().equals("/,/a,/a/b");
+ assert config.getFirstCacheLoaderConfig().getSingletonStoreConfig() == null;
+ }
+
+ public void testMultipleCacheLoaders() throws Exception
+ {
+ String xml =
+ " <loaders passivation=\"false\" shared=\"false\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.JDBCCacheLoader\" async=\"true\" fetchPersistentState=\"true\"\n" +
+ " ignoreModifications=\"true\" purgeOnStartup=\"true\"/>\n" +
+ " <loader class=\"org.jboss.cache.loader.bdbje.BdbjeCacheLoader\" async=\"true\" fetchPersistentState=\"true\"\n" +
+ " ignoreModifications=\"true\" purgeOnStartup=\"true\"/>\n" +
+ " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" async=\"true\" fetchPersistentState=\"true\"\n" +
+ " ignoreModifications=\"true\" purgeOnStartup=\"true\"/>\n" +
+ " </loaders>";
+ CacheLoaderConfig clConfig = getCacheLoaderConfig(xml);
+ List<CacheLoaderConfig.IndividualCacheLoaderConfig> indClConfigs = clConfig.getIndividualCacheLoaderConfigs();
+ assert indClConfigs.size() == 3;
+ assert indClConfigs.get(0).getClassName().equals("org.jboss.cache.loader.JDBCCacheLoader");
+ assert indClConfigs.get(1).getClassName().equals("org.jboss.cache.loader.bdbje.BdbjeCacheLoader");
+ assert indClConfigs.get(2).getClassName().equals("org.jboss.cache.loader.FileCacheLoader");
+
+ }
+
+ public void testSingletonStoreDisaled() throws Exception
+ {
+ String xml =
+ " <loaders passivation=\"true\" shared=\"true\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.JDBCCacheLoader\" async=\"true\" fetchPersistentState=\"true\"\n" +
+ " ignoreModifications=\"true\" purgeOnStartup=\"true\">\n" +
+ " <singletonStore enabled=\"false\" class=\"org.jboss.cache.loader.SingletonStoreCacheLoader\">\n" +
+ " <properties>\n" +
+ " pushStateWhenCoordinator=some\n" +
+ " pushStateWhenCoordinatorTimeout=cus\n" +
+ " </properties>\n" +
+ " </singletonStore>\n" +
+ " </loader>\n" +
+ " </loaders>";
+ CacheLoaderConfig clc = getCacheLoaderConfig(xml);
+ CacheLoaderConfig.IndividualCacheLoaderConfig icl = clc.getFirstCacheLoaderConfig();
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig singletonStoreConfig = icl.getSingletonStoreConfig();
+ assert singletonStoreConfig != null;
+ assert !singletonStoreConfig.isSingletonStoreEnabled();
+ assert singletonStoreConfig.getSingletonStoreClass().equals("org.jboss.cache.loader.SingletonStoreCacheLoader");
+ assert singletonStoreConfig.getProperties().size() == 2;
+ assert singletonStoreConfig.getProperties().get("pushStateWhenCoordinator").equals("some");
+ assert singletonStoreConfig.getProperties().get("pushStateWhenCoordinatorTimeout").equals("cus");
+
+ }
+
+ private CacheLoaderConfig getCacheLoaderConfig(String xmlStr)
+ throws Exception
+ {
Element element = XmlConfigHelper.stringToElement(xmlStr);
- CacheLoaderConfig config = parser.parseCacheLoadersElement(element);
- assert config.getPreload().length() == 0;
+ return parser.parseLoadersElement(element);
}
-
}
Added: core/trunk/src/test/java/org/jboss/cache/config/parsing/JGroupsStackParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/JGroupsStackParserTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/JGroupsStackParserTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -0,0 +1,77 @@
+package org.jboss.cache.config.parsing;
+
+import org.testng.annotations.Test;
+import org.w3c.dom.Element;
+
+/**
+ * Tester class for {@link org.jboss.cache.config.parsing.JGroupsStackParser}
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 3.0
+ */
+@Test(groups = "unit")
+public class JGroupsStackParserTest
+{
+ private JGroupsStackParser parser = new JGroupsStackParser();
+
+ public void testSimpleParse() throws Exception
+ {
+ String xml =
+ "<jgroupsConfig>\n" +
+ "<UDP mcast_addr=\"228.10.10.10\"\n" +
+ " mcast_port=\"45588\"\n" +
+ " tos=\"8\"\n" +
+ " ucast_recv_buf_size=\"20000000\"\n" +
+ " ucast_send_buf_size=\"640000\"\n" +
+ " mcast_recv_buf_size=\"25000000\"\n" +
+ " mcast_send_buf_size=\"640000\"\n" +
+ " loopback=\"false\"\n" +
+ " discard_incompatible_packets=\"true\"\n" +
+ " max_bundle_size=\"64000\"\n" +
+ " max_bundle_timeout=\"30\"\n" +
+ " use_incoming_packet_handler=\"true\"\n" +
+ " ip_ttl=\"2\"\n" +
+ " enable_bundling=\"false\"\n" +
+ " enable_diagnostics=\"true\"\n" +
+ " use_concurrent_stack=\"true\"\n" +
+ " thread_naming_pattern=\"pl\"\n" +
+ " thread_pool.enabled=\"true\"\n" +
+ " thread_pool.min_threads=\"1\"\n" +
+ " thread_pool.max_threads=\"25\"\n" +
+ " thread_pool.keep_alive_time=\"30000\"\n" +
+ " thread_pool.queue_enabled=\"true\"\n" +
+ " thread_pool.queue_max_size=\"10\"\n" +
+ " thread_pool.rejection_policy=\"Run\"\n" +
+ " oob_thread_pool.enabled=\"true\"\n" +
+ " oob_thread_pool.min_threads=\"1\"\n" +
+ " oob_thread_pool.max_threads=\"4\"\n" +
+ " oob_thread_pool.keep_alive_time=\"10000\"\n" +
+ " oob_thread_pool.queue_enabled=\"true\"\n" +
+ " oob_thread_pool.queue_max_size=\"10\"\n" +
+ " oob_thread_pool.rejection_policy=\"Run\"/>\n" +
+ " <PING timeout=\"2000\" num_initial_members=\"3\"/>\n" +
+ " <MERGE2 max_interval=\"30000\" min_interval=\"10000\"/>\n" +
+ " <FD_SOCK/>\n" +
+ " <FD timeout=\"10000\" max_tries=\"5\" shun=\"true\"/>\n" +
+ " <VERIFY_SUSPECT timeout=\"1500\"/>\n" +
+ " <pbcast.NAKACK max_xmit_size=\"60000\"\n" +
+ " use_mcast_xmit=\"false\" gc_lag=\"0\"\n" +
+ " retransmit_timeout=\"300,600,1200,2400,4800\"\n" +
+ " discard_delivered_msgs=\"true\"/>\n" +
+ " <UNICAST timeout=\"300,600,1200,2400,3600\"/>\n" +
+ " <pbcast.STABLE stability_delay=\"1000\" desired_avg_gossip=\"50000\"\n" +
+ " max_bytes=\"400000\"/>\n" +
+ " <pbcast.GMS print_local_addr=\"true\" join_timeout=\"5000\"\n" +
+ " join_retry_timeout=\"2000\" shun=\"false\"\n" +
+ " view_bundling=\"true\" view_ack_collection_timeout=\"5000\"/>\n" +
+ " <FRAG2 frag_size=\"60000\"/>\n" +
+ " <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
+ " <pbcast.FLUSH timeout=\"0\"/>\n" +
+ "</jgroupsConfig>";
+ Element element = XmlConfigHelper.stringToElement(xml);
+ String result = parser.parseClusterConfigXml(element);
+ assert result.indexOf("ucast_recv_buf_size=20000000") > 0;
+ assert result.indexOf("num_initial_members=3") > 0;
+ assert result.indexOf("min_interval=10000") > 0;
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -224,4 +224,18 @@
assert interceptorConfigs.get(3).getBeforeClass().equals("org.jboss.cache.interceptors.CallInterceptor");
assert interceptorConfigs.get(4).getAfterClass().equals("org.jboss.cache.interceptors.CallInterceptor");
}
+
+ public void testSingletonStore()
+ {
+ CacheLoaderConfig.IndividualCacheLoaderConfig clc = config.getCacheLoaderConfig().getFirstCacheLoaderConfig();
+ assert clc != null;
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig singlStoreConf = clc.getSingletonStoreConfig();
+ assert singlStoreConf != null;
+ assert singlStoreConf.isSingletonStoreEnabled();
+ assert singlStoreConf.getSingletonStoreClass().equals("org.jboss.cache.loader.SingletonStoreCacheLoader");
+ assert singlStoreConf.getProperties().size() == 2;
+ assert singlStoreConf.getProperties().get("pushStateWhenCoordinator").equals("true");
+ assert singlStoreConf.getProperties().get("pushStateWhenCoordinatorTimeout").equals("20000");
+
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,7 +11,7 @@
import static org.testng.AssertJUnit.fail;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,7 +11,7 @@
import static org.testng.AssertJUnit.fail;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -8,7 +8,7 @@
import static org.testng.AssertJUnit.assertEquals;
-import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -10,7 +10,7 @@
import static org.testng.AssertJUnit.assertTrue;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -10,7 +10,7 @@
import static org.testng.AssertJUnit.assertTrue;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -8,7 +8,7 @@
import static org.testng.AssertJUnit.fail;
-import org.jboss.cache.config.parsing.EvictionElementParser;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -3,9 +3,12 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManager;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.interceptors.EvictionInterceptor;
import org.jboss.cache.util.TestingUtil;
@@ -55,30 +58,31 @@
private EvictionConfig buildEvictionConfig() throws Exception
{
- String xml = " <attribute name=\"EvictionPolicyConfig\">\n" +
- " <config>\n" +
- " <attribute name=\"wakeUpIntervalSeconds\">1</attribute>\n" +
- " <!-- Name of the DEFAULT eviction policy class.-->\n" +
- " <attribute name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n" +
- " <region name=\"/_default_\">\n" +
- " <attribute name=\"maxNodes\">10</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">0</attribute>\n" +
- " <attribute name=\"maxAgeSeconds\">0</attribute>\n" +
- " </region>\n" +
- " <region name=\"/testingRegion\">\n" +
- " <attribute name=\"maxNodes\">10</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">0</attribute>\n" +
- " <attribute name=\"maxAgeSeconds\">0</attribute>\n" +
- " </region>\n" +
- " <region name=\"/timeBased\">\n" +
- " <attribute name=\"maxNodes\">10</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">1</attribute>\n" +
- " <attribute name=\"maxAgeSeconds\">1</attribute>\n" +
- " </region>\n" +
- " </config>\n" +
- " </attribute>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseEvictionConfig(element);
+ EvictionConfig result = new EvictionConfig("org.jboss.cache.eviction.LRUPolicy");
+ result.setWakeupInterval(1000);
+
+ LRUConfiguration lruConfiguration = new LRUConfiguration();
+ lruConfiguration.setMaxNodes(10);
+ lruConfiguration.setTimeToLive(0);
+ lruConfiguration.setMaxAge(0);
+ EvictionRegionConfig erConfig1 = new EvictionRegionConfig(RegionManager.DEFAULT_REGION, lruConfiguration);
+
+ LRUConfiguration lruConfiguration2 = new LRUConfiguration();
+ lruConfiguration2.setMaxNodes(10);
+ lruConfiguration2.setTimeToLive(0);
+ lruConfiguration2.setMaxAge(0);
+ EvictionRegionConfig erConfig2 = new EvictionRegionConfig(Fqn.fromString("/testingRegion"), lruConfiguration2);
+
+ LRUConfiguration lruConfiguration3 = new LRUConfiguration();
+ lruConfiguration3.setMaxNodes(10);
+ lruConfiguration3.setTimeToLive(1000);
+ lruConfiguration3.setMaxAge(1000);
+ EvictionRegionConfig erConfig3 = new EvictionRegionConfig(Fqn.fromString("/timeBased"), lruConfiguration3);
+
+ result.getEvictionRegionConfigs().add(erConfig1);
+ result.getEvictionRegionConfigs().add(erConfig2);
+ result.getEvictionRegionConfigs().add(erConfig3);
+ return result;
}
@AfterMethod(alwaysRun = true)
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -31,7 +31,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
@@ -51,18 +51,18 @@
@Test(groups = {"functional"})
public class ProgrammaticLRUPolicyTest
{
- CacheSPI<Object, Object> cache_;
- int wakeupIntervalMillis_ = 0;
+ CacheSPI<Object, Object> cache;
+ int wakeupIntervalMillis = 0;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
initCaches();
- wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
- log("wakeupInterval is " + wakeupIntervalMillis_);
- if (wakeupIntervalMillis_ < 0)
+ wakeupIntervalMillis = cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
+ log("wakeupInterval is " + wakeupIntervalMillis);
+ if (wakeupIntervalMillis < 0)
{
- fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
+ fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis);
}
}
@@ -71,35 +71,33 @@
{
Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
CacheFactory<Object, Integer> instance = new DefaultCacheFactory();
- cache_ = (CacheSPI) instance.createCache(conf, false);
+ cache = (CacheSPI) instance.createCache(conf, false);
conf.getEvictionConfig().setWakeupIntervalSeconds(5);
- cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache_.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
+ cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache_.create();
- cache_.start();
+ cache.create();
+ cache.start();
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache_.stop();
+ cache.stop();
}
private void addStringBasedRegion() throws Exception
{
- // region name is ignored here.
- String xml = "<region name=\"/dummy\">" +
- "<attribute name=\"maxNodes\">10000</attribute>" +
- "<attribute name=\"timeToLiveSeconds\">4</attribute>" +
- "</region>";
- Element element = XmlConfigHelper.stringToElement(xml);
- RegionManager regionManager = cache_.getRegionManager();
- EvictionConfig topConfig = cache_.getConfiguration().getEvictionConfig();
- EvictionRegionConfig erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element, topConfig.getDefaultEvictionPolicyClass(), topConfig.getDefaultEventQueueSize());
+ LRUConfiguration lruConfig = new LRUConfiguration();
+ lruConfig.setMaxNodes(1000);
+ lruConfig.setTimeToLive(4000);
+ EvictionRegionConfig regConfig = new EvictionRegionConfig(Fqn.fromString("/dummy"), lruConfig);
+
+ RegionManager regionManager = cache.getRegionManager();
+ EvictionConfig topConfig = cache.getConfiguration().getEvictionConfig();
regionManager.setEvictionConfig(topConfig);
// Fqn is the region name
- regionManager.getRegion("/programmatic", true).setEvictionPolicy(erc.getEvictionPolicyConfig());
+ regionManager.getRegion("/programmatic", true).setEvictionPolicy(regConfig.getEvictionPolicyConfig());
}
public void testStringBasedFqnEviction() throws Exception
@@ -111,36 +109,24 @@
{
String str = rootStr + i;
Fqn<String> fqn = Fqn.fromString(str);
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
- String val = (String) cache_.get(rootStr + "3", rootStr + "3");
+ String val = (String) cache.get(rootStr + "3", rootStr + "3");
assertNotNull("DataNode should be empty ", val);
- System.out.println(cache_.toString());
- TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 500);
- System.out.println(cache_.toString());
- val = (String) cache_.get(rootStr + "3", rootStr + "3");
+ System.out.println(cache.toString());
+ TestingUtil.sleepThread(2 * wakeupIntervalMillis + 500);
+ System.out.println(cache.toString());
+ val = (String) cache.get(rootStr + "3", rootStr + "3");
assertNull("DataNode should be empty ", val);
}
private void addObjectBasedRegion() throws Exception
{
- // region name is ignored here.
- String xml = "<region name=\"/dummy\">" +
- "<attribute name=\"maxNodes\">10000</attribute>" +
- "<attribute name=\"timeToLiveSeconds\">4</attribute>" +
- "</region>";
- Element element = XmlConfigHelper.stringToElement(xml);
- RegionManager regionManager = cache_.getRegionManager();
- EvictionConfig topEC = cache_.getConfiguration().getEvictionConfig();
- EvictionRegionConfig erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element,
- topEC.getDefaultEvictionPolicyClass(),
- topEC.getDefaultEventQueueSize());
- // Fqn is the region name
- Integer ii = 1;
- Fqn fqn = Fqn.fromElements(ii);
- regionManager.getRegion(fqn, true).setEvictionPolicy(erc.getEvictionPolicyConfig());
+ LRUConfiguration lruConfig = new LRUConfiguration(4000, 1000);
+ RegionManager regionManager = cache.getRegionManager();
+ regionManager.getRegion(Fqn.fromElements(1), true).setEvictionPolicy(lruConfig);
}
public void testObjectBasedFqnEviction1() throws Exception
@@ -155,7 +141,7 @@
Fqn fqn = Fqn.fromElements(rootStr, in);
try
{
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
catch (Exception e)
{
@@ -168,7 +154,7 @@
Fqn fqn = Fqn.fromElements(rootStr, in);
try
{
- String val = (String) cache_.get(fqn, in);
+ String val = (String) cache.get(fqn, in);
assertNull("DataNode should be empty ", val);
}
catch (Exception e)
@@ -177,13 +163,13 @@
fail("Failed to get" + e);
}
- System.out.println(cache_.toString());
- TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 500);
- System.out.println(cache_.toString());
+ System.out.println(cache.toString());
+ TestingUtil.sleepThread(2 * wakeupIntervalMillis + 500);
+ System.out.println(cache.toString());
try
{
- String val = (String) cache_.get(fqn, in);
+ String val = (String) cache.get(fqn, in);
assertNull("DataNode should be empty ", val);
}
catch (Exception e)
@@ -205,7 +191,7 @@
Fqn<Object> fqn = Fqn.fromRelativeElements(rootfqn, in);
try
{
- cache_.put(fqn, in, in);
+ cache.put(fqn, in, in);
}
catch (Exception e)
{
@@ -218,7 +204,7 @@
{
Integer in = 3;
Fqn<Object> fqn = Fqn.fromRelativeElements(rootfqn, in);
- Object val = cache_.get(fqn, in);
+ Object val = cache.get(fqn, in);
assertNotNull("DataNode should be empty ", val);
}
catch (Exception e)
@@ -227,14 +213,14 @@
fail("Failed to get" + e);
}
- System.out.println(cache_.toString());
- TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 500);
- System.out.println(cache_.toString());
+ System.out.println(cache.toString());
+ TestingUtil.sleepThread(2 * wakeupIntervalMillis + 500);
+ System.out.println(cache.toString());
try
{
Integer in = 3;
Fqn<Object> fqn = Fqn.fromRelativeElements(rootfqn, in);
- Object val = cache_.get(fqn, in);
+ Object val = cache.get(fqn, in);
assertNull("DataNode should be empty ", val);
}
catch (Exception e)
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -6,7 +6,7 @@
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
@@ -103,47 +103,6 @@
assertNotSame("Region ", DEFAULT_REGION, region.getFqn());
}
- public void testConfigureWithXML() throws Exception
- {
- // test the new style configuration
- String xml = "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.LFUPolicy\">" +
- "<attribute name=\"minNodes\">10</attribute>" +
- "<attribute name=\"maxNodes\">20</attribute>" +
- "</region>";
- Element element = XmlConfigHelper.stringToElement(xml);
- RegionManager regionManager = new RegionManager();
- regionManager.setUsingEvictions(true);
- EvictionRegionConfig erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element, null, EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
- Region region = regionManager.getRegion(erc.getRegionFqn(), true);
- region.setEvictionPolicy(erc.getEvictionPolicyConfig());
-
- assertTrue(region.getEvictionPolicy() instanceof LFUPolicy);
- assertTrue(region.getEvictionPolicyConfig() instanceof LFUConfiguration);
- LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
- assertEquals(20, config.getMaxNodes());
- assertEquals(10, config.getMinNodes());
- assertEquals(Fqn.fromString("/test/"), region.getFqn());
-
- // test the 1.2.x style configuration
- xml = "<region name=\"abc\">" +
- "<attribute name=\"minNodes\">10</attribute>" +
- "<attribute name=\"maxNodes\">20</attribute>" +
- "</region>";
- element = XmlConfigHelper.stringToElement(xml);
- erc = XmlConfigurationParserOld.parseEvictionRegionConfig(element, "org.jboss.cache.eviction.LFUPolicy", EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
- regionManager = new RegionManager();
- regionManager.setUsingEvictions(true);
- region = regionManager.getRegion(erc.getRegionFqn(), true);
- region.setEvictionPolicy(erc.getEvictionPolicyConfig());
-
- assertTrue(region.getEvictionPolicy() instanceof LFUPolicy);
- assertTrue(region.getEvictionPolicyConfig() instanceof LFUConfiguration);
- config = (LFUConfiguration) region.getEvictionPolicyConfig();
- assertEquals(20, config.getMaxNodes());
- assertEquals(10, config.getMinNodes());
- assertEquals(Fqn.fromString("/abc/"), region.getFqn());
- }
-
public void testRegionOrdering() throws Exception
{
Fqn A_B_C_D_E = Fqn.fromString("/a/b/c/d/e/");
Modified: core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -6,8 +6,9 @@
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
import org.jboss.cache.interceptors.*;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.util.TestingUtil;
@@ -89,24 +90,20 @@
protected CacheLoaderConfig getCacheLoaderConfig(boolean pasv, boolean fetchPersistentState) throws Exception
{
- String xml = " <config>\n" +
- " \n" +
- " <passivation>" + pasv + "</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- " <properties>\n" +
- " location=/tmp\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ String xmlStr =
+ " <loaders passivation=\"" + pasv + "\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" fetchPersistentState=\"" + fetchPersistentState + "\"\n" +
+ " ignoreModifications=\"false\">\n" +
+ " <properties>\n" +
+ " location=/tmp\n" +
+ " </properties>\n" +
+ " </loader>\n" +
+ " </loaders>";
+
+ Element element = XmlConfigHelper.stringToElement(xmlStr);
+ LoadersElementParser parser = new LoadersElementParser();
+ return parser.parseLoadersElement(element);
}
public void testSharedCacheLoaderConfig() throws Exception
@@ -386,15 +383,13 @@
public void testBuddyReplicationOptLocking() throws Exception
{
- String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- "<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
- " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
- " <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
-
- xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
- xmlString += "</config>";
- Element element = XmlConfigHelper.stringToElement(xmlString);
- BuddyReplicationConfig brc = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlStr =
+ " <buddy enabled=\"true\" buddyPoolName=\"buddyPoolName\" buddyCommunicationTimeout=\"600000\">\n" +
+ " <dataGravitation auto=\"true\" removeOnFind=\"true\" searchBackupTrees=\"true\"/>\n" +
+ " </buddy>";
+ Element element = XmlConfigHelper.stringToElement(xmlStr);
+ BuddyElementParser parser = new BuddyElementParser();
+ BuddyReplicationConfig brc = parser.parseBuddyElement(element);
cache.getConfiguration().setBuddyReplicationConfig(brc);
cache.getConfiguration().setCacheMode("REPL_SYNC");
@@ -425,17 +420,11 @@
public void testBuddyReplicationPessLocking() throws Exception
{
- String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- "<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
- " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
- " <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
-
- xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
- xmlString += "</config>";
- Element element = XmlConfigHelper.stringToElement(xmlString);
- BuddyReplicationConfig brc = XmlConfigurationParserOld.parseBuddyReplicationConfig(element);
+ String xmlStr = "<buddy enabled=\"true\" buddyPoolName=\"buddyPoolName\" buddyCommunicationTimeout=\"600000\"/>";
+ Element element = XmlConfigHelper.stringToElement(xmlStr);
+ BuddyElementParser parser = new BuddyElementParser();
+ BuddyReplicationConfig brc = parser.parseBuddyElement(element);
cache.getConfiguration().setBuddyReplicationConfig(brc);
-
cache.getConfiguration().setCacheMode("REPL_SYNC");
cache.create();// initialise various subsystems such as BRManager
InterceptorChain chain = getInterceptorChainFactory(cache).buildInterceptorChain();
Modified: core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,9 +11,10 @@
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.ParsedAttributes;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.transaction.TransactionSetup;
import org.jgroups.conf.XmlConfigurator;
@@ -78,34 +79,29 @@
return c;
}
- public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared) throws Exception
+ public static CacheLoaderConfig buildSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass,
+ String properties, boolean async, boolean fetchPersistentState,
+ boolean shared, boolean purgeOnStartup, boolean ignoreModifications) throws Exception
{
- return getSingleCacheLoaderConfig(preload, cacheloaderClass, properties, async, fetchPersistentState, shared, false);
+ String xmlStr =
+ " <loaders passivation=\"" + passivation + "\" shared=\"" + shared + "\">\n" +
+ " <loader class=\""+ cacheloaderClass + "\" async=\"" + async + "\" fetchPersistentState=\"" + fetchPersistentState + "\"\n" +
+ " purgeOnStartup=\"" + purgeOnStartup + "\" ignoreModifications=\"" + ignoreModifications + "\">\n" +
+ " <properties>" + properties + "</properties>\n" +
+ " </loader>\n" +
+ " </loaders>";
+ Element xmlElement = XmlConfigHelper.stringToElement(xmlStr);
+ LoadersElementParser parser = new LoadersElementParser();
+ CacheLoaderConfig clConfig = parser.parseLoadersElement(xmlElement);
+ clConfig.setPreload(preload);
+ return clConfig;
}
- public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
+ public static CacheLoaderConfig.IndividualCacheLoaderConfig buildIndividualCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean purgeOnStartup, boolean ignoreModifications) throws Exception
{
- return getSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties, async, fetchPersistentState, shared, purgeOnStartup);
+ return buildSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties, async, fetchPersistentState, false, purgeOnStartup, ignoreModifications).getFirstCacheLoaderConfig();
}
- protected static CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
- {
- String xml = "<config>\n" +
- "<passivation>" + passivation + "</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>" + async + "</async>\n" +
- "<shared>" + shared + "</shared>\n" +
- "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
- }
-
/**
* Helper method that takes a <b>JGroups</b> configuration file and creates an old-style JGroups config {@link String} that can be used
* in {@link org.jboss.cache.config.Configuration#setClusterConfig(String)}. Note that expressions
@@ -127,7 +123,6 @@
tmp = tmp.replace("${jgroups.udp.ip_ttl:2}", "2");
System.out.println("config string: " + tmp);
return tmp;
-
}
catch (Exception e)
{
@@ -176,7 +171,7 @@
return erc;
}
- private static class UnitTestXmlConfigurationParser extends XmlConfigurationParserOld
+ private static class UnitTestXmlConfigurationParser extends XmlConfigurationParser2x
{
public Configuration parseFile(String filename, CacheMode mode)
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -13,17 +13,15 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.util.internals.ReplicationListener;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
import javax.transaction.RollbackException;
import javax.transaction.Transaction;
@@ -907,20 +905,8 @@
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
- String xml = " <config>\n" +
- " <shared>shared</shared>\n" +
- " <passivation>false</passivation>\n" +
- " <preload></preload>\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.DummySharedInMemoryCacheLoader</class>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, "",
+ "org.jboss.cache.loader.DummySharedInMemoryCacheLoader", "", false, false, false, false, false);
}
protected void assertHasBeenInvalidated(Node n, String message)
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -40,6 +40,7 @@
import org.jgroups.JChannelFactory;
import org.jgroups.jmx.JChannelFactoryMBean;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
import org.w3c.dom.Element;
import javax.management.MBeanServerInvocationHandler;
@@ -57,6 +58,7 @@
* @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
* @version $Revision$
*/
+@Test(groups = "functional")
public class LegacyConfigurationTest extends CacheJmxWrapperTestBase
{
@SuppressWarnings({"deprecation", "unchecked"})
@@ -253,133 +255,123 @@
protected static Element getBuddyReplicationConfig() throws Exception
{
- String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- " <buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
- " <buddyLocatorClass>org.jboss.cache.buddyreplication.TestBuddyLocator</buddyLocatorClass>\n" +
- " <buddyLocatorProperties>numBuddies = 2</buddyLocatorProperties>\n" +
- " <buddyPoolName>testpool</buddyPoolName>" +
- " <autoDataGravitation>false</autoDataGravitation>\n" +
- " <dataGravitationRemoveOnFind>false</dataGravitationRemoveOnFind>\n" +
- " <dataGravitationSearchBackupTrees>false</dataGravitationSearchBackupTrees>" +
- "</config>";
- return XmlConfigHelper.stringToElement(xmlString);
+
+ String xmlStr =
+ " <buddy enabled=\"true\" buddyPoolName=\"testpool\" buddyCommunicationTimeout=\"600000\">\n" +
+ " <dataGravitation auto=\"false\" removeOnFind=\"false\" searchBackupTrees=\"false\"/>\n" +
+ " <buddyLocator class=\"org.jboss.cache.buddyreplication.TestBuddyLocator\">\n" +
+ " <properties>\n" +
+ " numBuddies = 2\n" +
+ " </properties>\n" +
+ " </buddyLocator>\n" +
+ " </buddy>";
+ return XmlConfigHelper.stringToElement(xmlStr);
}
protected static Element getCacheLoaderConfig() throws Exception
{
- String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload>/foo</preload>\n" +
- "<shared>true</shared>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- "<properties>" +
- " location=/tmp\n" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<ignoreModifications>true</ignoreModifications>\n" +
- "<purgeOnStartup>true</purgeOnStartup>\n" +
- "<singletonStore>" +
- "<enabled>true</enabled>" +
- "</singletonStore>" +
- "</cacheloader>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.jdbm.JdbmCacheLoader</class>\n" +
- "<properties>" +
- " location=/home/bstansberry\n" +
- "</properties>\n" +
- "<async>true</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<ignoreModifications>false</ignoreModifications>\n" +
- "<purgeOnStartup>false</purgeOnStartup>\n" +
- "<singletonStore>" +
- "<enabled>false</enabled>" +
- "</singletonStore>" +
- "</cacheloader>\n" +
- "</config>";
- return XmlConfigHelper.stringToElement(xml);
+ String xmlStr =
+ " <loaders passivation=\"false\" shared=\"true\">\n" +
+ " <preload>\n" +
+ " <node fqn=\"/foo\"/>\n" +
+ " </preload>\n" +
+ " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" async=\"false\" fetchPersistentState=\"true\"\n" +
+ " ignoreModifications=\"true\" purgeOnStartup=\"true\">\n" +
+ " <properties>\n" +
+ " location=/tmp\n " +
+ " </properties>\n" +
+ " <singletonStore enabled=\"true\" /> \n" +
+ " </loader>\n" +
+ " <loader class=\"org.jboss.cache.loader.jdbm.JdbmCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
+ " ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
+ " <properties>\n" +
+ " location=/home/bstansberry\n" +
+ " </properties>\n" +
+ " <singletonStore enabled=\"false\" /> \n" +
+ " </loader>\n" +
+ " </loaders>";
+ return XmlConfigHelper.stringToElement(xmlStr);
}
protected static Element getEvictionPolicyConfig() throws Exception
{
- String xml = "<config>\n" +
- "<attribute name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
- "<attribute name=\"eventQueueSize\">20000</attribute>\n" +
- "<attribute name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n" +
- "<region name=\"/_default_\" eventQueueSize=\"1000\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">1000</attribute>\n" +
- "</region>\n" +
- "<region name=\"/org/jboss/data\" policyClass=\"org.jboss.cache.eviction.FIFOPolicy\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- "</region>\n" +
- "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
- " <attribute name=\"maxNodes\">10000</attribute>\n" +
- "</region>\n" +
- "<region name=\"/maxAgeTest/\">\n" +
- " <attribute name=\"maxNodes\">10000</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
- " <attribute name=\"maxAgeSeconds\">10</attribute>\n" +
- "</region>\n" +
- " </config>\n";
- return XmlConfigHelper.stringToElement(xml);
+
+ String xmlStr =
+ " <eviction wakeUpInterval=\"5000\">\n" +
+ " <defaults policyClass=\"org.jboss.cache.eviction.LRUPolicy\" eventQueueSize=\"20000\"/>\n" +
+ " <root eventQueueSize=\"1000\">\n" +
+ " <attribute name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute name=\"timeToLive\">1000000</attribute>\n" +
+ " </root>\n" +
+ "<region name=\"/org/jboss/data\" policyClass=\"org.jboss.cache.eviction.FIFOPolicy\">\n" +
+ " <attribute name=\"maxNodes\">5000</attribute>\n" +
+ "</region>\n" +
+ "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
+ " <attribute name=\"maxNodes\">10000</attribute>\n" +
+ "</region>\n" +
+ "<region name=\"/maxAgeTest/\">\n" +
+ " <attribute name=\"maxNodes\">10000</attribute>\n" +
+ " <attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
+ " <attribute name=\"maxAgeSeconds\">10</attribute>\n" +
+ "</region>\n" +
+ " </eviction>";
+ return XmlConfigHelper.stringToElement(xmlStr);
}
protected static Element getClusterConfig() throws Exception
{
String xml =
- "<config>\n" +
- " <UDP mcast_addr=\"228.10.10.10\"\n" +
- " mcast_port=\"45588\"\n" +
- " tos=\"8\"\n" +
- " ucast_recv_buf_size=\"20000000\"\n" +
- " ucast_send_buf_size=\"640000\"\n" +
- " mcast_recv_buf_size=\"25000000\"\n" +
- " mcast_send_buf_size=\"640000\"\n" +
- " loopback=\"false\"\n" +
- " discard_incompatible_packets=\"true\"\n" +
- " max_bundle_size=\"64000\"\n" +
- " max_bundle_timeout=\"30\"\n" +
- " use_incoming_packet_handler=\"true\"\n" +
- " ip_ttl=\"2\"\n" +
- " enable_bundling=\"false\"\n" +
- " enable_diagnostics=\"true\"\n" +
- " use_concurrent_stack=\"true\"\n" +
- " thread_naming_pattern=\"pl\"\n" +
- " thread_pool.enabled=\"true\"\n" +
- " thread_pool.min_threads=\"1\"\n" +
- " thread_pool.max_threads=\"25\"\n" +
- " thread_pool.keep_alive_time=\"30000\"\n" +
- " thread_pool.queue_enabled=\"true\"\n" +
- " thread_pool.queue_max_size=\"10\"\n" +
- " thread_pool.rejection_policy=\"Run\"\n" +
- " oob_thread_pool.enabled=\"true\"\n" +
- " oob_thread_pool.min_threads=\"1\"\n" +
- " oob_thread_pool.max_threads=\"4\"\n" +
- " oob_thread_pool.keep_alive_time=\"10000\"\n" +
- " oob_thread_pool.queue_enabled=\"true\"\n" +
- " oob_thread_pool.queue_max_size=\"10\"\n" +
- " oob_thread_pool.rejection_policy=\"Run\"/>\n" +
- " <PING timeout=\"2000\" num_initial_members=\"3\"/>\n" +
- " <MERGE2 max_interval=\"30000\" min_interval=\"10000\"/>\n" +
- " <FD_SOCK/>\n" +
- " <FD timeout=\"10000\" max_tries=\"5\" shun=\"true\"/>\n" +
- " <VERIFY_SUSPECT timeout=\"1500\"/>\n" +
- " <pbcast.NAKACK max_xmit_size=\"60000\"\n" +
- " use_mcast_xmit=\"false\" gc_lag=\"0\"\n" +
- " retransmit_timeout=\"300,600,1200,2400,4800\"\n" +
- " discard_delivered_msgs=\"true\"/>\n" +
- " <UNICAST timeout=\"300,600,1200,2400,3600\"/>\n" +
- " <pbcast.STABLE stability_delay=\"1000\" desired_avg_gossip=\"50000\"\n" +
- " max_bytes=\"400000\"/>\n" +
- " <pbcast.GMS print_local_addr=\"true\" join_timeout=\"5000\"\n" +
- " join_retry_timeout=\"2000\" shun=\"false\"\n" +
- " view_bundling=\"true\" view_ack_collection_timeout=\"5000\"/>\n" +
- " <FRAG2 frag_size=\"60000\"/>\n" +
- " <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
- " <pbcast.FLUSH timeout=\"0\"/>\n" +
- "</config>";
+ "<jgroupsConfig>\n" +
+ "<UDP mcast_addr=\"228.10.10.10\"\n" +
+ " mcast_port=\"45588\"\n" +
+ " tos=\"8\"\n" +
+ " ucast_recv_buf_size=\"20000000\"\n" +
+ " ucast_send_buf_size=\"640000\"\n" +
+ " mcast_recv_buf_size=\"25000000\"\n" +
+ " mcast_send_buf_size=\"640000\"\n" +
+ " loopback=\"false\"\n" +
+ " discard_incompatible_packets=\"true\"\n" +
+ " max_bundle_size=\"64000\"\n" +
+ " max_bundle_timeout=\"30\"\n" +
+ " use_incoming_packet_handler=\"true\"\n" +
+ " ip_ttl=\"2\"\n" +
+ " enable_bundling=\"false\"\n" +
+ " enable_diagnostics=\"true\"\n" +
+ " use_concurrent_stack=\"true\"\n" +
+ " thread_naming_pattern=\"pl\"\n" +
+ " thread_pool.enabled=\"true\"\n" +
+ " thread_pool.min_threads=\"1\"\n" +
+ " thread_pool.max_threads=\"25\"\n" +
+ " thread_pool.keep_alive_time=\"30000\"\n" +
+ " thread_pool.queue_enabled=\"true\"\n" +
+ " thread_pool.queue_max_size=\"10\"\n" +
+ " thread_pool.rejection_policy=\"Run\"\n" +
+ " oob_thread_pool.enabled=\"true\"\n" +
+ " oob_thread_pool.min_threads=\"1\"\n" +
+ " oob_thread_pool.max_threads=\"4\"\n" +
+ " oob_thread_pool.keep_alive_time=\"10000\"\n" +
+ " oob_thread_pool.queue_enabled=\"true\"\n" +
+ " oob_thread_pool.queue_max_size=\"10\"\n" +
+ " oob_thread_pool.rejection_policy=\"Run\"/>\n" +
+ " <PING timeout=\"2000\" num_initial_members=\"3\"/>\n" +
+ " <MERGE2 max_interval=\"30000\" min_interval=\"10000\"/>\n" +
+ " <FD_SOCK/>\n" +
+ " <FD timeout=\"10000\" max_tries=\"5\" shun=\"true\"/>\n" +
+ " <VERIFY_SUSPECT timeout=\"1500\"/>\n" +
+ " <pbcast.NAKACK max_xmit_size=\"60000\"\n" +
+ " use_mcast_xmit=\"false\" gc_lag=\"0\"\n" +
+ " retransmit_timeout=\"300,600,1200,2400,4800\"\n" +
+ " discard_delivered_msgs=\"true\"/>\n" +
+ " <UNICAST timeout=\"300,600,1200,2400,3600\"/>\n" +
+ " <pbcast.STABLE stability_delay=\"1000\" desired_avg_gossip=\"50000\"\n" +
+ " max_bytes=\"400000\"/>\n" +
+ " <pbcast.GMS print_local_addr=\"true\" join_timeout=\"5000\"\n" +
+ " join_retry_timeout=\"2000\" shun=\"false\"\n" +
+ " view_bundling=\"true\" view_ack_collection_timeout=\"5000\"/>\n" +
+ " <FRAG2 frag_size=\"60000\"/>\n" +
+ " <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
+ " <pbcast.FLUSH timeout=\"0\"/>\n" +
+ "</jgroupsConfig>";
return XmlConfigHelper.stringToElement(xml);
}
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -6,8 +6,6 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.loader.CacheLoader;
@@ -15,7 +13,6 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
@@ -321,20 +318,8 @@
protected static CacheLoaderConfig getCacheLoaderConfig(String properties) throws Exception
{
- String xml = "<config>\n" +
- "<passivation>true</passivation>\n" +
- "<preload></preload>\n" +
- "<shared>true</shared>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<ignoreModifications>false</ignoreModifications>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "",
+ "org.jboss.cache.loader.FileCacheLoader", properties, false, false, true, false, false);
}
private static void validateHealthyListener(MyListener listener)
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -9,10 +9,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
/**
* Very basic test case that provides methods to create a cache loader config.
@@ -37,19 +35,7 @@
protected CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
{
- String xml = "<config>\n" +
- "<passivation>" + passivation + "</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>" + async + "</async>\n" +
- "<shared>" + shared + "</shared>\n" +
- "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(passivation, preload, cacheloaderClass,
+ properties, async, fetchPersistentState, shared, purgeOnStartup, false);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -3,19 +3,17 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.statetransfer.StateTransferManager;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -204,20 +202,7 @@
protected CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties) throws Exception
{
- String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>false</async>\n" +
- "<shared>false</shared>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<purgeOnStartup>false</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties, false, true, false, false, false);
}
protected Properties getProperties() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -31,7 +31,7 @@
{
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
- // cache.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.jdbm.JdbmCacheLoader",
+ // cache.setCacheLoaderConfiguration(buildSingleCacheLoaderConfig("", "org.jboss.cache.loader.jdbm.JdbmCacheLoader",
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", props, true, false, true));
cache.create();
cache.start();
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -7,9 +7,10 @@
package org.jboss.cache.loader;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -26,6 +27,8 @@
@Test(groups = "functional")
public class CacheLoaderManagerTest extends AbstractCacheLoaderTestBase
{
+ private LoadersElementParser loadersElementParser = new LoadersElementParser();;
+
private CacheLoaderConfig createCacheLoaderCfg(boolean passivation)
{
CacheLoaderConfig cfg = new CacheLoaderConfig();
@@ -128,73 +131,22 @@
public void testSingleCacheLoaderPassivationFromXml() throws Exception
{
- // without async
- String conf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<config><passivation>true</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader></config>";
- CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ CacheLoaderConfig clc = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "", "org.jboss.cache.loader.FileCacheLoader", "location=" + getTempDir(), false, false, false, false, false);
+ CacheLoaderConfig bdbjeCl = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "", "org.jboss.cache.loader.bdbje.BdbjeCacheLoader", "location=" + getTempDir(), false, false, false, false, false);
+ CacheLoaderConfig jdbCl = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "", "org.jboss.cache.loader.JDBCCacheLoader", "location=" + getTempDir(), false, false, false, false, false);
+ clc.getIndividualCacheLoaderConfigs().add(bdbjeCl.getFirstCacheLoaderConfig());
+ clc.getIndividualCacheLoaderConfigs().add(jdbCl.getFirstCacheLoaderConfig());
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
CacheLoader cl = mgr.getCacheLoader();
-
assertEquals(FileCacheLoader.class, cl.getClass());
- // with async
- conf = "<config><passivation>true</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader></config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ clc = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "", "org.jboss.cache.loader.FileCacheLoader", "location=" + getTempDir(), true, false, false, false, false);
+ bdbjeCl = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "", "org.jboss.cache.loader.bdbje.BdbjeCacheLoader", "location=" + getTempDir(), true, false, false, false, false);
+ jdbCl = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "", "org.jboss.cache.loader.JDBCCacheLoader", "location=" + getTempDir(), true, false, false, false, false);
+ clc.getIndividualCacheLoaderConfigs().add(bdbjeCl.getFirstCacheLoaderConfig());
+ clc.getIndividualCacheLoaderConfigs().add(jdbCl.getFirstCacheLoaderConfig());
+
mgr.setConfig(clc, null, null);
cl = mgr.getCacheLoader();
@@ -235,28 +187,10 @@
public void testChainingCacheLoaderFromXml() throws Exception
{
- // async = false
- String conf = "<config><passivation>false</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
-
- CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ CacheLoaderConfig clc = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, "",
+ "org.jboss.cache.loader.FileCacheLoader", "a=b", false, false, false, false, false);
+ clc.addIndividualCacheLoaderConfig(UnitTestCacheConfigurationFactory.buildIndividualCacheLoaderConfig("",
+ "org.jboss.cache.loader.JDBCCacheLoader", "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd", false, false, false, false));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
CacheLoader cl = mgr.getCacheLoader();
@@ -269,29 +203,13 @@
assertEquals(JDBCCacheLoader.class, loaders.get(1).getClass());
// async = true
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
- mgr.setConfig(clc, null, null);
- cl = mgr.getCacheLoader();
+ clc = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, "",
+ "org.jboss.cache.loader.FileCacheLoader", "a=b", false, false, false, false, false);
+ clc.addIndividualCacheLoaderConfig(UnitTestCacheConfigurationFactory.buildIndividualCacheLoaderConfig("",
+ "org.jboss.cache.loader.JDBCCacheLoader", "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd", true, false, false, false));
+ mgr = new CacheLoaderManager();
+ mgr.setConfig(clc, null, null);
+ cl = mgr.getCacheLoader();
assertEquals(ChainingCacheLoader.class, cl.getClass());
assertEquals(2, ((ChainingCacheLoader) cl).getSize());
@@ -364,160 +282,27 @@
mgr.setConfig(cfg, null, null);
}
- public void testConfigurationParsing() throws Exception
- {
-
- String conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>true</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
- CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
- CacheLoaderManager mgr = new CacheLoaderManager();
- mgr.setConfig(clc, null, null);
-
- assertEquals(ChainingCacheLoader.class, mgr.getCacheLoader().getClass());
- assertTrue("Should be true", mgr.isFetchPersistentState());
- assertTrue("Passivation shuld be false", !mgr.isPassivation());
- CacheLoaderConfig c = mgr.getCacheLoaderConfig();
- assertTrue("Should be using a chaining cache loader", c.useChainingCacheLoader());
- assertEquals("/, /blah, /blah2", c.getPreload());
- assertEquals(2, c.getIndividualCacheLoaderConfigs().size());
-
- CacheLoaderConfig.IndividualCacheLoaderConfig icfg = c.getIndividualCacheLoaderConfigs().get(0);
- assertEquals("org.jboss.cache.loader.FileCacheLoader", icfg.getClassName());
- assertTrue("Async shld be false", !icfg.isAsync());
- assertTrue("fetchPersistentState shld be false", !icfg.isFetchPersistentState());
- assertTrue("IgnoreMods should be true", icfg.isIgnoreModifications());
- assertEquals(1, icfg.getProperties().size());
-
- icfg = c.getIndividualCacheLoaderConfigs().get(1);
- assertEquals("org.jboss.cache.loader.JDBCCacheLoader", icfg.getClassName());
- assertTrue("Async shld be true", icfg.isAsync());
- assertTrue("fetchPersistentState shld be true", icfg.isFetchPersistentState());
- assertTrue("IgnoreMods should be false", !icfg.isIgnoreModifications());
- assertEquals(4, icfg.getProperties().size());
-
- // fetch PersistentState shld be false now
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
-
- mgr = new CacheLoaderManager();
- mgr.setConfig(clc, null, null);
-
- assertTrue("Should be false", !mgr.isFetchPersistentState());
-
-
- }
-
public void testSingletonConfiguration() throws Exception
{
- String conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "</config>";
- CacheLoaderConfig clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
- CacheLoaderManager mgr = new CacheLoaderManager();
- mgr.setConfig(clc, null, null);
-
- CacheLoaderConfig.IndividualCacheLoaderConfig iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
- assertNull("Singleton has not been configured", iclc.getSingletonStoreConfig());
-
/************************************************************************************************************/
+ String conf ;
+ CacheLoaderConfig clc;
+ CacheLoaderManager mgr;
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc;
+ conf =
+ "<loaders passivation=\"false\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.DummyInMemoryCacheLoader\">" +
+ " <singletonStore enabled=\"true\"/>\n" +
+ " </loader>"+
+ "</loaders>";
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>false</enabled>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ clc = loadersElementParser.parseLoadersElement(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null, null);
iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
- assertFalse("Singleton is not enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
-
- /************************************************************************************************************/
-
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
- mgr = new MockCacheLoaderManager();
- mgr.setConfig(clc, null, null);
-
- iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
- assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
assertNotNull("Singleton properties should be not null", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
@@ -527,25 +312,14 @@
assertEquals("Singleton pushStateWhenCoordinatorTimeout should be default value", 20000, ssdc.getPushStateWhenCoordinatorTimeout());
/************************************************************************************************************/
-
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <class>org.jboss.cache.loader.CacheLoaderManagerTest$MockSingletonStoreCacheLoader</class>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ conf =
+ "<loaders passivation=\"false\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.DummyInMemoryCacheLoader\">" +
+ " <singletonStore enabled=\"true\" class=\"org.jboss.cache.loader.CacheLoaderManagerTest$MockSingletonStoreCacheLoader\" />\n" +
+ " </loader>"+
+ "</loaders>";
+ clc = loadersElementParser.parseLoadersElement(strToElement(conf));
mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
@@ -559,119 +333,45 @@
/************************************************************************************************************/
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>false</enabled>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ conf =
+ " <loaders passivation=\"true\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.DummyInMemoryCacheLoader\">\n" +
+ " <singletonStore enabled=\"true\">\n" +
+ " <properties>\n" +
+ " pushStateWhenCoordinator=false\n" +
+ " </properties>\n" +
+ " </singletonStore>\n" +
+ " </loader>\n" +
+ " </loaders>";
+ clc = loadersElementParser.parseLoadersElement(strToElement(conf));
mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
-
+
iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
- assertFalse("Singleton is not enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
-
- /************************************************************************************************************/
-
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties></properties>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
- mgr = new MockCacheLoaderManager();
- mgr.setConfig(clc, null, null);
-
- iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
- assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
- assertNotNull("Singleton properties should be defined, but empty", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
- ssdc = ((SingletonStoreCacheLoader) mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
- assertTrue("Singleton pushStateWhenCoordinator should be true", ssdc.isPushStateWhenCoordinator());
-
- /************************************************************************************************************/
-
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties>" +
- " pushStateWhenCoordinator = false" +
- " </properties>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
- mgr = new MockCacheLoaderManager();
- mgr.setConfig(clc, null, null);
-
- iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
- assertNotNull("Singleton has been configured", iclc.getSingletonStoreConfig());
- assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
- assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
assertNotNull("Singleton properties should be defined", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
ssdc = ((SingletonStoreCacheLoader) mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
assertFalse("Singleton pushStateWhenCoordinator should be false", ssdc.isPushStateWhenCoordinator());
/************************************************************************************************************/
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties>" +
- " pushStateWhenCoordinator = true\n" +
- " pushStateWhenCoordinatorTimeout = 5000\n" +
- " </properties>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
- mgr = new MockCacheLoaderManager();
+ conf =
+ " <loaders passivation=\"true\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.DummyInMemoryCacheLoader\">\n" +
+ " <singletonStore enabled=\"true\">\n" +
+ " <properties>\n" +
+ " pushStateWhenCoordinator = true\n" +
+ " pushStateWhenCoordinatorTimeout = 5000\n" +
+ " </properties>\n" +
+ " </singletonStore>\n" +
+ " </loader>\n" +
+ " </loaders>";
+ clc = loadersElementParser.parseLoadersElement(strToElement(conf));
+ mgr = new CacheLoaderManager();
mgr.setConfig(clc, null, null);
iclc = mgr.getCacheLoaderConfig().getFirstCacheLoaderConfig();
@@ -684,25 +384,19 @@
assertEquals("Singleton pushStateWhenCoordinatorTimeout should be default value", 5000, ssdc.getPushStateWhenCoordinatorTimeout());
/************************************************************************************************************/
-
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<shared>true</shared>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ conf =
+ " <loaders passivation=\"false\" shared=\"true\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.DummyInMemoryCacheLoader\">\n" +
+ " <singletonStore enabled=\"true\">\n" +
+ " <properties>\n" +
+ " pushStateWhenCoordinator = true\n" +
+ " pushStateWhenCoordinatorTimeout = 5000\n" +
+ " </properties>\n" +
+ " </singletonStore>\n" +
+ " </loader>\n" +
+ " </loaders>";
+ clc = loadersElementParser.parseLoadersElement(strToElement(conf));
mgr = new CacheLoaderManager();
try
{
@@ -715,26 +409,16 @@
/************************************************************************************************************/
- conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
- clc = XmlConfigurationParserOld.parseCacheLoaderConfig(strToElement(conf));
+ conf =
+ " <loaders passivation=\"true\">\n" +
+ " <preload/>\n" +
+ " <loader class=\"org.jboss.cache.loader.DummyInMemoryCacheLoader\">\n" +
+ " <singletonStore enabled=\"true\" class=\"org.jboss.cache.loader.DummyInMemoryCacheLoader\">\n" +
+ " </singletonStore>\n" +
+ " </loader>\n" +
+ " </loaders>";
+ clc = loadersElementParser.parseLoadersElement(strToElement(conf));
mgr = new CacheLoaderManager();
-
try
{
mgr.setConfig(clc, null, null);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,12 +11,12 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
@@ -92,33 +92,21 @@
public void testTwoLoadersPurge() throws Exception
{
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
-
- String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>" + DummySharedInMemoryCacheLoader.class.getName() + "</class>\n" +
- "<properties>" +
- " bin=bin1\n" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<purgeOnStartup>" + true + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "<cacheloader>\n" +
- "<class>" + DummySharedInMemoryCacheLoader.class.getName() + "</class>\n" +
- "<properties>" +
- " bin=bin2\n" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<purgeOnStartup>" + false + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
-
+ String xml =
+ " <loaders passivation=\"false\">\n" +
+ " <loader class=\"org.jboss.cache.loader.DummySharedInMemoryCacheLoader\" fetchPersistentState=\"true\"\n" +
+ " purgeOnStartup=\"true\">\n" +
+ " <properties>bin=bin1</properties>\n" +
+ " </loader>" +
+ " <loader class=\"org.jboss.cache.loader.DummySharedInMemoryCacheLoader\" fetchPersistentState=\"false\"\n" +
+ " purgeOnStartup=\"false\">\n" +
+ " <properties>bin=bin2</properties>\n" +
+ " </loader>" +
+ " </loaders>";
+ LoadersElementParser parser = new LoadersElementParser();
+ CacheLoaderConfig cacheLoaderConfig = parser.parseLoadersElement(XmlConfigHelper.stringToElement(xml));
Configuration c = cache.getConfiguration();
- Element element = XmlConfigHelper.stringToElement(xml);
- c.setCacheLoaderConfig(XmlConfigurationParserOld.parseCacheLoaderConfig(element));
+ c.setCacheLoaderConfig(cacheLoaderConfig);
cache.start();
cache.put(fqn, key, value);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderBasicTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -7,8 +7,8 @@
package org.jboss.cache.loader;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.LoadersElementParser;
import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -45,27 +45,23 @@
protected CacheLoaderConfig getCacheLoaderConfig(String loc1, String loc2) throws Exception
{
- String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- "<properties>" +
- " location=" + loc1 + "\n" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "</cacheloader>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- "<properties>" +
- " location=" + loc2 + "\n" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ String xmlStr =
+ " <loaders passivation=\"false\">\n" +
+ " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" async=\"false\" fetchPersistentState=\"true\"\n" +
+ " ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
+ " <properties>\n" +
+ " location=" + loc1+ "\n" +
+ " </properties>\n" +
+ " </loader>\n" +
+ " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" async=\"false\" fetchPersistentState=\"false\"\n" +
+ " ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
+ " <properties>\n" +
+ " location=" + loc2+ "\n" +
+ " </properties>\n" +
+ " </loader>\n" +
+ " </loaders>";
+ Element element = XmlConfigHelper.stringToElement(xmlStr);
+ LoadersElementParser parser = new LoadersElementParser();
+ return parser.parseLoadersElement(element);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -9,9 +9,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.assertEquals;
@@ -66,28 +67,10 @@
protected CacheLoaderConfig getCacheLoaderConfig(boolean ignoreMods1, boolean ignoreMods2) throws Exception
{
- String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>" + DummyInMemoryCacheLoader.class.getName() + "</class>\n" +
- "<properties>" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<ignoreModifications>" + ignoreMods1 + "</ignoreModifications>\n" +
- "</cacheloader>\n" +
- "<cacheloader>\n" +
- "<class>" + DummyInMemoryCacheLoader.class.getName() + "</class>\n" +
- "<properties>" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<ignoreModifications>" + ignoreMods2 + "</ignoreModifications>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ CacheLoaderConfig clc = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, null, DummyInMemoryCacheLoader.class.getName(), "", false, true, false, false, ignoreMods1);
+ CacheLoaderConfig.IndividualCacheLoaderConfig ic = UnitTestCacheConfigurationFactory.buildIndividualCacheLoaderConfig(null,DummyInMemoryCacheLoader.class.getName(), "", false, false, false , ignoreMods2);
+ clc.addIndividualCacheLoaderConfig(ic);
+ return clc;
}
public void testCruds() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -13,7 +13,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.util.internals.ViewChangeListener;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
@@ -277,23 +277,12 @@
protected CacheLoaderConfig getSingletonStoreCacheLoaderConfig(String cacheloaderClass) throws Exception
{
- String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- " <class>" + cacheloaderClass + "</class>\n" +
- " <properties></properties>\n" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties>" +
- " pushStateWhenCoordinator = true\n" +
- " pushStateWhenCoordinatorTimeout = 5000\n" +
- " </properties>" +
- " </singletonStore>" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ CacheLoaderConfig clc = UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(false, null, cacheloaderClass, "", false, false, false, false, false);
+ CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig sc = new CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig();
+ sc.setSingletonStoreEnabled(true);
+ sc.setProperties("pushStateWhenCoordinator = true\n pushStateWhenCoordinatorTimeout = 5000\n");
+ clc.getFirstCacheLoaderConfig().setSingletonStoreConfig(sc);
+ return clc;
}
private void initSingletonNonPushCache(CacheSPI cache) throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -1,5 +1,6 @@
package org.jboss.cache.loader;
+import static org.jboss.cache.factories.UnitTestCacheConfigurationFactory.*;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
@@ -7,7 +8,7 @@
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.jmx.CacheJmxWrapper;
@@ -62,20 +63,8 @@
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
- String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.TcpDelegatingCacheLoader</class>\n" +
- "<properties>host=127.0.0.1\nport=12121</properties>\n" +
- "<async>false</async>\n" +
- "<shared>true</shared>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<purgeOnStartup>false</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ return buildSingleCacheLoaderConfig(false, null, "org.jboss.cache.loader.TcpDelegatingCacheLoader",
+ "host=127.0.0.1\nport=12121", false, true, true, false, false);
}
@AfterMethod(alwaysRun = true)
Modified: core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtTestBase.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -6,7 +6,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.config.parsing.XmlConfigHelper;
@@ -14,6 +14,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+import static org.jboss.cache.factories.UnitTestCacheConfigurationFactory.*;
import java.util.HashMap;
import java.util.Map;
@@ -107,19 +108,7 @@
private CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
- String xml = "<config>\n" +
- "<passivation>" + passivation + "</passivation>\n" +
- "<preload></preload>\n" +
- "<shared>false</shared>\n" +
- "<cacheloader>\n" +
- "<class>" + DummyInMemoryCacheLoader.class.getName() + "</class>\n" +
- "<properties>debug=true</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<ignoreModifications>false</ignoreModifications>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ return buildSingleCacheLoaderConfig(passivation, null, DummyInMemoryCacheLoader.class.getName(),
+ "debug=true", false, false, false, false, false);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/mgmt/PassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mgmt/PassivationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/mgmt/PassivationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -4,6 +4,7 @@
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
+import org.testng.annotations.Test;
import java.util.HashMap;
@@ -17,6 +18,7 @@
* @author Jerry Gauthier
* @version $Id$
*/
+@Test(groups = "functional")
public class PassivationTest extends MgmtTestBase
{
public PassivationTest()
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,15 +11,8 @@
import org.jboss.cache.commands.VersionedDataCommand;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.interceptors.CacheMgmtInterceptor;
-import org.jboss.cache.interceptors.CallInterceptor;
-import org.jboss.cache.interceptors.NotificationInterceptor;
-import org.jboss.cache.interceptors.OptimisticLockingInterceptor;
-import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
-import org.jboss.cache.interceptors.OptimisticValidatorInterceptor;
+import org.jboss.cache.interceptors.*;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.loader.DummySharedInMemoryCacheLoader;
@@ -28,11 +21,10 @@
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionSetup;
-import org.jboss.cache.util.TestingUtil;
import org.jgroups.Address;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
+import org.jboss.cache.util.TestingUtil;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
@@ -100,21 +92,8 @@
protected CacheLoaderConfig getCacheLoaderConfig(boolean shared, boolean passivation) throws Exception
{
- String xml = " <config>\n" +
- " <passivation>" + passivation + "</passivation>\n" +
- " <preload></preload>\n" +
- " <shared>" + shared + "</shared>\n" +
- " <cacheloader>\n" +
- " <class>" + (shared ? DummySharedInMemoryCacheLoader.class.getName() : DummyInMemoryCacheLoader.class.getName()) + "</class>\n" +
- " <properties>\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>" + (!shared) + "</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " </config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ String cacheLoaderClass = shared ? DummySharedInMemoryCacheLoader.class.getName() : DummyInMemoryCacheLoader.class.getName();
+ return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(passivation, null, cacheLoaderClass, "", false, (!shared), shared, false, false);
}
protected CacheSPI<Object, Object> createCacheWithLoader(boolean passivationEnabled) throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -8,12 +8,13 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
+import static org.jboss.cache.factories.UnitTestCacheConfigurationFactory.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -27,21 +28,8 @@
{
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
- String xml = " <config>\n" +
- " \n" +
- " <passivation>true</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
+ return buildSingleCacheLoaderConfig(true, null, "org.jboss.cache.loader.DummyInMemoryCacheLoader",
+ "", false, false, false, false, false);
}
private CacheSPI createLocalCache() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,7 +11,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.notifications.annotation.CacheListener;
@@ -59,7 +59,7 @@
private void initCaches()
{
CacheFactory<String, String> instance = new DefaultCacheFactory<String, String>();
- cache = (CacheSPI) instance.createCache(new XmlConfigurationParserOld().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
+ cache = (CacheSPI) instance.createCache(new XmlConfigurationParser2x().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
Object listener = new TestCacheListener();
cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -11,7 +11,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.fail;
@@ -47,7 +47,7 @@
private void initCaches()
{
CacheFactory<Integer, String> instance = new DefaultCacheFactory();
- cache = (CacheSPI) instance.createCache(new XmlConfigurationParserOld().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
+ cache = (CacheSPI) instance.createCache(new XmlConfigurationParser2x().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
cache.start();
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -13,7 +13,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.notifications.annotation.CacheListener;
@@ -44,7 +44,7 @@
public void setUp() throws Exception
{
CacheFactory<String, String> instance = new DefaultCacheFactory();
- cache = (CacheSPI<String, String>) instance.createCache(new XmlConfigurationParserOld().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
+ cache = (CacheSPI<String, String>) instance.createCache(new XmlConfigurationParser2x().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
cache.getConfiguration().setUseRegionBasedMarshalling(true);
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -10,7 +10,7 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.lock.IsolationLevel;
@@ -21,6 +21,7 @@
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import static org.testng.AssertJUnit.*;
+import static org.jboss.cache.factories.UnitTestCacheConfigurationFactory.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -53,23 +54,6 @@
CacheLoader loader = null;
static final Fqn<String> FQN = Fqn.fromString("/key");
-
- protected CacheLoaderConfig getCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState) throws Exception
- {
- String xml = "<config>\n" +
- "<passivation>true</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>" + async + "</async>\n" +
- "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
- }
-
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToBdbjeCacheLoaderTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -1,10 +1,7 @@
package org.jboss.cache.passivation;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
+import static org.jboss.cache.factories.UnitTestCacheConfigurationFactory.*;
import java.io.File;
import java.io.FileFilter;
@@ -54,28 +51,6 @@
}
}
- cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(tmp_location));
+ cache.getConfiguration().setCacheLoaderConfig(buildSingleCacheLoaderConfig(true, null, "org.jboss.cache.loader.bdbje.BdbjeCacheLoader", "", false, false, false, false, false));
}
-
-
- protected CacheLoaderConfig getCacheLoaderConfig(String loc) throws Exception
- {
- String xml = " <config>\n" +
- " \n" +
- " <passivation>true</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>\n" +
- " <properties>\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
- }
}
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToFileCacheLoaderTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -1,9 +1,7 @@
package org.jboss.cache.passivation;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.w3c.dom.Element;
+import static org.jboss.cache.factories.UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig;
+import org.testng.annotations.Test;
/**
* tests passivation using file cache loader
@@ -11,46 +9,23 @@
* @author <a href="mailto:{hmesha@novell.com}">{Hany Mesha}</a>
* @version $Id$
*/
+@Test(groups ="funtional")
public class PassivationToFileCacheLoaderTest extends PassivationTestsBase
{
-
-
protected void configureCache() throws Exception
{
- String tmp_location = null;
+ String tmpLocation = null;
String OS = System.getProperty("os.name").toLowerCase();
if (OS.contains("win") || OS.contains("nt"))
{
- tmp_location = System.getProperty("java.io.tmpdir", "c:\\tmp");
+ tmpLocation = System.getProperty("java.io.tmpdir", "c:\\tmp");
}
else
{
- tmp_location = System.getProperty("jva.io.tmpdir", "/tmp");
+ tmpLocation = System.getProperty("jva.io.tmpdir", "/tmp");
}
- cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(tmp_location));
+ cache.getConfiguration().setCacheLoaderConfig(buildSingleCacheLoaderConfig(true, null, "org.jboss.cache.loader.FileCacheLoader", "", false, false, false, false, false));
}
-
- protected CacheLoaderConfig getCacheLoaderConfig(String loc) throws Exception
- {
- String xml = " <config>\n" +
- " \n" +
- " <passivation>true</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- " <properties>\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
- }
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java 2008-06-25 17:04:10 UTC (rev 6042)
@@ -6,47 +6,21 @@
*/
package org.jboss.cache.passivation;
+import java.util.Properties;
+import static org.jboss.cache.factories.UnitTestCacheConfigurationFactory.*;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.w3c.dom.Element;
+import org.testng.annotations.Test;
-import java.util.Properties;
-
/**
* Tests passivation using JDBC Cache Loader.
* This test has MySQL hard-coded. To run it, run MySQL first: mysqld -u=root
*
* @author <a href="mailto:{hmesha@novell.com}">{Hany Mesha}</a>
- * @version $Id$
+ * @version $Id$
*/
+@Test(groups = "functional")
public class PassivationToJDBCCacheLoaderTest extends PassivationTestsBase
{
-
-
- protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
- {
- String xml = " <config>\n" +
- " \n" +
- " <passivation>true</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>\n" +
- " <properties>\n" +
- getJDBCProps() +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
- }
-
-
protected String getJDBCProps()
{
Properties prop = new Properties();
@@ -68,6 +42,8 @@
protected void configureCache() throws Exception
{
- cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig());
+ CacheLoaderConfig loaderConfig = buildSingleCacheLoaderConfig(true, null, "org.jboss.cache.loader.JDBCCacheLoader",
+ getJDBCProps(), false, false, false, false, false);
+ cache.getConfiguration().setCacheLoaderConfig(loaderConfig);
}
}
Modified: core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/resources/META-INF/conf-test/all-elements-file-3.x.xml 2008-06-25 17:04:10 UTC (rev 6042)
@@ -13,9 +13,16 @@
<!-- either replication or invalidation tags will be present, not both -->
<replication>
- <!-- either sync or async will be present, not both -->
- <async useReplQueue="false" replQueueInterval="12" replQueueMaxElements="12345"/>
<sync replTimeout="15421"/>
+ <buddy enabled="true" poolName="myBuddyPoolReplicationGroup" communicationTimeout="2000">
+ <dataGravitation auto="true" removeOnFind="true" searchBackupTrees="true"/>
+ <locator class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
+ <properties>
+ numBuddies = 1
+ ignoreColocatedBuddies = true
+ </properties>
+ </locator>
+ </buddy>
</replication>
<!-- either replication or invalidation tags will be present, not both -->
@@ -28,10 +35,10 @@
<startup fetchInMemoryState="true" stateRetrievalTimeout="1524" inactiveOnStartup="true"/>
<shutdown hookBehavior="REGISTER"/>
- <transport clusterName="JBossCache-Cluster">
- <clusterName>JBossCache-Cluster</clusterName>
- <multiplexer stack="file_name"/>
- <clusterConfig>
+ <jmxStatistics enabled="false"/>
+
+ <transport clusterName="JBossCache-Cluster" multiplexerStack="file_name">
+ <jgroupsConfig>
<PING timeout="2000" num_initial_members="3"/>
<MERGE2 max_interval="30000" min_interval="10000"/>
<FD_SOCK/>
@@ -48,17 +55,15 @@
<FRAG2 frag_size="60000"/>
<pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/>
<pbcast.FLUSH timeout="0"/>
- </clusterConfig>
+ </jgroupsConfig>
</transport>
-
- <jmxStatistics enabled="false"/>
-
- <eviction wakeUpInterval="5" defaultPolicyClass="org.jboss.cache.eviction.LRUPolicy" defaultEventQueueSize="200000">
- <default>
+ <eviction wakeUpInterval="5">
+ <defaults policyClass="org.jboss.cache.eviction.LRUPolicy" eventQueueSize="200000"/>
+ <root>
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
- </default>
+ </root>
<region name="/org/jboss/data">
<attribute name="timeToLive">1002</attribute>
</region>
@@ -68,34 +73,29 @@
</region>
</eviction>
- <!-- this should be deprecated in 3.0 and should be replaced with CacheLoaderConfig-->
- <cacheLoaders passivation="false" shared="false">
+ <loaders passivation="false" shared="false">
<preload>
<node fqn="/a/b/c"/>
<node fqn="/f/r/s"/>
</preload>
<!-- we can now have multiple cache loaders, which get chained -->
- <cacheLoader class="org.jboss.cache.loader.JDBCCacheLoader" async="true" fetchPersistentState="true"
- ignoreModifications="true" purgeOnStartup="true">
+ <loader class="org.jboss.cache.loader.JDBCCacheLoader" async="true" fetchPersistentState="true"
+ ignoreModifications="true" purgeOnStartup="true">
<properties>
cache.jdbc.table.name=jbosscache
cache.jdbc.table.create=true
cache.jdbc.table.drop=true
</properties>
- </cacheLoader>
- </cacheLoaders>
+ <singletonStore enabled="false" class="org.jboss.cache.loader.SingletonStoreCacheLoader">
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=20000
+ </properties>
+ </singletonStore>
+ </loader>
+ </loaders>
- <buddyReplication enabled="true" buddyPoolName="myBuddyPoolReplicationGroup" buddyCommunicationTimeout="2000">
- <dataGravitation auto="true" removeOnFind="true" searchBackupTrees="true"/>
- <buddyLocator class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
- <properties>
- numBuddies = 1
- ignoreColocatedBuddies = true
- </properties>
- </buddyLocator>
- </buddyReplication>
-
<!-- this is new behavior added within 3.x only. it support configuring custom interceptors through configurations -->
<customInterceptors>
<interceptor class="com.myCompany.MyInterceptor1">
Modified: core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-2.x.xml 2008-06-25 17:04:10 UTC (rev 6042)
@@ -10,7 +10,7 @@
<attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup
</attribute>
<attribute name="IsolationLevel">REPEATABLE_READ</attribute>
- <attribute name="CacheMode">REPL_SYNC</attribute>
+ <attribute name="CacheMode">REPL_ASYNC</attribute>
<attribute name="UseReplQueue">false</attribute>
<attribute name="ReplQueueInterval">12</attribute>
@@ -118,7 +118,24 @@
<fetchPersistentState>true</fetchPersistentState>
<ignoreModifications>true</ignoreModifications>
<purgeOnStartup>true</purgeOnStartup>
+ <singletonStore>
+ <enabled>false</enabled>
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=5000
+ </properties>
+ </singletonStore>
</cacheloader>
+ <cacheloader>
+ <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>
+ <properties>
+ location=/tmp/BdbjeCacheLoader
+ </properties>
+ <async>false</async>
+ <!-- only one cache loader in the chain may set fetchPersistentState to true.-->
+ <fetchPersistentState>false</fetchPersistentState>
+ <ignoreModifications>false</ignoreModifications>
+ </cacheloader>
</config>
</attribute>
Modified: core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml 2008-06-25 15:57:45 UTC (rev 6041)
+++ core/trunk/src/test/resources/META-INF/conf-test/parser-test-file-3.x.xml 2008-06-25 17:04:10 UTC (rev 6042)
@@ -13,14 +13,21 @@
<replication>
<sync replTimeout="15421"/>
+ <buddy enabled="true" poolName="myBuddyPoolReplicationGroup" communicationTimeout="2000">
+ <dataGravitation auto="true" removeOnFind="true" searchBackupTrees="true"/>
+ <locator class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
+ <properties>
+ numBuddies = 1
+ ignoreColocatedBuddies = true
+ </properties>
+ </locator>
+ </buddy>
</replication>
<startup fetchInMemoryState="true" stateRetrievalTimeout="15124" inactiveOnStartup="true"/>
<shutdown hookBehavior="REGISTER"/>
- <transport clusterName="JBossCache-Cluster">
- <clusterName>JBossCache-Cluster</clusterName>
- <multiplexer stack="file_name"/>
+ <transport clusterName="JBossCache-Cluster" multiplexerStack="file_name">
<jgroupsConfig>
<PING timeout="2000" num_initial_members="3"/>
<MERGE2 max_interval="30000" min_interval="10000"/>
@@ -45,11 +52,12 @@
<jmxStatistics enabled="false"/>
- <eviction wakeUpInterval="5" defaultPolicyClass="org.jboss.cache.eviction.LRUPolicy" defaultEventQueueSize="200000">
- <default>
+ <eviction wakeUpInterval="5">
+ <defaults policyClass="org.jboss.cache.eviction.LRUPolicy" eventQueueSize="200000"/>
+ <root>
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLive">1000</attribute>
- </default>
+ </root>
<region name="/org/jboss/data">
<attribute name="timeToLive">1002</attribute>
</region>
@@ -60,33 +68,29 @@
</eviction>
<!-- this should be deprecated in 3.0 and should be replaced with CacheLoaderConfig-->
- <cacheLoaders passivation="true" shared="true">
+ <loaders passivation="true" shared="true">
<preload>
<node fqn="/a/b/c"/>
<node fqn="/f/r/s"/>
</preload>
<!-- we can now have multiple cache loaders, which get chained -->
- <cacheLoader class="org.jboss.cache.loader.JDBCCacheLoader" async="true" fetchPersistentState="true"
+ <loader class="org.jboss.cache.loader.JDBCCacheLoader" async="true" fetchPersistentState="true"
ignoreModifications="true" purgeOnStartup="true">
<properties>
cache.jdbc.table.name=jbosscache
cache.jdbc.table.create=true
cache.jdbc.table.drop=true
</properties>
- </cacheLoader>
- </cacheLoaders>
+ <singletonStore enabled="true" class="org.jboss.cache.loader.SingletonStoreCacheLoader">
+ <properties>
+ pushStateWhenCoordinator=true
+ pushStateWhenCoordinatorTimeout=20000
+ </properties>
+ </singletonStore>
+ </loader>
+ </loaders>
- <buddyReplication enabled="true" buddyPoolName="myBuddyPoolReplicationGroup" buddyCommunicationTimeout="2000">
- <dataGravitation auto="true" removeOnFind="true" searchBackupTrees="true"/>
- <buddyLocator class="org.jboss.cache.buddyreplication.NextMemberBuddyLocator">
- <properties>
- numBuddies = 1
- ignoreColocatedBuddies = true
- </properties>
- </buddyLocator>
- </buddyReplication>
-
<!-- this is new behavior added within 3.x only. it support configuring custom interceptors through configurations -->
<customInterceptors>
<interceptor class="com.myCompany.MyInterceptor1">
16 years, 6 months
JBoss Cache SVN: r6041 - in core/trunk/src/main/java/org/jboss/cache: transaction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-25 11:57:45 -0400 (Wed, 25 Jun 2008)
New Revision: 6041
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java
Log:
Null chks
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-06-25 15:39:25 UTC (rev 6040)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-06-25 15:57:45 UTC (rev 6041)
@@ -202,7 +202,7 @@
{
// first check transactional scope
if (transactionContext != null) return transactionContext.getLocks();
- return Collections.unmodifiableList(new ArrayList(invocationLocks));
+ return invocationLocks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList(invocationLocks));
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java 2008-06-25 15:39:25 UTC (rev 6040)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionContext.java 2008-06-25 15:57:45 UTC (rev 6041)
@@ -267,7 +267,7 @@
@SuppressWarnings("unchecked")
public List getLocks()
{
- return Collections.unmodifiableList(new ArrayList(transactionLocks));
+ return transactionLocks == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList(transactionLocks));
}
@@ -455,7 +455,7 @@
if (modificationList != null) modificationList = null;
if (localModifications != null) localModifications = null;
option = null;
- transactionLocks.clear();
+ if (transactionLocks != null) transactionLocks.clear();
if (dummyNodesCreatedByCacheLoader != null) dummyNodesCreatedByCacheLoader.clear();
removedNodes.clear();
}
16 years, 6 months
JBoss Cache SVN: r6040 - in core/trunk/src/test/java/org/jboss/cache: api and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-25 11:39:25 -0400 (Wed, 25 Jun 2008)
New Revision: 6040
Added:
core/trunk/src/test/java/org/jboss/cache/mvcc/
Modified:
core/trunk/src/test/java/org/jboss/cache/api/SyncReplTest.java
core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java
core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java
Log:
Fixed broken tests
Modified: core/trunk/src/test/java/org/jboss/cache/api/SyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/SyncReplTest.java 2008-06-25 15:34:48 UTC (rev 6039)
+++ core/trunk/src/test/java/org/jboss/cache/api/SyncReplTest.java 2008-06-25 15:39:25 UTC (rev 6040)
@@ -136,7 +136,7 @@
{
InvocationContext ctx = c.getInvocationContext();
InvocationContext control;
- control = InvocationContext.copy(ctx);
+ control = ctx.copy();
control.reset();
control.setOptionOverrides(new Option());
Modified: core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java 2008-06-25 15:34:48 UTC (rev 6039)
+++ core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java 2008-06-25 15:39:25 UTC (rev 6040)
@@ -150,7 +150,7 @@
{
InvocationContext ctx = c.getInvocationContext();
InvocationContext control;
- control = InvocationContext.copy(ctx);
+ control = ctx.copy();
control.reset();
control.setOptionOverrides(new Option());
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java 2008-06-25 15:34:48 UTC (rev 6039)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java 2008-06-25 15:39:25 UTC (rev 6040)
@@ -142,7 +142,7 @@
{
InvocationContext ctx = c.getInvocationContext();
InvocationContext control;
- control = InvocationContext.copy(ctx);
+ control = ctx.copy();
control.reset();
control.setOptionOverrides(new Option());
16 years, 6 months