1 10 11 package org.mule.config; 12 13 import org.apache.commons.beanutils.BeanUtils; 14 import org.apache.commons.lang.StringUtils; 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 import org.mule.MuleRuntimeException; 18 import org.mule.config.i18n.Message; 19 import org.mule.config.i18n.Messages; 20 import org.mule.providers.ConnectionStrategy; 21 import org.mule.providers.SingleAttemptConnectionStrategy; 22 import org.mule.umo.manager.DefaultWorkListener; 23 import org.mule.util.queue.EventFilePersistenceStrategy; 24 import org.mule.util.queue.QueuePersistenceStrategy; 25 26 import javax.resource.spi.work.WorkListener ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.net.URL ; 30 import java.security.AccessController ; 31 import java.security.PrivilegedAction ; 32 import java.util.jar.Attributes ; 33 import java.util.jar.Manifest ; 34 import java.util.Enumeration ; 35 36 44 public class MuleConfiguration 45 { 46 49 protected transient Log logger = LogFactory.getLog(getClass()); 50 51 54 public static final String DEFAULT_SERVER_URL = "tcp://localhost:60504"; 55 56 60 public static final String USE_MANAGER_PROPERTIES = "org.mule.useManagerProperties"; 61 62 67 public static final String SYNCHRONOUS_PROPERTY = "synchronous"; 68 69 public static final String DEFAULT_ENCODING = "UTF-8"; 70 73 public static final String DEFAULT_OS_ENCODING = System.getProperty("file.encoding"); 74 75 95 98 public static final boolean DEFAULT_SYNCHRONOUS = false; 99 100 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 112 public static final String DEFAULT_WORKING_DIRECTORY = "./.mule"; 113 114 117 public static final String DEFAULT_QUEUE_STORE = "queuestore"; 118 119 122 private boolean synchronous = DEFAULT_SYNCHRONOUS; 123 124 127 private boolean enableMessageEvents = false; 128 129 132 private String model = null; 133 134 private String encoding = DEFAULT_ENCODING; 135 136 private String osEncoding = DEFAULT_OS_ENCODING; 137 138 private PoolingProfile poolingProfile = new PoolingProfile(); 139 140 143 private ThreadingProfile messageDispatcherThreadingProfile = null; 144 145 148 private ThreadingProfile messageReceiverThreadingProfile = null; 149 150 153 private ThreadingProfile componentPoolThreadingProfile = null; 154 155 private QueueProfile queueProfile = new QueueProfile(DEFAULT_MAX_OUTSTANDING_MESSAGES, false); 156 157 private QueuePersistenceStrategy persistenceStrategy = new EventFilePersistenceStrategy(); 158 159 163 private int synchronousEventTimeout = DEFAULT_TIMEOUT; 164 165 169 private int transactionTimeout = DEFAULT_TRANSACTION_TIMEOUT; 170 171 176 private boolean remoteSync = false; 177 178 183 private boolean recoverableMode = false; 184 188 private ThreadingProfile defaultThreadingProfile = new ThreadingProfile(); 189 190 193 private String workingDirectory = DEFAULT_WORKING_DIRECTORY; 194 195 198 private String [] configResources = new String []{}; 199 200 205 private String serverUrl = DEFAULT_SERVER_URL; 206 207 210 private Manifest manifest = null; 211 212 216 private boolean clientMode = false; 217 218 222 private boolean embedded = false; 223 224 227 private String modelType = "default"; 228 229 233 private ConnectionStrategy connectionStrategy = new SingleAttemptConnectionStrategy(); 234 235 private WorkListener workListener = new DefaultWorkListener(); 236 237 public MuleConfiguration() 238 { 239 super(); 240 } 241 242 245 public boolean isSynchronous() 246 { 247 return synchronous; 248 } 249 250 public void setSynchronous(boolean synchronous) 251 { 252 this.synchronous = synchronous; 253 } 254 255 public String getModel() 256 { 257 return model; 258 } 259 260 public void setModel(String model) 261 { 262 this.model = model; 263 } 264 265 public ThreadingProfile getMessageDispatcherThreadingProfile() 266 { 267 return getThreadingProfile(messageDispatcherThreadingProfile); 268 } 269 270 public void setMessageDispatcherThreadingProfile(ThreadingProfile messageDispatcherThreadingProfile) 271 { 272 this.messageDispatcherThreadingProfile = messageDispatcherThreadingProfile; 273 } 274 275 public ThreadingProfile getMessageReceiverThreadingProfile() 276 { 277 return getThreadingProfile(messageReceiverThreadingProfile); 278 } 279 280 public void setMessageReceiverThreadingProfile(ThreadingProfile messageReceiverThreadingProfile) 281 { 282 this.messageReceiverThreadingProfile = messageReceiverThreadingProfile; 283 } 284 285 public ThreadingProfile getComponentThreadingProfile() 286 { 287 return getThreadingProfile(componentPoolThreadingProfile); 288 } 289 290 public void setComponentThreadingProfile(ThreadingProfile componentPoolThreadingProfile) 291 { 292 this.componentPoolThreadingProfile = componentPoolThreadingProfile; 293 } 294 295 public ThreadingProfile getDefaultThreadingProfile() 296 { 297 return getThreadingProfile(defaultThreadingProfile); 298 } 299 300 public void setDefaultThreadingProfile(ThreadingProfile defaultThreadingProfile) 301 { 302 if (defaultThreadingProfile == null) 303 { 304 return; 305 } 306 this.defaultThreadingProfile = defaultThreadingProfile; 307 } 308 309 private ThreadingProfile getThreadingProfile(ThreadingProfile profile) 310 { 311 if (profile != null) 312 { 313 return new ThreadingProfile(profile); 314 } 315 return new ThreadingProfile(defaultThreadingProfile); 316 } 317 318 public PoolingProfile getPoolingProfile() 319 { 320 return new PoolingProfile(poolingProfile); 321 } 322 323 public void setPoolingProfile(PoolingProfile poolingProfile) 324 { 325 this.poolingProfile = poolingProfile; 326 } 327 328 public int getSynchronousEventTimeout() 329 { 330 return synchronousEventTimeout; 331 } 332 333 public void setSynchronousEventTimeout(int synchronousEventTimeout) 334 { 335 this.synchronousEventTimeout = synchronousEventTimeout; 336 } 337 338 public boolean isRemoteSync() 339 { 340 return remoteSync; 341 } 342 343 public void setRemoteSync(boolean remoteSync) 344 { 345 this.remoteSync = remoteSync; 346 } 347 348 public QueueProfile getQueueProfile() 349 { 350 return new QueueProfile(queueProfile); 351 } 352 353 public void setQueueProfile(QueueProfile queueProfile) 354 { 355 this.queueProfile = queueProfile; 356 } 357 358 public boolean isRecoverableMode() 359 { 360 return recoverableMode; 361 } 362 363 public void setRecoverableMode(boolean recoverableMode) 364 { 365 this.recoverableMode = recoverableMode; 366 if (recoverableMode) 367 { 368 queueProfile.setPersistent(true); 369 } 370 } 371 372 public String getWorkingDirectory() 373 { 374 return workingDirectory; 375 } 376 377 public void setWorkingDirectory(String workingDirectory) 378 { 379 this.workingDirectory = workingDirectory; 380 } 381 382 public String [] getConfigResources() 383 { 384 return configResources; 385 } 386 387 public void setConfigResources(String [] configResources) 388 { 389 if (configResources != null) 390 { 391 int current = this.configResources.length; 392 String [] newResources = new String [configResources.length + current]; 393 System.arraycopy(this.configResources, 0, newResources, 0, current); 394 System.arraycopy(configResources, 0, newResources, current, configResources.length); 395 this.configResources = newResources; 396 } 397 else 398 { 399 this.configResources = configResources; 400 } 401 } 402 403 public String getServerUrl() 404 { 405 return serverUrl; 406 } 407 408 public void setServerUrl(String serverUrl) 409 { 410 if (embedded) 411 { 412 serverUrl = null; 413 } 414 else 415 { 416 this.serverUrl = serverUrl; 417 } 418 } 419 420 public String getProductVersion() 421 { 422 return getManifestProperty("Implementation-Version"); 423 } 424 425 public String getVendorName() 426 { 427 return getManifestProperty("Specification-Vendor"); 428 } 429 430 public String getVendorUrl() 431 { 432 return getManifestProperty("Vendor-Url"); 433 } 434 435 public String getProductUrl() 436 { 437 return getManifestProperty("Product-Url"); 438 } 439 440 public String getProductName() 441 { 442 return getManifestProperty("Implementation-Title"); 443 } 444 445 public String getProductMoreInfo() 446 { 447 return getManifestProperty("More-Info"); 448 } 449 450 public String getProductSupport() 451 { 452 return getManifestProperty("Support"); 453 } 454 455 public String getProductLicenseInfo() 456 { 457 return getManifestProperty("License"); 458 } 459 460 public String getProductDescription() 461 { 462 return getManifestProperty("Description"); 463 } 464 465 public String getBuildDate() 466 { 467 return getManifestProperty("Build-Date"); 468 } 469 470 public Manifest getManifest() 471 { 472 if (manifest == null) 473 { 474 manifest = new Manifest (); 475 476 InputStream is = null; 477 try 478 { 479 URL url = (URL )AccessController.doPrivileged(new PrivilegedAction () 483 { 484 public Object run() 485 { 486 try 487 { 488 Enumeration e = MuleConfiguration.class.getClassLoader().getResources( 489 ("META-INF/MANIFEST.MF")); 490 while (e.hasMoreElements()) 491 { 492 URL url = (URL )e.nextElement(); 493 if (url.toExternalForm().indexOf("mule-core") > -1) 494 { 495 return url; 496 } 497 } 498 } 499 catch (IOException e1) 500 { 501 e1.printStackTrace(); 502 } 503 return null; 504 } 505 }); 506 507 if (url != null) 508 { 509 is = url.openStream(); 510 } 511 512 if (is != null) 513 { 514 manifest.read(is); 515 } 516 517 } 518 catch (IOException e) 519 { 520 logger.warn("Failed to read manifest Info, Manifest information will not display correctly: " 521 + e.getMessage()); 522 } 523 } 524 return manifest; 525 } 526 527 protected String getManifestProperty(String name) 528 { 529 return getManifest().getMainAttributes().getValue(new Attributes.Name (name)); 530 } 531 532 public int getTransactionTimeout() 533 { 534 return transactionTimeout; 535 } 536 537 public void setTransactionTimeout(int transactionTimeout) 538 { 539 this.transactionTimeout = transactionTimeout; 540 } 541 542 public boolean isClientMode() 543 { 544 return clientMode; 545 } 546 547 public void setClientMode(boolean clientMode) 548 { 549 this.clientMode = clientMode; 550 if (clientMode) 551 { 552 setServerUrl(""); 553 } 554 } 555 556 public QueuePersistenceStrategy getPersistenceStrategy() 557 { 558 return persistenceStrategy; 559 } 560 561 public void setPersistenceStrategy(QueuePersistenceStrategy persistenceStrategy) 562 { 563 this.persistenceStrategy = persistenceStrategy; 564 } 565 566 573 public ConnectionStrategy getConnectionStrategy() 574 { 575 try 576 { 577 return (ConnectionStrategy)BeanUtils.cloneBean(connectionStrategy); 578 } 579 catch (Exception e) 580 { 581 throw new MuleRuntimeException(new Message(Messages.FAILED_TO_CLONE_X, "Connection Strategy"), e); 582 } 583 } 584 585 591 public void setConnectionStrategy(ConnectionStrategy connectionStrategy) 592 { 593 this.connectionStrategy = connectionStrategy; 594 } 595 596 public boolean isEmbedded() 597 { 598 return embedded; 599 } 600 601 public void setEmbedded(boolean embedded) 602 { 603 this.embedded = embedded; 604 if (embedded) 605 { 606 serverUrl = null; 607 } 608 } 609 610 public String getModelType() 611 { 612 return modelType; 613 } 614 615 public void setModelType(String modelType) 616 { 617 this.modelType = modelType; 618 } 619 620 public String getEncoding() 621 { 622 return encoding; 623 } 624 625 public void setEncoding(String encoding) 626 { 627 if (StringUtils.isEmpty(encoding)) 628 { 629 logger.warn("Cannot set encoding to null or empty String"); 630 return; 631 } 632 this.encoding = encoding; 633 } 634 635 public String getOSEncoding() 636 { 637 return osEncoding; 638 } 639 640 public void setOSEncoding(String osEncoding) 641 { 642 this.osEncoding = osEncoding; 643 } 644 645 public boolean isEnableMessageEvents() 646 { 647 return enableMessageEvents; 648 } 649 650 public void setEnableMessageEvents(boolean enableMessageEvents) 651 { 652 this.enableMessageEvents = enableMessageEvents; 653 } 654 655 public WorkListener getWorkListener() 656 { 657 return workListener; 658 } 659 660 public void setWorkListener(WorkListener workListener) 661 { 662 if (workListener == null) 663 { 664 throw new NullPointerException ("workListener"); 665 } 666 this.workListener = workListener; 667 } 668 } 669 | Popular Tags |