home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / rmi / transport / tcp / TCPConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  3.5 KB  |  117 lines

  1. package sun.rmi.transport.tcp;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.BufferedOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.OutputStream;
  8. import java.net.ConnectException;
  9. import java.net.Socket;
  10. import java.net.UnknownHostException;
  11. import java.rmi.ConnectIOException;
  12. import java.rmi.RemoteException;
  13. import java.rmi.server.LogStream;
  14. import java.rmi.server.RMISocketFactory;
  15. import sun.rmi.transport.Channel;
  16. import sun.rmi.transport.Connection;
  17. import sun.rmi.transport.proxy.RMISocketInfo;
  18.  
  19. public class TCPConnection implements Connection {
  20.    private Socket socket;
  21.    private Channel channel;
  22.    // $FF: renamed from: in java.io.InputStream
  23.    private InputStream field_0;
  24.    private OutputStream out;
  25.    private long expiration = Long.MAX_VALUE;
  26.  
  27.    public TCPConnection(TCPChannel var1, InputStream var2, OutputStream var3) {
  28.       this.socket = null;
  29.       this.channel = var1;
  30.       this.field_0 = var2;
  31.       this.out = var3;
  32.    }
  33.  
  34.    public TCPConnection(Channel var1, TCPEndpoint var2) throws RemoteException {
  35.       this.channel = var1;
  36.       RMISocketFactory var3 = RMISocketFactory.getSocketFactory();
  37.       if (var3 == null) {
  38.          var3 = TCPTransport.defaultSocketFactory;
  39.       }
  40.  
  41.       try {
  42.          this.socket = var3.createSocket(var2.getHost(), var2.getPort());
  43.       } catch (UnknownHostException var6) {
  44.          throw new java.rmi.UnknownHostException("Unknown host: " + var2, var6);
  45.       } catch (ConnectException var7) {
  46.          throw new java.rmi.ConnectException("Connection refused to host: " + var2, var7);
  47.       } catch (IOException var8) {
  48.          throw new ConnectIOException("Error creating connection to: " + var2, var8);
  49.       }
  50.  
  51.       try {
  52.          this.socket.setTcpNoDelay(true);
  53.       } catch (Exception var5) {
  54.       }
  55.    }
  56.  
  57.    public TCPConnection(TCPChannel var1, Socket var2) {
  58.       this.socket = var2;
  59.       this.channel = var1;
  60.    }
  61.  
  62.    public OutputStream getOutputStream() throws IOException {
  63.       if (this.out == null) {
  64.          this.out = new BufferedOutputStream(this.socket.getOutputStream());
  65.       }
  66.  
  67.       return this.out;
  68.    }
  69.  
  70.    public void releaseOutputStream() throws IOException {
  71.       if (this.out != null) {
  72.          this.out.flush();
  73.       }
  74.  
  75.    }
  76.  
  77.    public InputStream getInputStream() throws IOException {
  78.       if (this.field_0 == null) {
  79.          this.field_0 = new BufferedInputStream(this.socket.getInputStream());
  80.       }
  81.  
  82.       return this.field_0;
  83.    }
  84.  
  85.    public void releaseInputStream() {
  86.    }
  87.  
  88.    public boolean isReusable() {
  89.       return this.socket != null && this.socket instanceof RMISocketInfo ? ((RMISocketInfo)this.socket).isReusable() : true;
  90.    }
  91.  
  92.    void setExpiration(long var1) {
  93.       this.expiration = var1;
  94.    }
  95.  
  96.    boolean expired(long var1) {
  97.       return this.expiration <= var1;
  98.    }
  99.  
  100.    public void close() throws IOException {
  101.       if (TCPTransport.logLevel >= 10) {
  102.          LogStream.log("tcp").println("TCPConnection.close: close connection");
  103.       }
  104.  
  105.       if (this.socket != null) {
  106.          this.socket.close();
  107.       } else {
  108.          this.field_0.close();
  109.          this.out.close();
  110.       }
  111.    }
  112.  
  113.    public Channel getChannel() {
  114.       return this.channel;
  115.    }
  116. }
  117.