001: package demo.notification.whiteboard;
002:
003: import java.util.Iterator;
004: import java.util.HashMap;
005: import java.util.List;
006: import java.util.ArrayList;
007:
008: import org.omg.CORBA.IntHolder;
009: import org.omg.CORBA.ORB;
010: import org.omg.CosEventChannelAdmin.AlreadyConnected;
011: import org.omg.CosNaming.NameComponent;
012: import org.omg.CosNaming.NamingContext;
013: import org.omg.CosNaming.NamingContextHelper;
014: import org.omg.CosNotification.Property;
015: import org.omg.CosNotification.UnsupportedAdmin;
016: import org.omg.CosNotification.UnsupportedQoS;
017: import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded;
018: import org.omg.CosNotifyChannelAdmin.EventChannel;
019: import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
020: import org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper;
021: import org.omg.PortableServer.POA;
022: import org.omg.PortableServer.POAHelper;
023:
024: import org.jacorb.notification.EventChannelFactoryImpl;
025:
026: /**
027: * WhiteBoardFactory.java
028: *
029: *
030: * @author Alphonse Bendt
031: * @version $Id: WhiteBoardFactory.java,v 1.5 2004/04/28 13:52:02 alphonse.bendt Exp $
032: */
033:
034: public class WhiteBoardFactory extends IFactoryPOA implements
035: IFactoryOperations {
036:
037: HashMap boards;
038: EventChannelFactory channelFactory_;
039: POA poa_;
040: ORB orb_;
041:
042: public WhiteBoardFactory(ORB orb, POA poa, EventChannelFactory ecf) {
043: _this (orb);
044: boards = new HashMap();
045: orb_ = orb;
046: poa_ = poa;
047: channelFactory_ = ecf;
048: }
049:
050: public IWhiteBoard getCreateWhiteboard(String name) {
051: try {
052: WhiteBoard board = null;
053: board = (WhiteBoard) boards.get(name);
054: if (board == null) {
055: synchronized (boards) {
056: board = (WhiteBoard) boards.get(name);
057: if (board == null) {
058: System.out.println("Create board " + name);
059: IntHolder _channelId = new IntHolder();
060: EventChannel _channel = channelFactory_
061: .create_channel(new Property[0],
062: new Property[0], _channelId);
063:
064: IntHolder _adminId = new IntHolder();
065:
066: board = new WhiteBoard(orb_, _channel);
067: boards.put(name, board);
068: }
069: }
070: }
071: System.out.println("return board");
072:
073: return board._this (orb_);
074: } catch (UnsupportedAdmin ua) {
075: ua.printStackTrace();
076: } catch (UnsupportedQoS uqos) {
077: uqos.printStackTrace();
078: } catch (AdminLimitExceeded ale) {
079: ale.printStackTrace();
080: }
081: throw new RuntimeException();
082: }
083:
084: public String[] listAllWhiteboards() {
085: return (String[]) boards.keySet().toArray(new String[0]);
086: }
087:
088: public static void main(String[] args) {
089: // CORBA initialisierung
090: try {
091: ORB _orb = ORB.init(args, null);
092:
093: POA _poa = POAHelper.narrow(_orb
094: .resolve_initial_references("RootPOA"));
095:
096: NamingContext nc = NamingContextHelper.narrow(_orb
097: .resolve_initial_references("NameService"));
098:
099: EventChannelFactory _factory;
100: if (args != null && args.length == 1) {
101: _factory = EventChannelFactoryHelper.narrow(_orb
102: .string_to_object(args[0]));
103: } else {
104: _factory = EventChannelFactoryHelper
105: .narrow(_orb
106: .resolve_initial_references("NotificationService"));
107: }
108:
109: org.omg.CORBA.Object cob = _poa
110: .servant_to_reference(new WhiteBoardFactory(_orb,
111: _poa, _factory));
112:
113: NameComponent[] name = new NameComponent[1];
114: name[0] = new NameComponent("WhiteBoard", "Factory");
115:
116: // an Namen binden
117: nc.rebind(name, cob);
118: _poa.the_POAManager().activate();
119:
120: System.out.println("Whiteboard online !");
121:
122: boolean non_exist = false;
123: try {
124: non_exist = _factory._non_existent();
125: } catch (org.omg.CORBA.SystemException e) {
126: non_exist = true;
127: }
128:
129: if (non_exist) {
130: System.out
131: .println("NotificationService not available !");
132: System.exit(1);
133: }
134:
135: _orb.run();
136: } catch (Exception e) {
137: e.printStackTrace();
138: System.exit(1);
139: }
140: }
141: } // WhiteBoardFactory
|