KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > common > AbstractService


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.common;
8
9 import org.jfox.ioc.annotation.Managable;
10 import org.jfox.ioc.ext.ServicableComponent;
11
12 /**
13  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
14  */

15
16 public abstract class AbstractService extends AbstractComponent implements ServicableComponent, Runnable JavaDoc {
17
18
19     public AbstractService() {
20         super();
21     }
22
23     public AbstractService(String JavaDoc name) {
24         super(name);
25     }
26
27     public boolean isStarted() {
28         return state == State.STARTED || state == State.STARTING;
29     }
30
31     @Managable
32     public void start() throws Exception JavaDoc {
33         if(!State.canStart(state)) {
34             logger.warn(name + " can not start, state = " + state);
35             return;
36         }
37
38         logger.info("starting...");
39
40         state = State.STARTING;
41
42         try {
43             doStart();
44         }
45         catch(Exception JavaDoc e) {
46             state = State.INTERRUPTED;
47             logger.error("starting failed", e);
48             throw e;
49         }
50         state = State.STARTED;
51         logger.info("started.");
52     }
53
54     @Managable
55     public void stop() throws Exception JavaDoc {
56         if(!State.canStop(state)) {
57             logger.warn(name + " can not stop, state = " + state);
58             return;
59         }
60
61         logger.info("stopping...");
62
63         state = State.STOPPING;
64
65         try {
66             doStop();
67         }
68         catch(Exception JavaDoc e) {
69             state = State.INTERRUPTED;
70             logger.error("stopping failed", e);
71             throw e;
72         }
73         state = State.STOPPED;
74         logger.info("stopped");
75
76     }
77
78     /**
79      * do actually start action
80      */

81     protected abstract void doStart() throws Exception JavaDoc;
82
83     /**
84      * do actually stop action
85      */

86     protected abstract void doStop() throws Exception JavaDoc;
87
88 }
89
90
Popular Tags