home *** CD-ROM | disk | FTP | other *** search
- package sun.rmi.transport.tcp;
-
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.net.ConnectException;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.rmi.ConnectIOException;
- import java.rmi.MarshalException;
- import java.rmi.RemoteException;
- import java.rmi.server.LogStream;
- import java.rmi.server.RMISocketFactory;
- import java.util.Enumeration;
- import java.util.Vector;
- import sun.rmi.transport.Channel;
- import sun.rmi.transport.Connection;
- import sun.rmi.transport.Endpoint;
- import sun.rmi.transport.Notifiable;
- import sun.rmi.transport.RMIThread;
- import sun.rmi.transport.Utils;
-
- public class TCPChannel implements Channel, Runnable {
- // $FF: renamed from: ep sun.rmi.transport.tcp.TCPEndpoint
- private TCPEndpoint field_0;
- // $FF: renamed from: tr sun.rmi.transport.tcp.TCPTransport
- private TCPTransport field_1;
- private Vector notifyList = new Vector();
- private Vector freeList = new Vector();
- private boolean usingMultiplexer = false;
- private ConnectionMultiplexer multiplexer;
- private ConnectionAcceptor acceptor;
- private static long timeout = Utils.getLong("sun.rmi.transport.connectionTimeout", 300000L);
-
- TCPChannel(TCPTransport var1, TCPEndpoint var2) {
- this.field_1 = var1;
- this.field_0 = var2;
- }
-
- public Endpoint getEndpoint() {
- return this.field_0;
- }
-
- public Connection newConnection() throws RemoteException {
- Vector var3 = this.freeList;
- synchronized(var3){}
-
- try {
- if (this.freeList.size() > 0) {
- TCPConnection var19 = (TCPConnection)this.freeList.lastElement();
- this.freeList.removeElementAt(this.freeList.size() - 1);
- if (TCPTransport.logLevel >= 10) {
- LogStream.log("tcp").println("TCPChannel.newConnection: reuse connection");
- }
-
- TCPConnection var20 = var19;
- return var20;
- }
- } catch (Throwable var18) {
- throw var18;
- }
-
- if (TCPTransport.logLevel >= 10) {
- LogStream.log("tcp").println("TCPChannel.newConnection: create connection");
- }
-
- TCPConnection var1;
- if (!this.usingMultiplexer) {
- Socket var2 = this.openSocket();
- var1 = new TCPConnection(this, var2);
-
- try {
- DataOutputStream var21 = new DataOutputStream(var1.getOutputStream());
- if (!var1.isReusable()) {
- var21.writeByte(76);
- } else {
- var21.writeByte(75);
- var21.flush();
- DataInputStream var4 = new DataInputStream(var1.getInputStream());
- byte var5 = var4.readByte();
- if (var5 != 78) {
- throw new MarshalException("Transport protocol not supported by server");
- }
-
- TCPEndpoint var6 = TCPEndpoint.read(var4);
- if (TCPTransport.logLevel >= 20) {
- LogStream.log("tcp").println("TCPChannel.newConnection: server suggested endpoint " + var6);
- }
-
- TCPEndpoint.setLocalHost(var6.getHost());
- var6 = TCPEndpoint.getLocalEndpoint(0);
- var6.write(var21);
- if (TCPTransport.logLevel >= 20) {
- LogStream.log("tcp").println("TCPChannel.newConnection: using endpoint " + var6);
- }
-
- var21.flush();
- }
- } catch (IOException var17) {
- if (var17 instanceof RemoteException) {
- throw (RemoteException)var17;
- }
-
- throw new MarshalException("Error marshaling transport header", var17);
- }
- } else {
- try {
- var1 = this.multiplexer.openConnection();
- } catch (IOException var16) {
- synchronized(this){}
-
- try {
- this.usingMultiplexer = false;
- this.multiplexer = null;
- } catch (Throwable var15) {
- throw var15;
- }
-
- throw new ConnectIOException("Error creating multiplexed connection", var16);
- }
- }
-
- return var1;
- }
-
- public void free(Connection var1, boolean var2) {
- if (var1 != null) {
- if (var2 && var1.isReusable()) {
- if (TCPTransport.logLevel >= 10) {
- LogStream.log("tcp").println("TCPChannel.free: reuse connection");
- }
-
- this.freeList.addElement(var1);
- ((TCPConnection)var1).setExpiration(System.currentTimeMillis() + timeout);
- } else {
- if (TCPTransport.logLevel >= 10) {
- LogStream.log("tcp").println("TCPChannel.free: close connection");
- }
-
- try {
- var1.close();
- } catch (IOException var3) {
- }
- }
- }
- }
-
- private Socket openSocket() throws RemoteException {
- if (TCPTransport.logLevel >= 20) {
- LogStream.log("tcp").println("TCPChannel.openSocket: opening socket to " + this.field_0.getHost() + ":" + this.field_0.getPort());
- }
-
- RMISocketFactory var2 = RMISocketFactory.getSocketFactory();
- if (var2 == null) {
- var2 = TCPTransport.defaultSocketFactory;
- }
-
- Socket var1;
- try {
- var1 = var2.createSocket(this.field_0.getHost(), this.field_0.getPort());
- } catch (UnknownHostException var7) {
- throw new java.rmi.UnknownHostException("Unknown host: " + this.field_0, var7);
- } catch (ConnectException var8) {
- throw new java.rmi.ConnectException("Connection refused to host: " + this.field_0, var8);
- } catch (IOException var9) {
- throw new ConnectIOException("Error creating connection to: " + this.field_0, var9);
- }
-
- try {
- var1.setTcpNoDelay(true);
- } catch (Exception var6) {
- }
-
- try {
- var1.getInputStream();
- OutputStream var3 = var1.getOutputStream();
- DataOutputStream var4 = new DataOutputStream(var3);
- var4.writeInt(1246907721);
- var4.writeShort(2);
- return var1;
- } catch (IOException var5) {
- throw new MarshalException("Error marshaling transport header", var5);
- }
- }
-
- private ConnectionMultiplexer openMultiplexer() throws RemoteException {
- Socket var1 = this.openSocket();
- TCPConnection var2 = new TCPConnection(this, var1);
-
- try {
- DataOutputStream var4 = new DataOutputStream(var1.getOutputStream());
- if (!var2.isReusable()) {
- throw new ConnectIOException("Cannot open multiplexed connection to " + this.field_0);
- } else {
- var4.writeByte(77);
- var4.flush();
- DataInputStream var5 = new DataInputStream(var1.getInputStream());
- byte var6 = var5.readByte();
- if (var6 != 78) {
- throw new MarshalException("Transport protocol not supported by receiver");
- } else {
- TCPEndpoint var7 = TCPEndpoint.read(var5);
- if (TCPTransport.logLevel >= 20) {
- LogStream.log("tcp").println("TCPTransport(" + var7.getPort() + ").run: " + "server suggested endpoint " + var7);
- }
-
- TCPEndpoint.setLocalHost(var7.getHost());
- TCPEndpoint.setDefaultPort(var7.getPort());
- var7 = TCPEndpoint.getLocalEndpoint(0);
- var7.write(var4);
- if (TCPTransport.logLevel >= 20) {
- LogStream.log("tcp").println("TCPTransport(" + var7.getPort() + ").run: " + "using endpoint " + var7);
- }
-
- var4.flush();
- ConnectionMultiplexer var3 = new ConnectionMultiplexer(this, var1.getInputStream(), var1.getOutputStream(), true);
- return var3;
- }
- }
- } catch (IOException var8) {
- if (var8 instanceof RemoteException) {
- throw (RemoteException)var8;
- } else {
- throw new MarshalException("Error marshaling transport header", var8);
- }
- }
- }
-
- public void run() {
- try {
- this.multiplexer.run();
- } catch (IOException var9) {
- IOException var1 = var9;
- if (TCPTransport.logLevel >= 20) {
- LogStream var2 = LogStream.log("tcp");
- synchronized(var2){}
-
- try {
- ((PrintStream)var2).print("exception occurred in multiplexer: ");
- ((Throwable)var1).printStackTrace(var2);
- } catch (Throwable var8) {
- throw var8;
- }
- }
-
- this.multiplexer = null;
-
- try {
- this.haveMultiplexer();
- } catch (RemoteException var7) {
- }
- }
- }
-
- void haveMultiplexer() throws RemoteException {
- if (this.multiplexer == null) {
- if (TCPTransport.logLevel >= 20) {
- LogStream.log("tcp").println("TCPChannel.haveMultiplexer(): attempting to open multiplex connection");
- }
-
- this.multiplexer = this.openMultiplexer();
- Thread var1 = RMIThread.newThread(this, "Multiplexer-" + this.field_0.getHost() + ":" + this.field_0.getPort(), true);
- var1.start();
- }
-
- }
-
- synchronized void useMultiplexer(ConnectionMultiplexer var1) {
- this.multiplexer = var1;
- this.usingMultiplexer = true;
- }
-
- void acceptMultiplexConnection(Connection var1) {
- if (this.acceptor == null) {
- this.acceptor = new ConnectionAcceptor(this.field_1);
- this.acceptor.startNewAcceptor();
- }
-
- this.acceptor.accept(var1);
- }
-
- int ping() {
- TCPConnection var1 = null;
- byte var2 = 0;
-
- try {
- var1 = (TCPConnection)this.newConnection();
- } catch (RemoteException var14) {
- var2 = 1;
- }
-
- try {
- if (var1 != null) {
- DataOutputStream var3 = new DataOutputStream(var1.getOutputStream());
- var3.writeByte(82);
- var1.releaseOutputStream();
- DataInputStream var4 = new DataInputStream(var1.getInputStream());
- byte var5 = var4.readByte();
- if (var5 == 83) {
- var2 = 0;
- } else {
- var2 = 2;
- }
- }
- } catch (IOException var13) {
- var2 = 2;
- }
-
- if (var2 == 0) {
- this.free(var1, true);
- } else {
- if (var1 != null) {
- this.free(var1, false);
- }
-
- this.dead(var2);
- }
-
- long var17 = System.currentTimeMillis();
- Vector var18 = this.freeList;
- synchronized(var18){}
-
- try {
- Enumeration var7 = this.freeList.elements();
-
- while(var7.hasMoreElements()) {
- var1 = (TCPConnection)var7.nextElement();
- if (var1.expired(var17)) {
- if (TCPTransport.logLevel >= 10) {
- LogStream.log("tcp").println("TCPChannel.ping: connection time out expired");
- }
-
- try {
- var1.close();
- } catch (IOException var12) {
- }
-
- this.freeList.removeElement(var1);
- }
- }
- } catch (Throwable var15) {
- throw var15;
- }
-
- return var2;
- }
-
- public void dead(int var1) {
- if (var1 == 1) {
- Vector var2 = this.freeList;
- synchronized(var2){}
-
- try {
- Enumeration var4 = this.freeList.elements();
-
- while(var4.hasMoreElements()) {
- Connection var5 = (Connection)var4.nextElement();
-
- try {
- var5.close();
- } catch (IOException var13) {
- }
- }
-
- this.freeList.removeAllElements();
- } catch (Throwable var14) {
- throw var14;
- }
- }
-
- Vector var3 = this.notifyList;
- synchronized(var3){}
-
- Vector var15;
- try {
- var15 = this.notifyList;
- this.notifyList = new Vector();
- } catch (Throwable var12) {
- throw var12;
- }
-
- Enumeration var17 = var15.elements();
-
- while(var17.hasMoreElements()) {
- Notifiable var18 = (Notifiable)var17.nextElement();
- var18.notify(this.field_0, var1);
- }
-
- Object var16 = null;
- }
-
- public void addNotifiable(Endpoint var1, Notifiable var2) {
- Vector var3 = this.notifyList;
- synchronized(var3){}
-
- try {
- if (!this.notifyList.contains(var2)) {
- this.notifyList.addElement(var2);
- }
- } catch (Throwable var5) {
- throw var5;
- }
-
- }
-
- public void removeNotifiable(Endpoint var1, Notifiable var2) {
- this.notifyList.removeElement(var2);
- }
- }
-