home *** CD-ROM | disk | FTP | other *** search
- package sun.rmi.server;
-
- import java.io.IOException;
- import java.io.ObjectInput;
- import java.io.ObjectOutput;
- import java.io.PrintStream;
- import java.rmi.Remote;
- import java.rmi.RemoteException;
- import java.rmi.ServerError;
- import java.rmi.ServerException;
- import java.rmi.ServerRuntimeException;
- import java.rmi.UnmarshalException;
- import java.rmi.server.RemoteCall;
- import java.rmi.server.RemoteRef;
- import java.rmi.server.RemoteServer;
- import java.rmi.server.RemoteStub;
- import java.rmi.server.ServerNotActiveException;
- import java.rmi.server.ServerRef;
- import java.rmi.server.Skeleton;
- import sun.rmi.transport.Channel;
- import sun.rmi.transport.LiveRef;
- import sun.rmi.transport.Target;
- import sun.rmi.transport.tcp.TCPChannel;
- import sun.rmi.transport.tcp.TCPEndpoint;
- import sun.rmi.transport.tcp.TCPTransport;
-
- public class UnicastServerRef extends UnicastRef implements ServerRef, Dispatcher {
- private transient Skeleton skel;
-
- public UnicastServerRef() {
- }
-
- public UnicastServerRef(LiveRef var1) {
- super(var1);
- }
-
- public RemoteStub exportObject(Remote var1, Object var2) throws RemoteException {
- int var3 = var2 != null ? (Integer)var2 : 0;
- if (super.ref == null) {
- super.ref = new LiveRef(var3);
- }
-
- RemoteStub var4 = this.setSkeleton(var1);
- Target var5 = new Target(var1, this, var4);
- super.ref.exportObject(var5);
- return var4;
- }
-
- public String getClientHost() throws ServerNotActiveException {
- Channel var1 = TCPTransport.getCurrentChannel();
- if (var1 instanceof TCPChannel) {
- TCPEndpoint var2 = (TCPEndpoint)((TCPChannel)var1).getEndpoint();
-
- try {
- return var2.getHost();
- } catch (Exception var3) {
- }
- }
-
- throw new ServerNotActiveException("not in a remote call");
- }
-
- public RemoteStub setSkeleton(Remote var1) throws RemoteException {
- this.skel = RemoteProxy.getSkeleton(var1);
- return RemoteProxy.getStub(var1, this.getClientRef());
- }
-
- public void dispatch(Remote var1, RemoteCall var2) throws IOException {
- try {
- int var3;
- long var4;
- try {
- ObjectInput var26 = var2.getInputStream();
- var3 = var26.readInt();
- var4 = var26.readLong();
- } catch (Exception var23) {
- throw new UnmarshalException("Error unmarshaling call header", var23);
- }
-
- PrintStream var27 = RemoteServer.getLog();
- if (var27 != null) {
- var27.println("[" + this.getClientHost() + ": " + var1.getClass().getName() + super.ref.getObjID().toString() + ": " + this.skel.getOperations()[var3] + "]");
- }
-
- this.skel.dispatch(var1, var2, var3, var4);
- } catch (Throwable var24) {
- Object var8 = var24;
- PrintStream var9 = RemoteServer.getLog();
- if (var9 != null) {
- synchronized(var9){}
-
- try {
- try {
- var9.print("[" + this.getClientHost() + "] ");
- } catch (ServerNotActiveException var21) {
- }
-
- var9.print("exception: ");
- ((Throwable)var8).printStackTrace(var9);
- } catch (Throwable var22) {
- throw var22;
- }
- }
-
- ObjectOutput var10 = var2.getResultStream(false);
- if (var24 instanceof RuntimeException) {
- var8 = new ServerRuntimeException("Server RuntimeException", (Exception)var24);
- } else if (var24 instanceof Error) {
- var8 = new ServerError("Server Error", (Error)var24);
- } else if (var24 instanceof RemoteException) {
- var8 = new ServerException("Server RemoteException", (Exception)var24);
- }
-
- var10.writeObject(var8);
- } finally {
- var2.releaseInputStream();
- var2.releaseOutputStream();
- }
-
- }
-
- public String getRefClass(ObjectOutput var1) {
- return var1 instanceof MarshalOutputStream ? "UnicastRef" : "UnicastServerRef";
- }
-
- private RemoteRef getClientRef() {
- return new UnicastRef(super.ref);
- }
-
- public void writeExternal(ObjectOutput var1) throws IOException {
- if (var1 instanceof MarshalOutputStream) {
- throw new Error("UnicastServerRef.writeExternal: internal error");
- }
- }
-
- public void readExternal(ObjectInput var1) throws IOException, ClassNotFoundException {
- super.ref = null;
- this.skel = null;
- }
- }
-