All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.quartz.impl.QuartzServer Maven / Gradle / Ivy

Go to download

SDK for dev_appserver (local development) with some of the dependencies shaded (repackaged)

There is a newer version: 2.0.31
Show newest version
/* 
 * Copyright 2004-2005 OpenSymphony 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 * use this file except in compliance with the License. You may obtain a copy 
 * of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 *   
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 * License for the specific language governing permissions and limitations 
 * under the License.
 * 
 */

/*
 * Previously Copyright (c) 2001-2004 James House
 */
package org.quartz.impl;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;

/**
 * 

* Instantiates an instance of Quartz Scheduler as a stand-alone program, if * the scheduler is configured for RMI it will be made available. *

* *

* The main() method of this class currently accepts 0 or 1 arguemtns, if there * is an argument, and its value is "console", then the program * will print a short message on the console (std-out) and wait for the user to * type "exit" - at which time the scheduler will be shutdown. *

* *

* Future versions of this server should allow additional configuration for * responding to scheduler events by allowing the user to specify {@link org.quartz.JobListener}, * {@link org.quartz.TriggerListener} and {@link org.quartz.SchedulerListener} * classes. *

* *

* Please read the Quartz FAQ entries about RMI before asking questions in the * forums or mail-lists. *

* * @author James House */ public class QuartzServer implements org.quartz.SchedulerListener { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Data members. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ private Scheduler sched = null; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constructors. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ QuartzServer() { } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ public void serve(SchedulerFactory schedFact, boolean console) throws Exception { sched = schedFact.getScheduler(); sched.start(); try { Thread.sleep(3000l); } catch (Exception ignore) { } System.out.println("\n*** The scheduler successfully started."); if (console) { System.out.println("\n"); System.out .println("The scheduler will now run until you type \"exit\""); System.out .println(" If it was configured to export itself via RMI,"); System.out.println(" then other process may now use it."); BufferedReader rdr = new BufferedReader(new InputStreamReader( System.in)); while (true) { System.out.print("Type 'exit' to shutdown the server: "); if ("exit".equals(rdr.readLine())) { break; } } System.out.println("\n...Shutting down server..."); sched.shutdown(true); } } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * SchedulerListener Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** *

* Called by the {@link Scheduler} when a {@link org.quartz.JobDetail} * is scheduled. *

*/ public void jobScheduled(Trigger trigger) { } /** *

* Called by the {@link Scheduler} when a {@link org.quartz.JobDetail} * is unscheduled. *

*/ public void jobUnscheduled(String triggerName, String triggerGroup) { } /** *

* Called by the {@link Scheduler} when a {@link Trigger} * has reached the condition in which it will never fire again. *

*/ public void triggerFinalized(Trigger trigger) { } /** *

* Called by the {@link Scheduler} when a {@link Trigger} * or group of {@link Trigger}s has been paused. *

* *

* If a group was paused, then the triggerName parameter * will be null. *

*/ public void triggersPaused(String triggerName, String triggerGroup) { } /** *

* Called by the {@link Scheduler} when a {@link Trigger} * or group of {@link Trigger}s has been un-paused. *

* *

* If a group was resumed, then the triggerName parameter * will be null. *

*/ public void triggersResumed(String triggerName, String triggerGroup) { } /** *

* Called by the {@link Scheduler} when a {@link org.quartz.JobDetail} * or group of {@link org.quartz.JobDetail}s has been * paused. *

* *

* If a group was paused, then the jobName parameter will be * null. *

*/ public void jobsPaused(String jobName, String jobGroup) { } /** *

* Called by the {@link Scheduler} when a {@link org.quartz.JobDetail} * or group of {@link org.quartz.JobDetail}s has been * un-paused. *

* *

* If a group was paused, then the jobName parameter will be * null. *

*/ public void jobsResumed(String jobName, String jobGroup) { } /** *

* Called by the {@link Scheduler} when a serious error has * occured within the scheduler - such as repeated failures in the JobStore, * or the inability to instantiate a Job instance when its * Trigger has fired. *

* *

* The getErrorCode() method of the given SchedulerException * can be used to determine more specific information about the type of * error that was encountered. *

*/ public void schedulerError(String msg, SchedulerException cause) { System.err.println("*** " + msg); cause.printStackTrace(); } /** *

* Called by the {@link Scheduler} to inform the listener * that it has shutdown. *

*/ public void schedulerShutdown() { System.out.println("\n*** The scheduler is now shutdown."); sched = null; } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Main Method. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ public static void main(String[] args) throws Exception { // //Configure Log4J // org.apache.log4j.PropertyConfigurator.configure( // System.getProperty("log4jConfigFile", "log4j.properties")); if (System.getSecurityManager() == null) { System.setSecurityManager(new java.rmi.RMISecurityManager()); } try { QuartzServer server = new QuartzServer(); if (args.length == 0) server.serve( new org.quartz.impl.StdSchedulerFactory(), false); else if (args.length == 1 && args[0].equalsIgnoreCase("console")) server .serve(new org.quartz.impl.StdSchedulerFactory(), true); else { System.err.println("\nUsage: QuartzServer [console]"); } } catch (Exception e) { e.printStackTrace(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy