Search in sources :

Example 1 with IDLEntity

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);
    }
}
Also used : AcsJCouldntPerformActionEx(alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx) NcEventSpec(alma.benchmark.NcEventSpec) IDLEntity(org.omg.CORBA.portable.IDLEntity) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(alma.acs.util.StopWatch)

Example 2 with IDLEntity

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();
    }
}
Also used : ADMINTEST2.statusBlockEvent2(alma.ADMINTEST2.statusBlockEvent2) ADMINTEST1.statusBlockEvent1(alma.ADMINTEST1.statusBlockEvent1) AcsJException(alma.acs.exceptions.AcsJException) IDLEntity(org.omg.CORBA.portable.IDLEntity)

Example 3 with IDLEntity

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.");
        }
    }
}
Also used : IDLEntity(org.omg.CORBA.portable.IDLEntity) EventDescription(alma.acsnc.EventDescription) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 4 with IDLEntity

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);
    }
}
Also used : AcsEventPublisher(alma.acs.nc.AcsEventPublisher) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) IDLEntity(org.omg.CORBA.portable.IDLEntity) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) AcsJException(alma.acs.exceptions.AcsJException)

Example 5 with IDLEntity

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;
}
Also used : LightweightMountStatusData(alma.benchmark.LightweightMountStatusData) MountStatusData(alma.benchmark.MountStatusData) SomeOtherEventType(alma.benchmark.SomeOtherEventType) IDLEntity(org.omg.CORBA.portable.IDLEntity) LightweightMountStatusData(alma.benchmark.LightweightMountStatusData)

Aggregations

IDLEntity (org.omg.CORBA.portable.IDLEntity)9 AcsJException (alma.acs.exceptions.AcsJException)3 ComponentLifecycleException (alma.acs.component.ComponentLifecycleException)2 EventDescription (alma.acsnc.EventDescription)2 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)1 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)1 AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)1 ADMINTEST1.statusBlockEvent1 (alma.ADMINTEST1.statusBlockEvent1)1 ADMINTEST2.statusBlockEvent2 (alma.ADMINTEST2.statusBlockEvent2)1 ThreadBurstExecutorService (alma.acs.concurrent.ThreadBurstExecutorService)1 AcsLogLevel (alma.acs.logging.AcsLogLevel)1 AcsEventPublisher (alma.acs.nc.AcsEventPublisher)1 AcsEventSubscriber (alma.acs.nc.AcsEventSubscriber)1 StopWatch (alma.acs.util.StopWatch)1 AcsJPublishEventFailureEx (alma.acsncErrType.wrappers.AcsJPublishEventFailureEx)1 LightweightMountStatusData (alma.benchmark.LightweightMountStatusData)1 MountStatusData (alma.benchmark.MountStatusData)1 NcEventSpec (alma.benchmark.NcEventSpec)1 SomeOtherEventType (alma.benchmark.SomeOtherEventType)1 CountDownLatch (java.util.concurrent.CountDownLatch)1