00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 package org.objectweb.david.libs.resources.giop;
00029
00030 import org.objectweb.jonathan.apis.kernel.Context;
00031 import org.objectweb.jonathan.apis.kernel.JonathanException;
00032 import org.objectweb.jonathan.apis.kernel.InternalException;
00033 import org.objectweb.jonathan.apis.protocols.ip.IpSession;
00034 import org.objectweb.jonathan.apis.protocols.ip.TcpIpConnectionMgr;
00035 import org.objectweb.jonathan.apis.protocols.ip.IpConnection;
00036 import org.objectweb.jonathan.apis.protocols.ip.TcpIpSrvConnectionFactory;
00037 import org.objectweb.jonathan.apis.resources.Chunk;
00038
00039 import org.omg.GIOP.MsgType_1_0;
00040
00041 import java.io.IOException;
00042
00047 public class GIOPConnectionFactory implements TcpIpConnectionMgr {
00048
00049
00050 TcpIpConnectionMgr mgr;
00051
00052 GIOPConnectionFactory(Context c,Object[] used_components) {
00053 mgr = (TcpIpConnectionMgr) used_components[0];
00054 }
00055
00061 public String getCanonicalHostName(String hostname) {
00062 return mgr.getCanonicalHostName(hostname);
00063 }
00064
00074 public IpConnection newCltConnection(String host, int port,
00075 IpSession session)
00076 throws JonathanException {
00077 return mgr.newCltConnection(host,port,session);
00078 }
00079
00088 public TcpIpSrvConnectionFactory newSrvConnectionFactory(int port)
00089 throws JonathanException {
00090 return new SrvConnectionFactory(mgr.newSrvConnectionFactory(port));
00091 }
00092 }
00093
00094
00095 class SrvConnectionFactory implements TcpIpSrvConnectionFactory {
00096 TcpIpSrvConnectionFactory delegate;
00097
00098 SrvConnectionFactory(TcpIpSrvConnectionFactory delegate) {
00099 this.delegate = delegate;
00100 }
00101
00102
00103 public IpConnection newSrvConnection(IpSession session)
00104 throws JonathanException {
00105 return new GIOPSrvConnection(delegate.newSrvConnection(session));
00106 }
00107
00108
00109 public int getPort() {
00110 return delegate.getPort();
00111 }
00112
00113 public String getHostName() {
00114 return delegate.getHostName();
00115 }
00116
00117 public void close() {
00118 delegate.close();
00119 }
00120 }
00121
00122
00123 class GIOPSrvConnection implements IpConnection {
00124
00125 static byte[] header_bytes = {
00126 71, 73, 79, 80,
00127 1, 0,
00128 0,
00129 (byte) MsgType_1_0._CloseConnection,
00130 0, 0, 0, 0
00131 };
00132
00133 static Chunk header = new Chunk(header_bytes,0,12);
00134
00135
00136 IpConnection delegate;
00137
00138 GIOPSrvConnection(IpConnection delegate)
00139 throws JonathanException {
00140 this.delegate = delegate;
00141 }
00142
00143 public IpSession getSession() {
00144 return delegate.getSession();
00145 }
00146
00147 public void setSession(IpSession session) {
00148 delegate.setSession(session);
00149 }
00150
00151 public void receive(Chunk chunk,int to_read) throws IOException {
00152 delegate.receive(chunk,to_read);
00153 }
00154 public void emit(Chunk chunk) throws IOException {
00155 delegate.emit(chunk);
00156 }
00157 public int available() throws IOException {
00158 return delegate.available();
00159 }
00160
00161 public int getPort() {
00162 return delegate.getPort();
00163 }
00164 public String getHostName() {
00165 return delegate.getHostName();
00166 }
00167 public void release() {
00168 delegate.release();
00169 }
00170
00171 public void delete() {
00172 try {
00173 delegate.emit(header);
00174 } catch (IOException ignored) {}
00175 delegate.delete();
00176 }
00177 }
00178