1 45 46 package org.exolab.jms.net.tunnel; 47 48 import java.io.IOException ; 49 import java.net.Socket ; 50 import java.rmi.server.ObjID ; 51 import java.util.Collections ; 52 import java.util.HashMap ; 53 import java.util.Map ; 54 55 56 62 class EndpointManager { 63 64 67 private Map _endpoints = Collections.synchronizedMap(new HashMap ()); 68 69 77 public String open(String host, int port) throws IOException { 78 Socket socket = new Socket (host, port); 79 String id = new ObjID ().toString(); 80 EndpointInfo result = new EndpointInfo(id, socket); 81 _endpoints.put(id, result); 82 return id; 83 } 84 85 92 public EndpointInfo getEndpointInfo(String id) { 93 return (EndpointInfo) _endpoints.get(id); 94 } 95 96 103 public Socket getEndpoint(String id) { 104 Socket endpoint = null; 105 EndpointInfo info = getEndpointInfo(id); 106 if (info != null) { 107 endpoint = info.getEndpoint(); 108 } 109 return endpoint; 110 } 111 112 118 public void close(String id) throws IOException { 119 Socket endpoint = getEndpoint(id); 120 if (endpoint != null) { 121 try { 122 endpoint.close(); 123 } finally { 124 _endpoints.remove(id); 125 } 126 } 127 } 128 129 } 130 | Popular Tags |