diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-27 01:23:40 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-27 01:23:40 +0000 |
commit | 3635a0ee6f59980439ec043f2251d950e4ffb8a4 (patch) | |
tree | df7870b015abf1b4e6559d8045fb81293e7e7b31 /java/sca/modules/host-rmi/src/main | |
parent | d8da679db3c406c9c56cc14d047645d0cebb7afd (diff) |
Add optional life cycle control for extension points (for example, RMI extension point needs to unexport the registry)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@778955 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/host-rmi/src/main')
4 files changed, 64 insertions, 27 deletions
diff --git a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHost.java b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHost.java index c5c1f16869..f98ce018e5 100644 --- a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHost.java +++ b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHost.java @@ -21,11 +21,13 @@ package org.apache.tuscany.sca.host.rmi; import java.net.URI; import java.rmi.AlreadyBoundException; +import java.rmi.NoSuchObjectException; import java.rmi.NotBoundException; import java.rmi.Remote; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; @@ -153,4 +155,15 @@ public class DefaultRMIHost implements RMIHost { } } + public void destroy() { + for (Registry registry : rmiRegistries.values()) { + try { + UnicastRemoteObject.unexportObject(registry, false); + } catch (NoSuchObjectException e) { + e.printStackTrace(); + } + } + rmiRegistries.clear(); + } + } diff --git a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHostExtensionPoint.java b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHostExtensionPoint.java index 3ac086a2ee..edfda79dd0 100644 --- a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHostExtensionPoint.java +++ b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHostExtensionPoint.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.host.rmi; @@ -22,15 +22,18 @@ package org.apache.tuscany.sca.host.rmi; import java.util.ArrayList; import java.util.List; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; + /** * Default implementation of an RMI host extension point. - * + * * @version $Rev$ $Date$ */ -public class DefaultRMIHostExtensionPoint implements RMIHostExtensionPoint { +public class DefaultRMIHostExtensionPoint implements RMIHostExtensionPoint, ModuleActivator { private List<RMIHost> rmiHosts = new ArrayList<RMIHost>(); - + public DefaultRMIHostExtensionPoint() { addRMIHost(new DefaultRMIHost()); } @@ -46,4 +49,13 @@ public class DefaultRMIHostExtensionPoint implements RMIHostExtensionPoint { public List<RMIHost> getRMIHosts() { return rmiHosts; } + + public void start(ExtensionPointRegistry registry) { + } + + public void stop(ExtensionPointRegistry registry) { + for (RMIHost host : rmiHosts) { + host.destroy(); + } + } } diff --git a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/ExtensibleRMIHost.java b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/ExtensibleRMIHost.java index 29b4e195c7..e2fad5d9b5 100644 --- a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/ExtensibleRMIHost.java +++ b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/ExtensibleRMIHost.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.host.rmi; @@ -24,36 +24,44 @@ import java.rmi.Remote; /** * Default implementation of an extensible RMI host. - * + * * @version $Rev$ $Date$ */ public class ExtensibleRMIHost implements RMIHost { - + private RMIHostExtensionPoint rmiHosts; - + public ExtensibleRMIHost(RMIHostExtensionPoint rmiHosts) { this.rmiHosts = rmiHosts; } - + public void registerService(String uri, Remote serviceObject) throws RMIHostException, RMIHostRuntimeException { if (rmiHosts.getRMIHosts().isEmpty()) { throw new RMIHostException("No RMI host available"); } - rmiHosts.getRMIHosts().get(0).registerService(uri, serviceObject); + getDefaultHost().registerService(uri, serviceObject); } - + public void unregisterService(String uri) throws RMIHostException, RMIHostRuntimeException { if (rmiHosts.getRMIHosts().isEmpty()) { throw new RMIHostException("No RMI host available"); } - rmiHosts.getRMIHosts().get(0).unregisterService(uri); + getDefaultHost().unregisterService(uri); } - + public Remote findService(String uri) throws RMIHostException, RMIHostRuntimeException { if (rmiHosts.getRMIHosts().isEmpty()) { throw new RMIHostException("No RMI host available"); } - return rmiHosts.getRMIHosts().get(0).findService(uri); + return getDefaultHost().findService(uri); } - + + protected RMIHost getDefaultHost() { + return rmiHosts.getRMIHosts().get(0); + } + + public void destroy() { + getDefaultHost().destroy(); + } + } diff --git a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHost.java b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHost.java index b95b91f003..b85cc2fc2a 100644 --- a/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHost.java +++ b/java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHost.java @@ -6,15 +6,15 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ package org.apache.tuscany.sca.host.rmi; @@ -31,17 +31,17 @@ public interface RMIHost { /** * Register an RMI service with the given name and port - * + * * @param uri the URI against which the server is to be registered * @param serviceObject the server object to be registered * @throws RMIHostException * @throws RMIHostRuntimeException - */ + */ void registerService(String uri, Remote serviceObject) throws RMIHostException, RMIHostRuntimeException; /** * Unregister a service registered under the given service name and port number - * + * * @param uri the URI of the server * @throws RMIHostException * @throws RMIHostRuntimeException @@ -50,12 +50,16 @@ public interface RMIHost { /** * find a remote service hosted on the given host, port and service name - * + * * @param uri the URI of the service - * @return the RMI server object + * @return the RMI server object * @throws RMIHostException * @throws RMIHostRuntimeException */ Remote findService(String uri) throws RMIHostException, RMIHostRuntimeException; + /** + * Destroy the host. It can be used to unbind the RMI registry + */ + void destroy(); } |