1 17 18 21 package org.quartz.impl; 22 23 import java.rmi.RemoteException ; 24 import java.rmi.registry.LocateRegistry ; 25 import java.rmi.registry.Registry ; 26 import java.util.Date ; 27 import java.util.List ; 28 import java.util.Set ; 29 30 import org.quartz.Calendar; 31 import org.quartz.JobDataMap; 32 import org.quartz.JobDetail; 33 import org.quartz.JobListener; 34 import org.quartz.Scheduler; 35 import org.quartz.SchedulerContext; 36 import org.quartz.SchedulerException; 37 import org.quartz.SchedulerListener; 38 import org.quartz.SchedulerMetaData; 39 import org.quartz.Trigger; 40 import org.quartz.TriggerListener; 41 import org.quartz.UnableToInterruptJobException; 42 import org.quartz.core.RemotableQuartzScheduler; 43 import org.quartz.core.SchedulingContext; 44 import org.quartz.spi.JobFactory; 45 46 59 public class RemoteScheduler implements Scheduler { 60 61 68 69 private RemotableQuartzScheduler rsched; 70 71 private SchedulingContext schedCtxt; 72 73 private String schedId; 74 75 private String rmiHost; 76 77 private int rmiPort; 78 79 86 87 94 public RemoteScheduler(SchedulingContext schedCtxt, String schedId, 95 String host, int port) { 96 97 this.schedCtxt = schedCtxt; 98 this.schedId = schedId; 99 this.rmiHost = host; 100 this.rmiPort = port; 101 } 102 103 110 111 protected RemotableQuartzScheduler getRemoteScheduler() 112 throws SchedulerException { 113 if (rsched != null) { 114 return rsched; 115 } 116 117 try { 118 Registry registry = LocateRegistry.getRegistry(rmiHost, rmiPort); 119 120 rsched = (RemotableQuartzScheduler) registry.lookup(schedId); 121 122 } catch (Exception e) { 123 SchedulerException initException = new SchedulerException( 124 "Could not get handle to remote scheduler: " 125 + e.getMessage(), e); 126 initException 127 .setErrorCode(SchedulerException.ERR_COMMUNICATION_FAILURE); 128 throw initException; 129 } 130 131 return rsched; 132 } 133 134 protected SchedulerException invalidateHandleCreateException(String msg, 135 Exception cause) { 136 rsched = null; 137 SchedulerException ex = new SchedulerException(msg, cause); 138 ex.setErrorCode(SchedulerException.ERR_COMMUNICATION_FAILURE); 139 return ex; 140 } 141 142 147 public String getSchedulerName() throws SchedulerException { 148 try { 149 return getRemoteScheduler().getSchedulerName(); 150 } catch (RemoteException re) { 151 throw invalidateHandleCreateException( 152 "Error communicating with remote scheduler.", re); 153 } 154 } 155 156 161 public String getSchedulerInstanceId() throws SchedulerException { 162 try { 163 return getRemoteScheduler().getSchedulerInstanceId(); 164 } catch (RemoteException re) { 165 throw invalidateHandleCreateException( 166 "Error communicating with remote scheduler.", re); 167 } 168 } 169 170 public SchedulerMetaData getMetaData() throws SchedulerException { 171 try { 172 RemotableQuartzScheduler sched = getRemoteScheduler(); 173 return new SchedulerMetaData(getSchedulerName(), 174 getSchedulerInstanceId(), getClass(), true, isStarted(), 175 isInStandbyMode(), isShutdown(), sched.runningSince(), 176 sched.numJobsExecuted(), sched.getJobStoreClass(), 177 sched.supportsPersistence(), sched.getThreadPoolClass(), 178 sched.getThreadPoolSize(), sched.getVersion()); 179 180 } catch (RemoteException re) { 181 throw invalidateHandleCreateException( 182 "Error communicating with remote scheduler.", re); 183 } 184 185 } 186 187 192 public SchedulerContext getContext() throws SchedulerException { 193 try { 194 return getRemoteScheduler().getSchedulerContext(); 195 } catch (RemoteException re) { 196 throw invalidateHandleCreateException( 197 "Error communicating with remote scheduler.", re); 198 } 199 } 200 201 207 212 public void start() throws SchedulerException { 213 try { 214 getRemoteScheduler().start(); 215 } catch (RemoteException re) { 216 throw invalidateHandleCreateException( 217 "Error communicating with remote scheduler.", re); 218 } 219 } 220 221 226 public void standby() throws SchedulerException { 227 try { 228 getRemoteScheduler().standby(); 229 } catch (RemoteException re) { 230 throw invalidateHandleCreateException( 231 "Error communicating with remote scheduler.", re); 232 } 233 } 234 235 239 public void pause() throws SchedulerException { 240 this.standby(); 241 } 242 243 244 245 259 public boolean isStarted() throws SchedulerException { 260 try { 261 return (getRemoteScheduler().runningSince() != null); 262 } catch (RemoteException re) { 263 throw invalidateHandleCreateException( 264 "Error communicating with remote scheduler.", re); 265 } 266 } 267 268 273 public boolean isInStandbyMode() throws SchedulerException { 274 try { 275 return getRemoteScheduler().isInStandbyMode(); 276 } catch (RemoteException re) { 277 throw invalidateHandleCreateException( 278 "Error communicating with remote scheduler.", re); 279 } 280 } 281 282 public boolean isPaused() throws SchedulerException { 283 return this.isInStandbyMode(); 284 } 285 290 public void shutdown() throws SchedulerException { 291 try { 292 String schedulerName = getSchedulerName(); 293 294 getRemoteScheduler().shutdown(); 295 296 SchedulerRepository.getInstance().remove(schedulerName); 297 } catch (RemoteException re) { 298 throw invalidateHandleCreateException( 299 "Error communicating with remote scheduler.", re); 300 } 301 } 302 303 308 public void shutdown(boolean waitForJobsToComplete) 309 throws SchedulerException { 310 try { 311 String schedulerName = getSchedulerName(); 312 313 getRemoteScheduler().shutdown(waitForJobsToComplete); 314 315 SchedulerRepository.getInstance().remove(schedulerName); 316 } catch (RemoteException re) { 317 throw invalidateHandleCreateException( 318 "Error communicating with remote scheduler.", re); 319 } 320 } 321 322 327 public boolean isShutdown() throws SchedulerException { 328 try { 329 return getRemoteScheduler().isShutdown(); 330 } catch (RemoteException re) { 331 throw invalidateHandleCreateException( 332 "Error communicating with remote scheduler.", re); 333 } 334 } 335 336 341 public List getCurrentlyExecutingJobs() throws SchedulerException { 342 try { 343 return getRemoteScheduler().getCurrentlyExecutingJobs(); 344 } catch (RemoteException re) { 345 throw invalidateHandleCreateException( 346 "Error communicating with remote scheduler.", re); 347 } 348 } 349 350 356 363 public Date scheduleJob(JobDetail jobDetail, Trigger trigger) 364 throws SchedulerException { 365 try { 366 return getRemoteScheduler().scheduleJob(schedCtxt, jobDetail, 367 trigger); 368 } catch (RemoteException re) { 369 throw invalidateHandleCreateException( 370 "Error communicating with remote scheduler.", re); 371 } 372 } 373 374 381 public Date scheduleJob(Trigger trigger) throws SchedulerException { 382 try { 383 return getRemoteScheduler().scheduleJob(schedCtxt, trigger); 384 } catch (RemoteException re) { 385 throw invalidateHandleCreateException( 386 "Error communicating with remote scheduler.", re); 387 } 388 } 389 390 397 public void addJob(JobDetail jobDetail, boolean replace) 398 throws SchedulerException { 399 try { 400 getRemoteScheduler().addJob(schedCtxt, jobDetail, replace); 401 } catch (RemoteException re) { 402 throw invalidateHandleCreateException( 403 "Error communicating with remote scheduler.", re); 404 } 405 } 406 407 414 public boolean deleteJob(String jobName, String groupName) 415 throws SchedulerException { 416 try { 417 return getRemoteScheduler() 418 .deleteJob(schedCtxt, jobName, groupName); 419 } catch (RemoteException re) { 420 throw invalidateHandleCreateException( 421 "Error communicating with remote scheduler.", re); 422 } 423 } 424 425 432 public boolean unscheduleJob(String triggerName, String groupName) 433 throws SchedulerException { 434 try { 435 return getRemoteScheduler().unscheduleJob(schedCtxt, triggerName, 436 groupName); 437 } catch (RemoteException re) { 438 throw invalidateHandleCreateException( 439 "Error communicating with remote scheduler.", re); 440 } 441 } 442 443 450 public Date rescheduleJob(String triggerName, 451 String groupName, Trigger newTrigger) throws SchedulerException { 452 try { 453 return getRemoteScheduler().rescheduleJob(schedCtxt, triggerName, 454 groupName, newTrigger); 455 } catch (RemoteException re) { 456 throw invalidateHandleCreateException( 457 "Error communicating with remote scheduler.", re); 458 } 459 } 460 461 462 469 public void triggerJob(String jobName, String groupName) 470 throws SchedulerException { 471 triggerJob(jobName, groupName, null); 472 } 473 474 481 public void triggerJob(String jobName, String groupName, JobDataMap data) 482 throws SchedulerException { 483 try { 484 getRemoteScheduler().triggerJob(schedCtxt, jobName, groupName, data); 485 } catch (RemoteException re) { 486 throw invalidateHandleCreateException( 487 "Error communicating with remote scheduler.", re); 488 } 489 } 490 491 498 public void triggerJobWithVolatileTrigger(String jobName, String groupName) 499 throws SchedulerException { 500 triggerJobWithVolatileTrigger(jobName, groupName, null); 501 } 502 503 510 public void triggerJobWithVolatileTrigger(String jobName, String groupName, JobDataMap data) 511 throws SchedulerException { 512 try { 513 getRemoteScheduler().triggerJobWithVolatileTrigger(schedCtxt, 514 jobName, groupName, data); 515 } catch (RemoteException re) { 516 throw invalidateHandleCreateException( 517 "Error communicating with remote scheduler.", re); 518 } 519 } 520 521 528 public void pauseTrigger(String triggerName, String groupName) 529 throws SchedulerException { 530 try { 531 getRemoteScheduler() 532 .pauseTrigger(schedCtxt, triggerName, groupName); 533 } catch (RemoteException re) { 534 throw invalidateHandleCreateException( 535 "Error communicating with remote scheduler.", re); 536 } 537 } 538 539 546 public void pauseTriggerGroup(String groupName) throws SchedulerException { 547 try { 548 getRemoteScheduler().pauseTriggerGroup(schedCtxt, groupName); 549 } catch (RemoteException re) { 550 throw invalidateHandleCreateException( 551 "Error communicating with remote scheduler.", re); 552 } 553 } 554 555 562 public void pauseJob(String jobName, String groupName) 563 throws SchedulerException { 564 try { 565 getRemoteScheduler().pauseJob(schedCtxt, jobName, groupName); 566 } catch (RemoteException re) { 567 throw invalidateHandleCreateException( 568 "Error communicating with remote scheduler.", re); 569 } 570 } 571 572 579 public void pauseJobGroup(String groupName) throws SchedulerException { 580 try { 581 getRemoteScheduler().pauseJobGroup(schedCtxt, groupName); 582 } catch (RemoteException re) { 583 throw invalidateHandleCreateException( 584 "Error communicating with remote scheduler.", re); 585 } 586 } 587 588 595 public void resumeTrigger(String triggerName, String groupName) 596 throws SchedulerException { 597 try { 598 getRemoteScheduler().resumeTrigger(schedCtxt, triggerName, 599 groupName); 600 } catch (RemoteException re) { 601 throw invalidateHandleCreateException( 602 "Error communicating with remote scheduler.", re); 603 } 604 } 605 606 613 public void resumeTriggerGroup(String groupName) throws SchedulerException { 614 try { 615 getRemoteScheduler().resumeTriggerGroup(schedCtxt, groupName); 616 } catch (RemoteException re) { 617 throw invalidateHandleCreateException( 618 "Error communicating with remote scheduler.", re); 619 } 620 } 621 622 629 public void resumeJob(String jobName, String groupName) 630 throws SchedulerException { 631 try { 632 getRemoteScheduler().resumeJob(schedCtxt, jobName, groupName); 633 } catch (RemoteException re) { 634 throw invalidateHandleCreateException( 635 "Error communicating with remote scheduler.", re); 636 } 637 } 638 639 646 public void resumeJobGroup(String groupName) throws SchedulerException { 647 try { 648 getRemoteScheduler().resumeJobGroup(schedCtxt, groupName); 649 } catch (RemoteException re) { 650 throw invalidateHandleCreateException( 651 "Error communicating with remote scheduler.", re); 652 } 653 } 654 655 662 public void pauseAll() throws SchedulerException { 663 try { 664 getRemoteScheduler().pauseAll(schedCtxt); 665 } catch (RemoteException re) { 666 throw invalidateHandleCreateException( 667 "Error communicating with remote scheduler.", re); 668 } 669 } 670 671 678 public void resumeAll() throws SchedulerException { 679 try { 680 getRemoteScheduler().resumeAll(schedCtxt); 681 } catch (RemoteException re) { 682 throw invalidateHandleCreateException( 683 "Error communicating with remote scheduler.", re); 684 } 685 } 686 687 694 public String [] getJobGroupNames() throws SchedulerException { 695 try { 696 return getRemoteScheduler().getJobGroupNames(schedCtxt); 697 } catch (RemoteException re) { 698 throw invalidateHandleCreateException( 699 "Error communicating with remote scheduler.", re); 700 } 701 } 702 703 710 public String [] getJobNames(String groupName) throws SchedulerException { 711 try { 712 return getRemoteScheduler().getJobNames(schedCtxt, groupName); 713 } catch (RemoteException re) { 714 throw invalidateHandleCreateException( 715 "Error communicating with remote scheduler.", re); 716 } 717 } 718 719 726 public Trigger[] getTriggersOfJob(String jobName, String groupName) 727 throws SchedulerException { 728 try { 729 return getRemoteScheduler().getTriggersOfJob(schedCtxt, jobName, 730 groupName); 731 } catch (RemoteException re) { 732 throw invalidateHandleCreateException( 733 "Error communicating with remote scheduler.", re); 734 } 735 } 736 737 744 public String [] getTriggerGroupNames() throws SchedulerException { 745 try { 746 return getRemoteScheduler().getTriggerGroupNames(schedCtxt); 747 } catch (RemoteException re) { 748 throw invalidateHandleCreateException( 749 "Error communicating with remote scheduler.", re); 750 } 751 } 752 753 760 public String [] getTriggerNames(String groupName) throws SchedulerException { 761 try { 762 return getRemoteScheduler().getTriggerNames(schedCtxt, groupName); 763 } catch (RemoteException re) { 764 throw invalidateHandleCreateException( 765 "Error communicating with remote scheduler.", re); 766 } 767 } 768 769 776 public JobDetail getJobDetail(String jobName, String jobGroup) 777 throws SchedulerException { 778 try { 779 return getRemoteScheduler().getJobDetail(schedCtxt, jobName, 780 jobGroup); 781 } catch (RemoteException re) { 782 throw invalidateHandleCreateException( 783 "Error communicating with remote scheduler.", re); 784 } 785 } 786 787 794 public Trigger getTrigger(String triggerName, String triggerGroup) 795 throws SchedulerException { 796 try { 797 return getRemoteScheduler().getTrigger(schedCtxt, triggerName, 798 triggerGroup); 799 } catch (RemoteException re) { 800 throw invalidateHandleCreateException( 801 "Error communicating with remote scheduler.", re); 802 } 803 } 804 805 812 public int getTriggerState(String triggerName, String triggerGroup) 813 throws SchedulerException { 814 try { 815 return getRemoteScheduler().getTriggerState(schedCtxt, triggerName, 816 triggerGroup); 817 } catch (RemoteException re) { 818 throw invalidateHandleCreateException( 819 "Error communicating with remote scheduler.", re); 820 } 821 } 822 823 830 public void addCalendar(String calName, Calendar calendar, boolean replace, boolean updateTriggers) 831 throws SchedulerException { 832 try { 833 getRemoteScheduler().addCalendar(schedCtxt, calName, calendar, 834 replace, updateTriggers); 835 } catch (RemoteException re) { 836 throw invalidateHandleCreateException( 837 "Error communicating with remote scheduler.", re); 838 } 839 } 840 841 848 public boolean deleteCalendar(String calName) throws SchedulerException { 849 try { 850 return getRemoteScheduler().deleteCalendar(schedCtxt, calName); 851 } catch (RemoteException re) { 852 throw invalidateHandleCreateException( 853 "Error communicating with remote scheduler.", re); 854 } 855 } 856 857 864 public Calendar getCalendar(String calName) throws SchedulerException { 865 try { 866 return getRemoteScheduler().getCalendar(schedCtxt, calName); 867 } catch (RemoteException re) { 868 throw invalidateHandleCreateException( 869 "Error communicating with remote scheduler.", re); 870 } 871 } 872 873 880 public String [] getCalendarNames() throws SchedulerException { 881 try { 882 return getRemoteScheduler().getCalendarNames(schedCtxt); 883 } catch (RemoteException re) { 884 throw invalidateHandleCreateException( 885 "Error communicating with remote scheduler.", re); 886 } 887 } 888 889 895 900 public void addGlobalJobListener(JobListener jobListener) 901 throws SchedulerException { 902 throw new SchedulerException( 903 "Operation not supported for remote schedulers.", 904 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 905 } 906 907 912 public void addJobListener(JobListener jobListener) 913 throws SchedulerException { 914 throw new SchedulerException( 915 "Operation not supported for remote schedulers.", 916 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 917 } 918 919 925 public boolean removeGlobalJobListener(JobListener jobListener) 926 throws SchedulerException { 927 throw new SchedulerException( 928 "Operation not supported for remote schedulers.", 929 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 930 } 931 932 937 public boolean removeGlobalJobListener(String name) 938 throws SchedulerException { 939 throw new SchedulerException( 940 "Operation not supported for remote schedulers.", 941 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 942 } 943 944 949 public boolean removeJobListener(String name) throws SchedulerException { 950 throw new SchedulerException( 951 "Operation not supported for remote schedulers.", 952 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 953 } 954 955 960 public List getGlobalJobListeners() throws SchedulerException { 961 throw new SchedulerException( 962 "Operation not supported for remote schedulers.", 963 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 964 } 965 966 971 public Set getJobListenerNames() throws SchedulerException { 972 throw new SchedulerException( 973 "Operation not supported for remote schedulers.", 974 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 975 } 976 977 982 public JobListener getGlobalJobListener(String name) throws SchedulerException { 983 throw new SchedulerException( 984 "Operation not supported for remote schedulers.", 985 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 986 } 987 988 993 public JobListener getJobListener(String name) throws SchedulerException { 994 throw new SchedulerException( 995 "Operation not supported for remote schedulers.", 996 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 997 } 998 999 1004 public void addGlobalTriggerListener(TriggerListener triggerListener) 1005 throws SchedulerException { 1006 throw new SchedulerException( 1007 "Operation not supported for remote schedulers.", 1008 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1009 } 1010 1011 1016 public void addTriggerListener(TriggerListener triggerListener) 1017 throws SchedulerException { 1018 throw new SchedulerException( 1019 "Operation not supported for remote schedulers.", 1020 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1021 } 1022 1023 1029 public boolean removeGlobalTriggerListener(TriggerListener triggerListener) 1030 throws SchedulerException { 1031 throw new SchedulerException( 1032 "Operation not supported for remote schedulers.", 1033 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1034 } 1035 1036 1041 public boolean removeGlobalTriggerListener(String name) 1042 throws SchedulerException { 1043 throw new SchedulerException( 1044 "Operation not supported for remote schedulers.", 1045 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1046 } 1047 1048 1053 public boolean removeTriggerListener(String name) throws SchedulerException { 1054 throw new SchedulerException( 1055 "Operation not supported for remote schedulers.", 1056 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1057 } 1058 1059 1064 public List getGlobalTriggerListeners() throws SchedulerException { 1065 throw new SchedulerException( 1066 "Operation not supported for remote schedulers.", 1067 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1068 } 1069 1070 1075 public Set getTriggerListenerNames() throws SchedulerException { 1076 throw new SchedulerException( 1077 "Operation not supported for remote schedulers.", 1078 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1079 } 1080 1081 1086 public TriggerListener getGlobalTriggerListener(String name) 1087 throws SchedulerException { 1088 throw new SchedulerException( 1089 "Operation not supported for remote schedulers.", 1090 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1091 } 1092 1093 1098 public TriggerListener getTriggerListener(String name) 1099 throws SchedulerException { 1100 throw new SchedulerException( 1101 "Operation not supported for remote schedulers.", 1102 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1103 } 1104 1105 1110 public void addSchedulerListener(SchedulerListener schedulerListener) 1111 throws SchedulerException { 1112 throw new SchedulerException( 1113 "Operation not supported for remote schedulers.", 1114 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1115 } 1116 1117 1122 public boolean removeSchedulerListener(SchedulerListener schedulerListener) 1123 throws SchedulerException { 1124 throw new SchedulerException( 1125 "Operation not supported for remote schedulers.", 1126 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1127 } 1128 1129 1134 public List getSchedulerListeners() throws SchedulerException { 1135 throw new SchedulerException( 1136 "Operation not supported for remote schedulers.", 1137 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1138 } 1139 1140 1143 public Set getPausedTriggerGroups() throws SchedulerException { 1144 try { 1145 return getRemoteScheduler().getPausedTriggerGroups(schedCtxt); 1146 } catch (RemoteException re) { 1147 throw invalidateHandleCreateException( 1148 "Error communicating with remote scheduler.", re); 1149 } 1150 } 1151 1152 1155 public boolean interrupt(String jobName, String groupName) throws UnableToInterruptJobException { 1156 try { 1157 return getRemoteScheduler().interrupt(schedCtxt, jobName, groupName); 1158 } catch (RemoteException re) { 1159 throw new UnableToInterruptJobException(invalidateHandleCreateException( 1160 "Error communicating with remote scheduler.", re)); 1161 } catch (SchedulerException se) { 1162 throw new UnableToInterruptJobException(se); 1163 } 1164 } 1165 1166 1169 public void setJobFactory(JobFactory factory) throws SchedulerException { 1170 throw new SchedulerException( 1171 "Operation not supported for remote schedulers.", 1172 SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); 1173 } 1174} 1175 | Popular Tags |