diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2008-12-29 16:09:52 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2008-12-29 16:09:52 +0000 |
commit | 152cf09b068bbb6f55d7335a429cb7bc46e833bd (patch) | |
tree | d60ae2d929fe8307132f9af82030967be9f55c29 /branches/sca-java-1.x/modules/core/src | |
parent | 1a8a1e729ec0939248249325966676d216c18f93 (diff) |
Merge r720913 change to 1.x so we can start looking at a pluggable impl for the geronimo integration work and to remove the dependency from the compact distro
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@729926 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/core/src')
11 files changed, 94 insertions, 74 deletions
diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/DefaultWorkScheduler.java index ffc34e7328..2085a796ab 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java index fb47a65edf..dad5968f65 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Work.java index adeb667277..c521c60f79 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEvent.java index 67d2b66f84..8e9a3b4c53 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItem.java index 170319b6e6..8320c7364f 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkListener.java new file mode 100644 index 0000000000..19bfaaa560 --- /dev/null +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler b/branches/sca-java-1.x/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler index 56e99be0f2..93d93491a8 100644 --- a/branches/sca-java-1.x/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java b/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java index 3184c3de92..c69a1908e8 100644 --- a/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java b/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java index 225f23cb93..185394d7e8 100644 --- a/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java b/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java index ba32a92c18..58a1b87c48 100644 --- a/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java +++ b/branches/sca-java-1.x/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/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java b/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java index 3b30d86f14..6c10057046 100644 --- a/branches/sca-java-1.x/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java +++ b/branches/sca-java-1.x/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; } |