KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > RMICommand


1 package org.sapia.ubik.rmi.server;
2
3 import java.io.Externalizable JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.ObjectInput JavaDoc;
6 import java.io.ObjectOutput JavaDoc;
7
8 import org.sapia.ubik.net.Connection;
9 import org.sapia.ubik.net.ServerAddress;
10 import org.sapia.ubik.rmi.server.command.Command;
11
12
13 /**
14  * This class models an executable command. Typically, a command object
15  * is created on the client side, then sent to the server where it is executed.
16  *
17  * @author Yanick Duchesne
18  * <dl>
19  * <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>
20  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
21  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
22  * </dl>
23  */

24 public abstract class RMICommand extends Command implements Externalizable JavaDoc {
25   protected transient Config _config;
26   protected VmId _vmId = VmId.getInstance();
27
28   public RMICommand() {
29   }
30
31   /**
32    * Initializes this instance with a <code>CommandConfig</code> upon its
33    * arrival at the server. It is a server's responsability to call this
34    * method once it receives a command.
35    * <p>
36    * When overriding this method, <code>super.init(config)</code> must
37    * be called. If a command nests another one, it should also call
38    * <code>init()</code> on the nested command.
39    *
40    * @param config <code>CommandConfig</code>
41    */

42   public void init(Config config) {
43     _config = config;
44   }
45
46   /**
47    * Returns the identifier of the VM from which this command comes from.
48    *
49    * @return a <code>VmId</code>.
50    */

51   public VmId getVmId() {
52     return _vmId;
53   }
54
55   /**
56    * Returns this command's target server address, which corresponds
57    * to the server that received this command.
58    *
59    * @return this command's <code>ServerAddress</code>
60    */

61   public ServerAddress getServerAddress() {
62     return _config.getServerAddress();
63   }
64
65   /**
66    * Returns this command's connection.
67    *
68    * @return a <code>Connection</code>
69    */

70   public final Connection getConnection() {
71     return _config.getConnection();
72   }
73
74   /**
75    * Executes this command.
76    *
77    * @throws Throwable if an error occurs while executing this command
78    */

79   public abstract Object JavaDoc execute() throws Throwable JavaDoc;
80
81   /**
82    * @see java.io.Externalizable#readExternal(ObjectInput)
83    */

84   public void readExternal(ObjectInput JavaDoc in)
85     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
86     _vmId = (VmId) in.readObject();
87   }
88
89   /**
90    * @see java.io.Externalizable#writeExternal(ObjectOutput)
91    */

92   public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
93     out.writeObject(_vmId);
94   }
95 }
96
Popular Tags