summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/extensibility
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 01:23:40 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 01:23:40 +0000
commit3635a0ee6f59980439ec043f2251d950e4ffb8a4 (patch)
treedf7870b015abf1b4e6559d8045fb81293e7e7b31 /java/sca/modules/extensibility
parentd8da679db3c406c9c56cc14d047645d0cebb7afd (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/extensibility')
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java30
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java11
2 files changed, 35 insertions, 6 deletions
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<Class<?>> 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<Class<?>> 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<ModuleActivator, ModuleActivator> map = new IdentityHashMap<ModuleActivator, ModuleActivator>();
+ 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();
}