Search in sources :

Example 1 with Disconnected

use of org.omg.CosEventComm.Disconnected in project ACS by ACS-Community.

the class NCSubscriber method push_structured_event.

////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// Corba callback methods  ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
/**
	 * This method is called by the notification channel (supplier proxy) each time an event is received.
	 * <p>
	 * It is declared <code>final</code> because it is crucial for the functioning of the NC library
	 * and thus cannot be overwritten by a subclass. 
	 * If for special purposes a notification of raw event reception is needed, 
	 * a subclass can implement {@link #push_structured_event_called(StructuredEvent)}, which gets called from this
	 * method as the first thing it does. 
	 * @param structuredEvent
	 *            The structured event sent by a supplier.
	 * @throws Disconnected If this subscriber is disconnected from the NC. 
	 *         See NC spec 3.3.7.1: "if the invocation of push_structured_event upon a StructuredPushConsumer instance 
	 *         by a StructuredProxyPushSupplier instance results in the Disconnected exception being raised, 
	 *         the StructuredProxyPushSupplier will invoke its own disconnect_structured_push_supplier operation, 
	 *         resulting in the destruction of that StructuredProxyPushSupplier instance."
	 *         This serves only as a backup mechanism, since normally we explicitly disconnect the subscriber.
	 * 
	 * @see org.omg.CosNotifyComm.StructuredPushConsumerOperations#push_structured_event(org.omg.CosNotification.StructuredEvent)
	 */
@Override
public final void push_structured_event(StructuredEvent structuredEvent) throws Disconnected {
    boolean shouldProcessEvent = true;
    numEventsReceived++;
    try {
        shouldProcessEvent = push_structured_event_called(structuredEvent);
    } catch (Throwable thr) {
    // ignore any exception, since push_structured_event_called is only meant for 
    // notification, to enable special tests or other exotic purposes.
    // In this case we also keep shouldProcessEvent=true, just in case.
    // TODO: It may be better to treat the exception like shouldProcessEvent==false
    //       since non-struct event data will cause more errors further down.
    }
    // got a subclass 'veto'?
    if (!shouldProcessEvent) {
        if (firstSubclassVeto) {
            logger.info("Event subscriber '" + getClass().getSimpleName() + "' handles one or more raw NC events itself, bypassing base class '" + NCSubscriber.class.getName() + "'. This non-standard behavior will not be logged again by this NCSubscriber.");
            firstSubclassVeto = false;
        }
        return;
    }
    if (isDisconnected()) {
        throw new Disconnected();
    }
    Object convertedAny = anyAide.complexAnyToObject(structuredEvent.filterable_data[0].value);
    if (convertedAny == null) {
        // @TODO: compare with ACS-NC specs and C++ impl, and perhaps call generic receiver with null data,
        //        if the event does not carry any data.
        LOG_NC_EventReceive_FAIL.log(logger, channelName, getNotificationFactoryName(), structuredEvent.header.fixed_header.event_type.type_name, "null");
    } else {
        // then we don't put it into the queue. We could improve this by checking for registered receivers already here...
        if (!eventType.isInstance(convertedAny) && !hasGenericReceiver()) {
            logNoEventReceiver(convertedAny.getClass().getName());
        }
        EventDescription eventDesc = EventDescriptionHelper.extract(structuredEvent.remainder_of_body);
        if (isTraceEventsEnabled()) {
            LOG_NC_EventReceive_OK.log(logger, channelName, getNotificationFactoryName(), structuredEvent.header.fixed_header.event_type.type_name);
        }
        // let the base class deal with queue and dispatching to receiver
        processEventAsync(convertedAny, eventDesc);
    }
}
Also used : EventDescription(alma.acsnc.EventDescription) Disconnected(org.omg.CosEventComm.Disconnected)

Aggregations

EventDescription (alma.acsnc.EventDescription)1 Disconnected (org.omg.CosEventComm.Disconnected)1