[jboss-svn-commits] JBL Code SVN: r26307 - in labs/jbossesb/workspace/blixen/product/rosetta: tests/src/org/jboss/internal/soa/esb/services/registry and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Apr 29 14:28:39 EDT 2009
Author: kevin.conner at jboss.com
Date: 2009-04-29 14:28:39 -0400 (Wed, 29 Apr 2009)
New Revision: 26307
Added:
labs/jbossesb/workspace/blixen/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptorUnitTest.java
Modified:
labs/jbossesb/workspace/blixen/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptor.java
Log:
Fix caching registry interceptor
Modified: labs/jbossesb/workspace/blixen/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptor.java
===================================================================
--- labs/jbossesb/workspace/blixen/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptor.java 2009-04-29 15:41:30 UTC (rev 26306)
+++ labs/jbossesb/workspace/blixen/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptor.java 2009-04-29 18:28:39 UTC (rev 26307)
@@ -19,9 +19,13 @@
*/
package org.jboss.internal.soa.esb.services.registry;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.commons.collections.map.LRUMap;
import org.apache.log4j.Logger;
@@ -67,12 +71,24 @@
*/
private final LRUMap serviceInfoMap = new LRUMap(MAX_CACHE_SIZE) ;
+ /**
+ * Find all Services assigned to the Red Hat/JBossESB organization.
+ * @return Collection of Strings containing the service names.
+ * @throws RegistryException
+ */
public List<String> findAllServices() throws RegistryException
{
// Do not cache, go direct to the registry
return getRegistry().findAllServices() ;
}
+ /**
+ * Find all services that belong to the supplied category.
+ *
+ * @param serviceCategoryName - name of the category to which the service belongs.
+ * @return Collection of Strings containing the service names
+ * @throws RegistryException
+ */
public List<String> findServices(final String category)
throws RegistryException
{
@@ -80,127 +96,280 @@
return getRegistry().findServices(category) ;
}
+ /**
+ * Returns the first EPR in the list that belong to a specific category and service combination.
+ *
+ * @param serviceCategoryName - name of the category to which the service belongs.
+ * @param serviceName - name of the service to which the EPS belongs.
+ * @return EPR.
+ * @throws RegistryException
+ */
public EPR findEPR(final String category, final String name)
throws RegistryException, ServiceNotFoundException
{
- final List<EPR> eprs = findEPRs(category, name) ;
- return eprs.get(0) ;
+ final Service service = new Service(category, name) ;
+ final ConcurrentMap<EPR, EPR> eprs = getEPRs(service) ;
+ final Iterator<EPR> eprIter = eprs.keySet().iterator() ;
+ if (eprIter.hasNext())
+ {
+ return eprIter.next() ;
+ }
+ else
+ {
+ return null;
+ }
}
+ /**
+ * Finds all the EPRs that belong to a specific category and service combination.
+ *
+ * @param serviceCategoryName - name of the category to which the service belongs.
+ * @param serviceName - name of the service to which the EPS belongs.
+ * @return Collection of EPRs.
+ * @throws RegistryException
+ */
public List<EPR> findEPRs(final String category, final String name)
throws RegistryException, ServiceNotFoundException
{
final Service service = new Service(category, name) ;
- return Collections.unmodifiableList(getEPRs(service)) ;
+ final ConcurrentMap<EPR, EPR> eprs = getEPRs(service) ;
+ return Arrays.asList(eprs.keySet().toArray(new EPR[0])) ;
}
+ /**
+ * Registers an EPR under the specified category and service. If the specified service does
+ * not exist, it will be created at the same time.
+ *
+ * @param serviceCategoryName - name of the category to which the service belongs.
+ * @param serviceName - name of the service to which the EPS belongs.
+ * @param serviceDescription - human readable description of the service,
+ * only used when it the service does not yet exist.
+ * @param epr - the EndPointReference (EPR) that needs to be registered.
+ * @param eprDescription - human readable description of the EPR
+ * @throws RegistryException
+ */
public void registerEPR(final String category, final String name,
final String serviceDescription, final EPR epr, final String eprDescription)
throws RegistryException
{
final Service service = new Service(category, name) ;
- synchronized(this)
+ final ServiceInfo serviceInfo = getServiceInfo(service) ;
+ if (serviceInfo != null)
{
+ serviceInfo.acquireWriteLock() ;
+ }
+ try
+ {
getRegistry().registerEPR(category, name, serviceDescription, epr, eprDescription) ;
- final List<EPR> eprs = getCurrentEPRs(service) ;
- if (eprs != null)
+ if (serviceInfo != null)
{
- eprs.add(epr) ;
+ final ConcurrentMap<EPR, EPR> eprs = serviceInfo.getEPRs() ;
+ if (eprs != null)
+ {
+ eprs.put(epr, epr) ;
+ }
}
}
+ finally
+ {
+ if (serviceInfo != null)
+ {
+ serviceInfo.releaseWriteLock() ;
+ }
+ }
}
+ /**
+ * Removes an EPR from the Registry.
+ * @param serviceCategoryName - name of the category to which the service belongs.
+ * @param serviceName - name of the service to which the EPS belongs.
+ * @param epr - the EndPointReference (EPR) that needs to be unregistered.
+ * @throws RegistryException
+ */
public void unRegisterEPR(final String category, final String name,
final EPR epr) throws RegistryException, ServiceNotFoundException
{
final Service service = new Service(category, name) ;
- synchronized(this)
+ final ServiceInfo serviceInfo = getServiceInfo(service) ;
+ if (serviceInfo != null)
{
- final List<EPR> eprs = getCurrentEPRs(service) ;
- if ((eprs != null) && eprs.remove(epr) && (eprs.size() == 0))
+ serviceInfo.acquireWriteLock() ;
+ }
+ try
+ {
+ getRegistry().unRegisterEPR(category, name, epr) ;
+ if (serviceInfo != null)
{
- serviceInfoMap.remove(service) ;
- if (LOGGER.isInfoEnabled())
+ final ConcurrentMap<EPR, EPR> eprs = serviceInfo.getEPRs() ;
+ if (eprs != null)
{
- LOGGER.debug("Cache removing service " + service) ;
+ eprs.remove(epr) ;
}
}
- getRegistry().unRegisterEPR(category, name, epr) ;
}
+ finally
+ {
+ if (serviceInfo != null)
+ {
+ serviceInfo.releaseWriteLock() ;
+ }
+ }
}
+ /**
+ * Removes a service from the Registry along with all the ServiceBindings underneath it.
+ *
+ * @param category - name of the service category, for example 'transformation'.
+ * @param serviceName - name of the service, for example 'smooks'.
+ * @throws RegistryException
+ */
public void unRegisterService(final String category, final String name)
throws RegistryException, ServiceNotFoundException
{
final Service service = new Service(category, name) ;
- synchronized(this)
+ final ServiceInfo serviceInfo = getServiceInfo(service) ;
+ if (serviceInfo != null)
{
- serviceInfoMap.remove(service) ;
- if (LOGGER.isInfoEnabled())
+ serviceInfo.acquireWriteLock() ;
+ }
+ try
+ {
+ getRegistry().unRegisterService(category, name) ;
+ removeServiceInfo(service) ;
+ if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Cache removing service " + service) ;
}
- getRegistry().unRegisterService(category, name) ;
}
+ finally
+ {
+ if (serviceInfo != null)
+ {
+ serviceInfo.releaseWriteLock() ;
+ }
+ }
}
- private synchronized List<EPR> getEPRs(final Service service)
- throws RegistryException, ServiceNotFoundException
+ /**
+ * Get the service information if it is still valid.
+ * @param service The service information.
+ * @return The service information or null
+ */
+ private synchronized ServiceInfo getServiceInfo(final Service service)
{
- final List<EPR> eprs = getCurrentEPRs(service) ;
- if (eprs != null)
+ final ServiceInfo serviceInfo = (ServiceInfo)serviceInfoMap.get(service) ;
+ if (serviceInfo != null)
{
- return eprs ;
+ if (serviceInfo.isValid())
+ {
+ return serviceInfo ;
+ }
+ removeServiceInfo(service) ;
}
+ return null ;
+ }
+
+ /**
+ * Create new service information or return current information if present.
+ * @param service The service information.
+ * @return The service information
+ */
+ private synchronized ServiceInfo createServiceInfo(final Service service)
+ {
+ final ServiceInfo serviceInfo = new ServiceInfo() ;
+ final ServiceInfo origServiceInfo = (ServiceInfo)serviceInfoMap.put(service, serviceInfo) ;
+ if ((origServiceInfo != null) && origServiceInfo.isValid())
+ {
+ serviceInfoMap.put(service, origServiceInfo) ;
+ return origServiceInfo ;
+ }
else
{
- final List<EPR> currentEPRs = getRegistry().findEPRs(service.getCategory(), service.getName()) ;
- final List<EPR> copyEPRs = new ArrayList<EPR>(currentEPRs) ;
- final ServiceInfo serviceInfo = new ServiceInfo(copyEPRs) ;
- serviceInfoMap.put(service, serviceInfo) ;
- if (LOGGER.isInfoEnabled())
- {
- LOGGER.debug("Cache reloaded for service " + service) ;
- }
- return copyEPRs ;
+ return serviceInfo ;
}
}
-
- private synchronized List<EPR> getCurrentEPRs(final Service service)
+
+ /**
+ * Remove the service information from map.
+ * @param service The service information
+ */
+ private synchronized void removeServiceInfo(final Service service)
{
- final ServiceInfo serviceInfo = (ServiceInfo)serviceInfoMap.get(service) ;
+ serviceInfoMap.remove(service) ;
+ }
+
+ /**
+ * Get the EPRs assocaited with the service, updating the cache if necessary
+ * @param service The service to query.
+ * @return The map of EPRs.
+ * @throws RegistryException For errors accessing the registry delegate.
+ * @throws ServiceNotFoundException If the service is not in the registry.
+ */
+ private ConcurrentMap<EPR, EPR> getEPRs(final Service service)
+ throws RegistryException, ServiceNotFoundException
+ {
+ final ServiceInfo serviceInfo = getServiceInfo(service) ;
if (serviceInfo != null)
{
- final boolean infoEnabled = LOGGER.isInfoEnabled() ;
- if (serviceInfo.isValid())
+ serviceInfo.acquireReadLock() ;
+ try
{
- if (infoEnabled)
+ final ConcurrentMap<EPR, EPR> eprs = serviceInfo.getEPRs() ;
+ if (eprs != null)
{
- LOGGER.debug("Cache hit for service " + service) ;
+ return eprs ;
}
- return serviceInfo.getEPRs() ;
}
+ finally
+ {
+ serviceInfo.releaseReadLock() ;
+ }
+ }
+ final ServiceInfo newServiceInfo = createServiceInfo(service) ;
+ newServiceInfo.acquireWriteLock() ;
+ try
+ {
+ final ConcurrentMap<EPR, EPR> eprs = newServiceInfo.getEPRs() ;
+ if (eprs != null)
+ {
+ return eprs ;
+ }
else
{
- if (infoEnabled)
+ final List<EPR> currentEPRs = getRegistry().findEPRs(service.getCategory(), service.getName()) ;
+ final ConcurrentMap<EPR, EPR> newEPRs = new ConcurrentHashMap<EPR, EPR>() ;
+ for(EPR epr: currentEPRs)
{
- LOGGER.debug("Cache expiry for service " + service) ;
+ newEPRs.put(epr, epr) ;
}
- serviceInfoMap.remove(service) ;
+ newServiceInfo.setEPRs(newEPRs) ;
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Cache reloaded for service " + service) ;
+ }
+ return newEPRs ;
}
}
- return null ;
+ finally
+ {
+ newServiceInfo.releaseWriteLock() ;
+ }
}
+ /**
+ * Class representing the service information
+ * @author kevin
+ */
private static class ServiceInfo
{
private final long expiryTime ;
- private List<EPR> eprs ;
+ private ConcurrentMap<EPR, EPR> eprs ;
- private ServiceInfo(final List<EPR> eprs)
+ private ReadWriteLock lock = new ReentrantReadWriteLock() ;
+
+ private ServiceInfo()
{
- this.eprs = eprs ;
if (VALIDITY_PERIOD > 0)
{
expiryTime = System.currentTimeMillis() + VALIDITY_PERIOD ;
@@ -216,10 +385,35 @@
return System.currentTimeMillis() < expiryTime ;
}
- List<EPR> getEPRs()
+ ConcurrentMap<EPR, EPR> getEPRs()
{
return eprs ;
}
+
+ void setEPRs(final ConcurrentMap<EPR, EPR> eprs)
+ {
+ this.eprs = eprs ;
+ }
+
+ void acquireWriteLock()
+ {
+ lock.writeLock().lock() ;
+ }
+
+ void releaseWriteLock()
+ {
+ lock.writeLock().unlock() ;
+ }
+
+ void acquireReadLock()
+ {
+ lock.readLock().lock() ;
+ }
+
+ void releaseReadLock()
+ {
+ lock.readLock().unlock() ;
+ }
}
static
Copied: labs/jbossesb/workspace/blixen/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptorUnitTest.java (from rev 26215, labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptorUnitTest.java)
===================================================================
--- labs/jbossesb/workspace/blixen/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptorUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/blixen/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/CachingRegistryInterceptorUnitTest.java 2009-04-29 18:28:39 UTC (rev 26307)
@@ -0,0 +1,416 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.services.registry;
+
+import java.util.List;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryInterceptor;
+import org.jboss.soa.esb.services.registry.ServiceNotFoundException;
+
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Unit tests for the caching registry interceptor
+ *
+ * @author <a href="mailto:Kevin.Conner at jboss.com">Kevin Conner</a>
+ */
+public class CachingRegistryInterceptorUnitTest extends TestCase
+{
+ /**
+ * Tests of caching, intended to run within the current cache validity period
+ */
+ public void testCaching()
+ throws Exception
+ {
+ final String category = "category" ;
+ final String name = "name" ;
+ final EPR epr1 = new EPR() ;
+ final EPR epr2 = new EPR() ;
+
+ final CachingRegistryInterceptor interceptor = new CachingRegistryInterceptor() ;
+ final CacheRegistryStatsInterceptor stats = new CacheRegistryStatsInterceptor() ;
+ final MockRegistry registry = new MockRegistry() ;
+ stats.setRegistry(registry) ;
+ interceptor.setRegistry(stats) ;
+
+ registry.registerEPR(category, name, "Description", epr1, "EPR description") ;
+
+ // findAllServices passes through to registry
+ assertEquals("findAllServices count", 0, stats.getFindAllServicesCount()) ;
+ interceptor.findAllServices() ;
+ assertEquals("findAllServices count", 1, stats.getFindAllServicesCount()) ;
+ interceptor.findAllServices() ;
+ assertEquals("findAllServices count", 2, stats.getFindAllServicesCount()) ;
+
+ // findServices passes through to registry
+ assertEquals("findServices count", 0, stats.getFindServicesCount()) ;
+ interceptor.findServices(category) ;
+ assertEquals("findServices count", 1, stats.getFindServicesCount()) ;
+ interceptor.findServices(category) ;
+ assertEquals("findServices count", 2, stats.getFindServicesCount()) ;
+
+ // findEPR/findEPRs go to registry on first call, then cache.
+ assertEquals("findEPRs count", 0, stats.getFindEPRsCount()) ;
+ interceptor.findEPRs(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ interceptor.findEPRs(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ interceptor.findEPR(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertEquals("findEPR count", 0, stats.getFindEPRCount()) ;
+
+ // registerEPR goes to registry and adds to cache
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertEquals("registerEPR count", 0, stats.getRegisterEPRCount()) ;
+ final List<EPR> registerOrigEPRs = interceptor.findEPRs(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertNotNull("Original EPRs", registerOrigEPRs) ;
+ assertEquals("Original EPR count", 1, registerOrigEPRs.size()) ;
+ interceptor.registerEPR(category, name, "Description", epr2, "EPR description") ;
+ assertEquals("registerEPR count", 1, stats.getRegisterEPRCount()) ;
+ final List<EPR> registerNewEPRs = interceptor.findEPRs(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertNotNull("New EPRs", registerNewEPRs) ;
+ assertEquals("New EPR count", 2, registerNewEPRs.size()) ;
+
+ // unRegister goes to registry and removes from cache
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertEquals("unRegisterEPR count", 0, stats.getUnRegisterEPRCount()) ;
+ final List<EPR> unRegisterOrigEPRs = interceptor.findEPRs(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertNotNull("Original EPRs", unRegisterOrigEPRs) ;
+ assertEquals("Original EPR count", 2, unRegisterOrigEPRs.size()) ;
+ interceptor.unRegisterEPR(category, name, epr2) ;
+ assertEquals("unRegisterEPR count", 1, stats.getUnRegisterEPRCount()) ;
+ final List<EPR> unRegisterNewEPRs = interceptor.findEPRs(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertNotNull("New EPRs", unRegisterNewEPRs) ;
+ assertEquals("New EPR count", 1, unRegisterNewEPRs.size()) ;
+ interceptor.unRegisterEPR(category, name, epr1) ;
+ assertEquals("unRegisterEPR count", 2, stats.getUnRegisterEPRCount()) ;
+ final List<EPR> finalEPRs = interceptor.findEPRs(category, name) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+ assertNotNull("Final EPRs", finalEPRs) ;
+ assertEquals("Final EPR count", 0, finalEPRs.size()) ;
+ final EPR finalEPR = interceptor.findEPR(category, name) ;
+ assertNull("Final EPR", finalEPR) ;
+ assertEquals("findEPR count", 0, stats.getFindEPRCount()) ;
+ assertEquals("findEPRs count", 1, stats.getFindEPRsCount()) ;
+
+ // Need to fix MockRegistry as it does not correctly handle
+ // service information. We cannot use unRegisterService unless
+ // there is an EPR present so we re-register the first one.
+ // Also findEPR and findEPRs should throw ServiceNotFoundException
+ // after unRegister but MockRegistry does not support it.
+ registry.registerEPR(category, name, "Description", epr1, "EPR description") ;
+ assertEquals("unRegisterService count", 0, stats.getUnRegisterServiceCount()) ;
+ interceptor.unRegisterService(category, name) ;
+ assertEquals("unRegisterService count", 1, stats.getUnRegisterServiceCount()) ;
+ }
+
+ /**
+ * Test concurrent access to next interceptor in chain.
+ * @throws Exception
+ */
+ public void testConcurrency()
+ throws Exception
+ {
+ final int numServices = 5 ;
+ final String category = "category" ;
+ final String name = "name" ;
+
+ final CachingRegistryInterceptor interceptor = new CachingRegistryInterceptor() ;
+ final CacheRegistryConcurrencyInterceptor concurrency = new CacheRegistryConcurrencyInterceptor(new CyclicBarrier(numServices)) ;
+ final MockRegistry registry = new MockRegistry() ;
+ concurrency.setRegistry(registry) ;
+ interceptor.setRegistry(concurrency) ;
+
+ final String[] names = new String[numServices] ;
+ for (int count = 0 ; count < numServices ; count++)
+ {
+ names[count] = name + count ;
+ registry.registerEPR(category, names[count], "description", new EPR(), "EPR description") ;
+ }
+ final int numThreads = numServices*2 ;
+
+ final CyclicBarrier barrier = new CyclicBarrier(numThreads) ;
+ final ConcurrencyTest[] tests = new ConcurrencyTest[numThreads] ;
+ for(int count = 0 ; count < numThreads ; count++)
+ {
+ tests[count] = new ConcurrencyTest(barrier, interceptor, category, names[count%numServices]) ;
+ tests[count].start() ;
+ }
+
+ for(int count = 0 ; count < numThreads ; count++)
+ {
+ tests[count].join();
+ }
+
+ for(int count = 0 ; count < numThreads ; count++)
+ {
+ assertNull("Throwable occurred", tests[count].getThrowable()) ;
+ }
+
+ assertEquals("Registry findEPRs invocation", numServices, concurrency.getFindEPRsCount()) ;
+ assertFalse("Barrier timeout", concurrency.isTimeout()) ;
+ }
+
+ private static final class CacheRegistryStatsInterceptor implements RegistryInterceptor
+ {
+ private Registry registry ;
+ final AtomicInteger findAllServicesCount = new AtomicInteger() ;
+ final AtomicInteger findEPRCount = new AtomicInteger() ;
+ final AtomicInteger findEPRsCount = new AtomicInteger() ;
+ final AtomicInteger findServicesCount = new AtomicInteger() ;
+ final AtomicInteger registerEPRCount = new AtomicInteger() ;
+ final AtomicInteger unRegisterEPRCount = new AtomicInteger() ;
+ final AtomicInteger unRegisterServiceCount = new AtomicInteger() ;
+
+ public List<String> findAllServices()
+ throws RegistryException
+ {
+ findAllServicesCount.incrementAndGet() ;
+ return registry.findAllServices() ;
+ }
+
+ public int getFindAllServicesCount()
+ {
+ return findAllServicesCount.get() ;
+ }
+
+ public EPR findEPR(final String serviceCategoryName, final String serviceName)
+ throws RegistryException, ServiceNotFoundException
+ {
+ findEPRCount.incrementAndGet() ;
+ return registry.findEPR(serviceCategoryName, serviceName) ;
+ }
+
+ public int getFindEPRCount()
+ {
+ return findEPRCount.get() ;
+ }
+
+ public List<EPR> findEPRs(final String serviceCategoryName, final String serviceName)
+ throws RegistryException, ServiceNotFoundException
+ {
+ findEPRsCount.incrementAndGet() ;
+ return registry.findEPRs(serviceCategoryName, serviceName) ;
+ }
+
+ public int getFindEPRsCount()
+ {
+ return findEPRsCount.get() ;
+ }
+
+ public List<String> findServices(final String serviceCategoryName)
+ throws RegistryException
+ {
+ findServicesCount.incrementAndGet() ;
+ return registry.findServices(serviceCategoryName) ;
+ }
+
+ public int getFindServicesCount()
+ {
+ return findServicesCount.get();
+ }
+
+ public void registerEPR(final String serviceCategoryName, final String serviceName,
+ final String serviceDescription, final EPR epr, final String eprDescription)
+ throws RegistryException
+ {
+ registerEPRCount.incrementAndGet() ;
+ registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription) ;
+ }
+
+ public int getRegisterEPRCount()
+ {
+ return registerEPRCount.get();
+ }
+
+ public void unRegisterEPR(final String serviceCategoryName,
+ final String serviceName, final EPR epr)
+ throws RegistryException, ServiceNotFoundException
+ {
+ unRegisterEPRCount.incrementAndGet() ;
+ registry.unRegisterEPR(serviceCategoryName, serviceName, epr) ;
+ }
+
+ public int getUnRegisterEPRCount()
+ {
+ return unRegisterEPRCount.get();
+ }
+
+ public void unRegisterService(final String category, final String serviceName)
+ throws RegistryException, ServiceNotFoundException
+ {
+ unRegisterServiceCount.incrementAndGet() ;
+ registry.unRegisterService(category, serviceName) ;
+ }
+
+ public int getUnRegisterServiceCount()
+ {
+ return unRegisterServiceCount.get();
+ }
+
+ public void setRegistry(final Registry registry)
+ {
+ this.registry = registry ;
+ }
+ }
+
+ private static final class ConcurrencyTest extends Thread
+ {
+ private final CyclicBarrier barrier ;
+ private final Registry registry ;
+ private final String category ;
+ private final String name ;
+
+ private Throwable throwable ;
+
+ ConcurrencyTest(final CyclicBarrier barrier, final Registry registry,
+ final String category, final String name)
+ {
+ this.barrier = barrier ;
+ this.registry = registry ;
+ this.category = category ;
+ this.name = name ;
+ }
+
+ public void run()
+ {
+ try
+ {
+ barrier.await() ;
+ registry.findEPRs(category, name) ;
+ }
+ catch (final Throwable th)
+ {
+ throwable = th ;
+ }
+ }
+
+ Throwable getThrowable()
+ {
+ return throwable ;
+ }
+ }
+
+ private static final class CacheRegistryConcurrencyInterceptor implements RegistryInterceptor
+ {
+ private final CyclicBarrier barrier ;
+
+ private volatile boolean timeout ;
+ private Registry registry ;
+ private final AtomicInteger findEPRsCount = new AtomicInteger() ;
+
+ public CacheRegistryConcurrencyInterceptor(final CyclicBarrier barrier)
+ {
+ this.barrier = barrier ;
+ }
+
+ public List<String> findAllServices()
+ throws RegistryException
+ {
+ return registry.findAllServices() ;
+ }
+
+ public EPR findEPR(final String serviceCategoryName, final String serviceName)
+ throws RegistryException, ServiceNotFoundException
+ {
+ return registry.findEPR(serviceCategoryName, serviceName) ;
+ }
+
+ public List<EPR> findEPRs(final String serviceCategoryName, final String serviceName)
+ throws RegistryException, ServiceNotFoundException
+ {
+ findEPRsCount.incrementAndGet() ;
+ if (!timeout)
+ {
+ try
+ {
+ barrier.await(10, TimeUnit.SECONDS) ;
+ }
+ catch (final TimeoutException te)
+ {
+ timeout = true ;
+ }
+ catch (final InterruptedException ie)
+ {
+ throw new RegistryException("Interrupted", ie) ;
+ }
+ catch (final BrokenBarrierException bbe)
+ {
+ throw new RegistryException("Broken barrier", bbe) ;
+ }
+ }
+ return registry.findEPRs(serviceCategoryName, serviceName) ;
+ }
+
+ public int getFindEPRsCount()
+ {
+ return findEPRsCount.get() ;
+ }
+
+ public boolean isTimeout()
+ {
+ return timeout ;
+ }
+
+ public List<String> findServices(final String serviceCategoryName)
+ throws RegistryException
+ {
+ return registry.findServices(serviceCategoryName) ;
+ }
+
+ public void registerEPR(final String serviceCategoryName, final String serviceName,
+ final String serviceDescription, final EPR epr, final String eprDescription)
+ throws RegistryException
+ {
+ registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription) ;
+ }
+
+ public void unRegisterEPR(final String serviceCategoryName,
+ final String serviceName, final EPR epr)
+ throws RegistryException, ServiceNotFoundException
+ {
+ registry.unRegisterEPR(serviceCategoryName, serviceName, epr) ;
+ }
+
+ public void unRegisterService(final String category, final String serviceName)
+ throws RegistryException, ServiceNotFoundException
+ {
+ registry.unRegisterService(category, serviceName) ;
+ }
+
+ public void setRegistry(final Registry registry)
+ {
+ this.registry = registry ;
+ }
+ }
+}
More information about the jboss-svn-commits
mailing list