diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-09 22:19:54 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-07-09 22:19:54 +0000 |
commit | e7bad91576a64b9116cd04504df80639333b5be5 (patch) | |
tree | ac1e1cffda85281f44c85dd597450db1d219dcb1 | |
parent | f6512d3190de77f1f14e74efc16ad61f96fd61ff (diff) |
Apply the patch from Wojtek for TUSCANY-2397. Thanks. (corbaname-improvement-jira-2357-09-july.patch)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@675361 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
9 files changed, 33 insertions, 195 deletions
diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java index cc78cacdbb..dec015be38 100644 --- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaReferenceBindingProvider.java @@ -21,7 +21,6 @@ package org.apache.tuscany.sca.binding.corba.impl; import org.apache.tuscany.sca.binding.corba.CorbaBinding; import org.apache.tuscany.sca.host.corba.CorbaHost; -import org.apache.tuscany.sca.host.corba.CorbaHostUtils; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; @@ -51,11 +50,7 @@ public class CorbaReferenceBindingProvider implements ReferenceBindingProvider { public Invoker createInvoker(Operation operation) { try { if (remoteObject == null) { - if (CorbaHostUtils.isValidCorbanameURI(binding.getURI())) { - remoteObject = host.lookup(binding.getURI()); - } else { - remoteObject = host.lookup(binding.getName(), binding.getHost(), binding.getPort()); - } + remoteObject = host.lookup(binding.getCorbaname()); } return new CorbaInvoker(remoteObject); } catch (Exception e) { diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java index 1d21fe1e25..a7cc210470 100644 --- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java @@ -22,11 +22,9 @@ package org.apache.tuscany.sca.binding.corba.impl; import org.apache.tuscany.sca.binding.corba.CorbaBinding; import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; import org.apache.tuscany.sca.host.corba.CorbaHost; -import org.apache.tuscany.sca.host.corba.CorbaHostUtils; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.omg.CORBA.ORB; import org.osoa.sca.ServiceRuntimeException; /** @@ -38,8 +36,7 @@ public class CorbaServiceBindingProvider implements ServiceBindingProvider { private CorbaHost host; private RuntimeComponentService service; private DynaCorbaServant servant; - private ORB orb; - + public CorbaServiceBindingProvider(CorbaBinding binding, CorbaHost host, RuntimeComponentService service) { this.binding = binding; this.host = host; @@ -58,15 +55,9 @@ public class CorbaServiceBindingProvider implements ServiceBindingProvider { */ public void start() { try { - servant = new DynaCorbaServant(service, binding); servant.setIds(new String[] {binding.getId()}); - if (CorbaHostUtils.isValidCorbanameURI(binding.getURI())) { - host.registerServant(binding.getURI(), servant); - } else { - orb = host.createORB(binding.getHost(), binding.getPort(), false); - host.registerServant(orb, binding.getName(), servant); - } + host.registerServant(binding.getCorbaname(), servant); } catch (Exception e) { throw new ServiceRuntimeException(e); } @@ -78,11 +69,7 @@ public class CorbaServiceBindingProvider implements ServiceBindingProvider { */ public void stop() { try { - if (CorbaHostUtils.isValidCorbanameURI(binding.getURI())) { - host.unregisterServant(binding.getURI()); - } else if (orb != null) { - host.unregisterServant(orb, binding.getName()); - } + host.unregisterServant(binding.getCorbaname()); } catch (Exception e) { throw new ServiceRuntimeException(e); } diff --git a/java/sca/modules/binding-corba/pom.xml b/java/sca/modules/binding-corba/pom.xml index 3f4d2127c2..2eda625e4a 100644 --- a/java/sca/modules/binding-corba/pom.xml +++ b/java/sca/modules/binding-corba/pom.xml @@ -42,6 +42,12 @@ <version>1.4-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-corba</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + </dependencies> <build> diff --git a/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.java b/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.java index 667bfa361b..0b79065cc3 100644 --- a/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.java +++ b/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/CorbaBinding.java @@ -41,4 +41,6 @@ public interface CorbaBinding extends Binding { String getId(); void setId(String id); + + String getCorbaname(); } diff --git a/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.java b/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.java index c98b41549b..6afe49717f 100644 --- a/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.java +++ b/java/sca/modules/binding-corba/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaBindingImpl.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.host.corba.CorbaHostUtils; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.PolicySet; @@ -124,4 +125,8 @@ public class CorbaBindingImpl implements CorbaBinding, PolicySetAttachPoint { this.id = id; } + public String getCorbaname() { + return CorbaHostUtils.isValidCorbanameURI(getURI()) ? getURI(): CorbaHostUtils.createCorbanameURI(getHost(), getPort(), getName()); + } + } diff --git a/java/sca/modules/host-corba-jdk/src/main/java/org/apache/tuscany/sca/host/corba/jdk/DefaultCorbaHost.java b/java/sca/modules/host-corba-jdk/src/main/java/org/apache/tuscany/sca/host/corba/jdk/DefaultCorbaHost.java index 9bba7b289e..7e78607fd9 100644 --- a/java/sca/modules/host-corba-jdk/src/main/java/org/apache/tuscany/sca/host/corba/jdk/DefaultCorbaHost.java +++ b/java/sca/modules/host-corba-jdk/src/main/java/org/apache/tuscany/sca/host/corba/jdk/DefaultCorbaHost.java @@ -19,11 +19,8 @@ package org.apache.tuscany.sca.host.corba.jdk; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.StringTokenizer; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -56,12 +53,6 @@ public class DefaultCorbaHost implements CorbaHost { } } - private void validateName(String name) throws IllegalArgumentException { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException("Object name shouldn't be null"); - } - } - private NamingContextExt getNamingContext(ORB orb, String nameService) throws Exception { org.omg.CORBA.Object objRef = orb.resolve_initial_references(nameService); return NamingContextExtHelper.narrow(objRef); @@ -78,34 +69,13 @@ public class DefaultCorbaHost implements CorbaHost { } } - private List<String> tokenizeNamePath(String name) { - List<String> namePath = new ArrayList<String>(); - StringTokenizer path = new StringTokenizer(name, "/"); - while (path.hasMoreTokens()) { - namePath.add(path.nextToken()); - } - return namePath; - } - public void registerServant(String uri, Object servantObject) throws CorbaHostException { CorbanameURL details = CorbaHostUtils.getServiceDetails(uri); ORB orb = createORB(details.getHost(), details.getPort(), false); - registerServantCommon(orb, details.getNameService(), details.getNamePath(), servantObject); - } - - public void registerServant(ORB orb, String name, Object servantObject) throws CorbaHostException { - validateName(name); - List<String> namePath = tokenizeNamePath(name); - registerServantCommon(orb, CorbanameURL.DEFAULT_NAME_SERVICE, namePath, servantObject); - } - - private void registerServantCommon(ORB orb, String nameService, List<String> namePath, Object servantObject) - throws CorbaHostException { - try { - NamingContext namingCtx = getNamingContext(orb, nameService); - for (int i = 0; i < namePath.size() - 1; i++) { - NameComponent nc = new NameComponent(namePath.get(i), ""); + NamingContext namingCtx = getNamingContext(orb, details.getNameService()); + for (int i = 0; i < details.getNamePath().size() - 1; i++) { + NameComponent nc = new NameComponent(details.getNamePath().get(i), ""); NameComponent[] path = new NameComponent[] {nc}; try { namingCtx = NamingContextHelper.narrow(namingCtx.resolve(path)); @@ -113,7 +83,7 @@ public class DefaultCorbaHost implements CorbaHost { namingCtx = namingCtx.bind_new_context(path); } } - NameComponent finalName = new NameComponent(namePath.get(namePath.size() - 1), ""); + NameComponent finalName = new NameComponent(details.getNamePath().get(details.getNamePath().size() - 1), ""); try { namingCtx.resolve(new NameComponent[] {finalName}); // no exception means that some object is already registered @@ -132,34 +102,14 @@ public class DefaultCorbaHost implements CorbaHost { public void unregisterServant(String uri) throws CorbaHostException { CorbanameURL details = CorbaHostUtils.getServiceDetails(uri); ORB orb = createORB(details.getHost(), details.getPort(), false); - unregisterServantCommon(orb, details.getNamePath()); - } - - public void unregisterServant(ORB orb, String name) throws CorbaHostException { - validateName(name); - List<String> namePath = tokenizeNamePath(name); - unregisterServantCommon(orb, namePath); - } - - private void unregisterServantCommon(ORB orb, List<String> namePath) throws CorbaHostException { try { - NamingContext namingCtx = getNamingContext(orb, CorbanameURL.DEFAULT_NAME_SERVICE); - for (int i = 0; i < namePath.size() - 1; i++) { - NameComponent nc = new NameComponent(namePath.get(i), ""); - namingCtx = NamingContextHelper.narrow(namingCtx.resolve(new NameComponent[] {nc})); - } - NameComponent finalName = new NameComponent(namePath.get(namePath.size() - 1), ""); - namingCtx.unbind(new NameComponent[] {finalName}); + NamingContextExt namingCtx = getNamingContext(orb, details.getNameService()); + namingCtx.unbind(namingCtx.to_name(details.getName())); } catch (Exception e) { handleException(e); } } - - public Object lookup(String name, String host, int port) throws CorbaHostException { - validateName(name); - return lookup(CorbaHostUtils.createCorbanameURI(host, port, name)); - } - + public Object lookup(String uri) throws CorbaHostException { Object result = null; try { diff --git a/java/sca/modules/host-corba-jdk/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java b/java/sca/modules/host-corba-jdk/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java index 1fa2e241f5..92fb97ceaa 100644 --- a/java/sca/modules/host-corba-jdk/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java +++ b/java/sca/modules/host-corba-jdk/src/test/java/org/apache/tuscany/sca/host/corba/testing/DefaultCorbaHostTestCase.java @@ -39,7 +39,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import org.omg.CORBA.ORB; /** * General tests @@ -83,21 +82,10 @@ public class DefaultCorbaHostTestCase { @Test public void test_registerServant() { try { - /** - * Tests using servant registered with name, host, port - */ - ORB orb = host.createORB(LOCALHOST, DEFAULT_PORT, false); + String uri = CorbaHostUtils.createCorbanameURI(LOCALHOST, DEFAULT_PORT, "Nested/Test"); TestInterface servant = new TestInterfaceServant(); - String objName = "Nested/Test"; - String uri = CorbaHostUtils.createCorbanameURI(LOCALHOST, DEFAULT_PORT, objName); - host.registerServant(orb, objName, servant); - - // lookup using name, host and port - TestInterface ref = TestInterfaceHelper.narrow(host.lookup(objName, LOCALHOST, DEFAULT_PORT)); - assertEquals(2, ref.getInt(2)); - - // lookup using corbaname URI - ref = TestInterfaceHelper.narrow(host.lookup(uri)); + host.registerServant(uri, servant); + TestInterface ref = TestInterfaceHelper.narrow(host.lookup(uri)); assertEquals(2, ref.getInt(2)); } catch (Exception e) { e.printStackTrace(); @@ -112,34 +100,16 @@ public class DefaultCorbaHostTestCase { public void test_unregisterServant() { try { String objName = "Unregistering/Test"; - ORB orb = host.createORB(LOCALHOST, DEFAULT_PORT, false); String uri = CorbaHostUtils.createCorbanameURI(LOCALHOST, DEFAULT_PORT, objName); TestInterface servant = new TestInterfaceServant(); - // creating and releasing using name, host, port - host.registerServant(orb, objName, servant); - host.unregisterServant(orb, objName); - host.registerServant(orb, objName, servant); - host.unregisterServant(orb, objName); - // creating and releasing using corbaname URI host.registerServant(uri, servant); host.unregisterServant(uri); host.registerServant(uri, servant); host.unregisterServant(uri); - - // creating using name, host, port, releasing using corbaname URI - host.registerServant(orb, objName, servant); - host.unregisterServant(uri); - host.registerServant(uri, servant); - host.unregisterServant(uri); - - // creating using corbaname URI, releasing using name, host, port - host.registerServant(uri, servant); - host.unregisterServant(orb, objName); - host.registerServant(orb, objName, servant); - host.unregisterServant(orb, objName); } catch (Exception e) { + e.printStackTrace(); fail(); } } @@ -149,20 +119,6 @@ public class DefaultCorbaHostTestCase { */ @Test public void test_nameAlreadyRegistered() { - // test using name, host, port - try { - ORB orb = host.createORB(LOCALHOST, DEFAULT_PORT, false); - TestInterface servant = new TestInterfaceServant(); - host.registerServant(orb, "AlreadyRegisteredTest1", servant); - host.registerServant(orb, "AlreadyRegisteredTest1", servant); - fail(); - } catch (CorbaHostException e) { - assertTrue(e.getMessage().equals(CorbaHostException.BINDING_IN_USE)); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - // test using URI try { TestInterface servant = new TestInterfaceServant(); @@ -194,17 +150,6 @@ public class DefaultCorbaHostTestCase { // e.printStackTrace(); fail(); } - - // try to fetch object with name, host, port params - try { - host.lookup("NonExistingOne", LOCALHOST, DEFAULT_PORT); - fail(); - } catch (CorbaHostException e) { - // assertTrue(e.getMessage().equals(CorbaHostException.NO_SUCH_OBJECT)); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } } /** @@ -212,18 +157,6 @@ public class DefaultCorbaHostTestCase { */ @Test public void test_unregisterNonExistentObject() { - // test using name, host, port - try { - ORB orb = host.createORB(LOCALHOST, DEFAULT_PORT, false); - host.unregisterServant(orb, "NonExistingReference2"); - fail(); - } catch (CorbaHostException e) { - assertTrue(e.getMessage().equals(CorbaHostException.NO_SUCH_OBJECT)); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - // test using URI try { String uri = CorbaHostUtils.createCorbanameURI(LOCALHOST, DEFAULT_PORT, "NonExistingReference1"); @@ -243,9 +176,9 @@ public class DefaultCorbaHostTestCase { @Test public void test_invalidHost() { try { - ORB orb = host.createORB("not_" + LOCALHOST, DEFAULT_PORT, false); + String url = CorbaHostUtils.createCorbanameURI("not_" + LOCALHOST, DEFAULT_PORT, "Name"); TestInterface servant = new TestInterfaceServant(); - host.registerServant(orb, "Test", servant); + host.registerServant(url, servant); fail(); } catch (CorbaHostException e) { // Expected @@ -261,9 +194,9 @@ public class DefaultCorbaHostTestCase { @Test public void test_invalidPort() { try { - ORB orb = host.createORB(LOCALHOST, DEFAULT_PORT + 1, false); + String url = CorbaHostUtils.createCorbanameURI(LOCALHOST, DEFAULT_PORT + 1, "Name"); TestInterface servant = new TestInterfaceServant(); - host.registerServant(orb, "Test", servant); + host.registerServant(url, servant); fail(); } catch (CorbaHostException e) { // Expected @@ -280,9 +213,8 @@ public class DefaultCorbaHostTestCase { @Ignore("SUN JDK 6 is happy with all kind of names") public void test_invalidBindingName() { try { - ORB orb = host.createORB(LOCALHOST, DEFAULT_PORT, false); TestInterface servant = new TestInterfaceServant(); - host.registerServant(orb, "---", servant); + host.registerServant("---", servant); fail(); } catch (CorbaHostException e) { assertTrue(e.getMessage().equals(CorbaHostException.WRONG_NAME)); diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java index edba92d190..d5922ad305 100644 --- a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java +++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/CorbaHost.java @@ -34,14 +34,6 @@ public interface CorbaHost { * @return */ ORB createORB(String host, int port, boolean server) throws CorbaHostException; - /** - * Registers servant in name server. - * @param orb The ORB instance - * @param name binding name - * @param serviceObject - * @throws CorbaHostException - */ - void registerServant(ORB orb, String name, Object serviceObject) throws CorbaHostException; /** * Registers servant in name server. @@ -50,14 +42,6 @@ public interface CorbaHost { * @throws CorbaHostException */ void registerServant(String uri, Object serviceObject) throws CorbaHostException; - - /** - * Removes servant from name server - * @param orb The ORB instance - * @param name binding name - * @throws CorbaHostException - */ - void unregisterServant(ORB orb, String name) throws CorbaHostException; /** * Removes servant from name server @@ -70,16 +54,6 @@ public interface CorbaHost { /** * Gets reference to object * @param name binding name - * @param host ORB host name - * @param port ORB port - * @return - * @throws CorbaHostException - */ - Object lookup(String name, String host, int port) throws CorbaHostException; - - /** - * Gets reference to object - * @param name binding name * @return objects reference * @throws CorbaHostException */ diff --git a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java index f4196bf401..ace61d934e 100644 --- a/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java +++ b/java/sca/modules/host-corba/src/main/java/org/apache/tuscany/sca/host/corba/ExtensibleCorbaHost.java @@ -37,23 +37,10 @@ public class ExtensibleCorbaHost implements CorbaHost { return getCorbaHost().lookup(uri); } - public Object lookup(String name, String host, int port) throws CorbaHostException { - return getCorbaHost().lookup(name, host, port); - } - - public void registerServant(ORB orb, String name, Object serviceObject) throws CorbaHostException { - getCorbaHost().registerServant(orb, name, serviceObject); - } - public void registerServant(String uri, Object serviceObject) throws CorbaHostException { getCorbaHost().registerServant(uri, serviceObject); } - public void unregisterServant(ORB orb, String name) throws CorbaHostException { - getCorbaHost().unregisterServant(orb, name); - } - - public void unregisterServant(String uri) throws CorbaHostException { getCorbaHost().unregisterServant(uri); } |