KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > remoting > Response


1 package hudson.remoting;
2
3 /**
4  * Request/response pattern over {@link Command}.
5  *
6  * This is layer 1.
7  *
8  * @author Kohsuke Kawaguchi
9  * @see Request
10  */

11 final class Response<RSP,EXC extends Throwable JavaDoc> extends Command {
12     /**
13      * ID of the {@link Request} for which
14      */

15     private final int id;
16
17     final RSP returnValue;
18     final EXC exception;
19
20     Response(int id, RSP returnValue) {
21         this.id = id;
22         this.returnValue = returnValue;
23         this.exception = null;
24     }
25
26     Response(int id, EXC exception) {
27         this.id = id;
28         this.returnValue = null;
29         this.exception = exception;
30     }
31
32     /**
33      * Notifies the waiting {@link Request}.
34      */

35     @Override JavaDoc
36     protected void execute(Channel channel) {
37         Request req = channel.pendingCalls.get(id);
38         if(req==null)
39             return; // maybe aborted
40
req.onCompleted(this);
41         channel.pendingCalls.remove(id);
42     }
43
44     public String JavaDoc toString() {
45         return "Response[retVal="+toString(returnValue)+",exception="+toString(exception)+"]";
46     }
47
48     private static String JavaDoc toString(Object JavaDoc o) {
49         if(o==null) return "null";
50         else return o.toString();
51     }
52
53     private static final long serialVersionUID = 1L;
54 }
55
Popular Tags