1 17 package org.quartz.impl; 18 19 import java.util.Date ; 20 import java.util.List ; 21 import java.util.Set ; 22 23 import javax.management.AttributeList ; 24 import javax.management.MalformedObjectNameException ; 25 import javax.management.ObjectName ; 26 27 import org.quartz.Calendar; 28 import org.quartz.JobDataMap; 29 import org.quartz.JobDetail; 30 import org.quartz.JobListener; 31 import org.quartz.Scheduler; 32 import org.quartz.SchedulerContext; 33 import org.quartz.SchedulerException; 34 import org.quartz.SchedulerListener; 35 import org.quartz.SchedulerMetaData; 36 import org.quartz.Trigger; 37 import org.quartz.TriggerListener; 38 import org.quartz.UnableToInterruptJobException; 39 import org.quartz.core.SchedulingContext; 40 import org.quartz.spi.JobFactory; 41 42 58 public abstract class RemoteMBeanScheduler implements Scheduler { 59 60 67 68 private SchedulingContext schedulingContext; 69 70 private ObjectName schedulerObjectName; 71 72 79 80 public RemoteMBeanScheduler() { 81 } 82 83 90 91 95 protected ObjectName getSchedulerObjectName() { 96 return schedulerObjectName; 97 } 98 99 103 public void setSchedulerObjectName(String schedulerObjectName) throws SchedulerException { 104 try { 105 this.schedulerObjectName = new ObjectName (schedulerObjectName); 106 } catch (MalformedObjectNameException e) { 107 throw new SchedulerException("Failed to parse Scheduler MBean name: " + schedulerObjectName, e); 108 } 109 } 110 111 115 public void setSchedulerObjectName(ObjectName schedulerObjectName) throws SchedulerException { 116 this.schedulerObjectName = schedulerObjectName; 117 } 118 119 122 public void setSchedulingContext(SchedulingContext schedulingContext) { 123 this.schedulingContext = schedulingContext; 124 } 125 126 127 128 135 136 140 public abstract void initialize() throws SchedulerException; 141 142 145 protected abstract Object getAttribute( 146 String attribute) throws SchedulerException; 147 148 151 protected abstract AttributeList getAttributes(String [] attributes) 152 throws SchedulerException; 153 154 157 protected abstract Object invoke( 158 String operationName, 159 Object [] params, 160 String [] signature) throws SchedulerException; 161 162 163 170 171 176 public String getSchedulerName() throws SchedulerException { 177 return (String )getAttribute("schedulerName"); 178 } 179 180 185 public String getSchedulerInstanceId() throws SchedulerException { 186 return (String )getAttribute("schedulerInstanceId"); 187 } 188 189 public SchedulerMetaData getMetaData() throws SchedulerException { 190 AttributeList attributeList = 191 getAttributes( 192 new String [] { 193 "schedulerName", 194 "schedulerInstanceId", 195 "inStandbyMode", 196 "shutdown", 197 "jobStoreClass", 198 "threadPoolClass", 199 "threadPoolSize", 200 "version" 201 }); 202 203 return new SchedulerMetaData( 204 (String )attributeList.get(0), 205 (String )attributeList.get(1), 206 getClass(), true, isStarted(), 207 ((Boolean )attributeList.get(2)).booleanValue(), 208 ((Boolean )attributeList.get(3)).booleanValue(), 209 (Date )invoke("runningSince", new Object [] {}, new String [] {}), 210 ((Integer )invoke("numJobsExecuted", new Object [] {}, new String [] {})).intValue(), 211 (Class )attributeList.get(4), 212 ((Boolean )invoke("supportsPersistence", new Object [] {}, new String [] {})).booleanValue(), 213 (Class )attributeList.get(5), 214 ((Integer )attributeList.get(6)).intValue(), 215 (String )attributeList.get(7)); 216 } 217 218 223 public SchedulerContext getContext() throws SchedulerException { 224 return (SchedulerContext)getAttribute("schedulerContext"); 225 } 226 227 233 238 public void start() throws SchedulerException { 239 invoke("start", new Object [] {}, new String [] {}); 240 } 241 242 247 public void standby() throws SchedulerException { 248 invoke("standby", new Object [] {}, new String [] {}); 249 } 250 251 255 public void pause() throws SchedulerException { 256 standby(); 257 } 258 259 260 274 public boolean isStarted() throws SchedulerException { 275 return (invoke("runningSince", new Object [] {}, new String [] {}) != null); 276 } 277 278 283 public boolean isInStandbyMode() throws SchedulerException { 284 return ((Boolean )getAttribute("inStandbyMode")).booleanValue(); 285 } 286 287 291 public boolean isPaused() throws SchedulerException { 292 return isInStandbyMode(); 293 } 294 295 300 public void shutdown() throws SchedulerException { 301 String schedulerName = getSchedulerName(); 303 304 invoke("shutdown", new Object [] {}, new String [] {}); 305 SchedulerRepository.getInstance().remove(schedulerName); 306 } 307 308 313 public void shutdown(boolean waitForJobsToComplete) 314 throws SchedulerException { 315 String schedulerName = getSchedulerName(); 317 318 invoke( 319 "shutdown", 320 new Object [] { toBoolean(waitForJobsToComplete) }, 321 new String [] { boolean.class.getName() }); 322 323 SchedulerRepository.getInstance().remove(schedulerName); 324 } 325 326 331 public boolean isShutdown() throws SchedulerException { 332 return ((Boolean )getAttribute("shutdown")).booleanValue(); 333 } 334 335 340 public List getCurrentlyExecutingJobs() throws SchedulerException { 341 return (List )invoke("getCurrentlyExecutingJobs", new Object [] {}, new String [] {}); 342 } 343 344 350 357 public Date scheduleJob(JobDetail jobDetail, Trigger trigger) 358 throws SchedulerException { 359 return (Date )invoke( 360 "scheduleJob", 361 new Object [] { schedulingContext, jobDetail, trigger }, 362 new String [] { SchedulingContext.class.getName(), JobDetail.class.getName(), Trigger.class.getName() }); 363 } 364 365 372 public Date scheduleJob(Trigger trigger) throws SchedulerException { 373 return (Date )invoke( 374 "scheduleJob", 375 new Object [] { schedulingContext, trigger }, 376 new String [] { SchedulingContext.class.getName(), Trigger.class.getName() }); 377 } 378 379 386 public void addJob(JobDetail jobDetail, boolean replace) 387 throws SchedulerException { 388 invoke( 389 "addJob", 390 new Object [] { schedulingContext, jobDetail, toBoolean(replace) }, 391 new String [] { SchedulingContext.class.getName(), JobDetail.class.getName(), boolean.class.getName() }); 392 } 393 394 401 public boolean deleteJob(String jobName, String groupName) 402 throws SchedulerException { 403 return ((Boolean )invoke( 404 "deleteJob", 405 new Object [] { schedulingContext, jobName, groupName}, 406 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() })).booleanValue(); 407 } 408 409 416 public boolean unscheduleJob(String triggerName, String groupName) 417 throws SchedulerException { 418 return ((Boolean )invoke( 419 "unscheduleJob", 420 new Object [] { schedulingContext, triggerName, groupName}, 421 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() })).booleanValue(); 422 } 423 424 431 public Date rescheduleJob(String triggerName, 432 String groupName, Trigger newTrigger) throws SchedulerException { 433 return (Date )invoke( 434 "unscheduleJob", 435 new Object [] { schedulingContext, triggerName, groupName, newTrigger}, 436 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName(), Trigger.class.getName() }); 437 } 438 439 440 447 public void triggerJob(String jobName, String groupName) 448 throws SchedulerException { 449 triggerJob(jobName, groupName, null); 450 } 451 452 459 public void triggerJob(String jobName, String groupName, JobDataMap data) 460 throws SchedulerException { 461 invoke( 462 "triggerJob", 463 new Object [] { schedulingContext, jobName, groupName, data}, 464 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName(), JobDataMap.class.getName() }); 465 } 466 467 474 public void triggerJobWithVolatileTrigger(String jobName, String groupName) 475 throws SchedulerException { 476 triggerJobWithVolatileTrigger(jobName, groupName, null); 477 } 478 479 486 public void triggerJobWithVolatileTrigger(String jobName, String groupName, JobDataMap data) 487 throws SchedulerException { 488 invoke( 489 "triggerJobWithVolatileTrigger", 490 new Object [] { schedulingContext, jobName, groupName, data}, 491 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName(), JobDataMap.class.getName() }); 492 } 493 494 501 public void pauseTrigger(String triggerName, String groupName) 502 throws SchedulerException { 503 invoke( 504 "pauseTrigger", 505 new Object [] { schedulingContext, triggerName, groupName}, 506 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() }); 507 } 508 509 516 public void pauseTriggerGroup(String groupName) throws SchedulerException { 517 invoke( 518 "pauseTriggerGroup", 519 new Object [] { schedulingContext, groupName}, 520 new String [] { SchedulingContext.class.getName(), String .class.getName() }); 521 } 522 523 530 public void pauseJob(String jobName, String groupName) 531 throws SchedulerException { 532 invoke( 533 "pauseJob", 534 new Object [] { schedulingContext, jobName, groupName}, 535 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() }); 536 } 537 538 545 public void pauseJobGroup(String groupName) throws SchedulerException { 546 invoke( 547 "pauseJobGroup", 548 new Object [] { schedulingContext, groupName}, 549 new String [] { SchedulingContext.class.getName(), String .class.getName() }); 550 } 551 552 559 public void resumeTrigger(String triggerName, String groupName) 560 throws SchedulerException { 561 invoke( 562 "resumeTrigger", 563 new Object [] { schedulingContext, triggerName, groupName}, 564 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() }); 565 } 566 567 574 public void resumeTriggerGroup(String groupName) throws SchedulerException { 575 invoke( 576 "resumeTriggerGroup", 577 new Object [] { schedulingContext, groupName}, 578 new String [] { SchedulingContext.class.getName(), String .class.getName() }); 579 } 580 581 588 public void resumeJob(String jobName, String groupName) 589 throws SchedulerException { 590 invoke( 591 "resumeJob", 592 new Object [] { schedulingContext, jobName, groupName}, 593 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() }); 594 } 595 596 603 public void resumeJobGroup(String groupName) throws SchedulerException { 604 invoke( 605 "resumeJobGroup", 606 new Object [] { schedulingContext, groupName}, 607 new String [] { SchedulingContext.class.getName(), String .class.getName() }); 608 } 609 610 617 public void pauseAll() throws SchedulerException { 618 invoke( 619 "pauseAll", 620 new Object [] { schedulingContext}, 621 new String [] { SchedulingContext.class.getName() }); 622 } 623 624 631 public void resumeAll() throws SchedulerException { 632 invoke( 633 "resumeAll", 634 new Object [] { schedulingContext}, 635 new String [] { SchedulingContext.class.getName() }); 636 } 637 638 645 public String [] getJobGroupNames() throws SchedulerException { 646 return (String [])invoke( 647 "getJobGroupNames", 648 new Object [] { schedulingContext}, 649 new String [] { SchedulingContext.class.getName() }); 650 } 651 652 659 public String [] getJobNames(String groupName) throws SchedulerException { 660 return (String [])invoke( 661 "getJobNames", 662 new Object [] { schedulingContext, groupName }, 663 new String [] { SchedulingContext.class.getName(), String .class.getName() }); 664 } 665 666 673 public Trigger[] getTriggersOfJob(String jobName, String groupName) 674 throws SchedulerException { 675 return (Trigger[])invoke( 676 "getTriggersOfJob", 677 new Object [] { schedulingContext, jobName, groupName }, 678 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() }); 679 } 680 681 688 public String [] getTriggerGroupNames() throws SchedulerException { 689 return (String [])invoke( 690 "getTriggerGroupNames", 691 new Object [] { schedulingContext}, 692 new String [] { SchedulingContext.class.getName() }); 693 } 694 695 702 public String [] getTriggerNames(String groupName) throws SchedulerException { 703 return (String [])invoke( 704 "getTriggerNames", 705 new Object [] { schedulingContext, groupName }, 706 new String [] { SchedulingContext.class.getName(), String .class.getName() }); 707 } 708 709 716 public JobDetail getJobDetail(String jobName, String jobGroup) 717 throws SchedulerException { 718 return (JobDetail)invoke( 719 "getJobDetail", 720 new Object [] { schedulingContext, jobName, jobGroup }, 721 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() }); 722 } 723 724 731 public Trigger getTrigger(String triggerName, String triggerGroup) 732 throws SchedulerException { 733 return (Trigger)invoke( 734 "getTrigger", 735 new Object [] { schedulingContext, triggerName, triggerGroup }, 736 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() }); 737 } 738 739 746 public int getTriggerState(String triggerName, String triggerGroup) 747 throws SchedulerException { 748 return ((Integer )invoke( 749 "getTriggerState", 750 new Object [] { schedulingContext, triggerName, triggerGroup }, 751 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() })).intValue(); 752 } 753 754 761 public void addCalendar(String calName, Calendar calendar, boolean replace, boolean updateTriggers) 762 throws SchedulerException { 763 invoke( 764 "addCalendar", 765 new Object [] { schedulingContext, calName, calendar, toBoolean(replace), toBoolean(updateTriggers) }, 766 new String [] { SchedulingContext.class.getName(), String .class.getName(), 767 Calendar.class.getName(), boolean.class.getName(), boolean.class.getName() }); 768 } 769 770 777 public boolean deleteCalendar(String calName) throws SchedulerException { 778 return ((Boolean )invoke( 779 "getTriggerState", 780 new Object [] { schedulingContext, calName }, 781 new String [] { SchedulingContext.class.getName(), String .class.getName() })).booleanValue(); 782 } 783 784 791 public Calendar getCalendar(String calName) throws SchedulerException { 792 return (Calendar)invoke( 793 "getCalendar", 794 new Object [] { schedulingContext, calName }, 795 new String [] { SchedulingContext.class.getName(), String .class.getName() }); 796 } 797 798 805 public String [] getCalendarNames() throws SchedulerException { 806 return (String [])invoke( 807 "getCalendarNames", 808 new Object [] { schedulingContext }, 809 new String [] { SchedulingContext.class.getName() }); 810 } 811 812 818 823 public void addGlobalJobListener(JobListener jobListener) 824 throws SchedulerException { 825 throw new SchedulerException( 826 "Operation not supported for remote schedulers.", 827 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 828 } 829 830 835 public void addJobListener(JobListener jobListener) 836 throws SchedulerException { 837 throw new SchedulerException( 838 "Operation not supported for remote schedulers.", 839 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 840 } 841 842 848 public boolean removeGlobalJobListener(JobListener jobListener) 849 throws SchedulerException { 850 throw new SchedulerException( 851 "Operation not supported for remote schedulers.", 852 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 853 } 854 855 860 public boolean removeGlobalJobListener(String name) 861 throws SchedulerException { 862 throw new SchedulerException( 863 "Operation not supported for remote schedulers.", 864 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 865 } 866 867 872 public boolean removeJobListener(String name) throws SchedulerException { 873 throw new SchedulerException( 874 "Operation not supported for remote schedulers.", 875 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 876 } 877 878 883 public List getGlobalJobListeners() throws SchedulerException { 884 throw new SchedulerException( 885 "Operation not supported for remote schedulers.", 886 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 887 } 888 889 894 public Set getJobListenerNames() throws SchedulerException { 895 throw new SchedulerException( 896 "Operation not supported for remote schedulers.", 897 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 898 } 899 900 905 public JobListener getGlobalJobListener(String name) throws SchedulerException { 906 throw new SchedulerException( 907 "Operation not supported for remote schedulers.", 908 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 909 } 910 911 916 public JobListener getJobListener(String name) throws SchedulerException { 917 throw new SchedulerException( 918 "Operation not supported for remote schedulers.", 919 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 920 } 921 922 927 public void addGlobalTriggerListener(TriggerListener triggerListener) 928 throws SchedulerException { 929 throw new SchedulerException( 930 "Operation not supported for remote schedulers.", 931 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 932 } 933 934 939 public void addTriggerListener(TriggerListener triggerListener) 940 throws SchedulerException { 941 throw new SchedulerException( 942 "Operation not supported for remote schedulers.", 943 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 944 } 945 946 952 public boolean removeGlobalTriggerListener(TriggerListener triggerListener) 953 throws SchedulerException { 954 throw new SchedulerException( 955 "Operation not supported for remote schedulers.", 956 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 957 } 958 959 964 public boolean removeGlobalTriggerListener(String name) 965 throws SchedulerException { 966 throw new SchedulerException( 967 "Operation not supported for remote schedulers.", 968 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 969 } 970 971 976 public boolean removeTriggerListener(String name) throws SchedulerException { 977 throw new SchedulerException( 978 "Operation not supported for remote schedulers.", 979 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 980 } 981 982 987 public List getGlobalTriggerListeners() throws SchedulerException { 988 throw new SchedulerException( 989 "Operation not supported for remote schedulers.", 990 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 991 } 992 993 998 public Set getTriggerListenerNames() throws SchedulerException { 999 throw new SchedulerException( 1000 "Operation not supported for remote schedulers.", 1001 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1002 } 1003 1004 1009 public TriggerListener getGlobalTriggerListener(String name) 1010 throws SchedulerException { 1011 throw new SchedulerException( 1012 "Operation not supported for remote schedulers.", 1013 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1014 } 1015 1016 1021 public TriggerListener getTriggerListener(String name) 1022 throws SchedulerException { 1023 throw new SchedulerException( 1024 "Operation not supported for remote schedulers.", 1025 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1026 } 1027 1028 1033 public void addSchedulerListener(SchedulerListener schedulerListener) 1034 throws SchedulerException { 1035 throw new SchedulerException( 1036 "Operation not supported for remote schedulers.", 1037 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1038 } 1039 1040 1045 public boolean removeSchedulerListener(SchedulerListener schedulerListener) 1046 throws SchedulerException { 1047 throw new SchedulerException( 1048 "Operation not supported for remote schedulers.", 1049 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1050 } 1051 1052 1057 public List getSchedulerListeners() throws SchedulerException { 1058 throw new SchedulerException( 1059 "Operation not supported for remote schedulers.", 1060 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1061 } 1062 1063 1066 public Set getPausedTriggerGroups() throws SchedulerException { 1067 return (Set )invoke( 1068 "getPausedTriggerGroups", 1069 new Object [] { schedulingContext }, 1070 new String [] { SchedulingContext.class.getName() }); 1071 } 1072 1073 1076 public boolean interrupt(String jobName, String groupName) throws UnableToInterruptJobException { 1077 try { 1078 return ((Boolean )invoke( 1079 "interrupt", 1080 new Object [] { schedulingContext, jobName, groupName}, 1081 new String [] { SchedulingContext.class.getName(), String .class.getName(), String .class.getName() })).booleanValue(); 1082 } catch (SchedulerException se) { 1083 throw new UnableToInterruptJobException(se); 1084 } 1085 } 1086 1087 1090 public void setJobFactory(JobFactory factory) throws SchedulerException { 1091 throw new SchedulerException( 1092 "Operation not supported for remote schedulers.", 1093 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1094 } 1095 1096 protected Boolean toBoolean(boolean bool) { 1097 return (bool) ? Boolean.TRUE : Boolean.FALSE; 1098 } 1099} 1100 | Popular Tags |