1 17 18 21 package org.quartz.impl; 22 23 import java.io.BufferedReader ; 24 import java.io.InputStreamReader ; 25 26 import org.quartz.Scheduler; 27 import org.quartz.SchedulerException; 28 import org.quartz.SchedulerFactory; 29 import org.quartz.listeners.SchedulerListenerSupport; 30 31 58 public class QuartzServer extends SchedulerListenerSupport { 59 60 67 68 private Scheduler sched = null; 69 70 77 78 QuartzServer() { 79 } 80 81 88 89 public void serve(SchedulerFactory schedFact, boolean console) 90 throws Exception { 91 sched = schedFact.getScheduler(); 92 93 sched.start(); 94 95 try { 96 Thread.sleep(3000l); 97 } catch (Exception ignore) { 98 } 99 100 System.out.println("\n*** The scheduler successfully started."); 101 102 if (console) { 103 System.out.println("\n"); 104 System.out 105 .println("The scheduler will now run until you type \"exit\""); 106 System.out 107 .println(" If it was configured to export itself via RMI,"); 108 System.out.println(" then other process may now use it."); 109 110 BufferedReader rdr = new BufferedReader (new InputStreamReader ( 111 System.in)); 112 113 while (true) { 114 System.out.print("Type 'exit' to shutdown the server: "); 115 if ("exit".equals(rdr.readLine())) { 116 break; 117 } 118 } 119 120 System.out.println("\n...Shutting down server..."); 121 122 sched.shutdown(true); 123 } 124 } 125 126 133 134 148 public void schedulerError(String msg, SchedulerException cause) { 149 System.err.println("*** " + msg); 150 cause.printStackTrace(); 151 } 152 153 159 public void schedulerShutdown() { 160 System.out.println("\n*** The scheduler is now shutdown."); 161 sched = null; 162 } 163 164 171 172 public static void main(String [] args) throws Exception { 173 174 178 if (System.getSecurityManager() == null) { 179 System.setSecurityManager(new java.rmi.RMISecurityManager ()); 180 } 181 182 try { 183 QuartzServer server = new QuartzServer(); 184 if (args.length == 0) { 185 server.serve( 186 new org.quartz.impl.StdSchedulerFactory(), false); 187 } else if (args.length == 1 && args[0].equalsIgnoreCase("console")) { 188 server.serve(new org.quartz.impl.StdSchedulerFactory(), true); 189 } else { 190 System.err.println("\nUsage: QuartzServer [console]"); 191 } 192 } catch (Exception e) { 193 e.printStackTrace(); 194 } 195 } 196 197 } 198 | Popular Tags |