// Get reference to Time Service
CosTime::TimeService_var time_svc = CosTime::TimeService::_bind("VBTimeService");
// Get reference to Timer Event Service
CosTimerEvent::TimerEventService_var timer_svc =
CosTimerEvent::TimerEventService::_bind
("VBTimerEventService");org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
// Get reference to Time Service
org.omg.CosTime.TimeService timeSvc =
org.omg.CosTime.TimeServiceHelper.bind(orb,
"VBTimeService");
// Get reference to Timer Event Service
org.omg.CosTimerEvent.TimerEventService timerSvc =
org.omg.CosTimerEvent.TimerEventServiceHelper.bind(orb,
"VBTimerEventService");Regardless of whether the Time Service is using in-process or out-of-process execution mode, user applications will use orb.resolve_initial_references("CosTimeService") and orb.resolve_initial_references("CosTimerEventService") to obtain initial references to the Time Service and Timer Event Service respectively. There would be a difference in the bootstrapping mechanism for in-process and remote Time Service respectively. User applications should not specify the ORBInitRef property with in-process Time Service. Instead, they must enable the VisiBroker property vbroker.time.enableInProc=true. If ORBInitRef is used together with vbroker.time.enableInProc=true, only ORBInitRef will take effect.The value for the vbroker.time.ntp.addr can be one or a sequence of comma-separated strings representing the NTP Server addresses. Both IPv4 and IPv6 format addresses can be specified as well. For example, consider three NTP server addresses given here:The first address, foo.com, relies on the internal DNS lookup. Since no port is specified, the default NTP port 123 is used. The second entry, [fe220::103:baaa:fbbb:fedf]:123, is an IPv6 format address enclosed in square brackets. Here, the port is defined specifically as 123. The final entry, 101.121.145.100:124 is the familiar IPv4 format, with the port number 124 specified as well.The VisiTime Service will first try to contact the first NTP Server in the sequence. If the address is valid and the server is available, the time of the NTP Server will be returned to the caller. Assuming that the first server in the list was not available, the implementation will transparently fail over to the second in the list and so on until it retrieves the required time value from one of the Server in the list. If all of the Servers are unreachable, VisiTime Service will throw an exception to the caller. Depending on the method called, the exception can be either CosTime::TimeUnavailable or a CORBA system exception such as COMM_FAILURE.
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
//Resolve the TimeService interface
CORBA::Object_var obj_t = orb->resolve_initial_references("CosTimeService");
//Narrow the TimeService interface
CosTime::TimeService_var time_svc = CosTime::TimeService::_narrow (obj_t.in());import org.omg.CORBA.ORB;
import org.omg.CosTime.*;
...
//Initialize the ORB
ORB orb = ORB.init(args, null);
//Resolve the TimeService interface
org.omg.CORBA.Object obj = orb.resolve_initial_references("CosTimeService");
//Narrow it properly using the Helper
TimeService timeService = TimeServiceHelper.narrow(obj);Once you have resolved to and narrowed the TimeService interface, you can use it to create UTOs and TIOs.Use the TimeService method universal_time() to create a Universal Time Object containing the current time. For example,creates a Universal Time Object uto whose time value is the current time at the execution of the method.You can also create a UTO containing a relative time of your choosing (not obtained using a Time Source) using the new_universal_time method. You provide three arguments to this method:
((CORBA::ULongLong)10000000,0,(CORBA::Short)0);You can create TIOs using the TimeService interface. The new_interval method takes two arguments of type CORBA::ULongLong (C++) or long (Java), which are the bounds of the time interval expressed as hundreds of nanoseconds since base time. For example://Create a TIO that represents a specific interval
CosTime::TIO_var tio =
time_svc->new_interval((CORBA::ULongLong)10000000,
(CORBA::ULongLong)20000000);//Create a TIO that represents a interval TIO tio
= _timeService.new_interval(10000000L, 20000000L);This section explains how to resolve to a Timer Event Service, obtain TimerEventHandlers, set alarms using the TimerEventHandlers, cancel an alarm that was previously set, and unregister a TimerEventHandler.Before creating and utilizing TimerEventHandlers, you must resolve to the Timer Event Service itself, as well as the ORB's standard Event Service providing the PushConsumer object. For example://Initialize the ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
//Resolve the TimerEventService
CORBA::Object_var obj_t = orb->resolve_initial_references("CosTimerEventService");
CosTime::TimerEventService_var time_evsvc =
CosTime:: TimerEventService::_narrow (obj_t.in());
//Resolve to the EventService
CORBA::Object_var obj_ev = orb->resolve_initial_references("EventService");
CosEventChannelAdmin::EventChannel_var channel =
CosEventChannelAdmin::EventChannel::_narrow(obj_ev.in());import org.omg.CORBA.*;
import org.omg.CosEventComm.*;
import org.omg.CosEventChannelAdmin.*;
import org.omg.CosTime.*;
import org.omg.CosTimerEvent.*;
import org.omg.TimeBase.*;
...
//Initialize the ORB
ORB orb = ORB.init(args, null);
//Resolve the TimerEventService
TimerEventService timerEventService=TimerEventServiceHelper.narrow(
_orb.resolve_initial_references("CosTimerEventService"));
//Resolve to the EventService
EventChannel channel =
EventChannelHelper.narrow(_orb.resolve_initial_references("EventService"));The Timer Event Service provides an operation to register a CosEventComm::PushConsumer together with a CORBA::Any that provides event data. Internally, an instance of TimerEventHandler is created, with which the event data and PushConsumer are associated. You can at any point change the event data, but the PushConsumer is immutably associated with the TimerEventHandler and cannot be changed.