1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.ra; |
12 | |
|
13 | |
import org.mule.MuleException; |
14 | |
import org.mule.MuleManager; |
15 | |
import org.mule.config.i18n.CoreMessages; |
16 | |
import org.mule.impl.MuleDescriptor; |
17 | |
import org.mule.impl.OptimizedRequestContext; |
18 | |
import org.mule.impl.RequestContext; |
19 | |
import org.mule.impl.model.AbstractComponent; |
20 | |
import org.mule.ra.i18n.JcaMessages; |
21 | |
import org.mule.umo.ComponentException; |
22 | |
import org.mule.umo.MessagingException; |
23 | |
import org.mule.umo.UMODescriptor; |
24 | |
import org.mule.umo.UMOEvent; |
25 | |
import org.mule.umo.UMOException; |
26 | |
import org.mule.umo.UMOMessage; |
27 | |
import org.mule.umo.lifecycle.InitialisationException; |
28 | |
import org.mule.umo.manager.ObjectNotFoundException; |
29 | |
import org.mule.umo.manager.UMOWorkManager; |
30 | |
import org.mule.umo.model.UMOEntryPoint; |
31 | |
|
32 | |
import javax.resource.spi.UnavailableException; |
33 | |
import javax.resource.spi.endpoint.MessageEndpointFactory; |
34 | |
import javax.resource.spi.work.Work; |
35 | |
import javax.resource.spi.work.WorkEvent; |
36 | |
import javax.resource.spi.work.WorkListener; |
37 | |
import javax.resource.spi.work.WorkManager; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class JcaComponent extends AbstractComponent implements WorkListener |
45 | |
{ |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
private static final long serialVersionUID = -1510441245219710451L; |
51 | |
|
52 | |
private transient UMOEntryPoint entryPoint; |
53 | |
protected UMOWorkManager workManager; |
54 | |
|
55 | |
public JcaComponent(MuleDescriptor descriptor, UMOWorkManager workManager) |
56 | |
{ |
57 | |
|
58 | 16 | super(descriptor, MuleManager.getInstance().lookupModel(descriptor.getModelName())); |
59 | 16 | this.workManager = workManager; |
60 | 16 | } |
61 | |
|
62 | |
public UMODescriptor getDescriptor() |
63 | |
{ |
64 | 60 | return descriptor; |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public UMOMessage sendEvent(UMOEvent event) throws UMOException |
76 | |
{ |
77 | 2 | throw new UnsupportedOperationException("sendEvent()"); |
78 | |
} |
79 | |
|
80 | |
public boolean isPaused() |
81 | |
{ |
82 | |
|
83 | |
|
84 | 0 | return false; |
85 | |
} |
86 | |
|
87 | |
protected void waitIfPaused(UMOEvent event) throws InterruptedException |
88 | |
{ |
89 | |
|
90 | |
|
91 | 2 | } |
92 | |
|
93 | |
protected void doPause() throws UMOException |
94 | |
{ |
95 | 2 | throw new ComponentException(JcaMessages.cannotPauseResumeJcaComponent(), null, this); |
96 | |
} |
97 | |
|
98 | |
protected void doResume() throws UMOException |
99 | |
{ |
100 | 2 | throw new ComponentException(JcaMessages.cannotPauseResumeJcaComponent(), null, this); |
101 | |
} |
102 | |
|
103 | |
public synchronized void doInitialise() throws InitialisationException |
104 | |
{ |
105 | |
try |
106 | |
{ |
107 | 4 | entryPoint = MuleManager.getInstance() |
108 | |
.lookupModel(this.getDescriptor().getModelName()) |
109 | |
.getEntryPointResolver() |
110 | |
.resolveEntryPoint(descriptor); |
111 | |
} |
112 | 0 | catch (UMOException e) |
113 | |
{ |
114 | 0 | throw new InitialisationException(e, this); |
115 | 4 | } |
116 | 4 | } |
117 | |
|
118 | |
protected void doDispatch(UMOEvent event) throws UMOException |
119 | |
{ |
120 | |
try |
121 | |
{ |
122 | 2 | workManager.scheduleWork(new MuleJcaWorker(event), WorkManager.INDEFINITE, null, this); |
123 | |
} |
124 | 0 | catch (Exception e) |
125 | |
{ |
126 | 0 | throw new MuleException(CoreMessages.failedToInvoke("UMO Component: " + descriptor.getName()), e); |
127 | 2 | } |
128 | 2 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
protected UMOMessage doSend(UMOEvent event) throws UMOException |
135 | |
{ |
136 | 0 | return null; |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public Object getManagedInstance() throws UMOException |
147 | |
{ |
148 | 0 | Object managedInstance = null; |
149 | |
try |
150 | |
{ |
151 | |
|
152 | 0 | MessageEndpointFactory messageEndpointFactory = (MessageEndpointFactory) descriptor.getImplementation(); |
153 | 0 | managedInstance = messageEndpointFactory.createEndpoint(null); |
154 | |
|
155 | |
} |
156 | 0 | catch (UnavailableException e) |
157 | |
{ |
158 | |
|
159 | 0 | logger.error("Request Failed to allocate Managed Instance" + e.getMessage(), e); |
160 | 0 | throw new ObjectNotFoundException(this.getName(), e); |
161 | 0 | } |
162 | |
|
163 | 0 | return managedInstance; |
164 | |
} |
165 | |
|
166 | |
public class MuleJcaWorker implements Work |
167 | |
{ |
168 | |
|
169 | |
private UMOEvent event; |
170 | |
|
171 | |
MuleJcaWorker(UMOEvent event) |
172 | 2 | { |
173 | 2 | this.event = event; |
174 | 2 | } |
175 | |
|
176 | |
public void release() |
177 | |
{ |
178 | |
|
179 | 0 | } |
180 | |
|
181 | |
public void run() |
182 | |
{ |
183 | |
|
184 | 0 | if (logger.isTraceEnabled()) |
185 | |
{ |
186 | 0 | logger.trace("MuleJcaWorker: async Event for Mule JCA EndPoint " + descriptor.getName()); |
187 | |
} |
188 | |
try |
189 | |
{ |
190 | |
|
191 | 0 | event = OptimizedRequestContext.criticalSetEvent(event); |
192 | 0 | entryPoint.invoke(getManagedInstance(), RequestContext.getEventContext()); |
193 | |
} |
194 | 0 | catch (Exception e) |
195 | |
{ |
196 | 0 | if (e instanceof MessagingException) |
197 | |
{ |
198 | 0 | logger.error("Failed to execute JCAEndPoint " + e.getMessage(), e); |
199 | 0 | handleException(e); |
200 | |
} |
201 | |
else |
202 | |
{ |
203 | 0 | handleException(new MessagingException(CoreMessages.eventProcessingFailedFor(descriptor.getName()), |
204 | |
e)); |
205 | |
} |
206 | 0 | } |
207 | 0 | } |
208 | |
} |
209 | |
|
210 | |
public void workAccepted(WorkEvent arg0) |
211 | |
{ |
212 | |
|
213 | 0 | } |
214 | |
|
215 | |
public void workCompleted(WorkEvent arg0) |
216 | |
{ |
217 | |
|
218 | 0 | } |
219 | |
|
220 | |
public void workRejected(WorkEvent arg0) |
221 | |
{ |
222 | |
|
223 | 0 | } |
224 | |
|
225 | |
public void workStarted(WorkEvent arg0) |
226 | |
{ |
227 | |
|
228 | 0 | } |
229 | |
} |