diff options
Diffstat (limited to '')
13 files changed, 96 insertions, 83 deletions
diff --git a/java/sca/modules/core/META-INF/MANIFEST.MF b/java/sca/modules/core/META-INF/MANIFEST.MF index bb0f164a14..3a87219d28 100644 --- a/java/sca/modules/core/META-INF/MANIFEST.MF +++ b/java/sca/modules/core/META-INF/MANIFEST.MF @@ -11,7 +11,7 @@ Export-Package: org.apache.tuscany.sca.core.assembly;uses:="org.apache cany.sca.interfacedef,org.apache.tuscany.sca.invocation,org.apache.tu
scany.sca.work,org.apache.tuscany.sca.contribution.processor";version
="1.4",org.apache.tuscany.sca.core.work;uses:="javax.naming,org.osoa.
- sca.annotations,commonj.work,org.apache.tuscany.sca.work";version="1.
+ sca.annotations,org.apache.tuscany.sca.work";version="1.
4",org.apache.tuscany.sca.core.context;uses:="org.apache.tuscany.sca.
runtime,org.apache.tuscany.sca.assembly,org.apache.tuscany.sca.contex
t,javax.security.auth,org.apache.tuscany.sca.monitor,org.apache.tusca
@@ -47,8 +47,7 @@ Bnd-LastModified: 1225397162265 Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA Core Runtime
-Import-Package: commonj.work,
- javax.naming,
+Import-Package: javax.naming,
javax.security.auth,
javax.xml.namespace,
javax.xml.stream,
diff --git a/java/sca/modules/core/pom.xml b/java/sca/modules/core/pom.xml index 49b98dc24a..e42a05ec52 100644 --- a/java/sca/modules/core/pom.xml +++ b/java/sca/modules/core/pom.xml @@ -60,12 +60,6 @@ </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-commonj_1.1_spec</artifactId> - <version>1.0</version> - </dependency> - - <dependency> <groupId>org.codehaus.woodstox</groupId> <artifactId>wstx-asl</artifactId> <version>3.2.4</version> diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java index ffc34e7328..2085a796ab 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java @@ -21,17 +21,10 @@ package org.apache.tuscany.sca.core.work; import java.security.AccessController; import java.security.PrivilegedAction; -import javax.naming.InitialContext; -import javax.naming.NamingException; - import org.apache.tuscany.sca.work.NotificationListener; import org.apache.tuscany.sca.work.WorkScheduler; import org.apache.tuscany.sca.work.WorkSchedulerException; -import commonj.work.WorkEvent; -import commonj.work.WorkListener; -import commonj.work.WorkManager; - /** * A work scheduler implementation based on a JSR 237 work manager. * <p/> @@ -43,31 +36,31 @@ import commonj.work.WorkManager; * * @version $Rev$ $Date$ */ -public class Jsr237WorkScheduler implements WorkScheduler { +public class DefaultWorkScheduler implements WorkScheduler { /** * Underlying JSR-237 work manager */ - private WorkManager jsr237WorkManager; + private ThreadPoolWorkManager jsr237WorkManager; /** * Initializes the JSR 237 work manager. * * @param jsr237WorkManager JSR 237 work manager. */ - public Jsr237WorkScheduler() { + public DefaultWorkScheduler() { } - private synchronized WorkManager getWorkManager() { + private synchronized ThreadPoolWorkManager getWorkManager() { if (jsr237WorkManager != null) { return jsr237WorkManager; } - try { - InitialContext ctx = new InitialContext(); - jsr237WorkManager = (WorkManager)ctx.lookup("java:comp/env/wm/TuscanyWorkManager"); - } catch (Throwable e) { - // ignore - } +// try { +// InitialContext ctx = new InitialContext(); +// jsr237WorkManager = (ThreadPoolWorkManager)ctx.lookup("java:comp/env/wm/TuscanyWorkManager"); +// } catch (Throwable e) { +// // ignore +// } if (jsr237WorkManager == null) { jsr237WorkManager = new ThreadPoolWorkManager(10); } @@ -97,7 +90,7 @@ public class Jsr237WorkScheduler implements WorkScheduler { throw new IllegalArgumentException("Work cannot be null"); } - Jsr237Work<T> jsr237Work = new Jsr237Work<T>(work); + Work<T> jsr237Work = new Work<T>(work); try { if (listener == null) { getWorkManager().schedule(jsr237Work); diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java index fb47a65edf..dad5968f65 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java @@ -27,15 +27,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ThreadFactory; +import org.apache.tuscany.sca.work.WorkSchedulerException; import org.osoa.sca.annotations.Destroy; -import commonj.work.Work; -import commonj.work.WorkEvent; -import commonj.work.WorkException; -import commonj.work.WorkItem; -import commonj.work.WorkListener; -import commonj.work.WorkManager; - /** * A thread-pool based implementation for the JSR-237 work manager. * <p/> @@ -46,10 +40,10 @@ import commonj.work.WorkManager; * * @version $Rev$ $Date$ */ -public class ThreadPoolWorkManager implements WorkManager { +public class ThreadPoolWorkManager { // Map of work items currently handled by the work manager - private Map<WorkItemImpl, WorkListener> workItems = new ConcurrentHashMap<WorkItemImpl, WorkListener>(); + private Map<WorkItem, WorkListener> workItems = new ConcurrentHashMap<WorkItem, WorkListener>(); // Thread-pool private ExecutorService executor; @@ -96,7 +90,7 @@ public class ThreadPoolWorkManager implements WorkManager { */ public WorkItem schedule(Work work, WorkListener workListener) throws IllegalArgumentException { - WorkItemImpl workItem = new WorkItemImpl(new UID().toString(), work); + WorkItem workItem = new WorkItem(new UID().toString(), work); if (workListener != null) { workItems.put(workItem, workListener); } @@ -106,7 +100,7 @@ public class ThreadPoolWorkManager implements WorkManager { } else { workItem.setStatus(WorkEvent.WORK_REJECTED); if (workListener != null) { - workListener.workRejected(new WorkEventImpl(workItem)); + workListener.workRejected(new WorkEvent(workItem)); } throw new IllegalArgumentException("Unable to schedule work"); } @@ -138,11 +132,11 @@ public class ThreadPoolWorkManager implements WorkManager { * @param workItem Work item representing the work that was accepted. * @param work Work that was accepted. */ - private void workAccepted(final WorkItemImpl 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); - WorkEvent event = new WorkEventImpl(workItem); + WorkEvent event = new WorkEvent(workItem); listener.workAccepted(event); } } @@ -150,11 +144,11 @@ public class ThreadPoolWorkManager implements WorkManager { /* * Method to indicate a work start. */ - private void workStarted(final WorkItemImpl 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); - WorkEvent event = new WorkEventImpl(workItem); + WorkEvent event = new WorkEvent(workItem); listener.workStarted(event); } } @@ -162,20 +156,20 @@ public class ThreadPoolWorkManager implements WorkManager { /* * Method to indicate a work completion. */ - private void workCompleted(final WorkItemImpl 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 WorkItemImpl workItem, final Work work, final WorkException 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); workItem.setResult(work); workItem.setException(exception); - WorkEvent event = new WorkEventImpl(workItem); + WorkEvent event = new WorkEvent(workItem); listener.workCompleted(event); workItems.remove(workItem); } @@ -184,7 +178,7 @@ public class ThreadPoolWorkManager implements WorkManager { /* * Schedules the work using the ThreadPool. */ - private boolean scheduleWork(final Work work, final WorkItemImpl workItem) { + private boolean scheduleWork(final Work work, final WorkItem workItem) { try { executor.execute(new DecoratingWork(workItem, work)); return true; @@ -199,7 +193,7 @@ public class ThreadPoolWorkManager implements WorkManager { private final class DecoratingWork implements Runnable { // Work item for this work. - private WorkItemImpl workItem; + private WorkItem workItem; // The original work. private Work decoratedWork; @@ -207,7 +201,7 @@ public class ThreadPoolWorkManager implements WorkManager { /* * Initializes the work item and underlying work. */ - private DecoratingWork(final WorkItemImpl workItem, final Work decoratedWork) { + private DecoratingWork(final WorkItem workItem, final Work decoratedWork) { this.workItem = workItem; this.decoratedWork = decoratedWork; } @@ -221,7 +215,7 @@ public class ThreadPoolWorkManager implements WorkManager { decoratedWork.run(); workCompleted(workItem, decoratedWork); } catch (Throwable th) { - workCompleted(workItem, decoratedWork, new WorkException(th.getMessage(), th)); + workCompleted(workItem, decoratedWork, new WorkSchedulerException(th.getMessage(), th)); } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Work.java index adeb667277..c521c60f79 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Work.java @@ -24,7 +24,7 @@ package org.apache.tuscany.sca.core.work; * * @version $Rev$ $Date$ */ -public class Jsr237Work<T extends Runnable> implements commonj.work.Work { +public class Work<T extends Runnable> { // Work that is being executed. private T work; @@ -32,7 +32,7 @@ public class Jsr237Work<T extends Runnable> implements commonj.work.Work { /* * Initializes the work instance. */ - public Jsr237Work(T work) { + public Work(T work) { this.work = work; } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEvent.java index 67d2b66f84..8e9a3b4c53 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEvent.java @@ -18,30 +18,34 @@ */ package org.apache.tuscany.sca.core.work; +import org.apache.tuscany.sca.work.WorkSchedulerException; + -import commonj.work.WorkEvent; -import commonj.work.WorkException; -import commonj.work.WorkItem; /** * Default immutable implementation of the <code>WorkEvent</code> class. * * @version $Rev$ $Date$ */ -class WorkEventImpl implements WorkEvent { +class WorkEvent { + public static final int WORK_ACCEPTED = 1; + public static final int WORK_REJECTED = 2; + public static final int WORK_STARTED = 3; + public static final int WORK_COMPLETED = 4; + // Work item for this event private WorkItem workItem; // Exception if something has gone wrong - private WorkException exception; + private WorkSchedulerException exception; /** * Instantiates the event. * * @param workItem Work item for this event. */ - public WorkEventImpl(final WorkItemImpl workItem) { + public WorkEvent(final WorkItem workItem) { this.workItem = workItem; this.exception = workItem.getException(); } @@ -70,7 +74,7 @@ class WorkEventImpl implements WorkEvent { * * @return Work exception. */ - public WorkException getException() { + public WorkSchedulerException getException() { return exception; } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItem.java index 170319b6e6..8320c7364f 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItem.java @@ -18,9 +18,7 @@ */ package org.apache.tuscany.sca.core.work; -import commonj.work.Work; -import commonj.work.WorkException; -import commonj.work.WorkItem; +import org.apache.tuscany.sca.work.WorkSchedulerException; /** * An identity based immutable implementation of the <code>WorkItem</code> @@ -28,7 +26,7 @@ import commonj.work.WorkItem; * * @version $Rev$ $Date$ */ -class WorkItemImpl implements WorkItem { +class WorkItem { // Id scoped for the VM private String id; @@ -43,14 +41,14 @@ class WorkItemImpl implements WorkItem { private Work originalWork; // Exception - private WorkException exception; + private WorkSchedulerException exception; /** * Instantiates an id for this item. * * @param id of this work event. */ - protected WorkItemImpl(final String id, final Work orginalWork) { + protected WorkItem(final String id, final Work orginalWork) { this.id = id; this.originalWork = orginalWork; } @@ -97,7 +95,7 @@ class WorkItemImpl implements WorkItem { * * @return Work exception. */ - protected WorkException getException() { + protected WorkSchedulerException getException() { return exception; } @@ -106,7 +104,7 @@ class WorkItemImpl implements WorkItem { * * @param exception Exception. */ - protected void setException(final WorkException exception) { + protected void setException(final WorkSchedulerException exception) { this.exception = exception; } @@ -146,7 +144,7 @@ class WorkItemImpl implements WorkItem { */ @Override public boolean equals(final Object obj) { - return (obj != null) && (obj.getClass() == WorkItemImpl.class) && ((WorkItemImpl) obj).id.equals(id); + return (obj != null) && (obj.getClass() == WorkItem.class) && ((WorkItem) obj).id.equals(id); } /** @@ -160,10 +158,10 @@ class WorkItemImpl implements WorkItem { * @throws ClassCastException needs better documentation. */ public int compareTo(final Object o) { - if (o.getClass() != WorkItemImpl.class) { + if (o.getClass() != WorkItem.class) { throw new ClassCastException(o.getClass().getName()); } else { - return ((WorkItemImpl) o).getId().compareTo(getId()); + return ((WorkItem) o).getId().compareTo(getId()); } } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java new file mode 100644 index 0000000000..19bfaaa560 --- /dev/null +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java @@ -0,0 +1,32 @@ +/*
+ * 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.work;
+
+public interface WorkListener {
+
+ static long IMMEDIATE = 0;
+ static long INDEFINITE = java.lang.Long.MAX_VALUE;
+
+ void workAccepted(WorkEvent event);
+ void workCompleted(WorkEvent event);
+ void workRejected(WorkEvent event);
+ void workStarted(WorkEvent event);
+
+}
diff --git a/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler index 56e99be0f2..93d93491a8 100644 --- a/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler +++ b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler @@ -15,4 +15,4 @@ # specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.core.work.Jsr237WorkScheduler
+org.apache.tuscany.sca.core.work.DefaultWorkScheduler
diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java index 3184c3de92..c69a1908e8 100644 --- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java +++ b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java @@ -18,14 +18,17 @@ */ package org.apache.tuscany.sca.core.work; -import commonj.work.Work; /** * Simple Work item that will throw an exception * * @version $Rev$ $Date$ */ -public class FailingWork implements Work { +public class FailingWork extends Work { + + public FailingWork() { + super(null); + } /** * {@inheritDoc} diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java index 225f23cb93..185394d7e8 100644 --- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java +++ b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java @@ -38,14 +38,14 @@ public class Jsr237WorkSchedulerTestCase { /** * This is the shared instance of the ThreadPoolWorkManager used by the tests */ - private static Jsr237WorkScheduler workSchedular = null; + private static DefaultWorkScheduler workSchedular = null; /** * Setup the Jsr237WorkScheduler */ @BeforeClass public static void setup() { - workSchedular = new Jsr237WorkScheduler(); + workSchedular = new DefaultWorkScheduler(); } /** diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java index ba32a92c18..58a1b87c48 100644 --- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java +++ b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java @@ -23,12 +23,9 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.tuscany.sca.work.WorkSchedulerException; import org.junit.Assert; -import commonj.work.WorkEvent; -import commonj.work.WorkException; -import commonj.work.WorkListener; - /** * A simple WorkListener that tracks invocations to it. * @@ -59,7 +56,7 @@ public class TestWorkListener implements WorkListener { /** * List of all exceptions thrown by Work items */ - private List<WorkException> workExceptions = Collections.synchronizedList(new ArrayList<WorkException>()); + private List<WorkSchedulerException> workExceptions = Collections.synchronizedList(new ArrayList<WorkSchedulerException>()); /** * {@inheritDoc} @@ -150,7 +147,7 @@ public class TestWorkListener implements WorkListener { * * @return A List of all exceptions that are thrown by the Work items */ - public List<WorkException> getWorkExceptions() { + public List<WorkSchedulerException> getWorkExceptions() { return Collections.unmodifiableList(workExceptions); } } diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java index 3b30d86f14..6c10057046 100644 --- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java +++ b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java @@ -20,15 +20,13 @@ package org.apache.tuscany.sca.core.work; import java.util.concurrent.atomic.AtomicInteger; -import commonj.work.Work; - /** * Simple Work item that will sleep in the run() method for the specified * period of time * * @version $Rev$ $Date$ */ -public class TimeDelayWork implements Work { +public class TimeDelayWork extends Work { /** * Count of completed run() method calls @@ -46,6 +44,7 @@ public class TimeDelayWork implements Work { * @param sleepTime The amount of time to sleep (in milliseconds) in the run() method */ public TimeDelayWork(long sleepTime) { + super(null); this.sleepTime = sleepTime; } |