import IE.Iona.Orbix2._CORBA; import IE.Iona.Orbix2.CORBA.SystemException; import java.util.Vector; public class GarbageCollectorImp extends Thread implements _GarbageCollectorOperations { private Vector garbageRefs; private Vector toDelete; private int waitTime = 5000; // in milliseconds /** * Constructor for the Garbage Collector */ public GarbageCollectorImp() { garbageRefs = new Vector(10, 5); toDelete = new Vector(10, 5); start(); } /** * Continually checks all referenced objects to see if they are garbage. If * any object is found to be garbage, it is disposed of. */ public void run() { while (true) { try { // check only as often as defined in waitTime sleep(waitTime); } catch (InterruptedException ie) { System.out.println("Garbage Collector Interrupted:\n" + ie); } int count = 0; boolean check; while (count < garbageRefs.size()) { check = true; try { // check an object to see if it is garbage check = ((_CollectableRef)garbageRefs.elementAt(count)).gcCheck(); } catch (SystemException se) { System.out.println("Garbage Collector: Could not check object:\n" + se); } // if an object is garbage if (check == false) { try { // dispose of the object reference within the ORB _CORBA.Orbix.dispose((_CollectableRef)garbageRefs.elementAt(count)); garbageRefs.removeElementAt(count); System.out.println("Garbage Collector: disposed of object"); } catch (SystemException se) { System.out.println("Garbage Collector: Could not dispose of object\n" + se); } } else count++; } } } /** * Registers an object to be checked by the collector. * * @param aRef@ * @return true if aRef was added successfully, otherwise false@ */ public boolean register(_CollectableRef aRef) { garbageRefs.addElement(aRef); return true; } }