[jboss-cvs] JBossAS SVN: r67111 - in projects/ejb3/trunk/locator/src: main/java/org/jboss/ejb3/locator/client and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 14 19:23:45 EST 2007
Author: ALRubinger
Date: 2007-11-14 19:23:45 -0500 (Wed, 14 Nov 2007)
New Revision: 67111
Added:
projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/integration/
projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/integration/DeployedEjbsRegistry.java
Modified:
projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/CachingServiceLocator.java
projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/Ejb3NotFoundException.java
projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiCachingServiceLocator.java
projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiHostConfigurationParser.java
projects/ejb3/trunk/locator/src/test/java/org/jboss/ejb3/test/locator/client/jndihostconfigparsing/JndiHostParsingTestCase.java
Log:
Minor refactoring of API, began planning for integration w/ EJB3 Core
Modified: projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/CachingServiceLocator.java
===================================================================
--- projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/CachingServiceLocator.java 2007-11-15 00:08:20 UTC (rev 67110)
+++ projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/CachingServiceLocator.java 2007-11-15 00:23:45 UTC (rev 67111)
@@ -169,7 +169,7 @@
}
// Obtain from the remote host
- T obj = this.getObjectFromRemoteHost(clazz);
+ T obj = this.getObject(clazz);
// If caching is enabled
if (useCache)
@@ -258,8 +258,29 @@
* @throws IllegalArgumentException
* If the specified class is a business interface implemented by more than
* one service across the configured local/remote hosts, or if the
- * specified class is no an interface
+ * specified class is not an interface
*/
- public abstract <T> T getObjectFromRemoteHost(Class<T> clazz) throws Ejb3NotFoundException, IllegalArgumentException;
+ public abstract <T> T getObject(Class<T> clazz) throws Ejb3NotFoundException, IllegalArgumentException;
+ /**
+ * Obtains the object associated with the specified business interface
+ * from the host with the specified ID.
+ *
+ * @param <T>
+ * @param hostId The ID of the host from which to obtain the
+ * object with the specified business interface
+ * @param clazz The business interface of the desired service
+ * @return
+ * @throws Ejb3NotFoundException
+ * If no services implementing the specified business interface
+ * could be found on the specified host
+ * @throws IllegalArgumentException
+ * If the specified class is a business interface implemented by more than
+ * one service across the specified host, if the
+ * specified class is not an interface, or if the specified host ID is not
+ * valid for one of the configured hosts
+ */
+ public abstract <T> T getObject(String hostId, Class<T> clazz) throws Ejb3NotFoundException,
+ IllegalArgumentException;
+
}
Modified: projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/Ejb3NotFoundException.java
===================================================================
--- projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/Ejb3NotFoundException.java 2007-11-15 00:08:20 UTC (rev 67110)
+++ projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/Ejb3NotFoundException.java 2007-11-15 00:23:45 UTC (rev 67111)
@@ -21,6 +21,12 @@
*/
package org.jboss.ejb3.locator.client;
+/**
+ *
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision $
+ *
+ */
public class Ejb3NotFoundException extends RuntimeException
{
// Class Members
Modified: projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiCachingServiceLocator.java
===================================================================
--- projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiCachingServiceLocator.java 2007-11-15 00:08:20 UTC (rev 67110)
+++ projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiCachingServiceLocator.java 2007-11-15 00:23:45 UTC (rev 67111)
@@ -22,10 +22,8 @@
package org.jboss.ejb3.locator.client;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -38,7 +36,7 @@
* services from one of a set of configured JNDI Directories (Hosts).
*
* @version $Revision $
- * @author <a href="mailto:alr at alrubinger.com">ALR</a>
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
*/
public final class JndiCachingServiceLocator extends CachingServiceLocator
{
@@ -53,22 +51,23 @@
/**
* List of JNDI Hosts on which Services may be bound
*/
- private List<JndiHost> jndiHosts = Collections.synchronizedList(new ArrayList<JndiHost>());
+ private final Map<String, JndiHost> jndiHosts = Collections.synchronizedMap(new HashMap<String, JndiHost>());
/**
* Mapping of Business Interface to the JNDI Host upon which it resides
*/
- private Map<Class<?>, JndiHost> serviceMappings = Collections.synchronizedMap(new HashMap<Class<?>, JndiHost>());
+ private final Map<Class<?>, JndiHost> serviceMappings = Collections
+ .synchronizedMap(new HashMap<Class<?>, JndiHost>());
// Constructor
/**
* Constructor
*/
- JndiCachingServiceLocator(List<JndiHost> jndiHosts)
+ JndiCachingServiceLocator(Map<String, JndiHost> jndiHosts)
{
super();
- this.jndiHosts = jndiHosts;
+ this.jndiHosts.putAll(jndiHosts);
}
// Contracts
@@ -87,10 +86,90 @@
* @throws IllegalArgumentException
* If the specified class is a business interface implemented by
* more than one service across the configured local/remote
- * hosts, or if the specified class is no an interface
+ * hosts, or if the specified class is not an interface
*/
- public <T> T getObjectFromRemoteHost(Class<T> clazz) throws Ejb3NotFoundException, IllegalArgumentException
+ public <T> T getObject(Class<T> clazz) throws Ejb3NotFoundException, IllegalArgumentException
{
+ // Initialize
+ T obj = null;
+
+ // For all configured hosts
+ for (JndiHost host : this.jndiHosts.values())
+ {
+ T retrievedObj = null;
+ try
+ {
+ retrievedObj = this.getObject(host, clazz);
+ }
+ // Ignore, simply not present on this one host
+ catch (Ejb3NotFoundException enfe)
+ {
+ continue;
+ }
+
+ // Ensure that an EJB with this business interface has not already been found on another host
+ if (obj != null)
+ {
+ throw new IllegalArgumentException("EJB3 with business interface " + clazz.getName()
+ + " is not unique across all configured hosts and may not be looked up by interface alone.");
+ }
+
+ // Set retrieved object to obj and continue searching through other configured hosts to ensure uniqueness
+ obj = retrievedObj;
+ }
+
+ // If not found on any hosts
+ if (obj == null)
+ {
+ throw new Ejb3NotFoundException("Could not find EJB3 with business interface " + clazz.getName()
+ + " on any configured hosts.");
+ }
+
+ // Return
+ return obj;
+ }
+
+ /**
+ * Obtains the object associated with the specified business interface
+ * from the host with the specified ID.
+ *
+ * @param <T>
+ * @param hostId The ID of the host from which to obtain the
+ * object with the specified business interface
+ * @param clazz The business interface of the desired service
+ * @return
+ * @throws Ejb3NotFoundException
+ * If no services implementing the specified business interface
+ * could be found on the specified host
+ * @throws IllegalArgumentException
+ * If the specified class is a business interface implemented by more than
+ * one service across the specified host, if the
+ * specified class is not an interface, or if the specified host ID is not
+ * valid for one of the configured hosts
+ */
+ public <T> T getObject(String hostId, Class<T> clazz) throws Ejb3NotFoundException, IllegalArgumentException
+ {
+ // Obtain configured host by ID
+ JndiHost host = this.jndiHosts.get(hostId);
+
+ // Ensure ID is valid
+ if (host == null)
+ {
+ throw new IllegalArgumentException("There are no configured hosts with ID of \"" + hostId + "\"");
+ }
+
+ // Return
+ return this.getObject(host, clazz);
+
+ }
+
+ // Internal Helper Methods
+
+ /**
+ *
+ */
+ private <T> T getObject(JndiHost host, Class<T> clazz) throws Ejb3NotFoundException, IllegalArgumentException
+ {
throw new RuntimeException("IMPLEMENT");
}
Modified: projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiHostConfigurationParser.java
===================================================================
--- projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiHostConfigurationParser.java 2007-11-15 00:08:20 UTC (rev 67110)
+++ projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/client/JndiHostConfigurationParser.java 2007-11-15 00:23:45 UTC (rev 67111)
@@ -24,7 +24,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
@@ -64,7 +66,7 @@
// Functional Methods
@SuppressWarnings(value = "unchecked")
- public List<JndiHost> parse(InputStream inStream)
+ public Map<String,JndiHost> parse(InputStream inStream)
{
// Initialize
Digester jndiHostDefinitionsDigester = new Digester();
@@ -110,7 +112,16 @@
ids.add(jndiHost.getId());
}
}
- return jndiHosts;
+
+ // Add to Map, indexed by ID
+ Map<String,JndiHost> hosts = new HashMap<String, JndiHost>();
+ for(JndiHost host : jndiHosts)
+ {
+ hosts.put(host.getId(), host);
+ }
+
+ // Return Map
+ return hosts;
}
// Internal Helper Methods
Added: projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/integration/DeployedEjbsRegistry.java
===================================================================
--- projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/integration/DeployedEjbsRegistry.java (rev 0)
+++ projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/integration/DeployedEjbsRegistry.java 2007-11-15 00:23:45 UTC (rev 67111)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.ejb3.locator.integration;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Registry to map all business interfaces of currently deployed EJBs
+ * to their names in JNDI
+ *
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
+ * @version $Revision $
+ */
+public class DeployedEjbsRegistry
+{
+
+ // Class Members
+
+ // Instance Members
+ private final Map<Class<?>, String> interfacesToJndiNameMappings = Collections
+ .synchronizedMap(new HashMap<Class<?>, String>());
+
+ // Constructor
+ public DeployedEjbsRegistry()
+ {
+ super();
+ }
+
+ // Functional Methods
+
+ /**
+ *
+ */
+ public void registerBusinessInterface(Class<?> clazz,String jndiName)
+ {
+ throw new RuntimeException("REVIEW API AND IMPLEMENT");
+ }
+
+}
Property changes on: projects/ejb3/trunk/locator/src/main/java/org/jboss/ejb3/locator/integration/DeployedEjbsRegistry.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: projects/ejb3/trunk/locator/src/test/java/org/jboss/ejb3/test/locator/client/jndihostconfigparsing/JndiHostParsingTestCase.java
===================================================================
--- projects/ejb3/trunk/locator/src/test/java/org/jboss/ejb3/test/locator/client/jndihostconfigparsing/JndiHostParsingTestCase.java 2007-11-15 00:08:20 UTC (rev 67110)
+++ projects/ejb3/trunk/locator/src/test/java/org/jboss/ejb3/test/locator/client/jndihostconfigparsing/JndiHostParsingTestCase.java 2007-11-15 00:23:45 UTC (rev 67111)
@@ -6,6 +6,7 @@
*/
package org.jboss.ejb3.test.locator.client.jndihostconfigparsing;
+import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
@@ -133,8 +134,10 @@
*/
private List<JndiHost> getConfigurationFromConfigFile(String fileName)
{
- return JndiHostConfigurationParser.getInstance().parse(
- Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName));
+ List<JndiHost> hosts = new ArrayList<JndiHost>();
+ hosts.addAll(JndiHostConfigurationParser.getInstance().parse(
+ Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)).values());
+ return hosts;
}
}
More information about the jboss-cvs-commits
mailing list