Back to Timer Event Service Examples Page
From this example, you will learn how to:
main creates a new instance of the class,
initialises it using the init method, and
connects it to an EventChannel using the connect method.
init performs the initialisation
necessary to run the example by obtaining references to the ORB,
Notification Service, Naming Service and Timer Event Service.
This method also writes the transient object reference for the
TimerEventConsumer object to the Naming Service.
connect connects the push consumer
to the Notification service. This method uses the
getEventChannel and getSupplier
methods to obtain the ProxyPushSupplier to connect
this consumer to.
push prints out the details of a
given event. The consumer receives events using the push
method.
getEventChannel is a utility method
that returns the event channel with id 0 from the Notification
Service if it is present and creates a new event
channel if it is not present.
getSupplier creates a new
ProxyPushSupplier on an event channel.
getNotificationServer is a utility
method that returns a reference to the Notification Service.
getNameServer is a utility
method that returns a reference to the Naming Service.
getTimerEventServer is a utility
method that returns a reference to the Timer Event Service.
writeIOR writes the reference to
this consumer object to the Naming Service.
disconnect_push_consumer is required
to be present in a PushConsumer but is not implemented as it is
not used in this example.
connect_push_consumer is required
to be present in a PushConsumer but is not implemented as it is
not used in this example.
offer_change is required
to be present in a PushConsumer but is not implemented as it is
not used in this example.
main
creates a new instance of the class,
initialises it using the init method, and
runs the example using the go method.
init performs the initialisation
necessary to run the example by obtaining references to the ORB,
Time Service, Naming Service, and Timer Event Service.
go method
obtains a push consumer using the
getPushConsumer method,
creates an Any object which is to be sent
as an event,
registers the consumer and event with the
TimerEventService, and obtains a handler.
The method
sends events using
absolute timer (the sendAbsoluteEvent method),
relative timer (the sendRelativeeEvent method), and
periodic timer (the sendPeriodicEvent method).
The method then unregisters the handler.
getPushConsumer obtains a reference
to the consumer that was written to the Naming Service
by the TimerEventConsumer part of this example.
sendAbsoluteEvent sets up a timed
event to be sent at an absolute time which is calculated to be
five seconds into the future. The method then sleeps for seven
seconds until after the event should have been sent. The
status of the handler is checked before and after the time is
set, and after the event has been sent.
sendRelativeEvent sets up a timed
event to be sent in five seconds time. The method then sleeps
for seven seconds until after the event should have been
sent. The status of the handler is checked before and after
the time is set, and after the event has been sent.
sendPeriodicEvent sets up a timed
event to be sent every two seconds. The method then sleeps for
seven seconds until the event should have been sent three
times. The data associated with the event is then changed. The
method then sleeps for eight seconds until the event, with the
changed data, should have been sent four times. The timed
event is then canceled and the method sleeps for four seconds
during which no further events should be sent. The status of
the handler is checked at several points in this process.
printDetails is a utility method
that prints details of a TimerEventHandler.
getNameServer is a utility method to
obtain a reference to the Naming Service.
getTimeServer is a utility method to
obtain a reference to the Time Service.
getTimerEventServer is a utility
method to obtain a reference to the Timer Event Service.
To run the example, first make sure that the OpenFusion Time, Notification and Naming Services are running on your network.
If using an ORB which requires persistent POAs to be registered before they
can be activated, ensure that the OpenFusion.TimerEventConsumer
POA is registered.
run com.prismt.cos.CosTime.examples.Event.TimerEventConsumer -ior iorfile
run com.prismt.cos.CosTime.examples.Event.EventExample -ior iorfile
After the EventExample has completed, the TimerEventConsumer can be terminated.