KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > scheduling > timer > MethodInvokingTimerTaskFactoryBean


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.scheduling.timer;
18
19 import java.util.TimerTask JavaDoc;
20
21 import org.springframework.beans.factory.FactoryBean;
22 import org.springframework.scheduling.support.MethodInvokingRunnable;
23
24 /**
25  * FactoryBean that exposes a TimerTask object that delegates
26  * job execution to a specified (static or non-static) method.
27  * Avoids the need to implement a one-line TimerTask that just
28  * invokes an existing business method.
29  *
30  * <p>Derives from MethodInvokingRunnable to share common properties
31  * and behavior, effectively providing a TimerTask adapter for it.
32  *
33  * <p>Often used to populate a ScheduledTimerTask object with a specific
34  * reflective method invocation. Note that you can alternatively populate
35  * a ScheduledTimerTask object with a plain MethodInvokingRunnable instance
36  * as well (as of Spring 1.2.4), without the need for this special FactoryBean.
37  *
38  * @author Juergen Hoeller
39  * @since 19.02.2004
40  * @see DelegatingTimerTask
41  * @see ScheduledTimerTask#setTimerTask
42  * @see ScheduledTimerTask#setRunnable
43  * @see org.springframework.scheduling.support.MethodInvokingRunnable
44  * @see org.springframework.beans.factory.config.MethodInvokingFactoryBean
45  */

46 public class MethodInvokingTimerTaskFactoryBean extends MethodInvokingRunnable implements FactoryBean {
47
48     private TimerTask JavaDoc timerTask;
49
50
51     public void afterPropertiesSet() throws ClassNotFoundException JavaDoc, NoSuchMethodException JavaDoc {
52         super.afterPropertiesSet();
53         this.timerTask = new DelegatingTimerTask(this);
54     }
55
56
57     public Object JavaDoc getObject() {
58         return this.timerTask;
59     }
60
61     public Class JavaDoc getObjectType() {
62         return TimerTask JavaDoc.class;
63     }
64
65     public boolean isSingleton() {
66         return true;
67     }
68
69 }
70
Popular Tags