1 2 package org.enhydra.shark.corba; 3 4 import java.util.HashSet ; 5 import java.util.Iterator ; 6 7 13 public interface Collective { 14 public void __recruit(org.omg.CORBA.Object obj); 15 16 public void __leave(org.omg.CORBA.Object _obj); 17 18 public void __disband(org.omg.CORBA.ORB _orb); 19 20 public final class CollectiveCORBA implements Collective { 21 22 private transient HashSet myObjects = new HashSet (); 23 24 public synchronized void __recruit(org.omg.CORBA.Object obj) { 25 myObjects.add(obj); 26 } 27 28 public synchronized void __disband(org.omg.CORBA.ORB _orb) { 29 for (Iterator it = myObjects.iterator(); it.hasNext();) { 30 _orb.disconnect((org.omg.CORBA.Object ) it.next()); 31 it.remove(); 32 } 33 myObjects = null; 34 } 35 36 public synchronized void __leave(org.omg.CORBA.Object obj) { 37 Iterator i=myObjects.iterator(); 38 Object toRemove=obj; 39 while (i.hasNext()) { 40 org.omg.CORBA.Object o=(org.omg.CORBA.Object )i.next(); 41 if (obj._is_equivalent(o)) { 42 toRemove=o; 43 break; 44 } 45 } 46 boolean r=myObjects.remove(toRemove); 47 if (r==false) System.out.println("Warning: object is not removed from collection!"); 48 } 49 50 } 51 52 } | Popular Tags |