1 4 5 package org.jfox.ioc.connector; 6 7 import java.io.IOException ; 8 import java.io.Serializable ; 9 import java.util.Collections ; 10 import java.util.HashMap ; 11 import java.util.Map ; 12 13 import org.jfox.ioc.util.Marshaller; 14 15 22 23 public class ServerNode implements Serializable { 24 25 public final static transient ServerNode THE_NODE = new ServerNode(); 26 27 30 private String ip; 31 32 35 private String hostName; 36 37 40 private int port; 41 42 45 private int jgport; 46 47 50 private transient Map <String , ConnectorRemote> connectors = new HashMap <String , ConnectorRemote>(); 51 52 public ServerNode() { 53 } 54 55 public void setIp(String ip) { 56 this.ip = ip; 57 } 58 59 public String getIp() { 60 return ip; 61 } 62 63 public void setHostName(String hostName) { 64 this.hostName = hostName; 65 } 66 67 public String getHostName() { 68 return hostName; 69 } 70 71 public void setPort(int port) { 72 this.port = port; 73 } 74 75 public int getPort() { 76 return port; 77 } 78 79 public int getJgport() { 80 return jgport; 81 } 82 83 public void setJgport(int jgport) { 84 this.jgport = jgport; 85 } 86 87 91 public void setConnectors(Map <String , ConnectorRemote> connectors){ 92 this.connectors = connectors; 93 } 94 95 public ConnectorRemote getConnector(String protocol) { 96 return connectors.get(protocol.trim().toUpperCase()); 97 } 98 99 public String toString() { 100 return ip + ":" + port; 101 } 102 103 public boolean equals(Object o) { 104 if(this == o) return true; 105 if(o == null || getClass() != o.getClass()) return false; 106 107 final ServerNode that = (ServerNode) o; 108 109 if(jgport != that.jgport) return false; 110 if(port != that.port) return false; 111 if(!ip.equals(that.ip)) return false; 112 113 return true; 114 } 115 116 public int hashCode() { 117 int result; 118 result = ip.hashCode(); 119 result = 29 * result + port; 120 result = 29 * result + jgport; 121 return result; 122 } 123 124 public void registerConnector(String protocol, ConnectorRemote remote) { 125 connectors.put(protocol.trim().toUpperCase(), remote); 127 } 128 129 public void unregisterConnector(String protocol) { 130 connectors.remove(protocol.trim().toUpperCase()); 131 } 132 133 public Map <String , ConnectorRemote> listConnectors() { 134 return Collections.unmodifiableMap(connectors); 135 } 136 137 public void removeConnector(String protocol) { 138 connectors.remove(protocol); 139 } 140 141 public Map <String , ConnectorRemote> getConnectors() { 142 return connectors; 143 } 144 145 private void writeObject(java.io.ObjectOutputStream out) 146 throws IOException { 147 out.defaultWriteObject(); 148 out.writeInt(connectors.size()); 149 for(Map.Entry <String ,ConnectorRemote> entry : connectors.entrySet()){ 150 out.writeObject(entry.getKey()); 151 out.writeObject(Marshaller.marshall(entry.getValue())); 152 } 153 } 154 155 private void readObject(java.io.ObjectInputStream in) 156 throws IOException , ClassNotFoundException { 157 in.defaultReadObject(); 158 int size = in.readInt(); 159 connectors = new HashMap <String ,ConnectorRemote>(size); 160 while(size-- > 0){ 161 String key = (String )in.readObject(); 162 ConnectorRemote remote = (ConnectorRemote)Marshaller.unmarshall(in.readObject()); 163 connectors.put(key,remote); 164 } 165 166 } 167 168 public static void main(String [] args) { 169 170 } 171 } 172 | Popular Tags |