KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > invocation > CallBackInvokeCommand


1 package org.sapia.ubik.rmi.server.invocation;
2
3 import org.sapia.ubik.net.ServerAddress;
4 import org.sapia.ubik.rmi.server.*;
5
6 import java.io.Externalizable JavaDoc;
7 import java.io.IOException JavaDoc;
8 import java.io.ObjectInput JavaDoc;
9 import java.io.ObjectOutput JavaDoc;
10
11
12 /**
13  * A method invocation command that handles call backs.
14  *
15  * @author Yanick Duchesne
16  * <dl>
17  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
18  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
19  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
20  * </dl>
21  */

22 public class CallBackInvokeCommand extends InvokeCommand
23   implements Externalizable JavaDoc {
24   static final long serialVersionUID = 1L;
25   private boolean _executed;
26   private String JavaDoc _respId;
27   private ServerAddress _callBackId;
28
29   /**
30    * Do not call; used for externalization only.
31    */

32   public CallBackInvokeCommand() {
33   }
34
35   /**
36    * Constructor for CallBackInvokeCommand.
37    * @param oid the object identifier of the object on which to perform the invocation.
38    * @param methodName the name of the method to call on the target object.
39    * @param params the parameters of the method.
40    * @param paramClasses the classes of the method's parameters (representing the method's signature).
41    */

42   public CallBackInvokeCommand(OID oid, String JavaDoc methodName, Object JavaDoc[] params,
43     Class JavaDoc[] paramClasses, String JavaDoc transportType) {
44     super(oid, methodName, params, paramClasses, transportType);
45   }
46
47   /**
48    * @see org.sapia.ubik.rmi.server.RMICommand#execute()
49    */

50   public Object JavaDoc execute() throws Throwable JavaDoc {
51     if (!_executed) {
52       _executed = true;
53
54       if (Log.isDebug()) {
55         Log.debug(getClass(), "dispatching callback command " + _respId);
56       }
57
58       Hub.serverRuntime.processor.processAsyncCommand(_respId, _vmId,
59         _callBackId, this);
60
61       return new Integer JavaDoc(0);
62     } else {
63       if (Log.isDebug()) {
64         Log.debug(getClass(), "executing callback command " + _respId);
65       }
66
67       return super.execute();
68     }
69   }
70
71   /**
72    * @see java.io.Externalizable#readExternal(ObjectInput)
73    */

74   public void readExternal(ObjectInput JavaDoc in)
75     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
76     super.readExternal(in);
77     _executed = in.readBoolean();
78     _respId = (String JavaDoc) in.readObject();
79     _callBackId = (ServerAddress) in.readObject();
80   }
81
82   /**
83    * @see java.io.Externalizable#writeExternal(ObjectOutput)
84    */

85   public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
86     super.writeExternal(out);
87     out.writeBoolean(_executed);
88     out.writeObject(_respId);
89     out.writeObject(_callBackId);
90   }
91
92   final void setUp(String JavaDoc respId, ServerAddress callBackId) {
93     _respId = respId;
94     _callBackId = callBackId;
95   }
96 }
97
Popular Tags