1 package demo.notification.whiteboard; 2 3 import java.util.Iterator ; 4 import java.util.HashMap ; 5 import java.util.List ; 6 import java.util.ArrayList ; 7 8 import org.omg.CORBA.IntHolder ; 9 import org.omg.CORBA.ORB ; 10 import org.omg.CosEventChannelAdmin.AlreadyConnected; 11 import org.omg.CosNaming.NameComponent ; 12 import org.omg.CosNaming.NamingContext ; 13 import org.omg.CosNaming.NamingContextHelper ; 14 import org.omg.CosNotification.Property; 15 import org.omg.CosNotification.UnsupportedAdmin; 16 import org.omg.CosNotification.UnsupportedQoS; 17 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded; 18 import org.omg.CosNotifyChannelAdmin.EventChannel; 19 import org.omg.CosNotifyChannelAdmin.EventChannelFactory; 20 import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper; 21 import org.omg.PortableServer.POA ; 22 import org.omg.PortableServer.POAHelper ; 23 24 import org.jacorb.notification.EventChannelFactoryImpl; 25 26 33 34 public class WhiteBoardFactory extends IFactoryPOA implements IFactoryOperations { 35 36 HashMap boards; 37 EventChannelFactory channelFactory_; 38 POA poa_; 39 ORB orb_; 40 41 public WhiteBoardFactory(ORB orb, POA poa, EventChannelFactory ecf) { 42 _this(orb); 43 boards = new HashMap (); 44 orb_ = orb; 45 poa_ = poa; 46 channelFactory_ = ecf; 47 } 48 49 public IWhiteBoard getCreateWhiteboard(String name) { 50 try { 51 WhiteBoard board = null; 52 board = (WhiteBoard)boards.get(name); 53 if (board == null) { 54 synchronized(boards) { 55 board = (WhiteBoard)boards.get(name); 56 if (board == null) { 57 System.out.println("Create board "+name); 58 IntHolder _channelId = new IntHolder (); 59 EventChannel _channel = 60 channelFactory_.create_channel(new Property[0], new Property[0], _channelId); 61 62 IntHolder _adminId = new IntHolder (); 63 64 board = new WhiteBoard(orb_, _channel); 65 boards.put(name,board); 66 } 67 } 68 } 69 System.out.println("return board"); 70 71 return board._this(orb_); 72 } catch (UnsupportedAdmin ua) { 73 ua.printStackTrace(); 74 } catch (UnsupportedQoS uqos) { 75 uqos.printStackTrace(); 76 } catch (AdminLimitExceeded ale) { 77 ale.printStackTrace(); 78 } 79 throw new RuntimeException (); 80 } 81 82 public String [] listAllWhiteboards() { 83 return (String []) boards.keySet().toArray(new String [0]); 84 } 85 86 87 public static void main(String [] args) { 88 try { 90 ORB _orb = ORB.init(args, null); 91 92 POA _poa = 93 POAHelper.narrow(_orb.resolve_initial_references("RootPOA")); 94 95 NamingContext nc = 96 NamingContextHelper.narrow(_orb.resolve_initial_references("NameService")); 97 98 EventChannelFactory _factory; 99 if (args != null && args.length == 1) { 100 _factory = 101 EventChannelFactoryHelper.narrow(_orb.string_to_object(args[0])); 102 } else { 103 _factory = EventChannelFactoryHelper.narrow(_orb.resolve_initial_references("NotificationService")); 104 } 105 106 org.omg.CORBA.Object cob = 107 _poa.servant_to_reference(new WhiteBoardFactory(_orb, _poa, _factory)); 108 109 NameComponent [] name = new NameComponent [1]; 110 name[0] = new NameComponent ( "WhiteBoard", "Factory"); 111 112 nc.rebind(name, cob); 114 _poa.the_POAManager().activate(); 115 116 System.out.println("Whiteboard online !"); 117 118 boolean non_exist = false; 119 try { 120 non_exist = _factory._non_existent(); 121 } catch (org.omg.CORBA.SystemException e) { 122 non_exist = true; 123 } 124 125 if (non_exist) { 126 System.out.println("NotificationService not available !"); 127 System.exit(1); 128 } 129 130 _orb.run(); 131 } catch (Exception e) { 132 e.printStackTrace(); 133 System.exit(1); 134 } 135 } 136 } 138 | Popular Tags |