From 3635a0ee6f59980439ec043f2251d950e4ffb8a4 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 27 May 2009 01:23:40 +0000 Subject: 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 --- .../sca/core/DefaultExtensionPointRegistry.java | 30 +++++++++++++++++++--- .../tuscany/sca/core/ExtensionPointRegistry.java | 11 +++++--- 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'java/sca/modules/extensibility') diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java index 3ed134dcec..3ea587c5f2 100644 --- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java +++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java @@ -25,6 +25,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.Map; import java.util.Set; @@ -64,7 +65,9 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { if (extensionPoint == null) { throw new IllegalArgumentException("Cannot register null as an ExtensionPoint"); } - + if (extensionPoint instanceof ModuleActivator) { + ((ModuleActivator)extensionPoint).start(this); + } Set> interfaces = getAllInterfaces(extensionPoint.getClass()); for (Class i : interfaces) { registerExtensionPoint(i, extensionPoint, declaration); @@ -112,13 +115,15 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { // Dynamically load an extension point class declared under META-INF/services try { - ServiceDeclaration extensionPointDeclaration = ServiceDiscovery.getInstance().getServiceDeclaration(extensionPointType.getName()); + ServiceDeclaration extensionPointDeclaration = + ServiceDiscovery.getInstance().getServiceDeclaration(extensionPointType.getName()); if (extensionPointDeclaration != null) { Class extensionPointClass = extensionPointDeclaration.loadClass(); // Construct the extension point Constructor[] constructors = extensionPointClass.getConstructors(); - Constructor constructor = getConstructor(constructors, new Class[] {ExtensionPointRegistry.class}); + Constructor constructor = + getConstructor(constructors, new Class[] {ExtensionPointRegistry.class}); if (constructor != null) { extensionPoint = constructor.newInstance(this); } else { @@ -165,6 +170,10 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { throw new IllegalArgumentException("Cannot remove null as an ExtensionPoint"); } + if (extensionPoint instanceof ModuleActivator) { + ((ModuleActivator)extensionPoint).stop(this); + } + Set> interfaces = getAllInterfaces(extensionPoint.getClass()); for (Class i : interfaces) { unregisterExtensionPoint(i); @@ -199,4 +208,19 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { } } + public void destroy() { + // Get a unique map as an extension point may exist in the map by different keys + Map map = new IdentityHashMap(); + for (Object extp : extensionPoints.values()) { + if (extp instanceof ModuleActivator) { + ModuleActivator activator = (ModuleActivator)extp; + map.put(activator, activator); + } + } + for (ModuleActivator activator : map.values()) { + activator.stop(this); + } + extensionPoints.clear(); + } + } diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java index f2f67b2d52..d5647d6601 100644 --- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java +++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.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.core; @@ -53,4 +53,9 @@ public interface ExtensionPointRegistry { * @throws IllegalArgumentException if extensionPoint is null */ void removeExtensionPoint(Object extensionPoint); + + /** + * Destroy the extension point registry + */ + void destroy(); } -- cgit v1.2.3