From 5a453f19a9723251f7ddb373d45bfdb19e3944cf Mon Sep 17 00:00:00 2001 From: mk1 Date: Thu, 16 Apr 1998 01:16:41 +0000 Subject: Wed Apr 15 20:20:58 1998 Michael Kircher --- TAO/ChangeLog-98c | 6 + .../Simulator/DOVEBrowser/PushConsumer.java.JDK1.2 | 200 +++++++++++++++++++++ .../DOVEBrowser/PushConsumerFactory.java.JDK1.2 | 187 +++++++++++++++++++ 3 files changed, 393 insertions(+) create mode 100644 TAO/examples/Simulator/DOVEBrowser/PushConsumer.java.JDK1.2 create mode 100644 TAO/examples/Simulator/DOVEBrowser/PushConsumerFactory.java.JDK1.2 diff --git a/TAO/ChangeLog-98c b/TAO/ChangeLog-98c index 860ba8e1e77..5c59c952836 100644 --- a/TAO/ChangeLog-98c +++ b/TAO/ChangeLog-98c @@ -1,3 +1,9 @@ +Wed Apr 15 20:20:58 1998 Michael Kircher + + * orbsvcs/tests/Simulator/DOVEBrowser/PushConsumer{Factory}.java.JDK1.2 + added these two files, they can be used by the JDK 1.2 instead + of by the Visigenic ORB. + Wed Apr 15 15:59:58 1998 Aniruddha Gokhale * TAO/tao/append.cpp: Added a bunch of methods that take a CDR diff --git a/TAO/examples/Simulator/DOVEBrowser/PushConsumer.java.JDK1.2 b/TAO/examples/Simulator/DOVEBrowser/PushConsumer.java.JDK1.2 new file mode 100644 index 00000000000..a780b25af54 --- /dev/null +++ b/TAO/examples/Simulator/DOVEBrowser/PushConsumer.java.JDK1.2 @@ -0,0 +1,200 @@ +// $Id$ +// +// ============================================================================ +// +// +// = FILENAME +// PushConsumer.java +// +// = AUTHOR +// Michael Kircher (mk1@cs.wustl.edu) +// +// = DESCRIPTION +// This is a Push Consumer which takes the data field of the +// event and updates with it a Data Handler. +// +// +// ============================================================================ + + + +// The Consumer has to implement the Skeleton Consumer + +public class PushConsumer extends RtecEventComm._PushConsumerImplBase +{ + + public static final int ACE_ES_EVENT_ANY = 0; + public static final int ACE_ES_EVENT_SHUTDOWN = 1; + public static final int ACE_ES_EVENT_ACT = 2; + public static final int ACE_ES_EVENT_NOTIFICATION = 3; + public static final int ACE_ES_EVENT_TIMEOUT = 4; + public static final int ACE_ES_EVENT_INTERVAL_TIMEOUT = 5; + public static final int ACE_ES_EVENT_DEADLINE_TIMEOUT = 6; + public static final int ACE_ES_GLOBAL_DESIGNATOR = 7; + public static final int ACE_ES_CONJUNCTION_DESIGNATOR = 8; + public static final int ACE_ES_DISJUNCTION_DESIGNATOR = 9; + public static final int ACE_ES_EVENT_UNDEFINED = 16; + public static final int TOTAL_MESSAGES = 30; + + // Store the number of received events + private int total_received_ = 0; + private org.omg.CORBA.ORB orb_; + private DataHandler dataHandler_; + private int rt_info_; + private RtecEventChannelAdmin.EventChannel channel_admin_; + private RtecEventChannelAdmin.ConsumerAdmin consumer_admin_; + private RtecEventChannelAdmin.ProxyPushSupplier suppliers_; + + public PushConsumer (org.omg.CORBA.ORB orb, DataHandler dataHandler) + { + orb_ = orb; + dataHandler_ = dataHandler; + } + + + public void push (RtecEventComm.Event[] events) + { + if (total_received_ < 5) + System.out.println ("Demo Consumer: Received an event! ->Number: " + total_received_); + else if (total_received_ == 5) + System.out.println ("Demo Consumer: Everything is fine. Going to be mute."); + + + if (events.length == 0) + { + System.err.println ("No events"); + } + else + { + total_received_++; + + for (int i = 0; i < events.length; ++i) + { + if(events[i].type_ == ACE_ES_EVENT_NOTIFICATION) + { + try + { + dataHandler_.update (events[i].data_.any_value); + } + catch(org.omg.CORBA.SystemException e) + { + System.err.println(e); + } + } + } + } + } + + public void disconnect_push_consumer() + { + System.out.println ("Demo Consumer: Have to disconnect!"); + } + + public void open_consumer (RtecEventChannelAdmin.EventChannel event_channel_, + RtecScheduler.Scheduler scheduler_, + String name) + { + + try + { + + // Define Real-time information + + rt_info_ = scheduler_.create (name); + + scheduler_.set (rt_info_, + RtecScheduler.Criticality.VERY_LOW_CRITICALITY, + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + 2500000, // period + RtecScheduler.Importance.VERY_LOW_IMPORTANCE, + new TimeBase.ulonglong (0,0), + 1, + RtecScheduler.Info_Type.OPERATION); + + + // Register for Notification and Shutdown events + + + RtecEventComm.Event disjunction_designator_ = + new RtecEventComm.Event (ACE_ES_DISJUNCTION_DESIGNATOR, 0, + 1, // ttl + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + new RtecEventComm.EventData (0, 0, orb_.create_any()) + ); + RtecEventComm.Event notification_event_ = + new RtecEventComm.Event (ACE_ES_EVENT_NOTIFICATION, 0, + 1, // ttl + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + new RtecEventComm.EventData (0, 0, orb_.create_any()) + ); + RtecEventComm.Event shutdown_event_ = + new RtecEventComm.Event (ACE_ES_EVENT_SHUTDOWN, 0, + 1, // ttl + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + new TimeBase.ulonglong (0,0), + new RtecEventComm.EventData (0, 0, orb_.create_any()) + ); + + + RtecEventChannelAdmin.Dependency dependencies_[] = new RtecEventChannelAdmin.Dependency[3]; + dependencies_[0] = new RtecEventChannelAdmin.Dependency (disjunction_designator_, rt_info_); + dependencies_[1] = new RtecEventChannelAdmin.Dependency (notification_event_, rt_info_); + dependencies_[2] = new RtecEventChannelAdmin.Dependency (shutdown_event_, rt_info_); + + + + RtecEventChannelAdmin.ConsumerQOS qos = new RtecEventChannelAdmin.ConsumerQOS (dependencies_); + + + // The channel administrator is the event channel we got from the invocation + // of this routine + + channel_admin_ = event_channel_; + + // Connect as a consumer + + consumer_admin_ = channel_admin_.for_consumers (); + + // Obtain a reference to the proxy push supplier + + suppliers_ = consumer_admin_.obtain_push_supplier (); + + suppliers_.connect_push_consumer (this, qos); + + System.out.println ("Registered the consumer successfully."); + + + } + catch (RtecScheduler.UNKNOWN_TASK e) + { + System.err.println ("Demo_Consumer.open_consumer: Unknown task"); + System.err.println (e); + } + catch (RtecScheduler.DUPLICATE_NAME e) + { + System.err.println ("Demo_Consumer.open_consumer: Duplicate names"); + System.err.println (e); + } + catch(org.omg.CORBA.SystemException e) + { + System.err.println(e); + } + } +} + + + + + + + + + + diff --git a/TAO/examples/Simulator/DOVEBrowser/PushConsumerFactory.java.JDK1.2 b/TAO/examples/Simulator/DOVEBrowser/PushConsumerFactory.java.JDK1.2 new file mode 100644 index 00000000000..02aec1452ce --- /dev/null +++ b/TAO/examples/Simulator/DOVEBrowser/PushConsumerFactory.java.JDK1.2 @@ -0,0 +1,187 @@ +// $Id$ +// +// ============================================================================ +// +// = FILENAME +// PushConsumerFactory.java +// +// = AUTHOR +// Michael Kircher (mk1@cs.wustl.edu) +// +// = DESCRIPTION +// This is the administor/factory for a PushConsumer. +// +// ============================================================================ + + + + +public class PushConsumerFactory { + + private org.omg.CORBA.ORB orb_; + private org.omg.CORBA.Object naming_service_object_; + + private DataHandler dataHandler_; + private Navigation navigation_; + private Weapons weapons_; + + + public PushConsumerFactory (DataHandler dataHandler, + String nameServiceIOR, + String[] args, + java.applet.Applet applet) + { + try { + dataHandler_ = dataHandler; + + // if the DOVE Browser is running as an Applet + if (applet != null) { + orb_ = org.omg.CORBA.ORB.init (applet, null); + } + else { // not running as an Applet, but as an normal Application + orb_ = org.omg.CORBA.ORB.init (args, null); + } + // @@ no more boa_init + + // Get the Naming Service initial reference + + // Name Service Lookup cannot be used when running as an Applet + if (nameServiceIOR == null && applet != null) { + System.out.println (" Name Service Lookup cannot be used when running as an Applet! Quit!"); + System.exit (1); + } + + if (nameServiceIOR == null) { // only used when running via "java" or "vbj" + System.out.println ("Using the lookup protocol!"); + NS_Resolve ns_resolve_ = new NS_Resolve (); + naming_service_object_ = ns_resolve_.resolve_name_service (orb_); + } + else { + System.out.println ("Using the following IOR: " + nameServiceIOR); + naming_service_object_ = orb_.string_to_object (nameServiceIOR); + } + + } + catch(org.omg.CORBA.SystemException e) { + System.err.println ("PushConsumerFactory constructor: ORB and Name Service initialization"); + System.err.println(e); + } + + } + + public class Object_is_null_exception extends Exception + { + Object_is_null_exception (String s) + { + super (s); + } + } + + public void run () + { + try + { + + // Get the Naming Context to allow resolving the EventService and + // ScheduleService + CosNaming.NamingContext naming_context_ = + CosNaming.NamingContextHelper.narrow (naming_service_object_); + + if (naming_context_ == null) + { + System.err.println ("The Naming Context is null"); + System.exit (1); + } + System.out.println ("Reference to the Naming Service is ok."); + + // Get a reference for the EventService + + CosNaming.NameComponent[] ec_name_components_ = new CosNaming.NameComponent[1]; + ec_name_components_[0] = new CosNaming.NameComponent ("EventService",""); + org.omg.CORBA.Object event_channel_object_ = naming_context_.resolve (ec_name_components_); + + if (event_channel_object_ == null) + { + throw new Object_is_null_exception("EventService Object is null"); + } + + RtecEventChannelAdmin.EventChannel event_channel_ = + RtecEventChannelAdmin.EventChannelHelper.narrow (event_channel_object_); + + System.out.println ("Reference to the Event Service is ok."); + + // Get a reference for the ScheduleService + + CosNaming.NameComponent[] s_name_components_ = new CosNaming.NameComponent[1]; + s_name_components_[0] = new CosNaming.NameComponent ("ScheduleService",""); + org.omg.CORBA.Object scheduler_object_ = naming_context_.resolve (s_name_components_); + + if (scheduler_object_ == null) + { + throw new Object_is_null_exception("ScheduleService Object is null"); + } + + RtecScheduler.Scheduler scheduler_ = + RtecScheduler.SchedulerHelper.narrow (scheduler_object_); + + System.out.println ("Reference to the Naming Service is ok."); + + + // Start the consumer + System.out.println ("Instantiating the Push Consumer."); + PushConsumer pushConsumer_ = new PushConsumer (orb_, dataHandler_); + System.out.println ("Initializing the Push Consumer."); + pushConsumer_.open_consumer (event_channel_, scheduler_, "demo_consumer"); + + // Tell the CORBA environment that we are ready + + // @@ no more impl_is ready + orb_.connect (pushConsumer_); + + System.out.println ("boa.obj_is_ready succeeded"); + + // no more orb. run + java.lang.Object sync = new java.lang.Object(); + synchronized (sync) { + sync.wait(); + } + } + catch (java.lang.InterruptedException e) + { + + } + catch (CosNaming.NamingContextPackage.CannotProceed e) + { + System.err.println ("CosNaming.NamingContextPackage.CannotProceed"); + System.err.println (e); + } + catch (CosNaming.NamingContextPackage.InvalidName e) + { + System.err.println ("CosNaming.NamingContextPackage.InvalidName"); + System.err.println (e); + } + catch (CosNaming.NamingContextPackage.NotFound e) + { + System.err.println ("CosNaming.NamingContextPackage.NotFound"); + System.err.println (e); + } + catch (Object_is_null_exception e) + { + System.err.println (e); + } + catch(org.omg.CORBA.SystemException e) + { + System.err.println ("PushConsumerFactory.run: Failure"); + System.err.println(e); + } + } + + +} // public class PushConsumerFactory + + + + + + + -- cgit v1.2.1