1 52 53 package com.go.teaservlet.util.cluster; 54 55 import java.rmi.server.UnicastRemoteObject ; 56 import java.rmi.RemoteException ; 57 import java.net.InetAddress ; 58 import java.net.UnknownHostException ; 59 import java.util.List ; 60 import java.util.Vector ; 61 62 71 public class ClusterHook extends UnicastRemoteObject 72 implements Clustered { 73 74 private List mPeers; 75 protected String mClusterName,mServerName; 76 77 public ClusterHook(String clusterName, String serverName) 78 throws RemoteException { 79 80 super(); 81 mPeers = new Vector (); 82 mClusterName = clusterName; 83 if (serverName != null) { 84 mServerName = serverName.toLowerCase(); 85 } 86 } 87 88 public String getServerName() throws RemoteException { 89 90 if (mServerName == null) { 91 try { 92 mServerName = InetAddress.getLocalHost() 93 .getHostName().toLowerCase(); 94 } 95 catch (UnknownHostException uhe) { 96 uhe.printStackTrace(); 97 } 98 } 99 return mServerName; 100 } 101 102 public Clustered[] getKnownPeers() throws RemoteException { 103 104 return (Clustered[])mPeers.toArray(new Clustered[mPeers.size()]); 105 } 106 107 public void addPeer(Clustered peer) throws RemoteException { 108 109 mPeers.add(peer); 110 } 111 112 public boolean containsPeer(Clustered peer) throws RemoteException { 113 114 return mPeers.contains(peer); 115 } 116 117 public void removePeer(Clustered peer) throws RemoteException { 118 119 mPeers.remove(peer); 120 } 121 122 public String getClusterName() throws RemoteException { 123 if (mClusterName == null) { 124 mClusterName = "Unnamed_Cluster"; 125 } 126 return mClusterName; 127 } 128 } 129 | Popular Tags |