KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > control > ServerControlBase


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.objectserver.control;
5
6 import java.io.IOException JavaDoc;
7 import java.net.Socket JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11
12 public abstract class ServerControlBase implements ServerControl {
13
14   private final List JavaDoc testSockets = new ArrayList JavaDoc();
15   private final int adminPort;
16   private final String JavaDoc host;
17   private final int dsoPort;
18
19   public ServerControlBase(String JavaDoc host, int dsoPort, int adminPort) {
20     this.host = host;
21     this.dsoPort = dsoPort;
22     this.adminPort = adminPort;
23   }
24
25   public boolean isRunning() {
26     try {
27       Socket JavaDoc socket = new Socket JavaDoc(host, adminPort);
28       testSockets.add(socket);
29       if (!socket.isConnected()) throw new AssertionError JavaDoc();
30       return true;
31     } catch (IOException JavaDoc e) {
32       return false;
33     }
34   }
35
36   public void clean() {
37     for (Iterator JavaDoc i = testSockets.iterator(); i.hasNext();) {
38       Socket JavaDoc s = (Socket JavaDoc) i.next();
39       try {
40         System.out.println("Checking socket: " + s);
41         if (s.isConnected()) s.close();
42       } catch (Exception JavaDoc e) {
43         e.printStackTrace();
44       }
45     }
46   }
47
48   protected int getAdminPort() {
49     return adminPort;
50   }
51
52   public int getDsoPort() {
53     return dsoPort;
54   }
55
56   protected String JavaDoc getHost() {
57     return host;
58   }
59
60 }
61
Popular Tags