예제 #1
0
    public void run() {

      try {
        isStarting = true;
        synchronized (this) {
          serverSocket = new ServerSocket(0);
          this.port = serverSocket.getLocalPort();
          setRunning(true);
          isStarting = false;
          this.notifyAll();
        }

        System.err.println("Child-process heartbeat server started on port: " + port);

        while (true) {
          Socket sock = serverSocket.accept();
          log("Got heartbeat connection from client; starting heartbeat.");
          synchronized (heartBeatThreads) {
            HeartbeatThread hbt = new HeartbeatThread(sock);
            heartBeatThreads.add(hbt);
            hbt.start();
          }
        }
      } catch (Exception e) {
        if (!running) log("Heartbeat server was shutdown.");
        else log("Got expcetion in heartbeat server: " + e.getMessage());
      } finally {
        setRunning(false);
        log("Heartbeat server terminated.");
      }
    }
예제 #2
0
 public synchronized boolean isAnyAppServerAlive() {
   boolean foundAlive = false;
   synchronized (heartBeatThreads) {
     for (Iterator it = heartBeatThreads.iterator(); it.hasNext(); ) {
       HeartbeatThread hb = (HeartbeatThread) it.next();
       boolean aliveStatus = hb.isAppServerAlive();
       log("pinging: " + hb.port + ", alive? = " + aliveStatus);
       foundAlive = foundAlive || aliveStatus;
     }
   }
   return foundAlive;
 }
예제 #3
0
 /**
  * Stops the channel.
  *
  * @param svc int
  * @throws ChannelException Stop error
  * @see org.apache.catalina.tribes.Channel#stop(int)
  */
 @Override
 public synchronized void stop(int svc) throws ChannelException {
   if (hbthread != null) {
     hbthread.stopHeartbeat();
     hbthread = null;
   }
   super.stop(svc);
 }
예제 #4
0
    private synchronized void shutdown() {
      setRunning(false);

      if (serverSocket != null) {
        try {
          serverSocket.close(); // this effectively interrupts the thread and force it to exit
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      synchronized (heartBeatThreads) {
        HeartbeatThread ht;
        for (Iterator i = heartBeatThreads.iterator(); i.hasNext(); ) {
          ht = (HeartbeatThread) i.next();
          ht.sendKillSignal();
        }
      }
    }
예제 #5
0
 /**
  * Starts the channel.
  *
  * @param svc int - what service to start
  * @throws ChannelException Start error
  * @see org.apache.catalina.tribes.Channel#start(int)
  */
 @Override
 public synchronized void start(int svc) throws ChannelException {
   setupDefaultStack();
   if (optionCheck) checkOptionFlags();
   super.start(svc);
   if (hbthread == null && heartbeat) {
     hbthread = new HeartbeatThread(this, heartbeatSleeptime);
     hbthread.start();
   }
 }