KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > timer > SingletonTimerFactory


1 /*
2
3    Derby - Class org.apache.derby.impl.services.timer.SingletonTimerFactory
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.timer;
23
24 import org.apache.derby.iapi.services.timer.TimerFactory;
25 import org.apache.derby.iapi.services.monitor.ModuleControl;
26
27 import org.apache.derby.iapi.error.StandardException;
28
29 import java.util.Timer JavaDoc;
30 import java.util.Properties JavaDoc;
31
32
33 /**
34  * This class implements the TimerFactory interface.
35  * It creates a singleton Timer instance.
36  *
37  * The class implements the ModuleControl interface,
38  * because it needs to cancel the Timer at system shutdown.
39  *
40  * @see TimerFactory
41  * @see ModuleControl
42  */

43 public class SingletonTimerFactory
44     implements
45         TimerFactory,
46         ModuleControl
47 {
48     /**
49      * Singleton Timer instance.
50      */

51     private Timer JavaDoc singletonTimer;
52
53     /**
54      * Initializes this TimerFactory with a singleton Timer instance.
55      */

56     public SingletonTimerFactory()
57     {
58         /**
59          * Even though we implement the ModuleControl interface,
60          * we initialize the object here rather than in boot, since
61          * a) We avoid synchronizing access to singletonTimer later
62          * b) We don't need any properties
63          */

64         singletonTimer = new Timer JavaDoc(true); // Run as daemon
65
}
66
67     /**
68      * Returns a Timer object that can be used for adding TimerTasks
69      * that cancel executing statements.
70      *
71      * Implements the TimerFactory interface.
72      *
73      * @return a Timer object for cancelling statements.
74      *
75      * @see TimerFactory
76      */

77     public Timer JavaDoc getCancellationTimer()
78     {
79         return singletonTimer;
80     }
81
82     /**
83      * Currently does nothing, singleton Timer instance is initialized
84      * in the constructor.
85      *
86      * Implements the ModuleControl interface.
87      *
88      * @see ModuleControl
89      */

90     public void boot(boolean create, Properties JavaDoc properties)
91         throws
92             StandardException
93     {
94         // Do nothing, instance already initialized in constructor
95
}
96
97     /**
98      * Cancels the singleton Timer instance.
99      *
100      * Implements the ModuleControl interface.
101      *
102      * @see ModuleControl
103      */

104     public void stop()
105     {
106         singletonTimer.cancel();
107     }
108 }
109
Popular Tags