Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

GIOPConnectionFactory.java

Go to the documentation of this file.
00001 /***
00002  * Jonathan: an Open Distributed Processing Environment 
00003  * Copyright (C) 1999-2000 France Telecom R&D
00004  * 
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  * 
00019  * Release: 3.0
00020  *
00021  * Contact: jonathan@objectweb.org
00022  *
00023  * Author: Bruno Dumant
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    // the delegate connection factory.
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    //public TcpIpConnection newSrvConnection(TcpIpSession session)
00103    public IpConnection newSrvConnection(IpSession session)
00104       throws JonathanException {
00105       return new GIOPSrvConnection(delegate.newSrvConnection(session));
00106    }
00107 
00108    //public short getPort() 
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 //class GIOPSrvConnection implements TcpIpConnection 
00123 class GIOPSrvConnection implements IpConnection {
00124 
00125    static byte[] header_bytes = {
00126       71, 73, 79, 80,
00127       1, 0, // version
00128       0,   // byte order: don't care
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    //TcpIpConnection delegate;
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 

Generated at Fri May 31 19:23:32 2002 for Jonathan by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001