1 4 package com.tc.objectserver.control; 5 6 import java.io.IOException ; 7 import java.net.Socket ; 8 import java.util.ArrayList ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 12 public abstract class ServerControlBase implements ServerControl { 13 14 private final List testSockets = new ArrayList (); 15 private final int adminPort; 16 private final String host; 17 private final int dsoPort; 18 19 public ServerControlBase(String 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 socket = new Socket (host, adminPort); 28 testSockets.add(socket); 29 if (!socket.isConnected()) throw new AssertionError (); 30 return true; 31 } catch (IOException e) { 32 return false; 33 } 34 } 35 36 public void clean() { 37 for (Iterator i = testSockets.iterator(); i.hasNext();) { 38 Socket s = (Socket ) i.next(); 39 try { 40 System.out.println("Checking socket: " + s); 41 if (s.isConnected()) s.close(); 42 } catch (Exception 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 getHost() { 57 return host; 58 } 59 60 } 61 | Popular Tags |