home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / rmi / server / UnicastServerRef.class (.txt) < prev   
Encoding:
Java Class File  |  1998-04-23  |  4.7 KB  |  141 lines

  1. package sun.rmi.server;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInput;
  5. import java.io.ObjectOutput;
  6. import java.io.PrintStream;
  7. import java.rmi.Remote;
  8. import java.rmi.RemoteException;
  9. import java.rmi.ServerError;
  10. import java.rmi.ServerException;
  11. import java.rmi.ServerRuntimeException;
  12. import java.rmi.UnmarshalException;
  13. import java.rmi.server.RemoteCall;
  14. import java.rmi.server.RemoteRef;
  15. import java.rmi.server.RemoteServer;
  16. import java.rmi.server.RemoteStub;
  17. import java.rmi.server.ServerNotActiveException;
  18. import java.rmi.server.ServerRef;
  19. import java.rmi.server.Skeleton;
  20. import sun.rmi.transport.Channel;
  21. import sun.rmi.transport.LiveRef;
  22. import sun.rmi.transport.Target;
  23. import sun.rmi.transport.tcp.TCPChannel;
  24. import sun.rmi.transport.tcp.TCPEndpoint;
  25. import sun.rmi.transport.tcp.TCPTransport;
  26.  
  27. public class UnicastServerRef extends UnicastRef implements ServerRef, Dispatcher {
  28.    private transient Skeleton skel;
  29.  
  30.    public UnicastServerRef() {
  31.    }
  32.  
  33.    public UnicastServerRef(LiveRef var1) {
  34.       super(var1);
  35.    }
  36.  
  37.    public RemoteStub exportObject(Remote var1, Object var2) throws RemoteException {
  38.       int var3 = var2 != null ? (Integer)var2 : 0;
  39.       if (super.ref == null) {
  40.          super.ref = new LiveRef(var3);
  41.       }
  42.  
  43.       RemoteStub var4 = this.setSkeleton(var1);
  44.       Target var5 = new Target(var1, this, var4);
  45.       super.ref.exportObject(var5);
  46.       return var4;
  47.    }
  48.  
  49.    public String getClientHost() throws ServerNotActiveException {
  50.       Channel var1 = TCPTransport.getCurrentChannel();
  51.       if (var1 instanceof TCPChannel) {
  52.          TCPEndpoint var2 = (TCPEndpoint)((TCPChannel)var1).getEndpoint();
  53.  
  54.          try {
  55.             return var2.getHost();
  56.          } catch (Exception var3) {
  57.          }
  58.       }
  59.  
  60.       throw new ServerNotActiveException("not in a remote call");
  61.    }
  62.  
  63.    public RemoteStub setSkeleton(Remote var1) throws RemoteException {
  64.       this.skel = RemoteProxy.getSkeleton(var1);
  65.       return RemoteProxy.getStub(var1, this.getClientRef());
  66.    }
  67.  
  68.    public void dispatch(Remote var1, RemoteCall var2) throws IOException {
  69.       try {
  70.          int var3;
  71.          long var4;
  72.          try {
  73.             ObjectInput var26 = var2.getInputStream();
  74.             var3 = var26.readInt();
  75.             var4 = var26.readLong();
  76.          } catch (Exception var23) {
  77.             throw new UnmarshalException("Error unmarshaling call header", var23);
  78.          }
  79.  
  80.          PrintStream var27 = RemoteServer.getLog();
  81.          if (var27 != null) {
  82.             var27.println("[" + this.getClientHost() + ": " + var1.getClass().getName() + super.ref.getObjID().toString() + ": " + this.skel.getOperations()[var3] + "]");
  83.          }
  84.  
  85.          this.skel.dispatch(var1, var2, var3, var4);
  86.       } catch (Throwable var24) {
  87.          Object var8 = var24;
  88.          PrintStream var9 = RemoteServer.getLog();
  89.          if (var9 != null) {
  90.             synchronized(var9){}
  91.  
  92.             try {
  93.                try {
  94.                   var9.print("[" + this.getClientHost() + "] ");
  95.                } catch (ServerNotActiveException var21) {
  96.                }
  97.  
  98.                var9.print("exception: ");
  99.                ((Throwable)var8).printStackTrace(var9);
  100.             } catch (Throwable var22) {
  101.                throw var22;
  102.             }
  103.          }
  104.  
  105.          ObjectOutput var10 = var2.getResultStream(false);
  106.          if (var24 instanceof RuntimeException) {
  107.             var8 = new ServerRuntimeException("Server RuntimeException", (Exception)var24);
  108.          } else if (var24 instanceof Error) {
  109.             var8 = new ServerError("Server Error", (Error)var24);
  110.          } else if (var24 instanceof RemoteException) {
  111.             var8 = new ServerException("Server RemoteException", (Exception)var24);
  112.          }
  113.  
  114.          var10.writeObject(var8);
  115.       } finally {
  116.          var2.releaseInputStream();
  117.          var2.releaseOutputStream();
  118.       }
  119.  
  120.    }
  121.  
  122.    public String getRefClass(ObjectOutput var1) {
  123.       return var1 instanceof MarshalOutputStream ? "UnicastRef" : "UnicastServerRef";
  124.    }
  125.  
  126.    private RemoteRef getClientRef() {
  127.       return new UnicastRef(super.ref);
  128.    }
  129.  
  130.    public void writeExternal(ObjectOutput var1) throws IOException {
  131.       if (var1 instanceof MarshalOutputStream) {
  132.          throw new Error("UnicastServerRef.writeExternal: internal error");
  133.       }
  134.    }
  135.  
  136.    public void readExternal(ObjectInput var1) throws IOException, ClassNotFoundException {
  137.       super.ref = null;
  138.       this.skel = null;
  139.    }
  140. }
  141.