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