View Javadoc
1 package org.apache.commons.jelly.tags.quartz; 2 3 /* 4 * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/quartz/QuartzTagSupport.java,v 1.2 2002/08/04 06:38:45 jefft Exp $ 5 * $Revision: 1.2 $ 6 * $Date: 2002/08/04 06:38:45 $ 7 * 8 * ==================================================================== 9 * 10 * The Apache Software License, Version 1.1 11 * 12 * Copyright (c) 1999-2001 The Apache Software Foundation. All rights 13 * reserved. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 19 * 1. Redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer. 21 * 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in 24 * the documentation and/or other materials provided with the 25 * distribution. 26 * 27 * 3. The end-user documentation included with the redistribution, if 28 * any, must include the following acknowlegement: 29 * "This product includes software developed by the 30 * Apache Software Foundation (http://www.apache.org/)." 31 * Alternately, this acknowlegement may appear in the software itself, 32 * if and wherever such third-party acknowlegements normally appear. 33 * 34 * 4. The names "The Jakarta Project", "Commons", and "Apache Software 35 * Foundation" must not be used to endorse or promote products derived 36 * from this software without prior written permission. For written 37 * permission, please contact apache@apache.org. 38 * 39 * 5. Products derived from this software may not be called "Apache" 40 * nor may "Apache" appear in their names without prior written 41 * permission of the Apache Group. 42 * 43 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 44 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 45 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 46 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 47 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 50 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 51 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 53 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * SUCH DAMAGE. 55 * ==================================================================== 56 * 57 * This software consists of voluntary contributions made by many 58 * individuals on behalf of the Apache Software Foundation. For more 59 * information on the Apache Software Foundation, please see 60 * <http://www.apache.org/>;. 61 * 62 */ 63 64 import org.apache.commons.jelly.TagSupport; 65 66 import org.quartz.Scheduler; 67 import org.quartz.SchedulerException; 68 import org.quartz.impl.StdScheduler; 69 import org.quartz.impl.StdSchedulerFactory; 70 71 /*** Basic support for all tags requiring a Quartz scheduler. 72 * 73 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 74 */ 75 public abstract class QuartzTagSupport extends TagSupport 76 { 77 /*** The scheduler variable name in the JellyContext. */ 78 public static final String SCHED_VAR_NAME = "org.apache.commons.jelly.quartz.Scheduler"; 79 80 81 /*** Retrieve or create a scheduler. 82 * 83 * <p> 84 * If a scheduler has already been created an installed 85 * in the variable {@link #SCHED_VAR_NAME}, then that scheduler 86 * will be returned. Otherwise, a new StdScheduler will be 87 * created, started, and installed. Additionally, a runtime 88 * shutdown hook will be added to cleanly shutdown the scheduler. 89 * 90 * @return The scheduler. 91 * 92 * @throws SchedulerException If there is an error creating the 93 * scheduler. 94 */ 95 public Scheduler getScheduler() throws SchedulerException 96 { 97 Scheduler sched = (Scheduler) getContext().getVariable( SCHED_VAR_NAME ); 98 99 if ( sched == null ) 100 { 101 StdSchedulerFactory factory = new StdSchedulerFactory(); 102 103 final Scheduler newSched = factory.getScheduler(); 104 105 sched = newSched; 106 107 getContext().setVariable( SCHED_VAR_NAME, 108 newSched ); 109 110 Runtime.getRuntime().addShutdownHook( 111 new Thread() { 112 public void run() 113 { 114 try 115 { 116 if ( ! newSched.isShutdown() ) 117 { 118 newSched.shutdown(); 119 } 120 } 121 catch (SchedulerException e) 122 { 123 e.printStackTrace(); 124 } 125 } 126 } 127 ); 128 newSched.start(); 129 } 130 131 132 return sched; 133 } 134 } 135

This page was automatically generated by Maven