2 // ============================================================================
5 // PushConsumerFactory.java
8 // Michael Kircher (mk1@cs.wustl.edu)
11 // This is the administor/factory for a PushConsumer.
13 // ============================================================================
18 public class PushConsumerFactory
{
20 private org
.omg
.CORBA
.ORB orb_
;
21 private org
.omg
.PortableServer
.POA poa_
;
22 private org
.omg
.CORBA
.Object naming_service_object_
;
24 private DataHandler dataHandler_
;
25 private Navigation navigation_
;
26 private Weapons weapons_
;
28 private String
[] ec_names_
= null;
29 private int ec_names_count_
= 0;
31 private String
[] ss_names_
= null;
32 private int ss_names_count_
= 0;
34 private boolean use_queueing_
= false;
36 public PushConsumerFactory (DataHandler dataHandler
,
37 String nameServiceIOR
,
38 String nameServicePort
,
41 java
.applet
.Applet applet
)
45 use_queueing_
= use_queueing
;
46 dataHandler_
= dataHandler
;
48 // if the DOVE Browser is running as an Applet
50 orb_
= org
.omg
.CORBA
.ORB
.init (applet
, null);
52 else { // not running as an Applet, but as an normal Application
53 orb_
= org
.omg
.CORBA
.ORB
.init (args
, null);
56 System
.out
.println ("Initialized ORB");
58 org
.omg
.CORBA
.Object obj
=
59 orb_
.resolve_initial_references ("RootPOA");
61 System
.out
.println ("Obtained RootPOA");
63 poa_
= org
.omg
.PortableServer
.POAHelper
.narrow (obj
);
65 System
.out
.println ("Narrowed RootPOA");
67 // Get the Naming Service initial reference
69 // Name Service Lookup cannot be used when running as an Applet
70 if (nameServiceIOR
== null && applet
!= null) {
71 System
.out
.println (" Name Service Lookup cannot be used when running as an Applet! Quit!");
75 if (nameServiceIOR
== null) { // only used when running via "java" or "vbj"
76 System
.out
.println ("Using the lookup protocol!");
77 NS_Resolve ns_resolve_
= new NS_Resolve (nameServicePort
);
78 naming_service_object_
= ns_resolve_
.resolve_name_service (orb_
);
81 System
.out
.println ("Using the following IOR: " + nameServiceIOR
);
82 naming_service_object_
= orb_
.string_to_object (nameServiceIOR
);
85 // Walk through args and count EC and Scheduling Service names.
87 while (args
.length
> arg_index
)
89 // Count an event service name
90 if ((args
[arg_index
].equals ("-eventservicename")) &&
91 (args
.length
> arg_index
+ 1))
93 System
.out
.println ("switch [" + args
[arg_index
] + "]");
94 System
.out
.println ("value [" + args
[arg_index
+ 1] + "]");
98 // Count a scheduling service name
99 else if ((args
[arg_index
].equals ("-scheduleservicename")) &&
100 (args
.length
> arg_index
+ 1))
102 System
.out
.println ("switch [" + args
[arg_index
] + "]");
103 System
.out
.println ("value [" + args
[arg_index
+ 1] + "]");
107 else if (args
[arg_index
].equals ("-dualECdemo"))
109 System
.out
.println ("switch [" + args
[arg_index
] + "]");
111 ec_names_count_
+= 2;
112 ss_names_count_
+= 2;
114 else if ((args
[arg_index
].equals ("-dualECdemo1")) ||
115 (args
[arg_index
].equals ("-dualECdemo2")))
117 System
.out
.println ("switch [" + args
[arg_index
] + "]");
122 // Skip over anything else
129 // Allocate arrays for the event and schedule service names (if any)
130 if (ec_names_count_
> 0)
132 ec_names_
= new String
[ec_names_count_
];
134 if (ss_names_count_
> 0)
136 ss_names_
= new String
[ss_names_count_
];
139 // Then traverse the args again to allocate and fill in a list
140 // of EC and Scheduling Service names.
144 while (args
.length
> arg_index
)
146 // Set an event service name.
147 if ((args
[arg_index
].equals ("-eventservicename")) &&
148 (args
.length
> arg_index
+ 1))
150 ec_names_
[ec_names_count_
] = args
[arg_index
+ 1];
154 // Set a schedule service name.
155 else if ((args
[arg_index
].equals ("-scheduleservicename")) &&
156 (args
.length
> arg_index
+ 1))
158 ss_names_
[ss_names_count_
] = args
[arg_index
+ 1];
162 else if (args
[arg_index
].equals ("-dualECdemo"))
164 ss_names_
[ss_names_count_
] = "DUAL_SCHED_HI";
165 ss_names_
[ss_names_count_
+ 1] = "DUAL_SCHED_LO";
166 ec_names_
[ec_names_count_
] = "DUAL_EC_HI";
167 ec_names_
[ec_names_count_
+ 1] = "DUAL_EC_LO";
169 ec_names_count_
+= 2;
170 ss_names_count_
+= 2;
172 else if (args
[arg_index
].equals ("-dualECdemo1"))
174 ss_names_
[ss_names_count_
] = "DUAL_SCHED_HI";
175 ec_names_
[ec_names_count_
] = "DUAL_EC_HI";
180 else if (args
[arg_index
].equals ("-dualECdemo2"))
182 ss_names_
[ss_names_count_
] = "DUAL_SCHED_LO";
183 ec_names_
[ec_names_count_
] = "DUAL_EC_LO";
188 // Skip over anything else.
195 // If names for event or scheduling services have not been provided
196 // already, provide the default names used by the service executables.
197 if (ec_names_count_
== 0)
200 ec_names_
= new String
[1];
201 ec_names_
[0] = "EventService";
203 if (ss_names_count_
== 0)
206 ss_names_
= new String
[1];
207 ss_names_
[0] = "ScheduleService";
210 catch (org
.omg
.CORBA
.ORBPackage
.InvalidName e
)
212 System
.err
.println ("CosNaming.NamingContextPackage.InvalidName");
213 System
.err
.println (e
);
215 catch(org
.omg
.CORBA
.SystemException e
) {
216 System
.err
.println ("PushConsumerFactory constructor: ORB and Name Service initialization");
217 System
.err
.println(e
);
222 public class Object_is_null_exception
extends Exception
224 Object_is_null_exception (String s
)
235 // Get the Naming Context to allow resolving the EventService and
237 CosNaming
.NamingContext naming_context_
=
238 CosNaming
.NamingContextHelper
.narrow (naming_service_object_
);
240 if (naming_context_
== null)
242 System
.err
.println ("The Naming Context is null");
245 System
.out
.println ("Reference to the Naming Service is ok.");
247 // Create Consumers connected to the EventService
249 RtecScheduler
.Scheduler scheduler_
= null;
250 for (int ec_number
= 0; ec_number
< ec_names_count_
; ++ec_number
)
252 // Get a reference for the next Scheduling Service if there is one.
253 // Invariant: we will always execute this code at least once.
254 if (ss_number
< ss_names_count_
)
256 CosNaming
.NameComponent
[] ss_name_components_
= new CosNaming
.NameComponent
[1];
257 ss_name_components_
[0] = new CosNaming
.NameComponent (ss_names_
[ss_number
],"");
258 org
.omg
.CORBA
.Object scheduler_object_
= naming_context_
.resolve (ss_name_components_
);
260 if (scheduler_object_
== null)
262 throw new Object_is_null_exception(ss_names_
[ss_number
] +
266 scheduler_
= RtecScheduler
.SchedulerHelper
.narrow (scheduler_object_
);
268 if (scheduler_
== null)
270 throw new Object_is_null_exception(ss_names_
[ss_number
] +
271 " narrowed ref is null");
274 System
.out
.println ("Reference to " +
275 ss_names_
[ss_number
] + " is ok.");
280 // Get a reference for the next Event Service
282 CosNaming
.NameComponent
[] ec_name_components_
= new CosNaming
.NameComponent
[1];
283 ec_name_components_
[0] = new CosNaming
.NameComponent (ec_names_
[ec_number
],"");
284 org
.omg
.CORBA
.Object event_channel_object_
= naming_context_
.resolve (ec_name_components_
);
286 if (event_channel_object_
== null)
288 throw new Object_is_null_exception(ec_names_
[ec_number
] +
292 RtecEventChannelAdmin
.EventChannel event_channel_
=
293 RtecEventChannelAdmin
.EventChannelHelper
.narrow (event_channel_object_
);
295 if (event_channel_
== null)
297 throw new Object_is_null_exception(ec_names_
[ec_number
] +
298 " narrowed ref is null");
301 System
.out
.println ("Reference to " +
302 ec_names_
[ec_number
] + " is ok.");
304 // Start the consumer
305 System
.out
.println ("Instantiating the Push Consumer for " +
306 ec_names_
[ec_number
] + ": demo_consumer_" +
309 PushConsumer pushConsumer_
= new PushConsumer (orb_
, poa_
,
312 System
.out
.println ("Initializing the Push Consumer for " +
313 ec_names_
[ec_number
] + ": demo_consumer_" +
316 pushConsumer_
.open_consumer (event_channel_
, scheduler_
,
317 "demo_consumer_" + ec_number
);
321 // Tell the CORBA environment that we are ready
323 System
.out
.println ("PushConsumer registered with POA");
324 poa_
.the_POAManager ().activate ();
325 System
.out
.println ("POA Activated");
327 catch (CosNaming
.NamingContextPackage
.CannotProceed e
)
329 System
.err
.println ("CosNaming.NamingContextPackage.CannotProceed");
330 System
.err
.println (e
);
332 catch (CosNaming
.NamingContextPackage
.InvalidName e
)
334 System
.err
.println ("CosNaming.NamingContextPackage.InvalidName");
335 System
.err
.println (e
);
337 catch (CosNaming
.NamingContextPackage
.NotFound e
)
339 System
.err
.println ("CosNaming.NamingContextPackage.NotFound");
340 System
.err
.println (e
);
343 catch (org
.omg
.PortableServer
.POAManagerPackage
.AdapterInactive e
)
345 System
.err
.println ("org.omg.PortableServer.POAManagerPackage.AdapterInactive");
346 System
.err
.println (e
);
348 catch (Object_is_null_exception e
)
350 System
.err
.println (e
);
352 catch(org
.omg
.CORBA
.SystemException e
)
354 System
.err
.println ("PushConsumerFactory.run: Failure");
355 System
.err
.println(e
);
360 } // public class PushConsumerFactory