[jboss-svn-commits] JBL Code SVN: r34291 - labs/jbossesb/workspace/platform/JBESB_4_4_SOA_4_3_CP2_1081443/product/rosetta/src/org/jboss/internal/soa/esb/services/registry.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 29 08:07:51 EDT 2010
Author: kevin.conner at jboss.com
Date: 2010-07-29 08:07:51 -0400 (Thu, 29 Jul 2010)
New Revision: 34291
Added:
labs/jbossesb/workspace/platform/JBESB_4_4_SOA_4_3_CP2_1081443/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/LocalRegistryInterceptor.java
Log:
Added local registry interceptor
Added: labs/jbossesb/workspace/platform/JBESB_4_4_SOA_4_3_CP2_1081443/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/LocalRegistryInterceptor.java
===================================================================
--- labs/jbossesb/workspace/platform/JBESB_4_4_SOA_4_3_CP2_1081443/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/LocalRegistryInterceptor.java (rev 0)
+++ labs/jbossesb/workspace/platform/JBESB_4_4_SOA_4_3_CP2_1081443/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/LocalRegistryInterceptor.java 2010-07-29 12:07:51 UTC (rev 34291)
@@ -0,0 +1,301 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.internal.soa.esb.services.registry;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.services.registry.AbstractRegistryInterceptor;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.ServiceNotFoundException;
+
+/**
+ * Local registry interceptor.
+ *
+ * @author <a href='mailto:Kevin.Conner at jboss.com'>Kevin Conner</a>
+ */
+public class LocalRegistryInterceptor extends AbstractRegistryInterceptor
+{
+ /**
+ * The logger for the registry cache
+ */
+ private static final Logger LOGGER = Logger.getLogger(LocalRegistryInterceptor.class) ;
+
+ /**
+ * Mapping of category names to service names and EPRs.
+ */
+ private final HashMap<String, HashMap<String, ArrayList<EPR>>> categoryToNameToEPRs = new HashMap<String, HashMap<String, ArrayList<EPR>>>() ;
+ /**
+ * The lock guarding access and modification to the structures.
+ */
+ private ReadWriteLock lock = new ReentrantReadWriteLock() ;
+
+ /**
+ * 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
+ {
+ 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
+ {
+ 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
+ {
+ acquireReadLock() ;
+ try
+ {
+ final HashMap<String, ArrayList<EPR>> nameToEPRs = categoryToNameToEPRs.get(category) ;
+ if (nameToEPRs != null)
+ {
+ final ArrayList<EPR> eprs = nameToEPRs.get(name) ;
+ if (eprs != null)
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Returning locally registered EPR for category " + category + ", name " + name) ;
+ }
+ return eprs.get(0) ;
+ }
+ }
+ return getRegistry().findEPR(category, name);
+ }
+ finally
+ {
+ releaseReadLock() ;
+ }
+ }
+
+ /**
+ * 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
+ */
+ @SuppressWarnings("unchecked")
+ public List<EPR> findEPRs(final String category, final String name)
+ throws RegistryException, ServiceNotFoundException
+ {
+ acquireReadLock() ;
+ try
+ {
+ final HashMap<String, ArrayList<EPR>> nameToEPRs = categoryToNameToEPRs.get(category) ;
+ if (nameToEPRs != null)
+ {
+ final ArrayList<EPR> eprs = nameToEPRs.get(name) ;
+ if (eprs != null)
+ {
+ final ArrayList<EPR> result = (ArrayList<EPR>)eprs.clone() ;
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Returning locally registered EPRs for category " + category + ", name " + name) ;
+ }
+ return result ;
+ }
+ }
+ return getRegistry().findEPRs(category, name) ;
+ }
+ finally
+ {
+ releaseReadLock() ;
+ }
+ }
+
+ /**
+ * 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
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Registering EPR " + epr + " for category " + category + ", name " + name) ;
+ }
+ acquireWriteLock() ;
+ try
+ {
+ HashMap<String, ArrayList<EPR>> nameToEPRs = categoryToNameToEPRs.get(category) ;
+ if (nameToEPRs == null)
+ {
+ nameToEPRs = new HashMap<String, ArrayList<EPR>>() ;
+ categoryToNameToEPRs.put(category, nameToEPRs) ;
+ }
+
+ ArrayList<EPR> eprs = nameToEPRs.get(name) ;
+ if (eprs == null)
+ {
+ eprs = new ArrayList<EPR>() ;
+ nameToEPRs.put(name, eprs) ;
+ }
+
+ eprs.add(epr) ;
+ }
+ finally
+ {
+ releaseWriteLock() ;
+ }
+ getRegistry().registerEPR(category, name, serviceDescription, epr, eprDescription) ;
+ }
+
+ /**
+ * 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
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Unregistering EPR " + epr + " for category " + category + ", name " + name) ;
+ }
+ acquireWriteLock() ;
+ try
+ {
+ final HashMap<String, ArrayList<EPR>> nameToEPRs = categoryToNameToEPRs.get(category) ;
+ if (nameToEPRs != null)
+ {
+ final ArrayList<EPR> eprs = nameToEPRs.get(name) ;
+ if (eprs != null)
+ {
+ eprs.remove(epr) ;
+ if (eprs.size() == 0)
+ {
+ nameToEPRs.remove(name) ;
+ if (nameToEPRs.isEmpty())
+ {
+ categoryToNameToEPRs.remove(category) ;
+ }
+ }
+ }
+ }
+ }
+ finally
+ {
+ releaseWriteLock() ;
+ }
+ getRegistry().unRegisterEPR(category, name, epr) ;
+ }
+
+ /**
+ * 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
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Unregistering service category " + category + ", name " + name) ;
+ }
+ acquireWriteLock() ;
+ try
+ {
+ final HashMap<String, ArrayList<EPR>> nameToEPRs = categoryToNameToEPRs.get(category) ;
+ if (nameToEPRs != null)
+ {
+ nameToEPRs.remove(name) ;
+ if (nameToEPRs.isEmpty())
+ {
+ categoryToNameToEPRs.remove(category) ;
+ }
+ }
+ }
+ finally
+ {
+ releaseWriteLock() ;
+ }
+ getRegistry().unRegisterService(category, name) ;
+ }
+
+ /**
+ * Acquire a read lock for accessing the data.
+ */
+ private void acquireReadLock()
+ {
+ lock.readLock().lock() ;
+ }
+
+ /**
+ * Release a read lock for accessing the data.
+ */
+ private void releaseReadLock()
+ {
+ lock.readLock().unlock() ;
+ }
+
+ /**
+ * Acquire a write lock for accessing the data.
+ */
+ private void acquireWriteLock()
+ {
+ lock.writeLock().lock() ;
+ }
+
+ /**
+ * Release a write lock for accessing the data.
+ */
+ private void releaseWriteLock()
+ {
+ lock.writeLock().unlock() ;
+ }
+}
Property changes on: labs/jbossesb/workspace/platform/JBESB_4_4_SOA_4_3_CP2_1081443/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/LocalRegistryInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list