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.RequestContext; |
18 | |
import org.mule.impl.container.ContainerKeyPair; |
19 | |
import org.mule.impl.internal.notifications.ComponentNotification; |
20 | |
import org.mule.management.stats.ComponentStatistics; |
21 | |
import org.mule.umo.UMOComponent; |
22 | |
import org.mule.umo.UMODescriptor; |
23 | |
import org.mule.umo.UMOEvent; |
24 | |
import org.mule.umo.UMOException; |
25 | |
import org.mule.umo.UMOMessage; |
26 | |
import org.mule.umo.lifecycle.InitialisationException; |
27 | |
import org.mule.umo.manager.ObjectNotFoundException; |
28 | |
import org.mule.umo.model.UMOEntryPoint; |
29 | |
|
30 | |
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class JcaComponent implements UMOComponent |
38 | |
{ |
39 | |
|
40 | |
|
41 | |
|
42 | |
private static final long serialVersionUID = -1510441245219710451L; |
43 | |
|
44 | |
private transient final MuleDescriptor descriptor; |
45 | |
private transient UMOEntryPoint entryPoint; |
46 | |
private Object component; |
47 | |
private ComponentStatistics stats; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | 0 | private final AtomicBoolean initialised = new AtomicBoolean(false); |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 0 | private final AtomicBoolean started = new AtomicBoolean(false); |
58 | |
|
59 | |
public JcaComponent(MuleDescriptor descriptor) |
60 | 0 | { |
61 | 0 | if (descriptor == null) |
62 | |
{ |
63 | 0 | throw new IllegalArgumentException("Descriptor cannot be null"); |
64 | |
} |
65 | |
|
66 | 0 | this.descriptor = descriptor; |
67 | 0 | } |
68 | |
|
69 | |
public UMODescriptor getDescriptor() |
70 | |
{ |
71 | 0 | return descriptor; |
72 | |
} |
73 | |
|
74 | |
public void dispatchEvent(UMOEvent event) throws UMOException |
75 | |
{ |
76 | |
try |
77 | |
{ |
78 | |
|
79 | 0 | entryPoint.invoke(component, RequestContext.getEventContext()); |
80 | |
} |
81 | 0 | catch (Exception e) |
82 | |
{ |
83 | 0 | throw new MuleException( |
84 | |
CoreMessages.failedToInvoke("UMO Component: " + descriptor.getName()), e); |
85 | 0 | } |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public UMOMessage sendEvent(UMOEvent event) throws UMOException |
97 | |
{ |
98 | 0 | throw new UnsupportedOperationException("sendEvent()"); |
99 | |
} |
100 | |
|
101 | |
public void pause() throws UMOException |
102 | |
{ |
103 | |
|
104 | 0 | } |
105 | |
|
106 | |
public void resume() throws UMOException |
107 | |
{ |
108 | |
|
109 | 0 | } |
110 | |
|
111 | |
public boolean isPaused() |
112 | |
{ |
113 | 0 | return false; |
114 | |
} |
115 | |
|
116 | |
public void start() throws UMOException |
117 | |
{ |
118 | 0 | started.set(true); |
119 | 0 | } |
120 | |
|
121 | |
public void stop() throws UMOException |
122 | |
{ |
123 | 0 | started.set(false); |
124 | 0 | } |
125 | |
|
126 | |
public void dispose() |
127 | |
{ |
128 | 0 | ((MuleManager)MuleManager.getInstance()).getStatistics().remove(stats); |
129 | 0 | } |
130 | |
|
131 | |
public synchronized void initialise() throws InitialisationException |
132 | |
{ |
133 | 0 | if (initialised.get()) |
134 | |
{ |
135 | 0 | throw new InitialisationException( |
136 | |
CoreMessages.objectAlreadyInitialised("Component '" + descriptor.getName() + "'"), this); |
137 | |
} |
138 | 0 | descriptor.initialise(); |
139 | |
try |
140 | |
{ |
141 | 0 | entryPoint = MuleManager.getInstance().lookupModel(JcaModel.JCA_MODEL_TYPE).getEntryPointResolver().resolveEntryPoint( |
142 | |
descriptor); |
143 | |
} |
144 | 0 | catch (UMOException e) |
145 | |
{ |
146 | 0 | throw new InitialisationException(e, this); |
147 | 0 | } |
148 | |
|
149 | |
|
150 | 0 | stats = new ComponentStatistics(descriptor.getName(), -1); |
151 | |
|
152 | 0 | stats.setEnabled(((MuleManager)MuleManager.getInstance()).getStatistics().isEnabled()); |
153 | 0 | ((MuleManager)MuleManager.getInstance()).getStatistics().add(stats); |
154 | 0 | stats.setOutboundRouterStat(getDescriptor().getOutboundRouter().getStatistics()); |
155 | 0 | stats.setInboundRouterStat(getDescriptor().getInboundRouter().getStatistics()); |
156 | |
|
157 | 0 | component = descriptor.getImplementation(); |
158 | |
|
159 | 0 | initialised.set(true); |
160 | 0 | MuleManager.getInstance().fireNotification( |
161 | |
new ComponentNotification(descriptor, ComponentNotification.COMPONENT_INITIALISED)); |
162 | 0 | } |
163 | |
|
164 | |
protected Object getDelegateComponent() throws InitialisationException |
165 | |
{ |
166 | 0 | Object impl = descriptor.getImplementation(); |
167 | 0 | Object component = null; |
168 | |
|
169 | |
try |
170 | |
{ |
171 | 0 | if (impl instanceof ContainerKeyPair) |
172 | |
{ |
173 | 0 | component = MuleManager.getInstance().getContainerContext().getComponent(impl); |
174 | |
|
175 | 0 | if (descriptor.isSingleton()) |
176 | |
{ |
177 | 0 | descriptor.setImplementation(component); |
178 | |
} |
179 | |
} |
180 | |
else |
181 | |
{ |
182 | 0 | component = impl; |
183 | |
} |
184 | |
} |
185 | 0 | catch (ObjectNotFoundException e) |
186 | |
{ |
187 | 0 | throw new InitialisationException(e, this); |
188 | 0 | } |
189 | |
|
190 | |
|
191 | 0 | descriptor.fireInitialisationCallbacks(component); |
192 | 0 | return component; |
193 | |
} |
194 | |
|
195 | |
public boolean isStarted() |
196 | |
{ |
197 | 0 | return started.get(); |
198 | |
} |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
public Object getInstance() throws UMOException |
210 | |
{ |
211 | 0 | return component; |
212 | |
} |
213 | |
} |