use of org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class CorbaNotifyConsumerImpl method receiveEvents.
@Override
public int receiveEvents(NcEventSpec[] ncEventSpecs, int processingDelayMillis, int numberOfEvents) throws CouldntPerformActionEx {
if (receiveMethodCalled.getAndSet(true)) {
AcsJCouldntPerformActionEx ex = new AcsJCouldntPerformActionEx("Method receiveEvents can be called only once during the component lifecycle.");
throw ex.toCouldntPerformActionEx();
}
if (cancel) {
AcsJCouldntPerformActionEx ex = new AcsJCouldntPerformActionEx("Method receiveEvents cannot be called after interrupt / ncDisconnect.");
throw ex.toCouldntPerformActionEx();
}
m_logger.info("Will receive events on " + ncEventSpecs.length + " NC(s), with processingDelayMillis=" + processingDelayMillis + ", numberOfEvents=" + (numberOfEvents > 0 ? numberOfEvents : "infinite"));
// sync object used to wait for numberOfEvents (if specified)
if (numberOfEvents > 0) {
sharedEventCountdown = new CountDownLatch(numberOfEvents);
}
StopWatch sw = new StopWatch();
try {
// iterate over NCs
for (NcEventSpec ncEventSpec : ncEventSpecs) {
AcsEventSubscriber<IDLEntity> sub = subsOrPubs.get(ncEventSpec.ncName);
if (sub == null) {
throw new AcsJCouldntPerformActionEx("No subscriber available for NC '" + ncEventSpec.ncName + "'.");
}
// iterate over event types
for (String eventName : ncEventSpec.eventNames) {
sub.addSubscription(createEventHandler(eventName, ncEventSpec.antennaName, processingDelayMillis));
m_logger.info("Added subscription for event=" + eventName + ", NC=" + ncEventSpec.ncName);
}
sub.startReceivingEvents();
}
} catch (AcsJCouldntPerformActionEx ex) {
ex.printStackTrace();
throw ex.toCouldntPerformActionEx();
} catch (Exception ex) {
ex.printStackTrace();
throw new AcsJCouldntPerformActionEx(ex).toCouldntPerformActionEx();
}
m_logger.info(ncEventSpecs.length + " subscriber(s) set up to receive events, which took " + sw.getLapTimeMillis() + " ms.");
if (numberOfEvents > 0) {
m_logger.info("Will wait for a total of " + numberOfEvents + " events to be received, with timeout after 10 minutes.");
try {
boolean cleanTermination = sharedEventCountdown.await(10, TimeUnit.MINUTES);
if (cleanTermination) {
m_logger.info("Received the expected " + numberOfEvents + " events in " + sw.getLapTimeMillis() + " ms.");
} else {
m_logger.warning("Unforeseen termination of event suppliers after 10 min (timeout).");
cancel = true;
}
} catch (InterruptedException ex) {
cancel = true;
}
} else {
m_logger.info("Will return from receiveEvents now but will keep receiving events.");
}
if (cancel) {
throw new AcsJCouldntPerformActionEx("Event receiving was interrupted or failed otherwise.").toCouldntPerformActionEx();
} else {
long receptionTimeNanos = (numberOfEvents > 0 && firstEventReceivedTimeNanos.longValue() > 0 ? (System.nanoTime() - firstEventReceivedTimeNanos.longValue()) : -1);
return (int) TimeUnit.NANOSECONDS.toMillis(receptionTimeNanos);
}
}
use of org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class NCSubscriberTest method publish.
/*===================================*/
/* Support methods */
/*===================================*/
private void publish(int nEvents, EventType type) {
IDLEntity event = null;
if (type.equals(EventType.statusBlock1)) {
event = new statusBlockEvent1();
((statusBlockEvent1) event).counter1 = 0;
((statusBlockEvent1) event).counter2 = 0;
((statusBlockEvent1) event).flipFlop = true;
((statusBlockEvent1) event).onOff = alma.ADMINTEST1.OnOffStates.ON;
} else if (type.equals(EventType.statusBlock2)) {
event = new statusBlockEvent2();
((statusBlockEvent2) event).counter1 = 0;
((statusBlockEvent2) event).counter2 = 0;
((statusBlockEvent2) event).flipFlop = true;
((statusBlockEvent2) event).onOff = alma.ADMINTEST2.OnOffStates.ON;
}
try {
for (int i = 0; i != nEvents; i++) m_publisher.publishEvent(event);
} catch (AcsJException e) {
e.printStackTrace();
}
}
use of org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class Consumer method push_structured_event.
/**
* As of ACS 3.0, override {@link #processEvent(Object)} instead of this
* CORBA method. push_structured_event is what is called each time an event
* is received. <b>Do not call it from your code!</b>
*
* @param structuredEvent
* The structured event sent by a supplier subclass.
* @throws org.omg.CosEventComm.Disconnected
*/
public void push_structured_event(StructuredEvent structuredEvent) throws org.omg.CosEventComm.Disconnected {
// time to get the event description
final EventDescription eDescrip = EventDescriptionHelper.extract(structuredEvent.remainder_of_body);
Object convertedAny = m_anyAide.complexAnyToObject(structuredEvent.filterable_data[0].value);
IDLEntity struct = null;
try {
struct = (IDLEntity) convertedAny;
if (isTraceEventsEnabled) {
m_logger.log(Level.INFO, "Channel:" + m_channelName + ", Publisher:" + eDescrip.name + ", Event Type:" + structuredEvent.header.fixed_header.event_type.type_name);
}
} catch (ClassCastException ex) {
if (isTraceEventsEnabled && convertedAny != null) {
m_logger.log(Level.INFO, "Channel:" + m_channelName + ", Publisher:" + eDescrip.name + ", Event Type:" + structuredEvent.header.fixed_header.event_type.type_name + ". Failed to convert event data of type '" + convertedAny.getClass().getName() + "' which is not derived from an IDL-defined struct.");
}
}
if (struct != null) {
// process the extracted data in a separate thread
final IDLEntity structToProcess = struct;
// to avoid unnecessary scary logs, we tolerate previous events up to half the queue size
boolean isReceiverBusyWithPreviousEvent = (eventHandlingExecutor.getQueue().size() > EVENT_QUEUE_CAPACITY / 2);
// m_logger.info("Queue size: " + eventHandlingExecutor.getQueue().size());
boolean thisEventDiscarded = false;
try {
eventHandlingExecutor.execute(new Runnable() {
public void run() {
// here we call processEvent from the worker thread
processEvent(structToProcess, eDescrip);
}
});
} catch (RejectedExecutionException ex) {
// receivers have been too slow, queue is full, will drop data.
thisEventDiscarded = true;
numEventsDiscarded++;
}
if ((thisEventDiscarded || isReceiverBusyWithPreviousEvent) && receiverTooSlowLogRepeatGuard.checkAndIncrement()) {
LOG_NC_ReceiverTooSlow.log(m_logger, m_clientName, numEventsDiscarded, struct.getClass().getName(), m_channelName, getNotificationFactoryName());
numEventsDiscarded = 0;
}
} else {
// Should compare this with specs and C++ impl
if (isTraceEventsEnabled) {
m_logger.info("Will ignore event of type " + structuredEvent.header.fixed_header.event_type.type_name + " which has no data attached.");
}
}
}
use of org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class EventSupplierImpl method initialize.
/**
* Sets up the AcsEventPublisher.
*/
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
super.initialize(containerServices);
try {
// Instantiate our supplier
m_supplier = containerServices.createNotificationChannelPublisher(alma.FRIDGE.CHANNELNAME_FRIDGE.value, IDLEntity.class);
// enable event queue and register callback handler, just to demonstrate how this is done
AcsEventPublisher.EventProcessingHandler<IDLEntity> cbHandler = new EventProcessingCallbackImpl();
m_supplier.enableEventQueue(100, cbHandler);
} catch (Exception e) {
throw new ComponentLifecycleException("failed to create AcsEventPublisher for channel " + alma.FRIDGE.CHANNELNAME_FRIDGE.value, e);
}
}
use of org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class CorbaNotifySupplierImpl method createTestEvent.
/**
* Factory method for event data that will be sent to the NCs.
* @param eventName
* @param antennaName Only used for eventName == MountStatusData or LightweightMountStatusData
* @return
* @throws IllegalArgumentException
*/
protected IDLEntity createTestEvent(String eventName, String antennaName) {
IDLEntity ret = null;
String antennaNameToSet = (antennaName != null && !antennaName.isEmpty() ? antennaName : "unknown");
if (eventName.equals("MountStatusData")) {
MountStatusData data = new MountStatusData();
data.antennaName = antennaNameToSet;
// @TODO set some of the boolean / double fields
ret = data;
} else if (eventName.equals("LightweightMountStatusData")) {
LightweightMountStatusData data = new LightweightMountStatusData();
data.antennaName = antennaNameToSet;
ret = data;
} else if (eventName.equals("SomeOtherEventType")) {
SomeOtherEventType data = new SomeOtherEventType();
ret = data;
} else // @TODO Add support for more event types as needed
{
throw new IllegalArgumentException("Unsupported event type '" + eventName + "'.");
}
return ret;
}
Aggregations