View Javadoc

1   /*
2    * $Id: DelegateWorkManager.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.jca;
12  
13  import org.mule.api.MuleException;
14  import org.mule.config.ImmutableThreadingProfile;
15  
16  import javax.resource.spi.work.ExecutionContext;
17  import javax.resource.spi.work.Work;
18  import javax.resource.spi.work.WorkException;
19  import javax.resource.spi.work.WorkListener;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionException;
22  
23  /**
24   * <code>DelegateWorkManager</code> is a wrapper around a WorkManager provided by a
25   * JCA container.
26   */
27  public class DelegateWorkManager implements org.mule.api.context.WorkManager
28  {
29      private final javax.resource.spi.work.WorkManager workManager;
30  
31      public DelegateWorkManager(javax.resource.spi.work.WorkManager workManager2)
32      {
33          this.workManager = workManager2;
34      }
35  
36      public void doWork(Work work) throws WorkException
37      {
38          workManager.doWork(work);
39      }
40  
41      public void doWork(Work work, long l, ExecutionContext executionContext, WorkListener workListener)
42          throws WorkException
43      {
44          workManager.doWork(work, l, executionContext, workListener);
45      }
46  
47      public long startWork(Work work) throws WorkException
48      {
49          return workManager.startWork(work);
50      }
51  
52      public long startWork(Work work, long l, ExecutionContext executionContext, WorkListener workListener)
53          throws WorkException
54      {
55          return workManager.startWork(work, l, executionContext, workListener);
56      }
57  
58      public void scheduleWork(Work work) throws WorkException
59      {
60          workManager.scheduleWork(work);
61      }
62  
63      public void scheduleWork(Work work, long l, ExecutionContext executionContext, WorkListener workListener)
64          throws WorkException
65      {
66          workManager.scheduleWork(work, l, executionContext, workListener);
67      }
68  
69      public void execute(Runnable command)
70      {
71          try
72          {
73              this.scheduleWork(new RunnableWorkAdapter(command));
74          }
75          catch (WorkException wex)
76          {
77              // unfortunately RejectedExecutionException is the closest thing we have
78              // as proper RuntimeException
79              throw new RejectedExecutionException(wex);
80          }
81      }
82  
83      public void start() throws MuleException
84      {
85          // nothing to do
86      }
87  
88      public boolean isStarted()
89      {
90          return true;
91      }
92  
93      public void stop() throws MuleException
94      {
95          // nothing to do
96      }
97  
98      public void dispose()
99      {
100         // nothing to do
101     }
102 
103     protected static class RunnableWorkAdapter implements Work
104     {
105         private final Runnable command;
106 
107         public RunnableWorkAdapter(Runnable command)
108         {
109             super();
110             this.command = command;
111         }
112 
113         public void release()
114         {
115             // nothing to do
116         }
117 
118         public void run()
119         {
120             command.run();
121         }
122     }
123 
124     public ImmutableThreadingProfile getThreadingProfile()
125     {
126         throw new UnsupportedOperationException("Container does not have a Mule ThreadingProfile");
127     }
128 
129 }