Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Still more diagnostics to keep track of where RemoteInvocationHandler came from.
  • Loading branch information
kohsuke committed Nov 5, 2014
1 parent 905d623 commit 16b9994
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/main/java/hudson/remoting/RemoteInvocationHandler.java
Expand Up @@ -84,13 +84,19 @@ final class RemoteInvocationHandler implements InvocationHandler, Serializable {
*/
private boolean goingHome;

/**
* Diagnostic information that remembers where the proxy was created.
*/
private final Throwable origin;

/**
* Creates a proxy that wraps an existing OID on the remote.
*/
RemoteInvocationHandler(Channel channel, int id, boolean userProxy, boolean autoUnexportByCaller) {
RemoteInvocationHandler(Channel channel, int id, boolean userProxy, boolean autoUnexportByCaller, Class proxyType) {
this.channel = channel;
this.oid = id;
this.userProxy = userProxy;
this.origin = new Exception("Proxy "+toString()+" was created for "+proxyType);
this.autoUnexportByCaller = autoUnexportByCaller;
}

Expand All @@ -103,7 +109,7 @@ public static <T> T wrap(Channel channel, int id, Class<T> type, boolean userPro
if(cl==null || cl==ClassLoader.getSystemClassLoader())
cl = IReadResolve.class.getClassLoader();
return type.cast(Proxy.newProxyInstance(cl, new Class[]{type,IReadResolve.class},
new RemoteInvocationHandler(channel,id,userProxy,autoUnexportByCaller)));
new RemoteInvocationHandler(channel,id,userProxy,autoUnexportByCaller,type)));
}

/*package*/ static Class getProxyClass(Class type) {
Expand Down Expand Up @@ -231,7 +237,7 @@ public int hashCode() {
protected void finalize() throws Throwable {
// unexport the remote object
if (channel!=null && !autoUnexportByCaller) {
channel.send(new UnexportCommand(oid));
channel.send(new UnexportCommand(oid,origin));
channel = null;
}
super.finalize();
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/hudson/remoting/UnexportCommand.java
Expand Up @@ -30,13 +30,23 @@
public class UnexportCommand extends Command {
private final int oid;

public UnexportCommand(int oid) {
UnexportCommand(int oid, Throwable cause) {
this.oid = oid;
this.createdAt.initCause(cause);
}

public UnexportCommand(int oid) {
this(oid,null);
}

protected void execute(Channel channel) {
channel.unexport(oid,createdAt);
}

@Override
public String toString() {
return super.toString();
}

private static final long serialVersionUID = 1L;
}

0 comments on commit 16b9994

Please sign in to comment.