summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java31
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java13
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/impl/ConversationManagerImpl.java24
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/DefaultWorkScheduler.java16
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManager.java53
-rw-r--r--java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/Jsr237WorkSchedulerTestCase.java8
-rw-r--r--java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManagerTestCase.java28
-rw-r--r--java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java32
-rw-r--r--java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java48
-rw-r--r--java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java6
-rw-r--r--java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java2
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java26
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java42
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java39
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java7
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/LifeCycleListener.java36
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java10
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java10
-rw-r--r--java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHost.java2
-rw-r--r--java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHostExtensionPoint.java16
-rw-r--r--java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/ExtensibleRMIHost.java5
-rw-r--r--java/sca/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHost.java5
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java2
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java27
24 files changed, 288 insertions, 200 deletions
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java
index b1beac78e2..6d18b48002 100644
--- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java
@@ -6,53 +6,48 @@
* 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.work;
/**
* Defines the contract for scheduling asynchronous units of work.
- *
+ *
* <p>
* Units of work can be scheduled with an optional <code>NotificationListener</code>.
- * If a notification listener is specified, the caller will be notified regarding the
- * status of the work. The unit of work can either be completed, rejected or completed
- * with an error. If the work completed with an error, the caller is notified with the
+ * If a notification listener is specified, the caller will be notified regarding the
+ * status of the work. The unit of work can either be completed, rejected or completed
+ * with an error. If the work completed with an error, the caller is notified with the
* error details.
* </p>
*
* @version $Rev$ $Date$
*/
public interface WorkScheduler {
-
+
/**
- * Schedules a unit of work for future execution. The notification listener
+ * Schedules a unit of work for future execution. The notification listener
* is used to register interest in callbacks regarding the status of the work.
- *
+ *
* @param work The unit of work that needs to be asynchronously executed.
* @param listener Notification listener for callbacks.
*/
<T extends Runnable>void scheduleWork(T work, NotificationListener<T> listener);
-
+
/**
- * Schedules a unit of work for future execution. The notification listener
+ * Schedules a unit of work for future execution. The notification listener
* is used to register interest in callbacks regarding the status of the work.
- *
+ *
* @param work The unit of work that needs to be asynchronously executed.
*/
<T extends Runnable>void scheduleWork(T work);
- /**
- * Destroys the work scheduler
- */
- void destroy();
-
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
index ed858bd499..89987a1117 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
@@ -6,22 +6,22 @@
* 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.conversation;
/**
* The manager of conversations
- *
+ *
* @version $Rev$ $Date$
*/
public interface ConversationManager {
@@ -58,14 +58,15 @@ public interface ConversationManager {
* @param listener
*/
void removeListener(ConversationListener listener);
-
+
/**
* @return the default max age for a conversation
*/
long getMaxAge();
-
+
/**
* @return the default max idle time for a conversation
*/
long getMaxIdleTime();
+
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/impl/ConversationManagerImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/impl/ConversationManagerImpl.java
index e23659b990..d2dff6ea09 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/impl/ConversationManagerImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/impl/ConversationManagerImpl.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.conversation.impl;
@@ -31,6 +31,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import org.apache.tuscany.sca.core.LifeCycleListener;
import org.apache.tuscany.sca.core.conversation.ConversationExt;
import org.apache.tuscany.sca.core.conversation.ConversationListener;
import org.apache.tuscany.sca.core.conversation.ConversationManager;
@@ -39,7 +40,7 @@ import org.apache.tuscany.sca.core.conversation.ConversationState;
/**
* @version $Rev$ $Date$
*/
-public class ConversationManagerImpl implements ConversationManager {
+public class ConversationManagerImpl implements ConversationManager, LifeCycleListener {
private List<ConversationListener> listeners = Collections.synchronizedList(new ArrayList<ConversationListener>());
private Map<Object, ConversationExt> conversations = new ConcurrentHashMap<Object, ConversationExt>();
@@ -174,8 +175,8 @@ public class ConversationManagerImpl implements ConversationManager {
*/
public synchronized void stopReaper() {
- // Prevent the scheduler from submitting any additional reapers,
- // initiate an orderly shutdown if a reaper task is in progress.
+ // Prevent the scheduler from submitting any additional reapers,
+ // initiate an orderly shutdown if a reaper task is in progress.
this.scheduler.shutdown();
}
@@ -215,4 +216,15 @@ public class ConversationManagerImpl implements ConversationManager {
public long getMaxAge() {
return maxAge;
}
+
+ public void stop() {
+ // REVIEW: A more graceful way?
+ scheduler.shutdownNow();
+ this.listeners.clear();
+ this.conversations.clear();
+ }
+
+ public void start() {
+ }
+
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/DefaultWorkScheduler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/DefaultWorkScheduler.java
index 3df2f7188b..9e6f3b3087 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/DefaultWorkScheduler.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/DefaultWorkScheduler.java
@@ -6,21 +6,22 @@
* 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.work.impl;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import org.apache.tuscany.sca.core.LifeCycleListener;
import org.apache.tuscany.sca.work.NotificationListener;
import org.apache.tuscany.sca.work.WorkScheduler;
import org.apache.tuscany.sca.work.WorkSchedulerException;
@@ -36,7 +37,7 @@ import org.apache.tuscany.sca.work.WorkSchedulerException;
*
* @version $Rev$ $Date$
*/
-public class DefaultWorkScheduler implements WorkScheduler {
+public class DefaultWorkScheduler implements WorkScheduler, LifeCycleListener {
/**
* Underlying JSR-237 work manager
@@ -62,7 +63,7 @@ public class DefaultWorkScheduler implements WorkScheduler {
// // ignore
// }
if (jsr237WorkManager == null) {
- jsr237WorkManager = new ThreadPoolWorkManager(10);
+ jsr237WorkManager = new ThreadPoolWorkManager(0);
}
return jsr237WorkManager;
}
@@ -110,7 +111,10 @@ public class DefaultWorkScheduler implements WorkScheduler {
}
- public void destroy() {
+ public void start() {
+ }
+
+ public void stop() {
if (jsr237WorkManager instanceof ThreadPoolWorkManager) {
// Allow privileged access to modify threads. Requires RuntimePermission in security
// policy.
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManager.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManager.java
index 12fa4a485d..e7728ca9a9 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManager.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManager.java
@@ -6,21 +6,21 @@
* 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.work.impl;
-import java.rmi.server.UID;
import java.util.Collection;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -28,7 +28,6 @@ import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadFactory;
import org.apache.tuscany.sca.work.WorkSchedulerException;
-import org.oasisopen.sca.annotation.Destroy;
/**
* A thread-pool based implementation for the JSR-237 work manager.
@@ -51,24 +50,24 @@ public class ThreadPoolWorkManager {
/**
* Initializes the thread-pool.
*
- * @param threadPoolSize Thread-pool size.
- * @throws IllegalArgumentException if threadPoolSize < 1
+ * @param threadPoolSize Thread-pool size. If the size <1, then a cached pool is created
*/
public ThreadPoolWorkManager(int threadPoolSize) {
- if (threadPoolSize < 1) {
- throw new IllegalArgumentException("Invalid threadPoolSize of "
- + threadPoolSize + ". It must be >= 1");
- }
-
- // Creates a new Executor, use a custom ThreadFactory that
- // creates daemon threads.
- executor = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() {
+ ThreadFactory factory = new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setDaemon(true);
return thread;
}
- });
+ };
+ if (threadPoolSize <= 0) {
+
+ // Creates a new Executor, use a custom ThreadFactory that
+ // creates daemon threads.
+ executor = Executors.newCachedThreadPool(factory);
+ } else {
+ executor = Executors.newFixedThreadPool(threadPoolSize);
+ }
}
/**
@@ -77,7 +76,7 @@ public class ThreadPoolWorkManager {
* @param work Work that needs to be scheduled.
* @return Work Work item representing the asynchronous work
*/
- public WorkItem schedule(Work<?> work) throws IllegalArgumentException {
+ public WorkItem schedule(Work work) throws IllegalArgumentException {
return schedule(work, null);
}
@@ -88,9 +87,9 @@ public class ThreadPoolWorkManager {
* @param workListener Work listener for callbacks.
* @return Work Work item representing the asynchronous work
*/
- public WorkItem schedule(Work<?> work, WorkListener workListener) throws IllegalArgumentException {
+ public WorkItem schedule(Work work, WorkListener workListener) throws IllegalArgumentException {
- WorkItem workItem = new WorkItem(new UID().toString(), work);
+ WorkItem workItem = new WorkItem(UUID.randomUUID().toString(), work);
if (workListener != null) {
workItems.put(workItem, workListener);
}
@@ -112,7 +111,7 @@ public class ThreadPoolWorkManager {
* @param works Units of the work that need to finish.
* @param timeout Timeout for waiting for the units of work to finish.
*/
- public boolean waitForAll(Collection<Work<?>> works, long timeout) {
+ public boolean waitForAll(Collection works, long timeout) {
throw new UnsupportedOperationException("waitForAll not supported");
}
@@ -122,7 +121,7 @@ public class ThreadPoolWorkManager {
* @param works Units of the work that need to finish.
* @param timeout Timeout for waiting for the units of work to finish.
*/
- public Collection<Work<?>> waitForAny(Collection<Work<?>> works, long timeout) {
+ public Collection waitForAny(Collection works, long timeout) {
throw new UnsupportedOperationException("waitForAny not supported");
}
@@ -132,7 +131,7 @@ public class ThreadPoolWorkManager {
* @param workItem Work item representing the work that was accepted.
* @param work Work that was accepted.
*/
- private void workAccepted(final WorkItem workItem, final Work<?> work) {
+ private void workAccepted(final WorkItem workItem, final Work work) {
WorkListener listener = workItems.get(workItem);
if (listener != null) {
workItem.setStatus(WorkEvent.WORK_ACCEPTED);
@@ -144,7 +143,7 @@ public class ThreadPoolWorkManager {
/*
* Method to indicate a work start.
*/
- private void workStarted(final WorkItem workItem, final Work<?> work) {
+ private void workStarted(final WorkItem workItem, final Work work) {
WorkListener listener = workItems.get(workItem);
if (listener != null) {
workItem.setStatus(WorkEvent.WORK_STARTED);
@@ -156,14 +155,14 @@ public class ThreadPoolWorkManager {
/*
* Method to indicate a work completion.
*/
- private void workCompleted(final WorkItem workItem, final Work<?> work) {
+ private void workCompleted(final WorkItem workItem, final Work work) {
workCompleted(workItem, work, null);
}
/*
* Method to indicate a work completion.
*/
- private void workCompleted(final WorkItem workItem, final Work<?> work, final WorkSchedulerException exception) {
+ private void workCompleted(final WorkItem workItem, final Work work, final WorkSchedulerException exception) {
WorkListener listener = workItems.get(workItem);
if (listener != null) {
workItem.setStatus(WorkEvent.WORK_COMPLETED);
@@ -178,7 +177,7 @@ public class ThreadPoolWorkManager {
/*
* Schedules the work using the ThreadPool.
*/
- private boolean scheduleWork(final Work<?> work, final WorkItem workItem) {
+ private boolean scheduleWork(final Work work, final WorkItem workItem) {
try {
executor.execute(new DecoratingWork(workItem, work));
return true;
@@ -221,9 +220,9 @@ public class ThreadPoolWorkManager {
}
- @Destroy
public void destroy() {
executor.shutdown();
}
}
+
diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/Jsr237WorkSchedulerTestCase.java b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/Jsr237WorkSchedulerTestCase.java
index 904f4ca5e0..c0f35d427c 100644
--- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/Jsr237WorkSchedulerTestCase.java
+++ b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/Jsr237WorkSchedulerTestCase.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.work.impl;
@@ -54,7 +54,7 @@ public class Jsr237WorkSchedulerTestCase {
@AfterClass
public static void destroy() {
if (workSchedular != null) {
- workSchedular.destroy();
+ workSchedular.stop();
}
}
diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManagerTestCase.java b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManagerTestCase.java
index b66fa75828..122609d7e6 100644
--- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManagerTestCase.java
+++ b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/impl/ThreadPoolWorkManagerTestCase.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.work.impl;
@@ -25,7 +25,7 @@ import org.junit.Test;
/**
* This test case will test the ThreadPoolWorkManager
- *
+ *
* @version $Rev$ $Date$
*/
public class ThreadPoolWorkManagerTestCase {
@@ -130,7 +130,7 @@ public class ThreadPoolWorkManagerTestCase {
}
/**
- * Tests running a mixture of fast and slow jobs some of which fail on the
+ * Tests running a mixture of fast and slow jobs some of which fail on the
* ThreadPoolWorkManager
*/
@Test
@@ -164,22 +164,6 @@ public class ThreadPoolWorkManagerTestCase {
}
/**
- * Tests creating a ThreadPoolWorkManager with invalid pool sizes of -10 to 0
- * inclusive
- */
- @Test
- public void testThreadPoolWorkManagerLessThan1Size() {
- for (int i = 0; i >= -10; i--) {
- try {
- new ThreadPoolWorkManager(i);
- Assert.fail("Should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException ex) {
- Assert.assertTrue(ex.toString().indexOf(Integer.toString(i)) != -1);
- }
- }
- }
-
- /**
* Tests running a single job that has no listener
*/
@Test
@@ -215,7 +199,7 @@ public class ThreadPoolWorkManagerTestCase {
/**
* Waits for the specified number of jobs to complete or the timeout to fire.
- *
+ *
* @param listener The listener to use to track Work unit completion
* @param completedWorkItemsToWaitFor The number of Work items to complete
*/
diff --git a/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java b/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
index 3d6ba89a74..0786e0e267 100644
--- a/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
+++ b/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
@@ -33,17 +33,17 @@ import org.apache.catalina.tribes.group.GroupChannel;
import org.apache.catalina.tribes.membership.McastService;
import org.apache.catalina.tribes.tipis.AbstractReplicatedMap;
import org.apache.catalina.tribes.tipis.ReplicatedMap;
-import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapEntry;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.EndpointReference;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.LifeCycleListener;
import org.apache.tuscany.sca.runtime.EndpointListener;
import org.apache.tuscany.sca.runtime.EndpointRegistry;
/**
* A replicated EndpointRegistry based on Apache Tomcat Tribes
*/
-public class ReplicatedEndpointRegistry implements EndpointRegistry {
+public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleListener {
private final static Logger logger = Logger.getLogger(ReplicatedEndpointRegistry.class.getName());
private static final String MULTICAST_ADDRESS = "228.0.0.100";
private static final int MULTICAST_PORT = 50000;
@@ -113,15 +113,18 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
if (timeoutStr != null) {
timeout = Integer.parseInt(timeoutStr);
}
- start();
+ // start();
}
public ReplicatedEndpointRegistry(String domainURI) {
this.domainURI = domainURI;
- start();
+ // start();
}
public void start() {
+ if (map != null) {
+ throw new IllegalStateException("The registry has already been started");
+ }
map =
new ReplicatedMap(null, createChannel(address, port, bind), timeout, this.domainURI,
new ClassLoader[] {ReplicatedEndpointRegistry.class.getClassLoader()});
@@ -133,12 +136,15 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
}
public void stop() {
- Channel channel = map.getChannel();
- map.breakdown();
- try {
- channel.stop(Channel.DEFAULT);
- } catch (ChannelException e) {
- throw new IllegalStateException(e);
+ if (map != null) {
+ Channel channel = map.getChannel();
+ map.breakdown();
+ try {
+ channel.stop(Channel.DEFAULT);
+ } catch (ChannelException e) {
+ throw new IllegalStateException(e);
+ }
+ map = null;
}
}
@@ -214,10 +220,10 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
Endpoint endpoint = (Endpoint)v;
// TODO: implement more complete matching
if (matches(targetEndpoint.getURI(), endpoint.getURI())) {
- MapEntry entry = map.getInternal(endpoint.getURI());
- if (!entry.isPrimary()) {
+ // MapEntry entry = map.getInternal(endpoint.getURI());
+ // if (!entry.isPrimary()) {
endpoint.setExtensionPointRegistry(registry);
- }
+ // }
foundEndpoints.add(endpoint);
logger.info("EndpointRegistry: Found endpoint with matching service - " + endpoint);
}
diff --git a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
index e963848c7f..ccb70b6a21 100644
--- a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
+++ b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointReferenceBuilderImpl.java
@@ -234,32 +234,36 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
if ((endpointReference.getReference().getBindings().size() == 0) ||
((endpointReference.getReference().getBindings().size() == 1) &&
(endpointReference.getReference().getBindings().get(0) instanceof SCABinding))){
- // OAISIS - choose a binding from the service side
+ // OAISIS - choose a binding from the service side
// (could have been specified as part of the target string)
// last part of this test that is looking for binding SCA is
// bogus. Just a temporary fix until we get rid of the OSOA
- // style reference side bindings.
-
- // retrieve the user specified binding name.
+ // style reference side bindings.
+
+ // retrieve the user specified binding name.
// TODO - EPR - we don't support this yet
-
+
// otherwise pick the first binding from the service
- endpointReference.setTargetEndpoint(endpoint.getService().getEndpoints().get(0));
+ if (local) {
+ endpointReference.setTargetEndpoint(endpoint.getService().getEndpoints().get(0));
+ } else {
+ endpointReference.setTargetEndpoint(endpoint);
+ }
endpointReference.setBinding(endpointReference.getTargetEndpoint().getBinding());
endpointReference.setUnresolved(false);
return;
-
+
} else {
- // OAISIS - this is an error
+ // OAISIS - this is an error
// (for now let it match bindings while we rewrite OSOA tests)
for (Binding referenceBinding : endpointReference.getReference().getBindings()) {
if (local) {
for (Endpoint serviceEndpoint : endpoint.getService().getEndpoints()) {
-
+
if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() && hasCompatiblePolicySets(referenceBinding,
serviceEndpoint
.getBinding())) {
-
+
matchedReferenceBinding.add(referenceBinding);
matchedServiceEndpoint.add(serviceEndpoint);
}
@@ -269,10 +273,10 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() && hasCompatiblePolicySets(referenceBinding,
serviceEndpoint
.getBinding())) {
-
+
matchedReferenceBinding.add(referenceBinding);
matchedServiceEndpoint.add(serviceEndpoint);
-
+
}
}
}
@@ -353,39 +357,39 @@ public class EndpointReferenceBuilderImpl implements CompositeBuilder, EndpointR
List<EndpointReference> callbackEndpointReferences = endpoint.getCallbackEndpointReferences();
List<Endpoint> matchedEndpoint = new ArrayList<Endpoint>();
-
+
// Find the corresponding bindings from callback service side
if ((callbackEndpointReferences.get(0).getReference().getBindings().size() == 0) ||
((callbackEndpointReferences.get(0).getReference().getBindings().size() == 1) &&
(callbackEndpointReferences.get(0).getReference().getBindings().get(0) instanceof SCABinding))){
- // OAISIS - choose a binding from the service side
+ // OAISIS - choose a binding from the service side
// (could have been specified as part of the target string)
// last part of this test that is looking for binding SCA is
// bogus. Just a temporary fix until we get rid of the OSOA
- // style reference side bindings.
-
- // retrieve the user specified binding name.
+ // style reference side bindings.
+
+ // retrieve the user specified binding name.
// TODO - EPR - we don't support this yet
-
+
// otherwise pick the first binding from the service
//endpointReference.setTargetEndpoint(endpoint.getService().getEndpoints().get(0));
//endpointReference.setBinding(endpointReference.getTargetEndpoint().getBinding());
endpointReference.setCallbackEndpoint(callbackEndpoints.get(0));
endpointReference.setUnresolved(false);
return;
-
+
} else {
- // OAISIS - this is an error
+ // OAISIS - this is an error
// (for now let it match bindings while we rewrite OSOA tests)
if ((callbackEndpoints != null) && (callbackEndpointReferences != null)){
// Find the corresponding bindings from the service side
for (EndpointReference epr : callbackEndpointReferences) {
for (Endpoint ep : callbackEndpoints) {
-
+
if (epr.getBinding().getClass() == ep.getBinding().getClass() &&
hasCompatiblePolicySets(epr.getBinding(), ep.getBinding())) {
-
+
matchedEndpoint.add(ep);
}
}
diff --git a/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java b/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java
index 1e44da4661..57733cce6c 100644
--- a/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java
+++ b/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java
@@ -43,7 +43,6 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.ModuleActivator;
import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
@@ -88,10 +87,7 @@ public class EndpointTestCase {
modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
// Initialize the Tuscany module activators
- ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
- for (ModuleActivator activator: moduleActivators.getModuleActivators()) {
- activator.start(extensionPoints);
- }
+ extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
// Get XML input/output factories
diff --git a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java
index 8c8ace95ad..bf03bfdb88 100644
--- a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java
+++ b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java
@@ -102,7 +102,7 @@ public class OSGiExtensionPointRegistry extends DefaultExtensionPointRegistry {
}
@Override
- public void destroy() {
+ public void stop() {
// 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 (ServiceRegistration reg : services.values()) {
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 3ea587c5f2..7fe79d6c00 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
@@ -65,8 +65,8 @@ 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);
+ if (extensionPoint instanceof LifeCycleListener) {
+ ((LifeCycleListener)extensionPoint).start();
}
Set<Class<?>> interfaces = getAllInterfaces(extensionPoint.getClass());
for (Class<?> i : interfaces) {
@@ -170,8 +170,8 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry {
throw new IllegalArgumentException("Cannot remove null as an ExtensionPoint");
}
- if (extensionPoint instanceof ModuleActivator) {
- ((ModuleActivator)extensionPoint).stop(this);
+ if (extensionPoint instanceof LifeCycleListener) {
+ ((LifeCycleListener)extensionPoint).stop();
}
Set<Class<?>> interfaces = getAllInterfaces(extensionPoint.getClass());
@@ -208,17 +208,21 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry {
}
}
- public void destroy() {
+ public void start() {
+ // Do nothing
+ }
+
+ public void stop() {
// Get a unique map as an extension point may exist in the map by different keys
- Map<ModuleActivator, ModuleActivator> map = new IdentityHashMap<ModuleActivator, ModuleActivator>();
+ Map<LifeCycleListener, LifeCycleListener> map = new IdentityHashMap<LifeCycleListener, LifeCycleListener>();
for (Object extp : extensionPoints.values()) {
- if (extp instanceof ModuleActivator) {
- ModuleActivator activator = (ModuleActivator)extp;
- map.put(activator, activator);
+ if (extp instanceof LifeCycleListener) {
+ LifeCycleListener listener = (LifeCycleListener)extp;
+ map.put(listener, listener);
}
}
- for (ModuleActivator activator : map.values()) {
- activator.stop(this);
+ for (LifeCycleListener listener : map.values()) {
+ listener.stop();
}
extensionPoints.clear();
}
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
index f9228efd71..60d933a443 100644
--- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
+++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
@@ -40,11 +40,14 @@ public class DefaultModuleActivatorExtensionPoint implements ModuleActivatorExte
private final static Logger logger = Logger.getLogger(DefaultModuleActivatorExtensionPoint.class.getName());
private List<ModuleActivator> activators = new ArrayList<ModuleActivator>();
private boolean loadedActivators;
+ private boolean started;
+ private ExtensionPointRegistry registry;
/**
* Constructs a new extension point.
*/
- public DefaultModuleActivatorExtensionPoint() {
+ public DefaultModuleActivatorExtensionPoint(ExtensionPointRegistry registry) {
+ this.registry = registry;
}
public void addModuleActivator(ModuleActivator activator) {
@@ -56,8 +59,10 @@ public class DefaultModuleActivatorExtensionPoint implements ModuleActivatorExte
return activators;
}
- public void removeModuleActivator(Object activator) {
- activators.remove(activator);
+ public void removeModuleActivator(ModuleActivator activator) {
+ if (activators.remove(activator)) {
+ activator.stop(registry);
+ }
}
/**
@@ -109,4 +114,35 @@ public class DefaultModuleActivatorExtensionPoint implements ModuleActivatorExte
loadedActivators = true;
}
+ public void start() {
+ if (started) {
+ return;
+ }
+ getModuleActivators();
+ for (ModuleActivator activator : activators) {
+ try {
+ activator.start(registry);
+ } catch (Throwable e) {
+ // Ignore the failing module for now
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ }
+ }
+ started = true;
+ }
+
+ public void stop() {
+ if (!started) {
+ return;
+ }
+ for (int i = activators.size() - 1; i >= 0; i--) {
+ try {
+ activators.get(i).stop(registry);
+ } catch (Throwable e) {
+ // Ignore the failing module for now
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ }
+ }
+ started = false;
+ }
+
}
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
index c7ff4e1858..1004fc3019 100644
--- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
+++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
@@ -23,7 +23,10 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -40,6 +43,7 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
private Map<Class<?>, Object> utilities = new ConcurrentHashMap<Class<?>, Object>();
private ExtensionPointRegistry extensionPoints;
+ private List<Object> unmapped = new ArrayList<Object>();
/**
* Constructs a new extension point.
@@ -61,6 +65,9 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
throw new IllegalArgumentException("Cannot register null as a Service");
}
+ if(utility instanceof LifeCycleListener) {
+ ((LifeCycleListener) utility).start();
+ }
Set<Class<?>> interfaces = getAllInterfaces(utility.getClass());
for (Class<?> i : interfaces) {
utilities.put(i, utility);
@@ -110,6 +117,10 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
throw new IllegalArgumentException("Cannot remove null as a Service");
}
+ if(utility instanceof LifeCycleListener) {
+ ((LifeCycleListener) utility).stop();
+ }
+
Set<Class<?>> interfaces = getAllInterfaces(utility.getClass());
for (Class<?> i : interfaces) {
utilities.remove(i);
@@ -178,6 +189,9 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
}
// Cache the loaded utility
addUtility(utility);
+ if (newInstance) {
+ unmapped.add(utility);
+ }
}
} catch (InvocationTargetException e) {
throw new IllegalArgumentException(e);
@@ -194,4 +208,29 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
return utilityType.cast(utility);
}
+ public void start() {
+ // NOOP
+ }
+
+ public void stop() {
+ // Get a unique map as an extension point may exist in the map by different keys
+ Map<LifeCycleListener, LifeCycleListener> map = new IdentityHashMap<LifeCycleListener, LifeCycleListener>();
+ for (Object util : utilities.values()) {
+ if (util instanceof LifeCycleListener) {
+ LifeCycleListener listener = (LifeCycleListener)util;
+ map.put(listener, listener);
+ }
+ }
+ for (Object util : unmapped) {
+ if (util instanceof LifeCycleListener) {
+ LifeCycleListener listener = (LifeCycleListener)util;
+ map.put(listener, listener);
+ }
+ }
+ for (LifeCycleListener listener : map.values()) {
+ listener.stop();
+ }
+ utilities.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 d5647d6601..4c6fbd283f 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
@@ -27,7 +27,7 @@ package org.apache.tuscany.sca.core;
*
* @version $Rev$ $Date$
*/
-public interface ExtensionPointRegistry {
+public interface ExtensionPointRegistry extends LifeCycleListener {
/**
* Add an extension point to the registry
@@ -53,9 +53,4 @@ public interface ExtensionPointRegistry {
* @throws IllegalArgumentException if extensionPoint is null
*/
void removeExtensionPoint(Object extensionPoint);
-
- /**
- * Destroy the extension point registry
- */
- void destroy();
}
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/LifeCycleListener.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/LifeCycleListener.java
new file mode 100644
index 0000000000..ff0ab113b2
--- /dev/null
+++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/LifeCycleListener.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.
+ */
+
+package org.apache.tuscany.sca.core;
+
+/**
+ * A listener that responds to the start/stop event of the ExtensionPointRegistry. Tuscany extension
+ * points or extensions can implement this interface to receive callbacks when the registry is started
+ * or stopped
+ */
+public interface LifeCycleListener {
+ /**
+ * The method will be invoked when the extension point registry is started
+ */
+ void start();
+ /**
+ * The method will be invoked when the extension point registry is stopped
+ */
+ void stop();
+}
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java
index ec0f12b8ba..7070d33f2c 100644
--- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java
+++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.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;
@@ -27,7 +27,7 @@ import java.util.List;
*
* @version $Rev$ $Date$
*/
-public interface ModuleActivatorExtensionPoint {
+public interface ModuleActivatorExtensionPoint extends LifeCycleListener {
/**
* Add a module activator extension to the extension point
@@ -49,5 +49,5 @@ public interface ModuleActivatorExtensionPoint {
*
* @throws IllegalArgumentException if activator is null
*/
- void removeModuleActivator(Object activator);
+ void removeModuleActivator(ModuleActivator activator);
}
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java
index 9804234850..4cf1db16d1 100644
--- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java
+++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.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;
@@ -25,7 +25,7 @@ package org.apache.tuscany.sca.core;
*
* @version $Rev$ $Date$
*/
-public interface UtilityExtensionPoint {
+public interface UtilityExtensionPoint extends LifeCycleListener {
/**
* Add a utility to the extension point
@@ -53,7 +53,7 @@ public interface UtilityExtensionPoint {
* @throws IllegalArgumentException if utilityType is null
*/
<T> T getUtility(Class<T> utilityType, boolean newInstance);
-
+
/**
* Remove a utility
* @param utility The utility to remove
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 f98ce018e5..99a6a5fab7 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
@@ -155,7 +155,7 @@ public class DefaultRMIHost implements RMIHost {
}
}
- public void destroy() {
+ public void stop() {
for (Registry registry : rmiRegistries.values()) {
try {
UnicastRemoteObject.unexportObject(registry, false);
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 edfda79dd0..b7435a1f84 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
@@ -22,15 +22,14 @@ 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;
+import org.apache.tuscany.sca.core.LifeCycleListener;
/**
* Default implementation of an RMI host extension point.
*
* @version $Rev$ $Date$
*/
-public class DefaultRMIHostExtensionPoint implements RMIHostExtensionPoint, ModuleActivator {
+public class DefaultRMIHostExtensionPoint implements RMIHostExtensionPoint, LifeCycleListener {
private List<RMIHost> rmiHosts = new ArrayList<RMIHost>();
@@ -40,6 +39,9 @@ public class DefaultRMIHostExtensionPoint implements RMIHostExtensionPoint, Modu
public void addRMIHost(RMIHost rmiHost) {
rmiHosts.add(rmiHost);
+ if(rmiHost instanceof LifeCycleListener) {
+ ((LifeCycleListener) rmiHost).start();
+ }
}
public void removeRMIHost(RMIHost rmiHost) {
@@ -50,12 +52,14 @@ public class DefaultRMIHostExtensionPoint implements RMIHostExtensionPoint, Modu
return rmiHosts;
}
- public void start(ExtensionPointRegistry registry) {
+ public void start() {
}
- public void stop(ExtensionPointRegistry registry) {
+ public void stop() {
for (RMIHost host : rmiHosts) {
- host.destroy();
+ if(host instanceof LifeCycleListener) {
+ ((LifeCycleListener) host).stop();
+ }
}
}
}
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 e2fad5d9b5..2f3e2311ed 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
@@ -59,9 +59,4 @@ public class ExtensibleRMIHost implements RMIHost {
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 b85cc2fc2a..bf8659c254 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
@@ -57,9 +57,4 @@ public interface RMIHost {
* @throws RMIHostRuntimeException
*/
Remote findService(String uri) throws RMIHostException, RMIHostRuntimeException;
-
- /**
- * Destroy the host. It can be used to unbind the RMI registry
- */
- void destroy();
}
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java
index fb2e8a8305..e597d62ef0 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/impl/NodeManager.java
@@ -68,7 +68,7 @@ public class NodeManager implements SynchronousBundleListener, ServiceListener {
if (headers.get("SCA-Composite") != null) {
return true;
}
- Enumeration<?> entries = bundle.findEntries("OSGI-INF/sca", "*", false);
+ Enumeration<?> entries = bundle.findEntries("OSGI-INF/sca", "*.composite", false);
if (entries != null && entries.hasMoreElements()) {
return true;
}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
index f637842afe..49310944e3 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
@@ -72,7 +72,6 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.ModuleActivator;
import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
@@ -121,12 +120,10 @@ public class NodeFactoryImpl extends NodeFactory {
private XMLInputFactory inputFactory;
protected FactoryExtensionPoint modelFactories;
private ModelResolverExtensionPoint modelResolvers;
- private List<ModuleActivator> moduleActivators = new ArrayList<ModuleActivator>();
private Monitor monitor;
protected ProxyFactory proxyFactory;
private Contribution systemContribution;
private Definitions systemDefinitions;
- private WorkScheduler workScheduler;
private StAXArtifactProcessorExtensionPoint xmlProcessors;
/**
@@ -198,14 +195,7 @@ public class NodeFactoryImpl extends NodeFactory {
node.destroy();
}
nodes.clear();
- // Stop the runtime modules in the reverse order
- for (int i = moduleActivators.size() - 1; i >= 0; i--) {
- moduleActivators.get(i).stop(extensionPoints);
- }
-
- // Stop and destroy the work manager
- workScheduler.destroy();
- extensionPoints.destroy();
+ extensionPoints.stop();
inited = false;
}
}
@@ -377,6 +367,7 @@ public class NodeFactoryImpl extends NodeFactory {
// Create extension point registry
extensionPoints = createExtensionPointRegistry();
+ extensionPoints.start();
// Enable schema validation only of the logger level is FINE or higher
if (isSchemaValidationEnabled()) {
@@ -398,16 +389,8 @@ public class NodeFactoryImpl extends NodeFactory {
monitor = monitorFactory.createMonitor();
// Initialize the Tuscany module activators
- ModuleActivatorExtensionPoint activators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
- for (ModuleActivator moduleActivator: activators.getModuleActivators()) {
- try {
- moduleActivator.start(extensionPoints);
- moduleActivators.add(moduleActivator);
- } catch (Throwable e) {
- // Ignore the failing module for now
- logger.log(Level.SEVERE, e.getMessage(), e);
- }
- }
+ // The module activators will be started
+ extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
// Get XML input/output factories
inputFactory = modelFactories.getFactory(XMLInputFactory.class);
@@ -440,7 +423,7 @@ public class NodeFactoryImpl extends NodeFactory {
ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class);
proxyFactory = new ExtensibleProxyFactory(proxyFactories);
- workScheduler = utilities.getUtility(WorkScheduler.class);
+ utilities.getUtility(WorkScheduler.class);
DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class);
systemDefinitions = definitionsFactory.createDefinitions();