1 // ============================================================================
4 // PushConsumerFactory.java
7 // Michael Kircher (mk1@cs.wustl.edu)
10 // This is the administor/factory for a PushConsumer.
12 // ============================================================================
15 public class PushConsumerFactory
18 private org.omg.CORBA.ORB orb_;
19 private org.omg.CORBA.Object naming_service_object_;
20 private DataHandler dataHandler_;
21 private Navigation navigation_;
22 private Weapons weapons_;
25 public PushConsumerFactory (DataHandler dataHandler,
26 String nameServiceIOR,
28 java.applet.Applet applet)
31 dataHandler_ = dataHandler;
33 // if the DOVE Browser is running as an Applet
35 orb_ = org.omg.CORBA.ORB.init (applet, null);
37 else { // not running as an Applet, but as an normal Application
38 orb_ = org.omg.CORBA.ORB.init (args, null);
41 // Get the Naming Service initial reference
43 // Name Service Lookup cannot be used when running as an Applet
44 if (nameServiceIOR == null && applet != null) {
45 System.out.println (" Name Service Lookup cannot be used when running as an Applet! Quit!");
49 if (nameServiceIOR == null) { // only used when running via "java" or "vbj"
50 System.out.println ("Using the lookup protocol!");
51 NS_Resolve ns_resolve = new NS_Resolve ();
52 naming_service_object_ = ns_resolve.resolve_name_service (orb_);
55 System.out.println ("Using the following IOR: " + nameServiceIOR);
56 naming_service_object_ = orb_.string_to_object (nameServiceIOR);
60 catch(org.omg.CORBA.SystemException e) {
61 System.err.println ("PushConsumerFactory constructor: ORB and Name Service initialization");
62 System.err.println(e);
67 public class Object_is_null_exception extends Exception
69 Object_is_null_exception (String s)
80 // Get the Naming Context to allow resolving the EventService and
82 CosNaming.NamingContext naming_context =
83 CosNaming.NamingContextHelper.narrow (naming_service_object_);
85 if (naming_context == null)
87 System.err.println ("The Naming Context is null");
90 System.out.println ("Reference to the Naming Service is ok.");
92 // Get a reference for the EventService
94 CosNaming.NameComponent[] ec_name_components = new CosNaming.NameComponent[1];
95 ec_name_components[0] = new CosNaming.NameComponent ("EventService","");
96 org.omg.CORBA.Object event_channel_object = naming_context.resolve (ec_name_components);
98 if (event_channel_object == null)
100 throw new Object_is_null_exception("EventService Object is null");
103 RtecEventChannelAdmin.EventChannel event_channel =
104 RtecEventChannelAdmin.EventChannelHelper.narrow (event_channel_object);
106 System.out.println ("Reference to the Event Service is ok.");
108 // Get a reference for the ScheduleService
110 CosNaming.NameComponent[] s_name_components = new CosNaming.NameComponent[1];
111 s_name_components[0] = new CosNaming.NameComponent ("ScheduleService","");
112 org.omg.CORBA.Object scheduler_object = naming_context.resolve (s_name_components);
114 if (scheduler_object == null)
116 throw new Object_is_null_exception("ScheduleService Object is null");
119 RtecScheduler.Scheduler scheduler =
120 RtecScheduler.SchedulerHelper.narrow (scheduler_object);
122 System.out.println ("Reference to the Naming Service is ok.");
125 // Start the consumer
126 System.out.println ("Instantiating the Push Consumer.");
127 PushConsumer pushConsumer = new PushConsumer (orb_, dataHandler_);
128 System.out.println ("Initializing the Push Consumer.");
129 pushConsumer.open_consumer (event_channel, scheduler, "demo_consumer");
131 // Tell the CORBA environment that we are ready
133 orb_.connect (pushConsumer);
135 System.out.println ("Going into the event dispatching loop.");
138 java.lang.Object sync = new java.lang.Object();
139 synchronized (sync) {
143 catch (java.lang.InterruptedException e)
146 catch (CosNaming.NamingContextPackage.CannotProceed e)
148 System.err.println ("CosNaming.NamingContextPackage.CannotProceed");
149 System.err.println (e);
151 catch (CosNaming.NamingContextPackage.InvalidName e)
153 System.err.println ("CosNaming.NamingContextPackage.InvalidName");
154 System.err.println (e);
156 catch (CosNaming.NamingContextPackage.NotFound e)
158 System.err.println ("CosNaming.NamingContextPackage.NotFound");
159 System.err.println (e);
161 catch (Object_is_null_exception e)
163 System.err.println (e);
165 catch(org.omg.CORBA.SystemException e)
167 System.err.println ("PushConsumerFactory.run: Failure");
168 System.err.println(e);
171 } // public class PushConsumerFactory