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