KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > pool > ClockPool


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

17
18 package org.apache.geronimo.pool;
19
20 import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
21 import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27
28 /**
29  * @version $Rev: 151106 $ $Date: 2005-02-02 18:49:54 -0800 (Wed, 02 Feb 2005) $
30  */

31 public class ClockPool implements GBeanLifecycle {
32
33     static private final Log log = LogFactory.getLog(ClockPool.class);
34
35     private String JavaDoc poolName;
36
37     /**
38      * Manages the thread that can used to schedule short
39      * running tasks in the future.
40      */

41     protected ClockDaemon clockDaemon;
42
43     public String JavaDoc getPoolName() {
44         return poolName;
45     }
46
47     public void setPoolName(String JavaDoc poolName) {
48         this.poolName = poolName;
49     }
50
51     public ClockDaemon getClockDaemon() {
52         return clockDaemon;
53     }
54
55     public void doStart() throws Exception JavaDoc {
56         clockDaemon = new ClockDaemon();
57         clockDaemon.setThreadFactory(new ThreadFactory() {
58             public Thread JavaDoc newThread(Runnable JavaDoc r) {
59                 Thread JavaDoc t = new Thread JavaDoc(r, poolName + " ");
60                 t.setDaemon(true);
61                 return t;
62             }
63         });
64         log.info("Clock pool " + poolName + " started");
65     }
66
67     public void doStop() throws Exception JavaDoc {
68         clockDaemon.shutDown();
69         log.info("Clock pool " + poolName + " stopped");
70     }
71
72     public void doFail() {
73     }
74
75     private static final GBeanInfo GBEAN_INFO;
76
77     static {
78         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(ClockPool.class);
79
80         infoFactory.addAttribute("poolName", String JavaDoc.class, true);
81
82         infoFactory.addOperation("getClockDaemon");
83
84         GBEAN_INFO = infoFactory.getBeanInfo();
85     }
86
87     public static GBeanInfo getGBeanInfo() {
88         return GBEAN_INFO;
89     }
90 }
91
Popular Tags