1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.MuleRuntimeException; |
15 | |
import org.mule.config.i18n.CoreMessages; |
16 | |
import org.mule.providers.ConnectionStrategy; |
17 | |
import org.mule.providers.SingleAttemptConnectionStrategy; |
18 | |
import org.mule.umo.manager.DefaultWorkListener; |
19 | |
import org.mule.util.FileUtils; |
20 | |
import org.mule.util.StringUtils; |
21 | |
import org.mule.util.queue.EventFilePersistenceStrategy; |
22 | |
import org.mule.util.queue.QueuePersistenceStrategy; |
23 | |
|
24 | |
import java.io.File; |
25 | |
import java.io.IOException; |
26 | |
import java.io.InputStream; |
27 | |
import java.net.URL; |
28 | |
import java.security.AccessController; |
29 | |
import java.security.PrivilegedAction; |
30 | |
import java.util.Enumeration; |
31 | |
import java.util.jar.Attributes; |
32 | |
import java.util.jar.Manifest; |
33 | |
|
34 | |
import javax.resource.spi.work.WorkListener; |
35 | |
|
36 | |
import org.apache.commons.beanutils.BeanUtils; |
37 | |
import org.apache.commons.logging.Log; |
38 | |
import org.apache.commons.logging.LogFactory; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public class MuleConfiguration |
46 | |
{ |
47 | |
private static final String DEFAULT_LOG_DIRECTORY = "logs"; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | 2296 | protected transient Log logger = LogFactory.getLog(getClass()); |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public static final String DEFAULT_SERVER_URL = "tcp://localhost:60504"; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public static final String USE_MANAGER_PROPERTIES = "org.mule.useManagerProperties"; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public static final String SYNCHRONOUS_PROPERTY = "synchronous"; |
71 | |
|
72 | |
public static final String DEFAULT_ENCODING = "UTF-8"; |
73 | |
|
74 | |
|
75 | |
|
76 | 2 | public static final String DEFAULT_OS_ENCODING = System.getProperty("file.encoding"); |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public static final boolean DEFAULT_SYNCHRONOUS = false; |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public static final int DEFAULT_MAX_OUTSTANDING_MESSAGES = 1000; |
107 | |
|
108 | |
public static final int DEFAULT_TIMEOUT = 10000; |
109 | |
|
110 | |
public static final int DEFAULT_TRANSACTION_TIMEOUT = 30000; |
111 | |
|
112 | |
public static final String DEFAULT_SYSTEM_MODEL_TYPE = "seda"; |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public static final String DEFAULT_WORKING_DIRECTORY = "./.mule"; |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public static final String DEFAULT_QUEUE_STORE = "queuestore"; |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | 2296 | private boolean synchronous = DEFAULT_SYNCHRONOUS; |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | 2296 | private String systemModelType = DEFAULT_SYSTEM_MODEL_TYPE; |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | 2296 | private boolean enableMessageEvents = false; |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | 2296 | private String model = null; |
144 | |
|
145 | 2296 | private String encoding = DEFAULT_ENCODING; |
146 | |
|
147 | 2296 | private String osEncoding = DEFAULT_OS_ENCODING; |
148 | |
|
149 | 2296 | private PoolingProfile poolingProfile = new PoolingProfile(); |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | 2296 | private ThreadingProfile messageDispatcherThreadingProfile = null; |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | 2296 | private ThreadingProfile messageReceiverThreadingProfile = null; |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | 2296 | private ThreadingProfile componentPoolThreadingProfile = null; |
165 | |
|
166 | 2296 | private QueueProfile queueProfile = new QueueProfile(DEFAULT_MAX_OUTSTANDING_MESSAGES, false); |
167 | |
|
168 | 2296 | private QueuePersistenceStrategy persistenceStrategy = new EventFilePersistenceStrategy(); |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | 2296 | private int synchronousEventTimeout = DEFAULT_TIMEOUT; |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | 2296 | private int transactionTimeout = DEFAULT_TRANSACTION_TIMEOUT; |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | 2296 | private boolean remoteSync = false; |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | 2296 | private boolean recoverableMode = false; |
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | 2296 | private ThreadingProfile defaultThreadingProfile = new ThreadingProfile(); |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
private String workingDirectory; |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | 2296 | private String[] configResources = new String[]{}; |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | 2296 | private String serverUrl = DEFAULT_SERVER_URL; |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | 2296 | private Manifest manifest = null; |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | 2296 | private boolean clientMode = false; |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | 2296 | private boolean embedded = false; |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | 2296 | private String modelType = "default"; |
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | 2296 | private ConnectionStrategy connectionStrategy = new SingleAttemptConnectionStrategy(); |
245 | |
|
246 | 2296 | private WorkListener workListener = new DefaultWorkListener(); |
247 | |
|
248 | |
public MuleConfiguration() |
249 | |
{ |
250 | 2296 | super(); |
251 | 2296 | setWorkingDirectory(DEFAULT_WORKING_DIRECTORY); |
252 | 2296 | } |
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
public boolean isSynchronous() |
258 | |
{ |
259 | 0 | return synchronous; |
260 | |
} |
261 | |
|
262 | |
public void setSynchronous(boolean synchronous) |
263 | |
{ |
264 | 66 | this.synchronous = synchronous; |
265 | 66 | } |
266 | |
|
267 | |
public String getModel() |
268 | |
{ |
269 | 0 | return model; |
270 | |
} |
271 | |
|
272 | |
public void setModel(String model) |
273 | |
{ |
274 | 0 | this.model = model; |
275 | 0 | } |
276 | |
|
277 | |
public ThreadingProfile getMessageDispatcherThreadingProfile() |
278 | |
{ |
279 | 778 | return getThreadingProfile(messageDispatcherThreadingProfile); |
280 | |
} |
281 | |
|
282 | |
public void setMessageDispatcherThreadingProfile(ThreadingProfile messageDispatcherThreadingProfile) |
283 | |
{ |
284 | 0 | this.messageDispatcherThreadingProfile = messageDispatcherThreadingProfile; |
285 | 0 | } |
286 | |
|
287 | |
public ThreadingProfile getMessageReceiverThreadingProfile() |
288 | |
{ |
289 | 778 | return getThreadingProfile(messageReceiverThreadingProfile); |
290 | |
} |
291 | |
|
292 | |
public void setMessageReceiverThreadingProfile(ThreadingProfile messageReceiverThreadingProfile) |
293 | |
{ |
294 | 0 | this.messageReceiverThreadingProfile = messageReceiverThreadingProfile; |
295 | 0 | } |
296 | |
|
297 | |
public ThreadingProfile getComponentThreadingProfile() |
298 | |
{ |
299 | 410 | return getThreadingProfile(componentPoolThreadingProfile); |
300 | |
} |
301 | |
|
302 | |
public void setComponentThreadingProfile(ThreadingProfile componentPoolThreadingProfile) |
303 | |
{ |
304 | 0 | this.componentPoolThreadingProfile = componentPoolThreadingProfile; |
305 | 0 | } |
306 | |
|
307 | |
public ThreadingProfile getDefaultThreadingProfile() |
308 | |
{ |
309 | 894 | return getThreadingProfile(defaultThreadingProfile); |
310 | |
} |
311 | |
|
312 | |
public void setDefaultThreadingProfile(ThreadingProfile defaultThreadingProfile) |
313 | |
{ |
314 | 0 | if (defaultThreadingProfile == null) |
315 | |
{ |
316 | 0 | return; |
317 | |
} |
318 | 0 | this.defaultThreadingProfile = defaultThreadingProfile; |
319 | 0 | } |
320 | |
|
321 | |
private ThreadingProfile getThreadingProfile(ThreadingProfile profile) |
322 | |
{ |
323 | 2860 | if (profile != null) |
324 | |
{ |
325 | 894 | return new ThreadingProfile(profile); |
326 | |
} |
327 | 1966 | return new ThreadingProfile(defaultThreadingProfile); |
328 | |
} |
329 | |
|
330 | |
public PoolingProfile getPoolingProfile() |
331 | |
{ |
332 | 460 | return new PoolingProfile(poolingProfile); |
333 | |
} |
334 | |
|
335 | |
public void setPoolingProfile(PoolingProfile poolingProfile) |
336 | |
{ |
337 | 0 | this.poolingProfile = poolingProfile; |
338 | 0 | } |
339 | |
|
340 | |
public int getSynchronousEventTimeout() |
341 | |
{ |
342 | 1062 | return synchronousEventTimeout; |
343 | |
} |
344 | |
|
345 | |
public void setSynchronousEventTimeout(int synchronousEventTimeout) |
346 | |
{ |
347 | 0 | this.synchronousEventTimeout = synchronousEventTimeout; |
348 | 0 | } |
349 | |
|
350 | |
public boolean isRemoteSync() |
351 | |
{ |
352 | 0 | return remoteSync; |
353 | |
} |
354 | |
|
355 | |
public void setRemoteSync(boolean remoteSync) |
356 | |
{ |
357 | 0 | this.remoteSync = remoteSync; |
358 | 0 | } |
359 | |
|
360 | |
public QueueProfile getQueueProfile() |
361 | |
{ |
362 | 412 | return new QueueProfile(queueProfile); |
363 | |
} |
364 | |
|
365 | |
public void setQueueProfile(QueueProfile queueProfile) |
366 | |
{ |
367 | 0 | this.queueProfile = queueProfile; |
368 | 0 | } |
369 | |
|
370 | |
public boolean isRecoverableMode() |
371 | |
{ |
372 | 0 | return recoverableMode; |
373 | |
} |
374 | |
|
375 | |
public void setRecoverableMode(boolean recoverableMode) |
376 | |
{ |
377 | 0 | this.recoverableMode = recoverableMode; |
378 | 0 | if (recoverableMode) |
379 | |
{ |
380 | 0 | queueProfile.setPersistent(true); |
381 | |
} |
382 | 0 | } |
383 | |
|
384 | |
public String getWorkingDirectory() |
385 | |
{ |
386 | 1974 | return workingDirectory; |
387 | |
} |
388 | |
|
389 | |
public String getMuleHomeDirectory() |
390 | |
{ |
391 | 0 | return System.getProperty(MuleProperties.MULE_HOME_DIRECTORY_PROPERTY); |
392 | |
} |
393 | |
|
394 | |
public String getLogDirectory() |
395 | |
{ |
396 | 0 | return getMuleHomeDirectory() + File.separator + DEFAULT_LOG_DIRECTORY; |
397 | |
} |
398 | |
|
399 | |
public void setWorkingDirectory(String workingDirectory) |
400 | |
{ |
401 | |
|
402 | 2296 | this.workingDirectory = FileUtils.newFile(workingDirectory).getAbsolutePath().replaceAll("\\\\", "/"); |
403 | 2296 | updateApplicationProperty(MuleProperties.MULE_WORKING_DIRECTORY_PROPERTY, this.workingDirectory); |
404 | 2296 | } |
405 | |
|
406 | |
public String[] getConfigResources() |
407 | |
{ |
408 | 0 | return configResources; |
409 | |
} |
410 | |
|
411 | |
public void setConfigResources(String[] configResources) |
412 | |
{ |
413 | 0 | if (configResources != null) |
414 | |
{ |
415 | 0 | int current = this.configResources.length; |
416 | 0 | String[] newResources = new String[configResources.length + current]; |
417 | 0 | System.arraycopy(this.configResources, 0, newResources, 0, current); |
418 | 0 | System.arraycopy(configResources, 0, newResources, current, configResources.length); |
419 | 0 | this.configResources = newResources; |
420 | 0 | } |
421 | |
else |
422 | |
{ |
423 | 0 | this.configResources = configResources; |
424 | |
} |
425 | 0 | } |
426 | |
|
427 | |
public String getServerUrl() |
428 | |
{ |
429 | 48 | return serverUrl; |
430 | |
} |
431 | |
|
432 | |
public void setServerUrl(String serverUrl) |
433 | |
{ |
434 | 910 | if (embedded) |
435 | |
{ |
436 | 0 | this.serverUrl = null; |
437 | |
} |
438 | |
else |
439 | |
{ |
440 | 910 | this.serverUrl = serverUrl; |
441 | |
} |
442 | 910 | } |
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
public String getProductVersion() |
448 | |
{ |
449 | 0 | return MuleManifest.getProductVersion(); |
450 | |
} |
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
public String getVendorName() |
456 | |
{ |
457 | 0 | return MuleManifest.getVendorName(); |
458 | |
} |
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
public String getVendorUrl() |
464 | |
{ |
465 | 0 | return MuleManifest.getVendorUrl(); |
466 | |
} |
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
public String getProductUrl() |
472 | |
{ |
473 | 0 | return MuleManifest.getProductUrl(); |
474 | |
} |
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
public String getProductName() |
480 | |
{ |
481 | 0 | return MuleManifest.getProductName(); |
482 | |
} |
483 | |
|
484 | |
|
485 | |
|
486 | |
|
487 | |
public String getProductMoreInfo() |
488 | |
{ |
489 | 0 | return MuleManifest.getProductMoreInfo(); |
490 | |
} |
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
public String getProductSupport() |
496 | |
{ |
497 | 0 | return MuleManifest.getProductSupport(); |
498 | |
} |
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
public String getProductLicenseInfo() |
504 | |
{ |
505 | 0 | return MuleManifest.getProductLicenseInfo(); |
506 | |
} |
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
public String getProductDescription() |
512 | |
{ |
513 | 0 | return MuleManifest.getProductDescription(); |
514 | |
} |
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
public String getBuildDate() |
520 | |
{ |
521 | 0 | return MuleManifest.getBuildDate(); |
522 | |
} |
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
public Manifest getManifest() |
528 | |
{ |
529 | 0 | if (manifest == null) |
530 | |
{ |
531 | 0 | manifest = new Manifest(); |
532 | |
|
533 | 0 | InputStream is = null; |
534 | |
try |
535 | |
{ |
536 | |
|
537 | |
|
538 | |
|
539 | 0 | URL url = (URL) AccessController.doPrivileged(new PrivilegedAction() |
540 | |
{ |
541 | 0 | public Object run() |
542 | |
{ |
543 | |
try |
544 | |
{ |
545 | 0 | Enumeration e = MuleConfiguration.class.getClassLoader().getResources( |
546 | |
("META-INF/MANIFEST.MF")); |
547 | 0 | while (e.hasMoreElements()) |
548 | |
{ |
549 | 0 | URL url = (URL) e.nextElement(); |
550 | 0 | if (url.toExternalForm().indexOf("mule-core") > -1) |
551 | |
{ |
552 | 0 | return url; |
553 | |
} |
554 | 0 | } |
555 | |
} |
556 | 0 | catch (IOException e1) |
557 | |
{ |
558 | 0 | logger.error("Failure reading manifest: " + e1.getMessage(), e1); |
559 | 0 | } |
560 | 0 | return null; |
561 | |
} |
562 | |
}); |
563 | |
|
564 | 0 | if (url != null) |
565 | |
{ |
566 | 0 | is = url.openStream(); |
567 | |
} |
568 | |
|
569 | 0 | if (is != null) |
570 | |
{ |
571 | 0 | manifest.read(is); |
572 | |
} |
573 | |
|
574 | |
} |
575 | 0 | catch (IOException e) |
576 | |
{ |
577 | 0 | logger.warn("Failed to read manifest Info, Manifest information will not display correctly: " |
578 | |
+ e.getMessage()); |
579 | 0 | } |
580 | |
} |
581 | 0 | return manifest; |
582 | |
} |
583 | |
|
584 | |
|
585 | |
|
586 | |
|
587 | |
protected String getManifestProperty(String name) |
588 | |
{ |
589 | 0 | return getManifest().getMainAttributes().getValue(new Attributes.Name(name)); |
590 | |
} |
591 | |
|
592 | |
public int getTransactionTimeout() |
593 | |
{ |
594 | 828 | return transactionTimeout; |
595 | |
} |
596 | |
|
597 | |
public void setTransactionTimeout(int transactionTimeout) |
598 | |
{ |
599 | 0 | this.transactionTimeout = transactionTimeout; |
600 | 0 | } |
601 | |
|
602 | |
public boolean isClientMode() |
603 | |
{ |
604 | 0 | return clientMode; |
605 | |
} |
606 | |
|
607 | |
public void setClientMode(boolean clientMode) |
608 | |
{ |
609 | 0 | this.clientMode = clientMode; |
610 | 0 | if (clientMode) |
611 | |
{ |
612 | 0 | setServerUrl(""); |
613 | |
} |
614 | 0 | } |
615 | |
|
616 | |
public QueuePersistenceStrategy getPersistenceStrategy() |
617 | |
{ |
618 | 44 | return persistenceStrategy; |
619 | |
} |
620 | |
|
621 | |
public void setPersistenceStrategy(QueuePersistenceStrategy persistenceStrategy) |
622 | |
{ |
623 | 0 | this.persistenceStrategy = persistenceStrategy; |
624 | 0 | } |
625 | |
|
626 | |
|
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
public ConnectionStrategy getConnectionStrategy() |
634 | |
{ |
635 | |
try |
636 | |
{ |
637 | 778 | return (ConnectionStrategy) BeanUtils.cloneBean(connectionStrategy); |
638 | |
} |
639 | 0 | catch (Exception e) |
640 | |
{ |
641 | 0 | throw new MuleRuntimeException(CoreMessages.failedToClone("Connection Strategy"), e); |
642 | |
} |
643 | |
} |
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | |
|
649 | |
|
650 | |
|
651 | |
public void setConnectionStrategy(ConnectionStrategy connectionStrategy) |
652 | |
{ |
653 | 0 | this.connectionStrategy = connectionStrategy; |
654 | 0 | } |
655 | |
|
656 | |
public boolean isEmbedded() |
657 | |
{ |
658 | 0 | return embedded; |
659 | |
} |
660 | |
|
661 | |
public void setEmbedded(boolean embedded) |
662 | |
{ |
663 | 0 | this.embedded = embedded; |
664 | 0 | if (embedded) |
665 | |
{ |
666 | 0 | serverUrl = null; |
667 | |
} |
668 | 0 | } |
669 | |
|
670 | |
public String getModelType() |
671 | |
{ |
672 | 0 | return modelType; |
673 | |
} |
674 | |
|
675 | |
public void setModelType(String modelType) |
676 | |
{ |
677 | 0 | this.modelType = modelType; |
678 | 0 | } |
679 | |
|
680 | |
public String getEncoding() |
681 | |
{ |
682 | 1052 | return encoding; |
683 | |
} |
684 | |
|
685 | |
public void setEncoding(String encoding) |
686 | |
{ |
687 | 42 | if (StringUtils.isEmpty(encoding)) |
688 | |
{ |
689 | 0 | logger.warn("Cannot set encoding to null or empty String"); |
690 | 0 | return; |
691 | |
} |
692 | 42 | this.encoding = encoding; |
693 | 42 | } |
694 | |
|
695 | |
public String getOSEncoding() |
696 | |
{ |
697 | 46 | return osEncoding; |
698 | |
} |
699 | |
|
700 | |
public void setOSEncoding(String osEncoding) |
701 | |
{ |
702 | 42 | this.osEncoding = osEncoding; |
703 | 42 | } |
704 | |
|
705 | |
public boolean isEnableMessageEvents() |
706 | |
{ |
707 | 822 | return enableMessageEvents; |
708 | |
} |
709 | |
|
710 | |
public void setEnableMessageEvents(boolean enableMessageEvents) |
711 | |
{ |
712 | 0 | this.enableMessageEvents = enableMessageEvents; |
713 | 0 | } |
714 | |
|
715 | |
public WorkListener getWorkListener() |
716 | |
{ |
717 | 392 | return workListener; |
718 | |
} |
719 | |
|
720 | |
public void setWorkListener(WorkListener workListener) |
721 | |
{ |
722 | 0 | if (workListener == null) |
723 | |
{ |
724 | 0 | throw new IllegalArgumentException("workListener is null"); |
725 | |
} |
726 | 0 | this.workListener = workListener; |
727 | 0 | } |
728 | |
|
729 | |
private void updateApplicationProperty(String name, Object value) |
730 | |
{ |
731 | 2296 | if (MuleManager.isInstanciated()) |
732 | |
{ |
733 | 392 | MuleManager.getInstance().setProperty(name, value); |
734 | |
} |
735 | 2296 | } |
736 | |
|
737 | |
public String getSystemModelType() |
738 | |
{ |
739 | 2684 | return systemModelType; |
740 | |
} |
741 | |
|
742 | |
public void setSystemModelType(String systemModelType) |
743 | |
{ |
744 | 0 | this.systemModelType = systemModelType; |
745 | 0 | } |
746 | |
} |