01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.process;
05:
06: public class HeartBeatService {
07: private static HeartBeatServer server;
08:
09: public static synchronized void startHeartBeatService() {
10: if (server == null) {
11: server = new HeartBeatServer();
12: server.start();
13: }
14: }
15:
16: public static synchronized void stopHeartBeatServer() {
17: if (server != null) {
18: server.shutdown();
19: server = null;
20: }
21: }
22:
23: public static synchronized int listenPort() {
24: ensureServerHasStarted();
25: return server.listeningPort();
26: }
27:
28: public static synchronized void registerForHeartBeat(
29: int listenPort, String clientName) {
30: registerForHeartBeat(listenPort, clientName, false);
31: }
32:
33: public static synchronized void registerForHeartBeat(
34: int listenPort, String clientName, boolean isAppServer) {
35: ensureServerHasStarted();
36: HeartBeatClient client = new HeartBeatClient(listenPort,
37: clientName, isAppServer);
38: client.setDaemon(true);
39: client.start();
40: }
41:
42: public static synchronized void sendKillSignalToChildren() {
43: ensureServerHasStarted();
44: server.sendKillSignalToChildren();
45: }
46:
47: public static synchronized boolean anyAppServerAlive() {
48: ensureServerHasStarted();
49: return server.anyAppServerAlive();
50: }
51:
52: private static void ensureServerHasStarted() {
53: if (server == null)
54: new IllegalStateException(
55: "Heartbeat service has not started yet!");
56: }
57: }
|