[jboss-svn-commits] JBL Code SVN: r35077 - in labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product: jbossesb-registry and 11 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Sep 9 04:27:27 EDT 2010
Author: dpalmer at redhat.com
Date: 2010-09-09 04:27:26 -0400 (Thu, 09 Sep 2010)
New Revision: 35077
Added:
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/pom.xml
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIServiceMBean.java
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/ESBInVMServerTransport.java
labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/JuddiInVMServerTransport.java
Log:
Modular rossetta
Added: labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/pom.xml
===================================================================
--- labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/pom.xml (rev 0)
+++ labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/pom.xml 2010-09-09 08:27:26 UTC (rev 35077)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.soa.esb</groupId>
+ <artifactId>jbossesb-registry</artifactId>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.jboss.soa</groupId>
+ <artifactId>esb</artifactId>
+ <version>4.9.SNAPSHOT</version>
+ </parent>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.soa.esb</groupId>
+ <artifactId>jbossesb-rosetta</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-system-jmx</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.juddi</groupId>
+ <artifactId>uddi-ws</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.juddi</groupId>
+ <artifactId>juddi-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-jaxws</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java
===================================================================
--- labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java (rev 0)
+++ labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIService.java 2010-09-09 08:27:26 UTC (rev 35077)
@@ -0,0 +1,179 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.internal.soa.esb.dependencies;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.registry.server.ESBInVMServerTransport;
+import org.jboss.internal.soa.esb.util.PropertiesHelper;
+import org.jboss.internal.soa.esb.util.XMLHelper;
+import org.jboss.system.ServiceMBeanSupport;
+import org.apache.juddi.Registry;
+
+public class JuddiRMIService extends ServiceMBeanSupport implements JuddiRMIServiceMBean
+{
+ private Logger logger = Logger.getLogger(this.getClass());
+
+ private static final String DEFAULT_PROPERTIES_RESOURCE_FILE = "esb.juddi.xml";
+ private static final String JUDDI_PROPERTIES_RESOURCE_FILE = "esb.juddi.properties";
+ private static final String JUDDI_PROPERTY_FILE_COMMENTS = "Auto generated property file, do not edit" ;
+
+ private String propertiesResourceFile ;
+ private String propertiesFileDir;
+ private int numThreads = 20 ;
+ private long timeout = 20 ;
+
+ private ESBInVMServerTransport inVMServerTransport ;
+
+ public String getPropertiesResourceFile()
+ {
+ return propertiesResourceFile;
+ }
+
+ public void setPropertiesResourceFile(String propertiesResourceFile)
+ {
+ this.propertiesResourceFile = propertiesResourceFile;
+ }
+
+ public int getNumThreads()
+ {
+ return numThreads;
+ }
+
+ public void setNumThreads(final int numThreads)
+ {
+ this.numThreads = numThreads;
+ }
+
+ public long getTimeout()
+ {
+ return timeout;
+ }
+
+ public void setTimeout(final long timeout)
+ {
+ this.timeout = timeout;
+ }
+
+ protected void startService() throws Exception
+ {
+ logger.info("starting juddi RMI service");
+ final String propertiesResourceFileVal ;
+ if (propertiesResourceFile == null)
+ {
+ propertiesResourceFileVal = DEFAULT_PROPERTIES_RESOURCE_FILE ;
+ }
+ else
+ {
+ propertiesResourceFileVal = propertiesResourceFile ;
+ }
+ final File baseFile = new File(propertiesResourceFileVal) ;
+
+ final InputStream xmlPropertyIS ;
+ if (baseFile.isAbsolute())
+ {
+ xmlPropertyIS = new FileInputStream(baseFile);
+ }
+ else
+ {
+ final URL url = Thread.currentThread().getContextClassLoader().getResource(propertiesResourceFileVal);
+ xmlPropertyIS = url.openStream() ;
+ }
+ final byte[] propertyFileContents ;
+ try {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
+ XMLHelper.replaceSystemProperties(XMLHelper.getXMLStreamReader(xmlPropertyIS),
+ XMLHelper.getXMLStreamWriter(baos)) ;
+ propertyFileContents = baos.toByteArray() ;
+ } finally {
+ xmlPropertyIS.close() ;
+ }
+
+ if (propertiesFileDir == null)
+ {
+ final String errorMsg = String.format("No property named '%s' was configured in jbossesb.sar/META-INF/jboss-service.xml for %s", "propertiesFileDir", getClass().getName());
+ throw new IllegalArgumentException(errorMsg);
+ }
+
+ File dataDir = new File(propertiesFileDir);
+ if (!dataDir.exists())
+ {
+ final String errorMsg = String.format("The directory configured for %s='%s' does not exist.", "warFilesDir", dataDir);
+ throw new FileNotFoundException(errorMsg);
+ }
+ final File juddiPropertyFile = new File(dataDir, JUDDI_PROPERTIES_RESOURCE_FILE) ;
+
+ final ByteArrayInputStream bais = new ByteArrayInputStream(propertyFileContents) ;
+ final FileOutputStream juddiPropertyOS = new FileOutputStream(juddiPropertyFile) ;
+ try {
+ PropertiesHelper.translateXMLToText(bais, juddiPropertyOS, JUDDI_PROPERTY_FILE_COMMENTS) ;
+ } finally {
+ juddiPropertyOS.close() ;
+ }
+
+ System.setProperty("juddi.propertiesFile", juddiPropertyFile.getAbsolutePath());
+
+ Registry.start();
+
+ try
+ {
+ final ESBInVMServerTransport inVMServerTransport = new ESBInVMServerTransport() ;
+ inVMServerTransport.start(numThreads) ;
+ this.inVMServerTransport = inVMServerTransport ;
+ }
+ finally
+ {
+ if (inVMServerTransport == null)
+ {
+ Registry.stop();
+ }
+ }
+ }
+
+ protected void stopService() throws Exception
+ {
+ try
+ {
+ inVMServerTransport.stop(timeout) ;
+ }
+ finally
+ {
+ inVMServerTransport = null ;
+ logger.info("Unbinding juddi services");
+ Registry.stop();
+ }
+ }
+
+ public void setPropertiesFileDir(final String directory)
+ {
+ this.propertiesFileDir = directory;
+ }
+}
Added: labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIServiceMBean.java
===================================================================
--- labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIServiceMBean.java (rev 0)
+++ labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/dependencies/JuddiRMIServiceMBean.java 2010-09-09 08:27:26 UTC (rev 35077)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.internal.soa.esb.dependencies;
+
+import org.jboss.system.ServiceMBean;
+
+public interface JuddiRMIServiceMBean extends ServiceMBean
+{
+
+ String getPropertiesResourceFile() ;
+
+ void setPropertiesResourceFile(String propertiesResourceFile) ;
+
+ void setPropertiesFileDir(final String directory);
+
+ public int getNumThreads() ;
+
+ public void setNumThreads(final int numThreads) ;
+
+ public long getTimeout() ;
+
+ public void setTimeout(final long timeout) ;
+}
Added: labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/ESBInVMServerTransport.java
===================================================================
--- labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/ESBInVMServerTransport.java (rev 0)
+++ labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/ESBInVMServerTransport.java 2010-09-09 08:27:26 UTC (rev 35077)
@@ -0,0 +1,267 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.registry.server;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.juddi.v3.client.transport.Transport;
+import org.apache.juddi.v3.client.transport.TransportException;
+import org.apache.juddi.v3_service.JUDDIApiPortType;
+import org.jboss.internal.soa.esb.registry.client.ESBInVMTransport;
+import org.jboss.internal.soa.esb.registry.client.JuddiInVMTransport;
+import org.uddi.v3_service.UDDICustodyTransferPortType;
+import org.uddi.v3_service.UDDIInquiryPortType;
+import org.uddi.v3_service.UDDIPublicationPortType;
+import org.uddi.v3_service.UDDISecurityPortType;
+import org.uddi.v3_service.UDDISubscriptionListenerPortType;
+import org.uddi.v3_service.UDDISubscriptionPortType;
+
+
+/**
+ * ESB InVM server side delegating to node specific transports.
+ *
+ * @author <a href='Kevin.Conner at jboss.com'>Kevin Conner</a>
+ */
+public class ESBInVMServerTransport implements ESBInVMTransport
+{
+ /**
+ * Our class loader.
+ */
+ private final ClassLoader classLoader = getClass().getClassLoader() ;
+
+ /**
+ * Default key for null managers.
+ */
+ private static final byte[] DEFAULT_KEY = new byte[0] ;
+
+ /**
+ * The configured transports.
+ */
+ private final ConcurrentHashMap<Object, ConcurrentHashMap<String, Transport>> managerTransports = new ConcurrentHashMap<Object, ConcurrentHashMap<String, Transport>>() ;
+
+ /**
+ * The executor service.
+ */
+ private final AtomicReference<ExecutorService> executorServiceReference = new AtomicReference<ExecutorService>();
+
+ /**
+ * Return an API service for the specified node name and endpoint URL.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @param endpointURL The endpoint URL
+ * @return The API service implementation.
+ * @throws TransportException For exceptions obtaining the service implementation.
+ */
+ public JUDDIApiPortType getJUDDIApiService(final String managerName, final String nodeName, final String endpointURL)
+ throws TransportException
+ {
+ return getTransport(managerName, nodeName).getJUDDIApiService(endpointURL) ;
+ }
+
+
+ /**
+ * Return a Custody Transfer service for the specified node name and endpoint URL.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @param endpointURL The endpoint URL
+ * @return The Custody Transfer service implementation.
+ * @throws TransportException For exceptions obtaining the service implementation.
+ */
+ public UDDICustodyTransferPortType getUDDICustodyTransferService(final String managerName, final String nodeName, final String endpointURL)
+ throws TransportException
+ {
+ return getTransport(managerName, nodeName).getUDDICustodyTransferService(endpointURL) ;
+ }
+
+
+ /**
+ * Return an Inquiry service for the specified node name and endpoint URL.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @param endpointURL The endpoint URL
+ * @return The Inquiry service implementation.
+ * @throws TransportException For exceptions obtaining the service implementation.
+ */
+ public UDDIInquiryPortType getUDDIInquiryService(final String managerName, final String nodeName, final String endpointURL)
+ throws TransportException
+ {
+ return getTransport(managerName, nodeName).getUDDIInquiryService(endpointURL) ;
+ }
+
+
+ /**
+ * Return a Publish service for the specified node name and endpoint URL.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @param endpointURL The endpoint URL
+ * @return The Publish service implementation.
+ * @throws TransportException For exceptions obtaining the service implementation.
+ */
+ public UDDIPublicationPortType getUDDIPublishService(final String managerName, final String nodeName, final String endpointURL)
+ throws TransportException
+ {
+ return getTransport(managerName, nodeName).getUDDIPublishService(endpointURL) ;
+ }
+
+
+ /**
+ * Return a Security service for the specified node name and endpoint URL.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @param endpointURL The endpoint URL
+ * @return The Security service implementation.
+ * @throws TransportException For exceptions obtaining the service implementation.
+ */
+ public UDDISecurityPortType getUDDISecurityService(final String managerName, final String nodeName, final String endpointURL)
+ throws TransportException
+ {
+ return getTransport(managerName, nodeName).getUDDISecurityService(endpointURL) ;
+ }
+
+
+ /**
+ * Return a Subscription Listener service for the specified node name and endpoint URL.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @param endpointURL The endpoint URL
+ * @return The Subscription Listener service implementation.
+ * @throws TransportException For exceptions obtaining the service implementation.
+ */
+ public UDDISubscriptionListenerPortType getUDDISubscriptionListenerService(final String managerName, final String nodeName, final String endpointURL)
+ throws TransportException
+ {
+ return getTransport(managerName, nodeName).getUDDISubscriptionListenerService(endpointURL) ;
+ }
+
+
+ /**
+ * Return a Subscription service for the specified node name and endpoint URL.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @param endpointURL The endpoint URL
+ * @return The Subscription service implementation.
+ * @throws TransportException For exceptions obtaining the service implementation.
+ */
+ public UDDISubscriptionPortType getUDDISubscriptionService(final String managerName, final String nodeName, final String endpointURL)
+ throws TransportException
+ {
+ return getTransport(managerName, nodeName).getUDDISubscriptionService(endpointURL) ;
+ }
+
+ /**
+ * Get the transport for the specified node.
+ * @param managerName The manager name.
+ * @param nodeName The node name.
+ * @return The in vm transport.
+ */
+ private Transport getTransport(final String managerName, final String nodeName)
+ {
+ final ConcurrentHashMap<String, Transport> transports = getTransports(managerName) ;
+ final Transport transport = transports.get(nodeName) ;
+ if (transport != null)
+ {
+ return transport ;
+ }
+
+ final JuddiInVMServerTransport juddiTransport = new JuddiInVMServerTransport(managerName, nodeName, executorServiceReference) ;
+ final Transport current = transports.putIfAbsent(nodeName, juddiTransport) ;
+ return (current != null ? current: juddiTransport) ;
+ }
+
+
+ /**
+ * Get the transports for the specified manager.
+ * @param managerName The manager name.
+ * @return The manager transports.
+ */
+ private ConcurrentHashMap<String, Transport> getTransports(final String managerName)
+ {
+ final Object key = (managerName != null ? managerName : DEFAULT_KEY) ;
+ final ConcurrentHashMap<String, Transport> transports = managerTransports.get(key) ;
+ if (transports != null)
+ {
+ return transports ;
+ }
+ final ConcurrentHashMap<String, Transport> newTransports = new ConcurrentHashMap<String, Transport>() ;
+ final ConcurrentHashMap<String, Transport> current = managerTransports.putIfAbsent(key, newTransports) ;
+ return (current != null ? current: newTransports) ;
+ }
+
+ /**
+ * Start the background executor.
+ * @param numThreads The number of threads for the background executor.
+ */
+ public void start(final int numThreads)
+ throws TransportException
+ {
+ if (!executorServiceReference.compareAndSet(null, Executors.newFixedThreadPool(numThreads, new ScopedThreadFactory())))
+ {
+ throw new TransportException("Executor service already initialised") ;
+ }
+ JuddiInVMTransport.setImplementation(this) ;
+ }
+
+ /**
+ * Stop the background executor.
+ * @param timeout The number of seconds to wait for the background executor to terminate.
+ */
+ public void stop(final long timeout)
+ throws InterruptedException
+ {
+ final ExecutorService executorService = executorServiceReference.getAndSet(null) ;
+ if (executorService != null)
+ {
+ JuddiInVMTransport.setImplementation(null) ;
+ executorService.shutdown() ;
+ executorService.awaitTermination(timeout, TimeUnit.SECONDS) ;
+ }
+ }
+
+ /**
+ * Thread factory executing within the scoped classloader.
+ *
+ * @author kevin
+ */
+ private final class ScopedThreadFactory implements ThreadFactory
+ {
+ /**
+ * The default executor factory.
+ */
+ private final ThreadFactory defaultFactory = Executors.defaultThreadFactory() ;
+
+ /**
+ * Return a new daemon thread.
+ * @param runnable The runnable associated with the thread.
+ */
+ public Thread newThread(final Runnable runnable)
+ {
+ final Thread thread = defaultFactory.newThread(runnable) ;
+ thread.setContextClassLoader(classLoader) ;
+ return thread ;
+ }
+ }
+}
Added: labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/JuddiInVMServerTransport.java
===================================================================
--- labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/JuddiInVMServerTransport.java (rev 0)
+++ labs/jbossesb/workspace/dpalmer/JBESB_4_9_CP/product/jbossesb-registry/src/main/java/org/jboss/internal/soa/esb/registry/server/JuddiInVMServerTransport.java 2010-09-09 08:27:26 UTC (rev 35077)
@@ -0,0 +1,467 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.registry.server;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.juddi.v3.client.config.UDDIClerkManager;
+import org.apache.juddi.v3.client.config.UDDIClientContainer;
+import org.apache.juddi.v3.client.transport.Transport;
+import org.apache.juddi.v3.client.transport.TransportException;
+import org.apache.juddi.v3_service.JUDDIApiPortType;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.uddi.v3_service.UDDICustodyTransferPortType;
+import org.uddi.v3_service.UDDIInquiryPortType;
+import org.uddi.v3_service.UDDIPublicationPortType;
+import org.uddi.v3_service.UDDISecurityPortType;
+import org.uddi.v3_service.UDDISubscriptionListenerPortType;
+import org.uddi.v3_service.UDDISubscriptionPortType;
+
+
+/**
+ * InVM server side (usually scoped) transport that can be exposed through a client delegation layer.
+ *
+ * There is no interface for this service so we extend the jUDDI transport class
+ * and delegate to another implementation.
+ */
+public class JuddiInVMServerTransport extends Transport
+{
+ /**
+ * The current transport manager name.
+ */
+ private final String managerName ;
+ /**
+ * The current transport node name.
+ */
+ private final String nodeName ;
+ /**
+ * Our class loader.
+ */
+ private final ClassLoader classLoader = getClass().getClassLoader() ;
+
+ /**
+ * The juddi api port type instance.
+ */
+ private final AtomicReference<JUDDIApiPortType> juddiApiPortTypeRef = new AtomicReference<JUDDIApiPortType>() ;
+ /**
+ * The uddi custody transfer port type instance.
+ */
+ private final AtomicReference<UDDICustodyTransferPortType> uddiCustodyTransferPortTypeRef = new AtomicReference<UDDICustodyTransferPortType>() ;
+ /**
+ * The uddi inquiry port type instance.
+ */
+ private final AtomicReference<UDDIInquiryPortType> uddiInquiryPortTypeRef = new AtomicReference<UDDIInquiryPortType>() ;
+ /**
+ * The uddi publication port type instance.
+ */
+ private final AtomicReference<UDDIPublicationPortType> uddiPublicationPortTypeRef = new AtomicReference<UDDIPublicationPortType>() ;
+ /**
+ * The uddi security port type instance.
+ */
+ private final AtomicReference<UDDISecurityPortType> uddiSecurityPortTypeRef = new AtomicReference<UDDISecurityPortType>() ;
+ /**
+ * The uddi subscription listener port type instance.
+ */
+ private final AtomicReference<UDDISubscriptionListenerPortType> uddiSubscriptionListenerPortTypeRef = new AtomicReference<UDDISubscriptionListenerPortType>() ;
+ /**
+ * The uddi subscription port type instance.
+ */
+ private final AtomicReference<UDDISubscriptionPortType> uddiSubscriptionPortTypeRef = new AtomicReference<UDDISubscriptionPortType>() ;
+
+ /**
+ * The executor service.
+ */
+ private final AtomicReference<ExecutorService> executorServiceReference ;
+
+ /**
+ * Construct the InVM server transport instance with the delegated instance.
+ * @param managerName The manager name of the transport.
+ * @param nodeName The node name of the transport.
+ * @param executorServiceReference The task executor.
+ */
+ public JuddiInVMServerTransport(final String managerName, final String nodeName, final AtomicReference<ExecutorService> executorServiceReference)
+ {
+ this.managerName = managerName ;
+ this.nodeName = nodeName ;
+ this.executorServiceReference = executorServiceReference ;
+ }
+
+ @Override
+ public JUDDIApiPortType getJUDDIApiService(final String endpointURL)
+ throws TransportException
+ {
+ final JUDDIApiPortType current = juddiApiPortTypeRef.get() ;
+ if (current != null)
+ {
+ return current ;
+ }
+ final String juddiApiUrl ;
+ if (endpointURL == null)
+ {
+ try
+ {
+ final UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName) ;
+ juddiApiUrl = manager.getClientConfig().getUDDINode(nodeName).getJuddiApiUrl() ;
+ }
+ catch (final ConfigurationException ce)
+ {
+ throw new TransportException("Could not discover juddiApiUrl for node " + nodeName, ce) ;
+ }
+ }
+ else
+ {
+ juddiApiUrl = endpointURL ;
+ }
+ final Object delegatePortType = createDelegate(juddiApiUrl) ;
+
+ final InvocationHandler handler = new TaskHandler(delegatePortType) ;
+ final JUDDIApiPortType juddiApiPortType = (JUDDIApiPortType) Proxy.newProxyInstance(classLoader,
+ new Class[] {JUDDIApiPortType.class}, handler) ;
+ if (juddiApiPortTypeRef.compareAndSet(null, juddiApiPortType))
+ {
+ return juddiApiPortType ;
+ }
+ else
+ {
+ return juddiApiPortTypeRef.get() ;
+ }
+ }
+
+ @Override
+ public UDDICustodyTransferPortType getUDDICustodyTransferService(final String endpointURL)
+ throws TransportException
+ {
+ final UDDICustodyTransferPortType current = uddiCustodyTransferPortTypeRef.get() ;
+ if (current != null)
+ {
+ return current ;
+ }
+ final String custodyTransferUrl ;
+ if (endpointURL == null)
+ {
+ try
+ {
+ final UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName) ;
+ custodyTransferUrl = manager.getClientConfig().getUDDINode(nodeName).getCustodyTransferUrl() ;
+ }
+ catch (final ConfigurationException ce)
+ {
+ throw new TransportException("Could not discover custodyTransferUrl for node " + nodeName, ce) ;
+ }
+ }
+ else
+ {
+ custodyTransferUrl = endpointURL ;
+ }
+ final Object delegatePortType = createDelegate(custodyTransferUrl) ;
+ final InvocationHandler handler = new TaskHandler(delegatePortType) ;
+ final UDDICustodyTransferPortType uddiCustodyTransferPortType = (UDDICustodyTransferPortType) Proxy.newProxyInstance(classLoader,
+ new Class[] {UDDICustodyTransferPortType.class}, handler) ;
+ if (uddiCustodyTransferPortTypeRef.compareAndSet(null, uddiCustodyTransferPortType))
+ {
+ return uddiCustodyTransferPortType ;
+ }
+ else
+ {
+ return uddiCustodyTransferPortTypeRef.get() ;
+ }
+ }
+
+ @Override
+ public UDDIInquiryPortType getUDDIInquiryService(final String endpointURL)
+ throws TransportException
+ {
+ final UDDIInquiryPortType current = uddiInquiryPortTypeRef.get() ;
+ if (current != null)
+ {
+ return current ;
+ }
+ final String inquiryUrl ;
+ if (endpointURL == null)
+ {
+ try
+ {
+ final UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName) ;
+ inquiryUrl = manager.getClientConfig().getUDDINode(nodeName).getInquiryUrl() ;
+ }
+ catch (final ConfigurationException ce)
+ {
+ throw new TransportException("Could not discover inquiryUrl for node " + nodeName, ce) ;
+ }
+ }
+ else
+ {
+ inquiryUrl = endpointURL ;
+ }
+ final Object delegatePortType = createDelegate(inquiryUrl) ;
+ final InvocationHandler handler = new TaskHandler(delegatePortType) ;
+ final UDDIInquiryPortType uddiInquiryPortType = (UDDIInquiryPortType) Proxy.newProxyInstance(classLoader,
+ new Class[] {UDDIInquiryPortType.class}, handler) ;
+ if (uddiInquiryPortTypeRef.compareAndSet(null, uddiInquiryPortType))
+ {
+ return uddiInquiryPortType ;
+ }
+ else
+ {
+ return uddiInquiryPortTypeRef.get() ;
+ }
+ }
+
+ @Override
+ public UDDIPublicationPortType getUDDIPublishService(final String endpointURL)
+ throws TransportException
+ {
+ final UDDIPublicationPortType current = uddiPublicationPortTypeRef.get() ;
+ if (current != null)
+ {
+ return current ;
+ }
+ final String publishUrl ;
+ if (endpointURL == null)
+ {
+ try
+ {
+ final UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName) ;
+ publishUrl = manager.getClientConfig().getUDDINode(nodeName).getPublishUrl() ;
+ }
+ catch (final ConfigurationException ce)
+ {
+ throw new TransportException("Could not discover publishUrl for node " + nodeName, ce) ;
+ }
+ }
+ else
+ {
+ publishUrl = endpointURL ;
+ }
+ final Object delegatePortType = createDelegate(publishUrl) ;
+ final InvocationHandler handler = new TaskHandler(delegatePortType) ;
+ final UDDIPublicationPortType uddiPublicationPortType = (UDDIPublicationPortType) Proxy.newProxyInstance(classLoader,
+ new Class[] {UDDIPublicationPortType.class}, handler) ;
+ if (uddiPublicationPortTypeRef.compareAndSet(null, uddiPublicationPortType))
+ {
+ return uddiPublicationPortType ;
+ }
+ else
+ {
+ return uddiPublicationPortTypeRef.get() ;
+ }
+ }
+
+ @Override
+ public UDDISecurityPortType getUDDISecurityService(final String endpointURL)
+ throws TransportException
+ {
+ final UDDISecurityPortType current = uddiSecurityPortTypeRef.get() ;
+ if (current != null)
+ {
+ return current ;
+ }
+ final String securityUrl ;
+ if (endpointURL == null)
+ {
+ try
+ {
+ final UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName) ;
+ securityUrl = manager.getClientConfig().getUDDINode(nodeName).getSecurityUrl() ;
+ }
+ catch (final ConfigurationException ce)
+ {
+ throw new TransportException("Could not discover securityUrl for node " + nodeName, ce) ;
+ }
+ }
+ else
+ {
+ securityUrl = endpointURL ;
+ }
+ final Object delegatePortType = createDelegate(securityUrl) ;
+ final InvocationHandler handler = new TaskHandler(delegatePortType) ;
+ final UDDISecurityPortType uddiSecurityPortType = (UDDISecurityPortType) Proxy.newProxyInstance(classLoader,
+ new Class[] {UDDISecurityPortType.class}, handler) ;
+ if (uddiSecurityPortTypeRef.compareAndSet(null, uddiSecurityPortType))
+ {
+ return uddiSecurityPortType ;
+ }
+ else
+ {
+ return uddiSecurityPortTypeRef.get() ;
+ }
+ }
+
+ @Override
+ public UDDISubscriptionListenerPortType getUDDISubscriptionListenerService(final String endpointURL)
+ throws TransportException
+ {
+ final UDDISubscriptionListenerPortType current = uddiSubscriptionListenerPortTypeRef.get() ;
+ if (current != null)
+ {
+ return current ;
+ }
+ final String subscriptionListenerUrl ;
+ if (endpointURL == null)
+ {
+ try
+ {
+ final UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName) ;
+ subscriptionListenerUrl = manager.getClientConfig().getUDDINode(nodeName).getSubscriptionListenerUrl() ;
+ }
+ catch (final ConfigurationException ce)
+ {
+ throw new TransportException("Could not discover subscriptionListenerUrl for node " + nodeName, ce) ;
+ }
+ }
+ else
+ {
+ subscriptionListenerUrl = endpointURL ;
+ }
+ final Object delegatePortType = createDelegate(subscriptionListenerUrl) ;
+ final InvocationHandler handler = new TaskHandler(delegatePortType) ;
+ final UDDISubscriptionListenerPortType uddiSubscriptionListenerPortType = (UDDISubscriptionListenerPortType) Proxy.newProxyInstance(classLoader,
+ new Class[] {UDDISubscriptionListenerPortType.class}, handler) ;
+ if (uddiSubscriptionListenerPortTypeRef.compareAndSet(null, uddiSubscriptionListenerPortType))
+ {
+ return uddiSubscriptionListenerPortType ;
+ }
+ else
+ {
+ return uddiSubscriptionListenerPortTypeRef.get() ;
+ }
+ }
+
+ @Override
+ public UDDISubscriptionPortType getUDDISubscriptionService(final String endpointURL)
+ throws TransportException
+ {
+ final UDDISubscriptionPortType current = uddiSubscriptionPortTypeRef.get() ;
+ if (current != null)
+ {
+ return current ;
+ }
+ final String subscriptionUrl ;
+ if (endpointURL == null)
+ {
+ try
+ {
+ final UDDIClerkManager manager = UDDIClientContainer.getUDDIClerkManager(managerName) ;
+ subscriptionUrl = manager.getClientConfig().getUDDINode(nodeName).getSubscriptionUrl() ;
+ }
+ catch (final ConfigurationException ce)
+ {
+ throw new TransportException("Could not discover subscriptionUrl for node " + nodeName, ce) ;
+ }
+ }
+ else
+ {
+ subscriptionUrl = endpointURL ;
+ }
+ final Object delegatePortType = createDelegate(subscriptionUrl) ;
+ final InvocationHandler handler = new TaskHandler(delegatePortType) ;
+ final UDDISubscriptionPortType uddiSubscriptionPortType = (UDDISubscriptionPortType) Proxy.newProxyInstance(classLoader,
+ new Class[] {UDDISubscriptionPortType.class}, handler) ;
+ if (uddiSubscriptionPortTypeRef.compareAndSet(null, uddiSubscriptionPortType))
+ {
+ return uddiSubscriptionPortType ;
+ }
+ else
+ {
+ return uddiSubscriptionPortTypeRef.get() ;
+ }
+ }
+
+ /**
+ * Create an instance of the delegate class.
+ * @param delegate The name of the delegate class.
+ * @return The delegate class instance.
+ * @throws TransportException For errors during loading/instantiation.
+ */
+ private Object createDelegate(final String delegate)
+ throws TransportException
+ {
+ try
+ {
+ final Class<?> delegateClass = ClassUtil.forName(delegate, getClass()) ;
+ return delegateClass.newInstance() ;
+ }
+ catch (final ClassNotFoundException cnfe)
+ {
+ throw new TransportException("Failed to locate delegate class " + delegate, cnfe) ;
+ }
+ catch (final InstantiationException ie)
+ {
+ throw new TransportException("Failed to instantiate delegate class " + delegate, ie) ;
+ }
+ catch (final IllegalAccessException iae)
+ {
+ throw new TransportException("Failed to instantiate delegate class " + delegate, iae) ;
+ }
+ }
+
+ /**
+ * Task handler responsible for executing juddi requests on the executor service.
+ * @author kevin
+ */
+ private final class TaskHandler implements InvocationHandler
+ {
+ private final Object target ;
+
+ /**
+ * Construct the task handler for the specified target instance.
+ * @param target The target instance.
+ */
+ TaskHandler(final Object target)
+ {
+ this.target = target ;
+ }
+
+ /**
+ * Handle the proxy invocation using the executor.
+ * @param proxy The proxy instance.
+ * @param method The method being invoked.
+ * @param args The arguments for the method invocation.
+ */
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
+ throws Throwable
+ {
+ final ExecutorService executorService = executorServiceReference.get() ;
+ if (executorService == null)
+ {
+ throw new TransportException("InVM Server executor service not initialised") ;
+ }
+ else
+ {
+ final Callable<Object> task = new Callable<Object>() {
+ public Object call() throws Exception {
+ return method.invoke(target, args) ;
+ }
+ };
+ final Future<Object> future = executorService.submit(task) ;
+ return future.get() ;
+ }
+ }
+ }
+}
More information about the jboss-svn-commits
mailing list