1 2 18 19 22 package org.quartz.core; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.quartz.spi.JobStore; 28 import org.quartz.spi.SchedulerPlugin; 29 import org.quartz.spi.ThreadPool; 30 31 41 public class QuartzSchedulerResources { 42 43 50 51 public static final String CREATE_REGISTRY_NEVER = "never"; 52 53 public static final String CREATE_REGISTRY_ALWAYS = "always"; 54 55 public static final String CREATE_REGISTRY_AS_NEEDED = "as_needed"; 56 57 private String name; 58 59 private String instanceId; 60 61 private String threadName; 62 63 private String rmiRegistryHost = null; 64 65 private int rmiRegistryPort = 1099; 66 67 private int rmiServerPort = -1; 68 69 private String rmiCreateRegistryStrategy = CREATE_REGISTRY_NEVER; 70 71 private ThreadPool threadPool; 72 73 private JobStore jobStore; 74 75 private JobRunShellFactory jobRunShellFactory; 76 77 private ArrayList schedulerPlugins = new ArrayList (10); 78 79 private boolean makeSchedulerThreadDaemon = false; 80 81 private String rmiBindName; 82 83 private boolean jmxExport; 84 85 private String jmxObjectName; 86 87 94 95 100 public QuartzSchedulerResources() { 101 } 103 104 111 112 117 public String getName() { 118 return name; 119 } 120 121 129 public void setName(String name) { 130 if (name == null || name.trim().length() == 0) { 131 throw new IllegalArgumentException ( 132 "Scheduler name cannot be empty."); 133 } 134 135 this.name = name; 136 137 if (threadName == null) { 138 setThreadName(name + "_QuartzSchedulerThread"); 140 } 141 } 142 143 148 public String getInstanceId() { 149 return instanceId; 150 } 151 152 160 public void setInstanceId(String instanceId) { 161 if (instanceId == null || instanceId.trim().length() == 0) { 162 throw new IllegalArgumentException ( 163 "Scheduler instanceId cannot be empty."); 164 } 165 166 this.instanceId = instanceId; 167 } 168 169 public static String getUniqueIdentifier(String schedName, 170 String schedInstId) { 171 return schedName + "_$_" + schedInstId; 172 } 173 174 public String getUniqueIdentifier() { 175 return getUniqueIdentifier(name, instanceId); 176 } 177 178 184 public String getRMIRegistryHost() { 185 return rmiRegistryHost; 186 } 187 188 194 public void setRMIRegistryHost(String hostName) { 195 this.rmiRegistryHost = hostName; 196 } 197 198 204 public int getRMIRegistryPort() { 205 return rmiRegistryPort; 206 } 207 208 214 public void setRMIRegistryPort(int port) { 215 this.rmiRegistryPort = port; 216 } 217 218 219 224 public int getRMIServerPort() { 225 return rmiServerPort; 226 } 227 228 233 public void setRMIServerPort(int port) { 234 this.rmiServerPort = port; 235 } 236 237 243 public String getRMICreateRegistryStrategy() { 244 return rmiCreateRegistryStrategy; 245 } 246 247 252 public String getThreadName() { 253 return threadName; 254 } 255 256 264 public void setThreadName(String threadName) { 265 if (threadName == null || threadName.trim().length() == 0) { 266 throw new IllegalArgumentException ( 267 "Scheduler thread name cannot be empty."); 268 } 269 270 this.threadName = threadName; 271 } 272 273 282 public void setRMICreateRegistryStrategy(String rmiCreateRegistryStrategy) { 283 if (rmiCreateRegistryStrategy == null 284 || rmiCreateRegistryStrategy.trim().length() == 0) { 285 rmiCreateRegistryStrategy = CREATE_REGISTRY_NEVER; 286 } else if (rmiCreateRegistryStrategy.equalsIgnoreCase("true")) { 287 rmiCreateRegistryStrategy = CREATE_REGISTRY_AS_NEEDED; 288 } else if (rmiCreateRegistryStrategy.equalsIgnoreCase("false")) { 289 rmiCreateRegistryStrategy = CREATE_REGISTRY_NEVER; 290 } else if (rmiCreateRegistryStrategy.equalsIgnoreCase(CREATE_REGISTRY_ALWAYS)) { 291 rmiCreateRegistryStrategy = CREATE_REGISTRY_ALWAYS; 292 } else if (rmiCreateRegistryStrategy.equalsIgnoreCase(CREATE_REGISTRY_AS_NEEDED)) { 293 rmiCreateRegistryStrategy = CREATE_REGISTRY_AS_NEEDED; 294 } else if (rmiCreateRegistryStrategy.equalsIgnoreCase(CREATE_REGISTRY_NEVER)) { 295 rmiCreateRegistryStrategy = CREATE_REGISTRY_NEVER; 296 } else { 297 throw new IllegalArgumentException ( 298 "Faild to set RMICreateRegistryStrategy - strategy unknown: '" 299 + rmiCreateRegistryStrategy + "'"); 300 } 301 302 this.rmiCreateRegistryStrategy = rmiCreateRegistryStrategy; 303 } 304 305 311 public ThreadPool getThreadPool() { 312 return threadPool; 313 } 314 315 324 public void setThreadPool(ThreadPool threadPool) { 325 if (threadPool == null) { 326 throw new IllegalArgumentException ("ThreadPool cannot be null."); 327 } 328 329 this.threadPool = threadPool; 330 } 331 332 338 public JobStore getJobStore() { 339 return jobStore; 340 } 341 342 351 public void setJobStore(JobStore jobStore) { 352 if (jobStore == null) { 353 throw new IllegalArgumentException ("JobStore cannot be null."); 354 } 355 356 this.jobStore = jobStore; 357 } 358 359 365 public JobRunShellFactory getJobRunShellFactory() { 366 return jobRunShellFactory; 367 } 368 369 378 public void setJobRunShellFactory(JobRunShellFactory jobRunShellFactory) { 379 if (jobRunShellFactory == null) { 380 throw new IllegalArgumentException ( 381 "JobRunShellFactory cannot be null."); 382 } 383 384 this.jobRunShellFactory = jobRunShellFactory; 385 } 386 387 395 public void addSchedulerPlugin(SchedulerPlugin plugin) { 396 schedulerPlugins.add(plugin); 397 } 398 399 406 public List getSchedulerPlugins() { 407 return schedulerPlugins; 408 } 409 410 415 public boolean getMakeSchedulerThreadDaemon() { 416 return makeSchedulerThreadDaemon; 417 } 418 419 424 public void setMakeSchedulerThreadDaemon(boolean makeSchedulerThreadDaemon) { 425 this.makeSchedulerThreadDaemon = makeSchedulerThreadDaemon; 426 } 427 428 435 public String getRMIBindName() { 436 return (rmiBindName == null) ? getUniqueIdentifier() : rmiBindName; 437 } 438 439 445 public void setRMIBindName(String rmiBindName) { 446 this.rmiBindName = rmiBindName; 447 } 448 449 453 public boolean getJMXExport() { 454 return jmxExport; 455 } 456 457 461 public void setJMXExport(boolean jmxExport) { 462 this.jmxExport = jmxExport; 463 } 464 465 472 public String getJMXObjectName() { 473 return (jmxObjectName == null) ? generateJMXObjectName(name, instanceId) : jmxObjectName; 474 } 475 476 483 public void setJMXObjectName(String jmxObjectName) { 484 this.jmxObjectName = jmxObjectName; 485 } 486 487 494 public static String generateJMXObjectName(String schedName, String schedInstId) { 495 return "quartz:type=QuartzScheduler" + 496 ",name=" + schedName + 497 ",instance=" + schedInstId; 498 } 499 } 500 | Popular Tags |