1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule; |
12 | |
|
13 | |
|
14 | |
import org.mule.config.ConfigurationException; |
15 | |
import org.mule.config.MuleConfiguration; |
16 | |
import org.mule.config.MuleProperties; |
17 | |
import org.mule.config.ThreadingProfile; |
18 | |
import org.mule.config.i18n.CoreMessages; |
19 | |
import org.mule.impl.container.MultiContainerContext; |
20 | |
import org.mule.impl.internal.admin.MuleAdminAgent; |
21 | |
import org.mule.impl.internal.notifications.AdminNotification; |
22 | |
import org.mule.impl.internal.notifications.AdminNotificationListener; |
23 | |
import org.mule.impl.internal.notifications.ComponentNotification; |
24 | |
import org.mule.impl.internal.notifications.ComponentNotificationListener; |
25 | |
import org.mule.impl.internal.notifications.ConnectionNotification; |
26 | |
import org.mule.impl.internal.notifications.ConnectionNotificationListener; |
27 | |
import org.mule.impl.internal.notifications.CustomNotification; |
28 | |
import org.mule.impl.internal.notifications.CustomNotificationListener; |
29 | |
import org.mule.impl.internal.notifications.ExceptionNotification; |
30 | |
import org.mule.impl.internal.notifications.ExceptionNotificationListener; |
31 | |
import org.mule.impl.internal.notifications.ManagementNotification; |
32 | |
import org.mule.impl.internal.notifications.ManagementNotificationListener; |
33 | |
import org.mule.impl.internal.notifications.ManagerNotification; |
34 | |
import org.mule.impl.internal.notifications.ManagerNotificationListener; |
35 | |
import org.mule.impl.internal.notifications.MessageNotification; |
36 | |
import org.mule.impl.internal.notifications.MessageNotificationListener; |
37 | |
import org.mule.impl.internal.notifications.ModelNotification; |
38 | |
import org.mule.impl.internal.notifications.ModelNotificationListener; |
39 | |
import org.mule.impl.internal.notifications.NotificationException; |
40 | |
import org.mule.impl.internal.notifications.SecurityNotification; |
41 | |
import org.mule.impl.internal.notifications.SecurityNotificationListener; |
42 | |
import org.mule.impl.internal.notifications.ServerNotificationManager; |
43 | |
import org.mule.impl.internal.notifications.TransactionNotification; |
44 | |
import org.mule.impl.internal.notifications.TransactionNotificationListener; |
45 | |
import org.mule.impl.model.ModelFactory; |
46 | |
import org.mule.impl.model.ModelHelper; |
47 | |
import org.mule.impl.security.MuleSecurityManager; |
48 | |
import org.mule.impl.work.MuleWorkManager; |
49 | |
import org.mule.management.stats.AllStatistics; |
50 | |
import org.mule.umo.UMOException; |
51 | |
import org.mule.umo.UMOInterceptorStack; |
52 | |
import org.mule.umo.endpoint.UMOEndpoint; |
53 | |
import org.mule.umo.lifecycle.FatalException; |
54 | |
import org.mule.umo.lifecycle.InitialisationException; |
55 | |
import org.mule.umo.manager.UMOAgent; |
56 | |
import org.mule.umo.manager.UMOContainerContext; |
57 | |
import org.mule.umo.manager.UMOManager; |
58 | |
import org.mule.umo.manager.UMOServerNotification; |
59 | |
import org.mule.umo.manager.UMOServerNotificationListener; |
60 | |
import org.mule.umo.manager.UMOWorkManager; |
61 | |
import org.mule.umo.model.UMOModel; |
62 | |
import org.mule.umo.provider.UMOConnector; |
63 | |
import org.mule.umo.security.UMOSecurityManager; |
64 | |
import org.mule.umo.transformer.UMOTransformer; |
65 | |
import org.mule.util.ClassUtils; |
66 | |
import org.mule.util.CollectionUtils; |
67 | |
import org.mule.util.SpiUtils; |
68 | |
import org.mule.util.StringMessageUtils; |
69 | |
import org.mule.util.StringUtils; |
70 | |
import org.mule.util.UUID; |
71 | |
import org.mule.util.queue.CachingPersistenceStrategy; |
72 | |
import org.mule.util.queue.QueueManager; |
73 | |
import org.mule.util.queue.QueuePersistenceStrategy; |
74 | |
import org.mule.util.queue.TransactionalQueueManager; |
75 | |
|
76 | |
import java.net.InetAddress; |
77 | |
import java.net.UnknownHostException; |
78 | |
import java.nio.charset.Charset; |
79 | |
import java.util.ArrayList; |
80 | |
import java.util.Collection; |
81 | |
import java.util.Collections; |
82 | |
import java.util.Date; |
83 | |
import java.util.HashMap; |
84 | |
import java.util.Iterator; |
85 | |
import java.util.LinkedHashMap; |
86 | |
import java.util.List; |
87 | |
import java.util.Map; |
88 | |
import java.util.jar.Manifest; |
89 | |
|
90 | |
import javax.transaction.TransactionManager; |
91 | |
|
92 | |
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; |
93 | |
import org.apache.commons.collections.MapUtils; |
94 | |
import org.apache.commons.collections.list.CursorableLinkedList; |
95 | |
import org.apache.commons.logging.Log; |
96 | |
import org.apache.commons.logging.LogFactory; |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | 0 | public class MuleManager implements UMOManager |
102 | |
{ |
103 | |
|
104 | |
|
105 | |
|
106 | 0 | private static UMOManager instance = null; |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | 0 | private static MuleConfiguration config = new MuleConfiguration(); |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | 0 | private Map connectors = new HashMap(); |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | 0 | private Map endpointIdentifiers = new HashMap(); |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | 0 | private Map applicationProps = new HashMap(); |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | 0 | private Map agents = new LinkedHashMap(); |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | 0 | private Map endpoints = new HashMap(); |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | 0 | private Map models = new LinkedHashMap(); |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | 0 | private String id = UUID.getUUID(); |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | 0 | private TransactionManager transactionManager = null; |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | 0 | private Map transformers = new HashMap(); |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | 0 | private AtomicBoolean initialised = new AtomicBoolean(false); |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | 0 | private AtomicBoolean initialising = new AtomicBoolean(false); |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | 0 | private AtomicBoolean started = new AtomicBoolean(false); |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | 0 | private AtomicBoolean starting = new AtomicBoolean(false); |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | 0 | private AtomicBoolean stopping = new AtomicBoolean(false); |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | 0 | private AtomicBoolean disposed = new AtomicBoolean(false); |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | 0 | private static MuleServer server = null; |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | 0 | private Map interceptorsMap = new HashMap(); |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | 0 | private long startDate = 0; |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | 0 | private AllStatistics stats = new AllStatistics(); |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | 0 | private ServerNotificationManager notificationManager = null; |
214 | |
|
215 | 0 | private MultiContainerContext containerContext = null; |
216 | |
|
217 | |
private UMOSecurityManager securityManager; |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
private QueueManager queueManager; |
223 | |
|
224 | |
private UMOWorkManager workManager; |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | 0 | private static Log logger = LogFactory.getLog(MuleManager.class); |
230 | |
|
231 | 0 | private ShutdownContext shutdownContext = new ShutdownContext(true, null); |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
private MuleManager() |
237 | 0 | { |
238 | 0 | if (config == null) |
239 | |
{ |
240 | 0 | config = new MuleConfiguration(); |
241 | |
} |
242 | 0 | containerContext = new MultiContainerContext(); |
243 | 0 | securityManager = new MuleSecurityManager(); |
244 | 0 | Runtime.getRuntime().addShutdownHook(new ShutdownThread()); |
245 | |
|
246 | |
|
247 | 0 | notificationManager = new ServerNotificationManager(); |
248 | 0 | notificationManager.registerEventType(ManagerNotification.class, ManagerNotificationListener.class); |
249 | 0 | notificationManager.registerEventType(ModelNotification.class, ModelNotificationListener.class); |
250 | 0 | notificationManager.registerEventType(ComponentNotification.class, |
251 | |
ComponentNotificationListener.class); |
252 | 0 | notificationManager.registerEventType(SecurityNotification.class, SecurityNotificationListener.class); |
253 | 0 | notificationManager.registerEventType(ManagementNotification.class, |
254 | |
ManagementNotificationListener.class); |
255 | 0 | notificationManager.registerEventType(AdminNotification.class, AdminNotificationListener.class); |
256 | 0 | notificationManager.registerEventType(CustomNotification.class, CustomNotificationListener.class); |
257 | 0 | notificationManager.registerEventType(ConnectionNotification.class, |
258 | |
ConnectionNotificationListener.class); |
259 | 0 | notificationManager.registerEventType(ExceptionNotification.class, ExceptionNotificationListener.class); |
260 | 0 | notificationManager.registerEventType(TransactionNotification.class, TransactionNotificationListener.class); |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
try |
266 | |
{ |
267 | 0 | Class spaceNotificationClass = ClassUtils.loadClass( |
268 | |
"org.mule.impl.space.SpaceMonitorNotification", this.getClass()); |
269 | 0 | Class spaceListenerClass = ClassUtils.loadClass( |
270 | |
"org.mule.impl.space.SpaceMonitorNotificationListener", this.getClass()); |
271 | 0 | notificationManager.registerEventType(spaceNotificationClass, spaceListenerClass); |
272 | |
} |
273 | 0 | catch (ClassNotFoundException cnf) |
274 | |
{ |
275 | |
|
276 | 0 | } |
277 | 0 | } |
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
public static synchronized UMOManager getInstance() |
285 | |
{ |
286 | 0 | if (instance == null) |
287 | |
{ |
288 | 0 | logger.info("Creating new MuleManager instance"); |
289 | |
|
290 | 0 | Class clazz = SpiUtils.findService(UMOManager.class, MuleManager.class.getName(), |
291 | |
MuleManager.class); |
292 | |
try |
293 | |
{ |
294 | |
|
295 | 0 | instance = (UMOManager) clazz.newInstance(); |
296 | 0 | registerSystemModel(config.getSystemModelType()); |
297 | |
} |
298 | 0 | catch (Exception e) |
299 | |
{ |
300 | 0 | throw new MuleRuntimeException( |
301 | |
CoreMessages.failedToCreateManagerInstance(clazz.getName()), e); |
302 | 0 | } |
303 | |
} |
304 | |
|
305 | 0 | return instance; |
306 | |
} |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
public static synchronized boolean isInstanciated() |
319 | |
{ |
320 | 0 | return (instance != null); |
321 | |
} |
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
public static synchronized void setInstance(UMOManager manager) |
329 | |
{ |
330 | 0 | instance = manager; |
331 | 0 | if (instance == null) |
332 | |
{ |
333 | 0 | config = new MuleConfiguration(); |
334 | |
} |
335 | 0 | } |
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
public AllStatistics getStatistics() |
343 | |
{ |
344 | 0 | return stats; |
345 | |
} |
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
public void setStatistics(AllStatistics stat) |
353 | |
{ |
354 | 0 | this.stats = stat; |
355 | 0 | } |
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
public static synchronized MuleConfiguration getConfiguration() |
362 | |
{ |
363 | 0 | return config; |
364 | |
} |
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
public static synchronized void setConfiguration(MuleConfiguration config) throws UMOException |
375 | |
{ |
376 | 0 | if (config == null) |
377 | |
{ |
378 | 0 | throw new IllegalArgumentException( |
379 | |
CoreMessages.objectIsNull("MuleConfiguration object").getMessage()); |
380 | |
} |
381 | |
|
382 | 0 | MuleManager.config = config; |
383 | |
|
384 | 0 | registerSystemModel(config.getSystemModelType()); |
385 | |
|
386 | 0 | } |
387 | |
|
388 | |
protected static void registerSystemModel(String type) throws UMOException |
389 | |
{ |
390 | 0 | if (instance != null) |
391 | |
{ |
392 | |
|
393 | 0 | UMOModel model = instance.lookupModel(type); |
394 | 0 | if (model != null && model.getComponentNames().hasNext()) |
395 | |
{ |
396 | 0 | throw new IllegalStateException("System model is already registered and contains components. Cannot overwrite"); |
397 | |
} |
398 | 0 | model = ModelFactory.createModel(config.getSystemModelType()); |
399 | 0 | model.setName(ModelHelper.SYSTEM_MODEL); |
400 | 0 | instance.registerModel(model); |
401 | |
} |
402 | 0 | } |
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
public synchronized void dispose() |
411 | |
{ |
412 | 0 | if (disposed.get()) |
413 | |
{ |
414 | 0 | return; |
415 | |
} |
416 | |
try |
417 | |
{ |
418 | 0 | if (started.get()) |
419 | |
{ |
420 | 0 | stop(); |
421 | |
} |
422 | |
} |
423 | 0 | catch (UMOException e) |
424 | |
{ |
425 | |
|
426 | 0 | logger.error("Failed to stop manager: " + e.getMessage(), e); |
427 | 0 | } |
428 | 0 | disposed.set(true); |
429 | 0 | disposeConnectors(); |
430 | |
|
431 | 0 | for (Iterator i = models.values().iterator(); i.hasNext();) |
432 | |
{ |
433 | 0 | UMOModel model = (UMOModel) i.next(); |
434 | 0 | model.dispose(); |
435 | |
} |
436 | |
|
437 | 0 | disposeAgents(); |
438 | |
|
439 | 0 | transformers.clear(); |
440 | 0 | endpoints.clear(); |
441 | 0 | endpointIdentifiers.clear(); |
442 | 0 | containerContext.dispose(); |
443 | 0 | containerContext = null; |
444 | |
|
445 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_DISPOSED)); |
446 | |
|
447 | 0 | transformers = null; |
448 | 0 | endpoints = null; |
449 | 0 | endpointIdentifiers = null; |
450 | |
|
451 | 0 | initialised.set(false); |
452 | 0 | if (notificationManager != null) |
453 | |
{ |
454 | 0 | notificationManager.dispose(); |
455 | |
} |
456 | 0 | if (workManager != null) |
457 | |
{ |
458 | 0 | workManager.dispose(); |
459 | |
} |
460 | |
|
461 | 0 | if (queueManager != null) |
462 | |
{ |
463 | 0 | queueManager.close(); |
464 | 0 | queueManager = null; |
465 | |
} |
466 | |
|
467 | 0 | if ((startDate > 0) && logger.isInfoEnabled()) |
468 | |
{ |
469 | 0 | logger.info(this.getEndSplash()); |
470 | |
} |
471 | |
|
472 | 0 | config = new MuleConfiguration(); |
473 | 0 | instance = null; |
474 | 0 | } |
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
private synchronized void disposeConnectors() |
480 | |
{ |
481 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_DISPOSING_CONNECTORS)); |
482 | 0 | for (Iterator iterator = connectors.values().iterator(); iterator.hasNext();) |
483 | |
{ |
484 | 0 | UMOConnector c = (UMOConnector) iterator.next(); |
485 | 0 | c.dispose(); |
486 | |
} |
487 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_DISPOSED_CONNECTORS)); |
488 | 0 | } |
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
public Object getProperty(Object key) |
494 | |
{ |
495 | 0 | return applicationProps.get(key); |
496 | |
} |
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
public Map getProperties() |
502 | |
{ |
503 | 0 | return applicationProps; |
504 | |
} |
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
public TransactionManager getTransactionManager() |
510 | |
{ |
511 | 0 | return transactionManager; |
512 | |
} |
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | |
public UMOConnector lookupConnector(String name) |
518 | |
{ |
519 | 0 | return (UMOConnector) connectors.get(name); |
520 | |
} |
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
public String lookupEndpointIdentifier(String logicalName, String defaultName) |
528 | |
{ |
529 | 0 | String name = (String) endpointIdentifiers.get(logicalName); |
530 | 0 | if (name == null) |
531 | |
{ |
532 | 0 | return defaultName; |
533 | |
} |
534 | 0 | return name; |
535 | |
} |
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | |
public UMOEndpoint lookupEndpoint(String logicalName) |
541 | |
{ |
542 | 0 | UMOEndpoint endpoint = (UMOEndpoint) endpoints.get(logicalName); |
543 | 0 | if (endpoint != null) |
544 | |
{ |
545 | 0 | return (UMOEndpoint) endpoint.clone(); |
546 | |
} |
547 | |
else |
548 | |
{ |
549 | 0 | return null; |
550 | |
} |
551 | |
} |
552 | |
|
553 | |
|
554 | |
|
555 | |
|
556 | |
public UMOEndpoint lookupEndpointByAddress(String address) |
557 | |
{ |
558 | 0 | UMOEndpoint endpoint = null; |
559 | 0 | if (address != null) |
560 | |
{ |
561 | 0 | boolean found = false; |
562 | 0 | Iterator iterator = endpoints.keySet().iterator(); |
563 | 0 | while (!found && iterator.hasNext()) |
564 | |
{ |
565 | 0 | endpoint = (UMOEndpoint) endpoints.get(iterator.next()); |
566 | 0 | found = (address.equals(endpoint.getEndpointURI().toString())); |
567 | |
} |
568 | |
} |
569 | 0 | return endpoint; |
570 | |
} |
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | |
public UMOTransformer lookupTransformer(String name) |
576 | |
{ |
577 | 0 | UMOTransformer trans = (UMOTransformer) transformers.get(name); |
578 | 0 | if (trans != null) |
579 | |
{ |
580 | |
try |
581 | |
{ |
582 | 0 | return (UMOTransformer) trans.clone(); |
583 | |
} |
584 | 0 | catch (Exception e) |
585 | |
{ |
586 | 0 | throw new MuleRuntimeException( |
587 | |
CoreMessages.failedToClone("Transformer: " + trans.getName()), e); |
588 | |
} |
589 | |
} |
590 | 0 | return null; |
591 | |
} |
592 | |
|
593 | |
|
594 | |
|
595 | |
|
596 | |
public void registerConnector(UMOConnector connector) throws UMOException |
597 | |
{ |
598 | 0 | connectors.put(connector.getName(), connector); |
599 | 0 | if (initialised.get() || initialising.get()) |
600 | |
{ |
601 | 0 | connector.initialise(); |
602 | |
} |
603 | 0 | if ((started.get() || starting.get()) && !connector.isStarted()) |
604 | |
{ |
605 | 0 | connector.startConnector(); |
606 | |
} |
607 | 0 | } |
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
public void unregisterConnector(String connectorName) throws UMOException |
613 | |
{ |
614 | 0 | UMOConnector c = (UMOConnector) connectors.remove(connectorName); |
615 | 0 | if (c != null) |
616 | |
{ |
617 | 0 | c.dispose(); |
618 | |
} |
619 | 0 | } |
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
public void registerEndpointIdentifier(String logicalName, String endpoint) |
627 | |
{ |
628 | 0 | endpointIdentifiers.put(logicalName, endpoint); |
629 | 0 | } |
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
public void unregisterEndpointIdentifier(String logicalName) |
637 | |
{ |
638 | 0 | endpointIdentifiers.remove(logicalName); |
639 | 0 | } |
640 | |
|
641 | |
|
642 | |
|
643 | |
|
644 | |
public void registerEndpoint(UMOEndpoint endpoint) |
645 | |
{ |
646 | 0 | endpoints.put(endpoint.getName(), endpoint); |
647 | 0 | } |
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
public void unregisterEndpoint(String endpointName) |
653 | |
{ |
654 | 0 | UMOEndpoint p = (UMOEndpoint) endpoints.get(endpointName); |
655 | 0 | if (p != null) |
656 | |
{ |
657 | 0 | endpoints.remove(p); |
658 | |
} |
659 | 0 | } |
660 | |
|
661 | |
|
662 | |
|
663 | |
|
664 | |
public void registerTransformer(UMOTransformer transformer) throws InitialisationException |
665 | |
{ |
666 | 0 | transformer.initialise(); |
667 | 0 | transformers.put(transformer.getName(), transformer); |
668 | 0 | logger.info("Transformer " + transformer.getName() + " has been initialised successfully"); |
669 | 0 | } |
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
public void unregisterTransformer(String transformerName) |
675 | |
{ |
676 | 0 | transformers.remove(transformerName); |
677 | 0 | } |
678 | |
|
679 | |
|
680 | |
|
681 | |
|
682 | |
public void setProperty(Object key, Object value) |
683 | |
{ |
684 | 0 | applicationProps.put(key, value); |
685 | 0 | } |
686 | |
|
687 | |
public void addProperties(Map props) |
688 | |
{ |
689 | 0 | applicationProps.putAll(props); |
690 | 0 | } |
691 | |
|
692 | |
|
693 | |
|
694 | |
|
695 | |
public void setTransactionManager(TransactionManager newManager) throws UMOException |
696 | |
{ |
697 | 0 | if (transactionManager != null) |
698 | |
{ |
699 | 0 | throw new ConfigurationException(CoreMessages.transactionManagerAlreadySet()); |
700 | |
} |
701 | 0 | transactionManager = newManager; |
702 | 0 | } |
703 | |
|
704 | |
|
705 | |
|
706 | |
|
707 | |
public synchronized void initialise() throws UMOException |
708 | |
{ |
709 | 0 | validateEncoding(); |
710 | 0 | validateOSEncoding(); |
711 | |
|
712 | 0 | if (!initialised.get()) |
713 | |
{ |
714 | 0 | initialising.set(true); |
715 | 0 | startDate = System.currentTimeMillis(); |
716 | |
|
717 | 0 | if (workManager == null) |
718 | |
{ |
719 | 0 | ThreadingProfile tp = config.getDefaultThreadingProfile(); |
720 | 0 | logger.debug("Creating default work manager using default threading profile: " + tp); |
721 | 0 | workManager = new MuleWorkManager(tp, "UMOManager"); |
722 | 0 | workManager.start(); |
723 | |
} |
724 | |
|
725 | |
|
726 | 0 | notificationManager.start(workManager); |
727 | |
|
728 | |
|
729 | |
|
730 | |
|
731 | 0 | if (config.isEnableMessageEvents()) |
732 | |
{ |
733 | 0 | notificationManager.registerEventType(MessageNotification.class, |
734 | |
MessageNotificationListener.class); |
735 | |
} |
736 | |
|
737 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_INITIALISNG)); |
738 | 0 | if (id == null) |
739 | |
{ |
740 | 0 | logger.warn("No unique id has been set on this manager"); |
741 | |
} |
742 | |
|
743 | |
|
744 | |
try |
745 | |
{ |
746 | 0 | if (securityManager != null) |
747 | |
{ |
748 | 0 | securityManager.initialise(); |
749 | |
} |
750 | 0 | if (queueManager == null) |
751 | |
{ |
752 | |
try |
753 | |
{ |
754 | 0 | TransactionalQueueManager queueMgr = new TransactionalQueueManager(); |
755 | 0 | QueuePersistenceStrategy ps = new CachingPersistenceStrategy( |
756 | |
getConfiguration().getPersistenceStrategy()); |
757 | 0 | queueMgr.setPersistenceStrategy(ps); |
758 | 0 | queueManager = queueMgr; |
759 | |
} |
760 | 0 | catch (Exception e) |
761 | |
{ |
762 | 0 | throw new InitialisationException( |
763 | |
CoreMessages.initialisationFailure("QueueManager"), e); |
764 | 0 | } |
765 | |
} |
766 | |
|
767 | 0 | initialiseConnectors(); |
768 | 0 | initialiseEndpoints(); |
769 | 0 | initialiseAgents(); |
770 | 0 | for (Iterator i = models.values().iterator(); i.hasNext();) |
771 | |
{ |
772 | 0 | UMOModel model = (UMOModel) i.next(); |
773 | 0 | model.initialise(); |
774 | |
} |
775 | |
|
776 | 0 | } |
777 | |
finally |
778 | |
{ |
779 | 0 | initialised.set(true); |
780 | 0 | initialising.set(false); |
781 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_INITIALISED)); |
782 | 0 | } |
783 | |
} |
784 | 0 | } |
785 | |
|
786 | |
protected void validateEncoding() throws FatalException |
787 | |
{ |
788 | 0 | String encoding = System.getProperty(MuleProperties.MULE_ENCODING_SYSTEM_PROPERTY); |
789 | 0 | if (encoding == null) |
790 | |
{ |
791 | 0 | encoding = config.getEncoding(); |
792 | 0 | System.setProperty(MuleProperties.MULE_ENCODING_SYSTEM_PROPERTY, encoding); |
793 | |
} |
794 | |
else |
795 | |
{ |
796 | 0 | config.setEncoding(encoding); |
797 | |
} |
798 | |
|
799 | 0 | if (!Charset.isSupported(config.getEncoding())) |
800 | |
{ |
801 | 0 | throw new FatalException( |
802 | |
CoreMessages.propertyHasInvalidValue("encoding", config.getEncoding()), this); |
803 | |
} |
804 | 0 | } |
805 | |
|
806 | |
protected void validateOSEncoding() throws FatalException |
807 | |
{ |
808 | 0 | String encoding = System.getProperty(MuleProperties.MULE_OS_ENCODING_SYSTEM_PROPERTY); |
809 | 0 | if (encoding == null) |
810 | |
{ |
811 | 0 | encoding = config.getOSEncoding(); |
812 | 0 | System.setProperty(MuleProperties.MULE_OS_ENCODING_SYSTEM_PROPERTY, encoding); |
813 | |
} |
814 | |
else |
815 | |
{ |
816 | 0 | config.setOSEncoding(encoding); |
817 | |
} |
818 | |
|
819 | 0 | if (!Charset.isSupported(config.getOSEncoding())) |
820 | |
{ |
821 | 0 | throw new FatalException( |
822 | |
CoreMessages.propertyHasInvalidValue("osEncoding", config.getOSEncoding()), this); |
823 | |
} |
824 | 0 | } |
825 | |
|
826 | |
protected void registerAdminAgent() throws UMOException |
827 | |
{ |
828 | |
|
829 | |
|
830 | 0 | boolean disable = MapUtils.getBooleanValue(System.getProperties(), |
831 | |
MuleProperties.DISABLE_SERVER_CONNECTIONS_SYSTEM_PROPERTY, false); |
832 | |
|
833 | |
|
834 | 0 | if (StringUtils.isBlank(config.getServerUrl())) |
835 | |
{ |
836 | 0 | logger.info("Server endpointUri is null, not registering Mule Admin agent"); |
837 | 0 | disable = true; |
838 | |
} |
839 | |
|
840 | 0 | if (disable) |
841 | |
{ |
842 | 0 | unregisterAgent(MuleAdminAgent.AGENT_NAME); |
843 | |
} |
844 | |
else |
845 | |
{ |
846 | 0 | if (lookupAgent(MuleAdminAgent.AGENT_NAME) == null) |
847 | |
{ |
848 | 0 | registerAgent(new MuleAdminAgent()); |
849 | |
} |
850 | |
} |
851 | 0 | } |
852 | |
|
853 | |
protected void initialiseEndpoints() throws InitialisationException |
854 | |
{ |
855 | |
UMOEndpoint ep; |
856 | 0 | for (Iterator iterator = this.endpoints.values().iterator(); iterator.hasNext();) |
857 | |
{ |
858 | 0 | ep = (UMOEndpoint) iterator.next(); |
859 | 0 | ep.initialise(); |
860 | |
|
861 | |
|
862 | |
|
863 | 0 | ep.setCreateConnector(0); |
864 | |
} |
865 | 0 | } |
866 | |
|
867 | |
|
868 | |
|
869 | |
|
870 | |
|
871 | |
|
872 | |
|
873 | |
public synchronized void start() throws UMOException |
874 | |
{ |
875 | 0 | initialise(); |
876 | |
|
877 | 0 | if (!started.get()) |
878 | |
{ |
879 | 0 | starting.set(true); |
880 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STARTING)); |
881 | 0 | registerAdminAgent(); |
882 | 0 | if (queueManager != null) |
883 | |
{ |
884 | 0 | queueManager.start(); |
885 | |
} |
886 | 0 | startConnectors(); |
887 | 0 | startAgents(); |
888 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STARTING_MODELS)); |
889 | 0 | for (Iterator i = models.values().iterator(); i.hasNext();) |
890 | |
{ |
891 | 0 | UMOModel model = (UMOModel) i.next(); |
892 | 0 | model.start(); |
893 | |
} |
894 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STARTED_MODELS)); |
895 | |
|
896 | 0 | started.set(true); |
897 | 0 | starting.set(false); |
898 | 0 | if (logger.isInfoEnabled()) |
899 | |
{ |
900 | 0 | logger.info(this.getStartSplash()); |
901 | |
} |
902 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STARTED)); |
903 | |
} |
904 | 0 | } |
905 | |
|
906 | |
|
907 | |
|
908 | |
|
909 | |
|
910 | |
|
911 | |
|
912 | |
|
913 | |
public void start(String serverUrl) throws UMOException |
914 | |
{ |
915 | |
|
916 | 0 | config.setServerUrl(serverUrl); |
917 | 0 | start(); |
918 | 0 | } |
919 | |
|
920 | |
|
921 | |
|
922 | |
|
923 | |
|
924 | |
|
925 | |
private void startConnectors() throws UMOException |
926 | |
{ |
927 | 0 | for (Iterator iterator = connectors.values().iterator(); iterator.hasNext();) |
928 | |
{ |
929 | 0 | UMOConnector c = (UMOConnector) iterator.next(); |
930 | 0 | c.startConnector(); |
931 | |
} |
932 | 0 | logger.info("Connectors have been started successfully"); |
933 | 0 | } |
934 | |
|
935 | |
private void initialiseConnectors() throws InitialisationException |
936 | |
{ |
937 | 0 | for (Iterator iterator = connectors.values().iterator(); iterator.hasNext();) |
938 | |
{ |
939 | 0 | UMOConnector c = (UMOConnector) iterator.next(); |
940 | 0 | c.initialise(); |
941 | |
} |
942 | 0 | logger.info("Connectors have been initialised successfully"); |
943 | 0 | } |
944 | |
|
945 | |
|
946 | |
|
947 | |
|
948 | |
|
949 | |
|
950 | |
public synchronized void stop() throws UMOException |
951 | |
{ |
952 | 0 | started.set(false); |
953 | 0 | stopping.set(true); |
954 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STOPPING)); |
955 | |
|
956 | 0 | stopConnectors(); |
957 | 0 | stopAgents(); |
958 | |
|
959 | 0 | if (queueManager != null) |
960 | |
{ |
961 | 0 | queueManager.stop(); |
962 | |
} |
963 | |
|
964 | 0 | logger.debug("Stopping model..."); |
965 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STOPPING_MODELS)); |
966 | 0 | for (Iterator i = models.values().iterator(); i.hasNext();) |
967 | |
{ |
968 | 0 | UMOModel model = (UMOModel) i.next(); |
969 | 0 | model.stop(); |
970 | |
} |
971 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STOPPED_MODELS)); |
972 | |
|
973 | 0 | stopping.set(false); |
974 | 0 | initialised.set(false); |
975 | 0 | fireSystemEvent(new ManagerNotification(this, ManagerNotification.MANAGER_STOPPED)); |
976 | 0 | } |
977 | |
|
978 | |
|
979 | |
|
980 | |
|
981 | |
|
982 | |
|
983 | |
private void stopConnectors() throws UMOException |
984 | |
{ |
985 | 0 | logger.debug("Stopping connectors..."); |
986 | 0 | for (Iterator iterator = connectors.values().iterator(); iterator.hasNext();) |
987 | |
{ |
988 | 0 | UMOConnector c = (UMOConnector) iterator.next(); |
989 | 0 | c.stopConnector(); |
990 | |
} |
991 | 0 | logger.info("Connectors have been stopped successfully"); |
992 | 0 | } |
993 | |
|
994 | |
|
995 | |
|
996 | |
|
997 | |
|
998 | |
|
999 | |
|
1000 | |
void setServer(MuleServer server) |
1001 | |
{ |
1002 | 0 | MuleManager.server = server; |
1003 | 0 | } |
1004 | |
|
1005 | |
|
1006 | |
|
1007 | |
|
1008 | |
|
1009 | |
|
1010 | |
|
1011 | |
|
1012 | |
|
1013 | |
|
1014 | |
public void shutdown(Throwable e, boolean aggressive) |
1015 | |
{ |
1016 | 0 | shutdownContext = new ShutdownContext(aggressive, e); |
1017 | 0 | System.exit(0); |
1018 | 0 | } |
1019 | |
|
1020 | |
public UMOModel lookupModel(String name) |
1021 | |
{ |
1022 | 0 | return (UMOModel) models.get(name); |
1023 | |
} |
1024 | |
|
1025 | |
public void registerModel(UMOModel model) throws UMOException |
1026 | |
{ |
1027 | 0 | models.put(model.getName(), model); |
1028 | 0 | if (initialised.get()) |
1029 | |
{ |
1030 | 0 | model.initialise(); |
1031 | |
} |
1032 | |
|
1033 | 0 | if (started.get()) |
1034 | |
{ |
1035 | 0 | model.start(); |
1036 | |
} |
1037 | 0 | } |
1038 | |
|
1039 | |
public void unregisterModel(String name) |
1040 | |
{ |
1041 | 0 | UMOModel model = lookupModel(name); |
1042 | 0 | if (model != null) |
1043 | |
{ |
1044 | 0 | models.remove(model); |
1045 | 0 | model.dispose(); |
1046 | |
} |
1047 | 0 | } |
1048 | |
|
1049 | |
public Map getModels() |
1050 | |
{ |
1051 | 0 | return Collections.unmodifiableMap(models); |
1052 | |
} |
1053 | |
|
1054 | |
|
1055 | |
|
1056 | |
|
1057 | |
public void registerInterceptorStack(String name, UMOInterceptorStack stack) |
1058 | |
{ |
1059 | 0 | interceptorsMap.put(name, stack); |
1060 | 0 | } |
1061 | |
|
1062 | |
|
1063 | |
|
1064 | |
|
1065 | |
public UMOInterceptorStack lookupInterceptorStack(String name) |
1066 | |
{ |
1067 | 0 | return (UMOInterceptorStack) interceptorsMap.get(name); |
1068 | |
} |
1069 | |
|
1070 | |
|
1071 | |
|
1072 | |
|
1073 | |
public Map getConnectors() |
1074 | |
{ |
1075 | 0 | return Collections.unmodifiableMap(connectors); |
1076 | |
} |
1077 | |
|
1078 | |
|
1079 | |
|
1080 | |
|
1081 | |
|
1082 | |
|
1083 | |
public Map getEndpointIdentifiers() |
1084 | |
{ |
1085 | 0 | return Collections.unmodifiableMap(endpointIdentifiers); |
1086 | |
} |
1087 | |
|
1088 | |
|
1089 | |
|
1090 | |
|
1091 | |
public Map getEndpoints() |
1092 | |
{ |
1093 | 0 | return Collections.unmodifiableMap(endpoints); |
1094 | |
} |
1095 | |
|
1096 | |
|
1097 | |
|
1098 | |
|
1099 | |
public Map getTransformers() |
1100 | |
{ |
1101 | 0 | return Collections.unmodifiableMap(transformers); |
1102 | |
} |
1103 | |
|
1104 | |
|
1105 | |
|
1106 | |
|
1107 | |
public boolean isStarted() |
1108 | |
{ |
1109 | 0 | return started.get(); |
1110 | |
} |
1111 | |
|
1112 | |
|
1113 | |
|
1114 | |
|
1115 | |
public boolean isInitialised() |
1116 | |
{ |
1117 | 0 | return initialised.get(); |
1118 | |
} |
1119 | |
|
1120 | |
|
1121 | |
|
1122 | |
|
1123 | |
|
1124 | |
|
1125 | |
public boolean isInitialising() |
1126 | |
{ |
1127 | 0 | return initialising.get(); |
1128 | |
} |
1129 | |
|
1130 | |
|
1131 | |
|
1132 | |
|
1133 | |
public boolean isStopping() |
1134 | |
{ |
1135 | 0 | return stopping.get(); |
1136 | |
} |
1137 | |
|
1138 | |
|
1139 | |
|
1140 | |
|
1141 | |
public long getStartDate() |
1142 | |
{ |
1143 | 0 | return startDate; |
1144 | |
} |
1145 | |
|
1146 | |
|
1147 | |
|
1148 | |
|
1149 | |
|
1150 | |
|
1151 | |
|
1152 | |
|
1153 | |
private String getStartSplash() |
1154 | |
{ |
1155 | 0 | String notset = CoreMessages.notSet().getMessage(); |
1156 | |
|
1157 | |
|
1158 | 0 | List message = new ArrayList(); |
1159 | 0 | Manifest mf = config.getManifest(); |
1160 | 0 | Map att = mf.getMainAttributes(); |
1161 | 0 | if (att.values().size() > 0) |
1162 | |
{ |
1163 | 0 | message.add(StringUtils.defaultString(config.getProductDescription(), notset) + " " |
1164 | |
+ CoreMessages.version().getMessage() + " " |
1165 | |
+ StringUtils.defaultString(config.getProductVersion(), notset)); |
1166 | |
|
1167 | 0 | message.add(StringUtils.defaultString(config.getVendorName(), notset)); |
1168 | 0 | message.add(StringUtils.defaultString(config.getProductMoreInfo(), notset)); |
1169 | |
} |
1170 | |
else |
1171 | |
{ |
1172 | 0 | message.add(CoreMessages.versionNotSet().getMessage()); |
1173 | |
} |
1174 | 0 | message.add(" "); |
1175 | 0 | message.add(CoreMessages.serverStartedAt(this.getStartDate())); |
1176 | 0 | message.add("Server ID: " + id); |
1177 | |
|
1178 | |
|
1179 | 0 | message.add("JDK: " + System.getProperty("java.version") + " (" + System.getProperty("java.vm.info") |
1180 | |
+ ")"); |
1181 | 0 | String patch = System.getProperty("sun.os.patch.level", null); |
1182 | 0 | message.add("OS: " + System.getProperty("os.name") |
1183 | |
+ (patch != null && !"unknown".equalsIgnoreCase(patch) ? " - " + patch : "") + " (" |
1184 | |
+ System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")"); |
1185 | |
try |
1186 | |
{ |
1187 | 0 | InetAddress host = InetAddress.getLocalHost(); |
1188 | 0 | message.add("Host: " + host.getHostName() + " (" + host.getHostAddress() + ")"); |
1189 | |
} |
1190 | 0 | catch (UnknownHostException e) |
1191 | |
{ |
1192 | |
|
1193 | 0 | } |
1194 | |
|
1195 | |
|
1196 | 0 | message.add(" "); |
1197 | 0 | if (agents.size() == 0) |
1198 | |
{ |
1199 | 0 | message.add(CoreMessages.agentsRunning().getMessage() + " " |
1200 | |
+ CoreMessages.none()); |
1201 | |
} |
1202 | |
else |
1203 | |
{ |
1204 | 0 | message.add(CoreMessages.agentsRunning()); |
1205 | |
UMOAgent umoAgent; |
1206 | 0 | for (Iterator iterator = agents.values().iterator(); iterator.hasNext();) |
1207 | |
{ |
1208 | 0 | umoAgent = (UMOAgent) iterator.next(); |
1209 | 0 | message.add(" " + umoAgent.getDescription()); |
1210 | |
} |
1211 | |
} |
1212 | 0 | return StringMessageUtils.getBoilerPlate(message, '*', 70); |
1213 | |
} |
1214 | |
|
1215 | |
private String getEndSplash() |
1216 | |
{ |
1217 | 0 | List message = new ArrayList(2); |
1218 | 0 | long currentTime = System.currentTimeMillis(); |
1219 | 0 | message.add(CoreMessages.shutdownNormally(new Date())); |
1220 | 0 | long duration = 10; |
1221 | 0 | if (startDate > 0) |
1222 | |
{ |
1223 | 0 | duration = currentTime - startDate; |
1224 | |
} |
1225 | 0 | message.add(CoreMessages.serverWasUpForDuration(duration)); |
1226 | |
|
1227 | 0 | return StringMessageUtils.getBoilerPlate(message, '*', 78); |
1228 | |
} |
1229 | |
|
1230 | |
|
1231 | |
|
1232 | |
|
1233 | |
public void registerAgent(UMOAgent agent) throws UMOException |
1234 | |
{ |
1235 | 0 | agents.put(agent.getName(), agent); |
1236 | 0 | agent.registered(); |
1237 | |
|
1238 | |
|
1239 | |
|
1240 | 0 | if (initialised.get()) |
1241 | |
{ |
1242 | 0 | agent.initialise(); |
1243 | |
} |
1244 | 0 | if ((started.get() || starting.get())) |
1245 | |
{ |
1246 | 0 | agent.start(); |
1247 | |
} |
1248 | 0 | } |
1249 | |
|
1250 | |
public UMOAgent lookupAgent(String name) |
1251 | |
{ |
1252 | 0 | return (UMOAgent) agents.get(name); |
1253 | |
} |
1254 | |
|
1255 | |
|
1256 | |
|
1257 | |
|
1258 | |
public UMOAgent unregisterAgent(String name) throws UMOException |
1259 | |
{ |
1260 | 0 | if (name == null) |
1261 | |
{ |
1262 | 0 | return null; |
1263 | |
} |
1264 | 0 | UMOAgent agent = (UMOAgent) agents.remove(name); |
1265 | 0 | if (agent != null) |
1266 | |
{ |
1267 | 0 | agent.dispose(); |
1268 | 0 | agent.unregistered(); |
1269 | |
} |
1270 | 0 | return agent; |
1271 | |
} |
1272 | |
|
1273 | |
|
1274 | |
|
1275 | |
|
1276 | |
|
1277 | |
|
1278 | |
protected void initialiseAgents() throws InitialisationException |
1279 | |
{ |
1280 | 0 | logger.info("Initialising agents..."); |
1281 | |
|
1282 | |
|
1283 | |
|
1284 | |
|
1285 | |
|
1286 | |
|
1287 | 0 | Collection agentsSnapshot = agents.values(); |
1288 | 0 | CursorableLinkedList agentRegistrationQueue = new CursorableLinkedList(agentsSnapshot); |
1289 | 0 | CursorableLinkedList.Cursor cursor = agentRegistrationQueue.cursor(); |
1290 | |
|
1291 | |
|
1292 | |
|
1293 | |
|
1294 | |
try |
1295 | |
{ |
1296 | 0 | while (cursor.hasNext()) |
1297 | |
{ |
1298 | 0 | UMOAgent umoAgent = (UMOAgent) cursor.next(); |
1299 | |
|
1300 | 0 | int originalSize = agentsSnapshot.size(); |
1301 | 0 | logger.debug("Initialising agent: " + umoAgent.getName()); |
1302 | 0 | umoAgent.initialise(); |
1303 | |
|
1304 | 0 | cursor.remove(); |
1305 | |
|
1306 | |
|
1307 | |
|
1308 | |
|
1309 | 0 | int newSize = agentsSnapshot.size(); |
1310 | 0 | int delta = newSize - originalSize; |
1311 | 0 | if (delta > 0) |
1312 | |
{ |
1313 | |
|
1314 | |
|
1315 | |
|
1316 | 0 | Collection tail = CollectionUtils.retainAll(agentsSnapshot, agentRegistrationQueue); |
1317 | 0 | Collection head = CollectionUtils.subtract(agentsSnapshot, tail); |
1318 | |
|
1319 | |
|
1320 | |
|
1321 | |
|
1322 | 0 | agentRegistrationQueue.clear(); |
1323 | |
|
1324 | 0 | agentRegistrationQueue.addAll(head); |
1325 | |
|
1326 | 0 | agentRegistrationQueue.addAll(tail); |
1327 | |
|
1328 | |
|
1329 | |
|
1330 | 0 | this.agents.clear(); |
1331 | 0 | for (Iterator it = agentRegistrationQueue.iterator(); it.hasNext();) |
1332 | |
{ |
1333 | 0 | UMOAgent theAgent = (UMOAgent) it.next(); |
1334 | 0 | this.agents.put(theAgent.getName(), theAgent); |
1335 | |
} |
1336 | |
} |
1337 | |
} |
1338 | |
} |
1339 | |
finally |
1340 | |
{ |
1341 | |
|
1342 | 0 | cursor.close(); |
1343 | 0 | } |
1344 | 0 | logger.info("Agents Successfully Initialised"); |
1345 | 0 | } |
1346 | |
|
1347 | |
|
1348 | |
|
1349 | |
|
1350 | |
protected void startAgents() throws UMOException |
1351 | |
{ |
1352 | |
UMOAgent umoAgent; |
1353 | 0 | logger.info("Starting agents..."); |
1354 | 0 | for (Iterator iterator = agents.values().iterator(); iterator.hasNext();) |
1355 | |
{ |
1356 | 0 | umoAgent = (UMOAgent) iterator.next(); |
1357 | 0 | logger.info("Starting agent: " + umoAgent.getDescription()); |
1358 | 0 | umoAgent.start(); |
1359 | |
|
1360 | |
} |
1361 | 0 | logger.info("Agents Successfully Started"); |
1362 | 0 | } |
1363 | |
|
1364 | |
|
1365 | |
|
1366 | |
|
1367 | |
protected void stopAgents() throws UMOException |
1368 | |
{ |
1369 | 0 | logger.info("Stopping agents..."); |
1370 | 0 | for (Iterator iterator = agents.values().iterator(); iterator.hasNext();) |
1371 | |
{ |
1372 | 0 | UMOAgent umoAgent = (UMOAgent) iterator.next(); |
1373 | 0 | logger.debug("Stopping agent: " + umoAgent.getName()); |
1374 | 0 | umoAgent.stop(); |
1375 | |
} |
1376 | 0 | logger.info("Agents Successfully Stopped"); |
1377 | 0 | } |
1378 | |
|
1379 | |
|
1380 | |
|
1381 | |
|
1382 | |
protected void disposeAgents() |
1383 | |
{ |
1384 | |
UMOAgent umoAgent; |
1385 | 0 | logger.info("disposing agents..."); |
1386 | 0 | for (Iterator iterator = agents.values().iterator(); iterator.hasNext();) |
1387 | |
{ |
1388 | 0 | umoAgent = (UMOAgent) iterator.next(); |
1389 | 0 | logger.debug("Disposing agent: " + umoAgent.getName()); |
1390 | 0 | umoAgent.dispose(); |
1391 | |
} |
1392 | 0 | logger.info("Agents Successfully Disposed"); |
1393 | 0 | } |
1394 | |
|
1395 | |
|
1396 | |
|
1397 | |
|
1398 | |
|
1399 | |
|
1400 | |
|
1401 | |
|
1402 | |
|
1403 | |
|
1404 | |
public void setContainerContext(UMOContainerContext container) throws UMOException |
1405 | |
{ |
1406 | 0 | if (container == null) |
1407 | |
{ |
1408 | 0 | if (containerContext != null) |
1409 | |
{ |
1410 | 0 | containerContext.dispose(); |
1411 | |
} |
1412 | 0 | containerContext = new MultiContainerContext(); |
1413 | |
} |
1414 | |
else |
1415 | |
{ |
1416 | 0 | container.initialise(); |
1417 | 0 | containerContext.addContainer(container); |
1418 | |
} |
1419 | 0 | } |
1420 | |
|
1421 | |
|
1422 | |
|
1423 | |
|
1424 | |
|
1425 | |
|
1426 | |
|
1427 | |
public UMOContainerContext getContainerContext() |
1428 | |
{ |
1429 | 0 | return containerContext; |
1430 | |
} |
1431 | |
|
1432 | |
|
1433 | |
|
1434 | |
|
1435 | |
public void registerListener(UMOServerNotificationListener l) throws NotificationException |
1436 | |
{ |
1437 | 0 | registerListener(l, null); |
1438 | 0 | } |
1439 | |
|
1440 | |
public void registerListener(UMOServerNotificationListener l, String resourceIdentifier) |
1441 | |
throws NotificationException |
1442 | |
{ |
1443 | 0 | if (notificationManager == null) |
1444 | |
{ |
1445 | 0 | throw new NotificationException(CoreMessages.serverEventManagerNotEnabled()); |
1446 | |
} |
1447 | 0 | notificationManager.registerListener(l, resourceIdentifier); |
1448 | 0 | } |
1449 | |
|
1450 | |
|
1451 | |
|
1452 | |
|
1453 | |
public void unregisterListener(UMOServerNotificationListener l) |
1454 | |
{ |
1455 | 0 | if (notificationManager != null) |
1456 | |
{ |
1457 | 0 | notificationManager.unregisterListener(l); |
1458 | |
} |
1459 | 0 | } |
1460 | |
|
1461 | |
|
1462 | |
|
1463 | |
|
1464 | |
|
1465 | |
|
1466 | |
|
1467 | |
|
1468 | |
protected void fireSystemEvent(UMOServerNotification e) |
1469 | |
{ |
1470 | 0 | if (notificationManager != null) |
1471 | |
{ |
1472 | 0 | notificationManager.fireEvent(e); |
1473 | |
} |
1474 | 0 | else if (logger.isDebugEnabled()) |
1475 | |
{ |
1476 | 0 | logger.debug("Event Manager is not enabled, ignoring event: " + e); |
1477 | |
} |
1478 | 0 | } |
1479 | |
|
1480 | |
|
1481 | |
|
1482 | |
|
1483 | |
|
1484 | |
|
1485 | |
|
1486 | |
|
1487 | |
|
1488 | |
|
1489 | |
|
1490 | |
|
1491 | |
|
1492 | |
|
1493 | |
public void fireNotification(UMOServerNotification notification) |
1494 | |
{ |
1495 | |
|
1496 | 0 | if (notificationManager != null) |
1497 | |
{ |
1498 | 0 | notificationManager.fireEvent(notification); |
1499 | |
} |
1500 | 0 | else if (logger.isDebugEnabled()) |
1501 | |
{ |
1502 | 0 | logger.debug("Event Manager is not enabled, ignoring notification: " + notification); |
1503 | |
} |
1504 | |
|
1505 | |
|
1506 | |
|
1507 | |
|
1508 | 0 | } |
1509 | |
|
1510 | |
public void setId(String id) |
1511 | |
{ |
1512 | 0 | this.id = id; |
1513 | 0 | } |
1514 | |
|
1515 | |
public String getId() |
1516 | |
{ |
1517 | 0 | return id; |
1518 | |
} |
1519 | |
|
1520 | |
|
1521 | |
|
1522 | |
|
1523 | |
|
1524 | |
|
1525 | |
|
1526 | |
|
1527 | |
|
1528 | |
public void setSecurityManager(UMOSecurityManager securityManager) throws InitialisationException |
1529 | |
{ |
1530 | 0 | this.securityManager = securityManager; |
1531 | 0 | if (securityManager != null && isInitialised()) |
1532 | |
{ |
1533 | 0 | this.securityManager.initialise(); |
1534 | |
} |
1535 | 0 | } |
1536 | |
|
1537 | |
|
1538 | |
|
1539 | |
|
1540 | |
|
1541 | |
|
1542 | |
|
1543 | |
|
1544 | |
public UMOSecurityManager getSecurityManager() |
1545 | |
{ |
1546 | 0 | return securityManager; |
1547 | |
} |
1548 | |
|
1549 | |
|
1550 | |
|
1551 | |
|
1552 | |
|
1553 | |
|
1554 | |
|
1555 | |
|
1556 | |
|
1557 | |
|
1558 | |
|
1559 | |
|
1560 | |
|
1561 | |
|
1562 | |
|
1563 | |
public UMOWorkManager getWorkManager() |
1564 | |
{ |
1565 | 0 | return workManager; |
1566 | |
} |
1567 | |
|
1568 | |
|
1569 | |
|
1570 | |
|
1571 | |
|
1572 | |
|
1573 | |
|
1574 | |
|
1575 | |
|
1576 | |
|
1577 | |
|
1578 | |
|
1579 | |
|
1580 | |
|
1581 | |
|
1582 | |
|
1583 | |
|
1584 | |
public void setWorkManager(UMOWorkManager workManager) |
1585 | |
{ |
1586 | 0 | if (this.workManager != null) |
1587 | |
{ |
1588 | 0 | throw new IllegalStateException( |
1589 | |
CoreMessages.cannotSetObjectOnceItHasBeenSet("workManager").getMessage()); |
1590 | |
} |
1591 | 0 | this.workManager = workManager; |
1592 | 0 | } |
1593 | |
|
1594 | |
public QueueManager getQueueManager() |
1595 | |
{ |
1596 | 0 | return queueManager; |
1597 | |
} |
1598 | |
|
1599 | |
public void setQueueManager(QueueManager queueManager) |
1600 | |
{ |
1601 | 0 | this.queueManager = queueManager; |
1602 | 0 | } |
1603 | |
|
1604 | |
|
1605 | |
|
1606 | |
|
1607 | |
private class ShutdownThread extends Thread |
1608 | |
{ |
1609 | |
Throwable t; |
1610 | 0 | boolean aggressive = true; |
1611 | |
|
1612 | |
public ShutdownThread() |
1613 | 0 | { |
1614 | 0 | super(); |
1615 | 0 | this.t = shutdownContext.getException(); |
1616 | 0 | this.aggressive = shutdownContext.isAggressive(); |
1617 | 0 | } |
1618 | |
|
1619 | |
|
1620 | |
|
1621 | |
|
1622 | |
|
1623 | |
|
1624 | |
public void run() |
1625 | |
{ |
1626 | 0 | dispose(); |
1627 | 0 | if (!aggressive) |
1628 | |
{ |
1629 | |
|
1630 | |
|
1631 | |
} |
1632 | |
|
1633 | 0 | if (server != null) |
1634 | |
{ |
1635 | 0 | if (t != null) |
1636 | |
{ |
1637 | 0 | server.shutdown(t); |
1638 | |
} |
1639 | |
else |
1640 | |
{ |
1641 | 0 | server.shutdown(); |
1642 | |
} |
1643 | |
} |
1644 | 0 | } |
1645 | |
} |
1646 | |
|
1647 | |
private class ShutdownContext |
1648 | |
{ |
1649 | 0 | private boolean aggressive = false; |
1650 | 0 | private Throwable exception = null; |
1651 | |
|
1652 | |
public ShutdownContext(boolean aggressive, Throwable exception) |
1653 | 0 | { |
1654 | 0 | this.aggressive = aggressive; |
1655 | 0 | this.exception = exception; |
1656 | 0 | } |
1657 | |
|
1658 | |
public boolean isAggressive() |
1659 | |
{ |
1660 | 0 | return aggressive; |
1661 | |
} |
1662 | |
|
1663 | |
public Throwable getException() |
1664 | |
{ |
1665 | 0 | return exception; |
1666 | |
} |
1667 | |
} |
1668 | |
} |