KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > gc > CommandGc


1 package org.sapia.ubik.rmi.server.gc;
2
3 import org.sapia.ubik.rmi.server.*;
4
5 import java.io.IOException JavaDoc;
6 import java.io.ObjectInput JavaDoc;
7 import java.io.ObjectOutput JavaDoc;
8
9
10 /**
11  * This command is sent by clients (<code>ClientGC</code> instances) that wish
12  * to notify the server that they have garbage-collected remote references.
13  * The server-side GC (<code>ServerGC</code>) updates the reference count
14  * for all object identifiers it receives (which are passed in through this
15  * command).
16  *
17  * @author Yanick Duchesne
18  * 2002-09-11
19  */

20 public class CommandGc extends RMICommand {
21   private int _count;
22   private OID[] _oids;
23
24   /** Do not call; used for externalization only. */
25   public CommandGc() {
26   }
27
28   CommandGc(OID[] oids, int count) {
29     _oids = oids;
30     _count = count;
31   }
32
33   /**
34    * @see org.sapia.ubik.rmi.server.RMICommand#execute()
35    */

36   public Object JavaDoc execute() throws Throwable JavaDoc {
37     int i = 0;
38
39     for (; i < _count; i++) {
40       Hub.serverRuntime.dispatchEvent(new GcEvent(getConnection()
41                                                     .getServerAddress(), _count));
42       Hub.serverRuntime.gc.dereference(_vmId, _oids[i]);
43     }
44
45     Hub.serverRuntime.gc.touch(_vmId);
46
47     if (Log.isDebug()) {
48       Log.debug(getClass(), "cleaned " + i + " objects");
49     }
50
51     return null;
52   }
53
54   /**
55    * @see org.sapia.ubik.rmi.server.RMICommand#readExternal(ObjectInput)
56    */

57   public void readExternal(ObjectInput JavaDoc in)
58     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
59     super.readExternal(in);
60     _count = in.readInt();
61     _oids = (OID[]) in.readObject();
62   }
63
64   /**
65    * @see org.sapia.ubik.rmi.server.RMICommand#writeExternal(ObjectOutput)
66    */

67   public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
68     super.writeExternal(out);
69     out.writeInt(_count);
70     out.writeObject(_oids);
71   }
72 }
73
Popular Tags