KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > core > AbstractTCComm


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.net.core;
5
6 import com.tc.logging.TCLogger;
7 import com.tc.logging.TCLogging;
8 import com.tc.net.core.event.TCListenerEvent;
9 import com.tc.net.core.event.TCListenerEventListener;
10
11 /**
12  * Common base class for TCComm implementations
13  *
14  * @author teck
15  */

16 abstract class AbstractTCComm implements TCComm, TCListenerEventListener {
17   protected static final TCLogger logger = TCLogging.getLogger(TCComm.class);
18   private volatile boolean started = false;
19
20   public final boolean isStarted() {
21     return started;
22   }
23
24   public final boolean isStopped() {
25     return !started;
26   }
27
28   public final synchronized void start() {
29     if (!started) {
30       started = true;
31       if (logger.isDebugEnabled()) {
32         logger.debug("Start requested");
33       }
34
35       startImpl();
36     }
37   }
38
39   public final synchronized void stop() {
40     if (started) {
41       started = false;
42       if (logger.isDebugEnabled()) {
43         logger.debug("Stop requested");
44       }
45
46       stopImpl();
47     }
48   }
49
50   public void closeEvent(TCListenerEvent event) {
51     // override me if desired
52
}
53
54   void listenerAdded(TCListener listener) {
55     // override me if desired
56
}
57
58   protected abstract void startImpl();
59
60   protected abstract void stopImpl();
61 }
Popular Tags