1 18 package net.sf.mybatchfwk; 19 20 import java.lang.reflect.Field ; 21 import java.util.Date ; 22 import java.util.Properties ; 23 24 import net.sf.mybatchfwk.utils.PropertiesLoader; 25 import net.sf.mybatchfwk.utils.Property; 26 27 33 public class BatchConfiguration { 34 35 38 public static final String CONFIGURATION_FILENAME = "my-batch-fwk.properties"; 39 40 43 public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss z"; 44 45 48 private PropertiesLoader propertiesLoader; 49 50 51 55 @Property("mbf.batch.className") 56 private String batchClassName; 57 58 61 @Property("mbf.batch.executionReportClassName") 62 private String executionReportClassName; 63 64 67 @Property("mbf.batch.deferredStart") 68 private boolean deferredStart = false; 69 70 73 @Property("mbf.batch.stayAliveAfterShutdown") 74 private boolean stayAliveAfterShutdown = false; 75 76 80 @Property("mbf.batch.executeNewTasks") 81 private boolean executeNewTasks = true; 82 83 87 @Property("mbf.batch.executeCompletedTasks") 88 private boolean executeCompletedTasks = true; 89 90 94 @Property("mbf.batch.executeFailedTasks") 95 private boolean executeFailedTasks = true; 96 97 98 102 @Property("mbf.threadPool.minSize") 103 private int threadPoolMinSize = 0; 104 105 108 @Property("mbf.threadPool.maxSize") 109 private int threadPoolMaxSize = 1; 110 111 117 @Property("mbf.threadPool.blockingQueueCapacity") 118 private int blockingQueueCapacity = Integer.MAX_VALUE; 119 120 121 125 @Property("mbf.schedule.enable") 126 private boolean scheduleEnable; 127 128 132 @Property("mbf.schedule.startDate") 133 private Date scheduleStartDate; 134 135 139 @Property("mbf.schedule.periodTime") 140 private long schedulePeriodTime = 0; 141 142 146 @Property("mbf.schedule.endDate") 147 private Date scheduleEndDate; 148 149 153 @Property("mbf.schedule.numberOfLoop") 154 private long scheduleNumberOfLoop; 155 156 157 161 @Property("mbf.jmx.enable") 162 private boolean jmxEnable = false; 163 164 167 @Property("mbf.jmx.enableNotifications") 168 private boolean jmxEnableNotifications = false; 169 170 174 @Property("mbf.executionHistory.className") 175 private String executionHistoryClassName; 176 177 178 188 public BatchConfiguration() { 189 this.propertiesLoader = new PropertiesLoader(new Properties ()); 190 } 191 192 199 public BatchConfiguration(Properties properties) throws BatchException { 200 this.propertiesLoader = new PropertiesLoader(properties); 201 202 try { 204 this.propertiesLoader.assignProperties(this); 205 } catch (Exception e) { 206 throw new BatchException("an error occured during the loading of the configuration", e); 207 } 208 } 209 210 217 protected void checkConsistency() throws BatchException { 218 219 if (getThreadPoolMaxSize() < getThreadPoolMinSize()) { 220 throw new BatchException("thread pool: the minimum size cannot be greater than the maximum size"); 221 } 222 223 if ((isScheduleEnable()) && (getScheduleStartDate() == null) && (getScheduleEndDate() == null) && (getSchedulePeriodTime() <= 0)) { 224 throw new BatchException("schedule: at least one of this parameter must be set (startDate, endDate or periodTime)"); 225 } 226 } 227 228 @Override 229 public String toString() { 230 StringBuffer buffer = new StringBuffer ().append(getClass().getName()).append(" ["); 231 232 int i = 0; 233 for (Field field : PropertiesLoader.getPropertyFields(getClass())) { 234 if (i++ > 0) { 235 buffer.append(", "); 236 } 237 try { 238 buffer.append(field.getName()).append("='").append(field.get(this)).append("'"); 239 } catch (Exception e) {} 240 } 241 buffer.append("]"); 242 243 return buffer.toString(); 244 } 245 246 249 public void setExecutionHistoryClass(Class executionHistoryClass) { 250 this.executionHistoryClassName = executionHistoryClass.getName(); 251 } 252 253 254 257 public void setExecutionReportClass(Class executionReportClass) { 258 this.executionReportClassName = executionReportClass.getName(); 259 } 260 261 262 265 public void setBatchClass(Class batchClass) { 266 this.batchClassName = batchClass.getName(); 267 } 268 269 273 public boolean isTaskFilterEnable() { 274 return (!(executeNewTasks && executeCompletedTasks && executeFailedTasks)); 275 } 276 277 281 284 public String getBatchClassName() { 285 return batchClassName; 286 } 287 290 public void setBatchClassName(String batchClassName) { 291 this.batchClassName = batchClassName; 292 } 293 296 public boolean isScheduleEnable() { 297 return scheduleEnable; 298 } 299 302 public void setScheduleEnable(boolean scheduleEnabled) { 303 this.scheduleEnable = scheduleEnabled; 304 } 305 308 public Date getScheduleEndDate() { 309 return scheduleEndDate; 310 } 311 314 public void setScheduleEndDate(Date scheduleEndDate) { 315 this.scheduleEndDate = scheduleEndDate; 316 } 317 320 public long getScheduleNumberOfLoop() { 321 return scheduleNumberOfLoop; 322 } 323 326 public void setScheduleNumberOfLoop(long scheduleNumberOfLoop) { 327 this.scheduleNumberOfLoop = scheduleNumberOfLoop; 328 } 329 332 public long getSchedulePeriodTime() { 333 return schedulePeriodTime; 334 } 335 338 public void setSchedulePeriodTime(long schedulePeriodTime) { 339 this.schedulePeriodTime = schedulePeriodTime; 340 } 341 344 public Date getScheduleStartDate() { 345 return scheduleStartDate; 346 } 347 350 public void setScheduleStartDate(Date scheduleStartDate) { 351 this.scheduleStartDate = scheduleStartDate; 352 } 353 356 public int getThreadPoolMaxSize() { 357 return threadPoolMaxSize; 358 } 359 362 public void setThreadPoolMaxSize(int threadPoolMaxSize) { 363 this.threadPoolMaxSize = threadPoolMaxSize; 364 } 365 368 public int getThreadPoolMinSize() { 369 return threadPoolMinSize; 370 } 371 374 public void setThreadPoolMinSize(int threadPoolMinSize) { 375 this.threadPoolMinSize = threadPoolMinSize; 376 } 377 378 381 public boolean isDeferredStart() { 382 return deferredStart; 383 } 384 385 388 public void setDeferredStart(boolean batchDeferredStart) { 389 this.deferredStart = batchDeferredStart; 390 } 391 392 395 public boolean isStayAliveAfterShutdown() { 396 return stayAliveAfterShutdown; 397 } 398 399 402 public void setStayAliveAfterShutdown(boolean stayAliveAfterShutdown) { 403 this.stayAliveAfterShutdown = stayAliveAfterShutdown; 404 } 405 406 409 public boolean isJmxEnable() { 410 return jmxEnable; 411 } 412 413 416 public void setJmxEnable(boolean jmxEnable) { 417 this.jmxEnable = jmxEnable; 418 } 419 420 423 public boolean isJmxEnableNotifications() { 424 return jmxEnableNotifications; 425 } 426 427 430 public void setJmxEnableNotifications(boolean jmxEnableNotifications) { 431 this.jmxEnableNotifications = jmxEnableNotifications; 432 } 433 434 437 public String getExecutionReportClassName() { 438 return executionReportClassName; 439 } 440 441 444 public void setExecutionReportClassName(String executionReportClassName) { 445 this.executionReportClassName = executionReportClassName; 446 } 447 448 451 public int getBlockingQueueCapacity() { 452 return blockingQueueCapacity; 453 } 454 455 458 public void setBlockingQueueCapacity(int blockingQueueCapacity) { 459 this.blockingQueueCapacity = blockingQueueCapacity; 460 } 461 462 465 public String getExecutionHistoryClassName() { 466 return executionHistoryClassName; 467 } 468 469 472 public void setExecutionHistoryClassName(String historyStorageClassName) { 473 this.executionHistoryClassName = historyStorageClassName; 474 } 475 476 479 public boolean isExecuteCompletedTasks() { 480 return executeCompletedTasks; 481 } 482 483 486 public void setExecuteCompletedTasks(boolean executeCompletedTasks) { 487 this.executeCompletedTasks = executeCompletedTasks; 488 } 489 490 493 public boolean isExecuteFailedTasks() { 494 return executeFailedTasks; 495 } 496 497 500 public void setExecuteFailedTasks(boolean executeFailedTasks) { 501 this.executeFailedTasks = executeFailedTasks; 502 } 503 504 507 public boolean isExecuteNewTasks() { 508 return executeNewTasks; 509 } 510 511 514 public void setExecuteNewTasks(boolean executeNewTasks) { 515 this.executeNewTasks = executeNewTasks; 516 } 517 518 521 public PropertiesLoader getPropertiesLoader() { 522 return propertiesLoader; 523 } 524 525 528 public void setPropertiesLoader(PropertiesLoader propertiesManager) { 529 this.propertiesLoader = propertiesManager; 530 } 531 } 532 | Popular Tags |