[jboss-svn-commits] JBL Code SVN: r35277 - labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Sep 24 13:39:26 EDT 2010
Author: tcunning
Date: 2010-09-24 13:39:24 -0400 (Fri, 24 Sep 2010)
New Revision: 35277
Added:
labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionSingleton.java
Modified:
labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
Log:
JBESB-2849
Add a connection cache which stores connections and then recycles them.
Connections are stored by factory.
Added: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionSingleton.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionSingleton.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionSingleton.java 2010-09-24 17:39:24 UTC (rev 35277)
@@ -0,0 +1,85 @@
+package org.jboss.internal.soa.esb.services.registry;
+
+import java.util.Hashtable;
+import javax.xml.registry.Connection;
+import javax.xml.registry.JAXRException;
+
+import org.apache.log4j.Logger;
+
+import java.util.Stack;
+
+/**
+ * JAXR Connection Singleton.
+ * <p/>
+ * Provides a cache for JAXRConnection.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class JAXRConnectionSingleton {
+ private static Logger logger = Logger.getLogger(JAXRConnectionSingleton.class);
+
+ private static JAXRConnectionSingleton instance = new JAXRConnectionSingleton();
+ private static Hashtable cachedConnectionHash = new Hashtable();
+
+ private JAXRConnectionSingleton() {
+ }
+
+ /**
+ * Return a connection, from the cache if possible.
+ * @param factory
+ * @return connection
+ */
+ public static Connection getConnection(JAXRConnectionFactory factory) {
+ if (instance == null) {
+ instance = new JAXRConnectionSingleton();
+ }
+
+ if (cachedConnectionHash.containsKey(factory)) {
+ Stack stack = (Stack) cachedConnectionHash.get(factory);
+ try {
+ Connection connection = null;
+ if (stack.isEmpty()) {
+ connection = factory.getConnection();
+ return connection;
+ } else {
+ connection = (Connection) stack.pop();
+ if ((connection != null) && (!connection.isClosed())) {
+ return connection;
+ } else {
+ logger.error("Cached connection was null or closed, creating new connection");
+ connection = factory.getConnection();
+ return connection;
+ }
+ }
+ } catch (JAXRException jaxre) {
+ return null;
+ }
+ } else {
+ Stack stack = new Stack();
+ cachedConnectionHash.put(factory, stack);
+ Connection connection = factory.getConnection();
+ return connection;
+ }
+ }
+
+ /**
+ * Recycle connection to the cache.
+ * @param factory
+ * @param connection
+ */
+ public static void recycleConnection(JAXRConnectionFactory factory,
+ Connection connection) {
+ if (instance == null) {
+ instance = new JAXRConnectionSingleton();
+ } else {
+ if (cachedConnectionHash.containsKey(factory)) {
+ Stack stack = (Stack) cachedConnectionHash.get(factory);
+ stack.push(connection);
+ } else {
+ Stack stack = new Stack();
+ stack.push(connection);
+ cachedConnectionHash.put(factory, stack);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2010-09-24 17:00:34 UTC (rev 35276)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2010-09-24 17:39:24 UTC (rev 35277)
@@ -101,7 +101,7 @@
{
Service service =null;
Organization organization = getJBossESBOrganization();
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
RegistryService rs = connection.getRegistryService();
BusinessQueryManager bqm = rs.getBusinessQueryManager();
@@ -115,7 +115,7 @@
organization.addService(service);
saveRegistryObject(service, jaxrConnectionFactory);
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
return service;
}
@@ -128,7 +128,7 @@
*/
public void unRegisterService(String category, String serviceName) throws RegistryException, ServiceNotFoundException{
// first find the ServiceBindings for this service
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
Service service = null;
try {
service = findService(category, serviceName);
@@ -143,7 +143,7 @@
} catch (JAXRException je) {
throw new RegistryException(je.getLocalizedMessage(), je);
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
/**
@@ -169,7 +169,7 @@
{
throw new RegistryException("Null EPR argument specified") ;
}
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
final Concept jbossTModel = getJBossESBTModel(connection);
@@ -211,9 +211,10 @@
} catch (MarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
+
/**
* Remove an EPR from the Registry
* @param category
@@ -224,7 +225,7 @@
*/
public void unRegisterEPR(String category, String serviceName, EPR toBeDeletedEPR) throws RegistryException, ServiceNotFoundException{
//first find the ServiceBindings for this service
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
Service service = null;
try {
service = findService(category, serviceName);
@@ -265,7 +266,7 @@
} catch (MarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
@@ -318,7 +319,7 @@
{
List<EPR> eprs = new ArrayList<EPR>();
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
final Concept jbossTModel = getJBossESBTModel(connection);
RegistryService rs = connection.getRegistryService();
@@ -357,7 +358,7 @@
} catch (UnmarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
return eprs;
}
@@ -372,7 +373,7 @@
public EPR findEPR(String category, String serviceName) throws RegistryException, ServiceNotFoundException
{
EPR epr = null ;
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
final Concept jbossTModel = getJBossESBTModel(connection);
RegistryService rs = connection.getRegistryService();
@@ -407,7 +408,7 @@
} catch (UnmarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
return epr;
@@ -425,7 +426,7 @@
if (organizationName==null) {
organizationName="";
}
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
// Get registry service and business query manager
RegistryService rs = connection.getRegistryService();
@@ -462,7 +463,7 @@
}
return null;
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
@@ -478,7 +479,7 @@
if ((category==null) || (serviceName == null)) {
return null ;
}
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
final Concept jbossTModel = getJBossESBTModel(connection);
// Get registry service and business query manager
@@ -536,7 +537,7 @@
}
return null;
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
@@ -688,7 +689,7 @@
if (category == null) {
return services;
}
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
// Get registry service and business query manager
RegistryService rs = connection.getRegistryService();
@@ -716,7 +717,7 @@
}
return services;
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
@@ -729,7 +730,7 @@
protected static Organization createJBossESBOrganization(JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException
{
// Getting the connection to the Registry (reading config)
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
//Logging in
RegistryService rs = connection.getRegistryService();
@@ -771,7 +772,7 @@
saveRegistryObject(organization, jaxrConnectionFactory);
return organization;
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
@@ -819,7 +820,7 @@
protected static void saveRegistryObject(RegistryObject registryObject, JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException
{
// Getting the connection to the Registry (reading config)
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
BulkResponse br = null;
@@ -883,7 +884,7 @@
throw new JAXRException("Errors occurred during save");
}
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
@@ -957,7 +958,7 @@
}
Collection<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
- Connection connection = jaxrConnectionFactory.getConnection();
+ Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
try {
final Concept jbossTModel = getJBossESBTModel(connection);
RegistryService rs = connection.getRegistryService();
@@ -988,7 +989,7 @@
} catch (Exception je) {
throw new RegistryException(je.getLocalizedMessage(), je);
} finally {
- jaxrConnectionFactory.closeConnection(connection);
+ JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
}
}
More information about the jboss-svn-commits
mailing list