Search in sources :

Example 1 with PendingPollEvent

use of org.opennms.netmgt.poller.pollables.PendingPollEvent in project opennms by OpenNMS.

the class DefaultPollContext method onEvent.

/* (non-Javadoc)
     * @see org.opennms.netmgt.eventd.EventListener#onEvent(org.opennms.netmgt.xml.event.Event)
     */
/** {@inheritDoc} */
@Override
public void onEvent(final Event event) {
    if (LOG.isDebugEnabled()) {
        // CAUTION: m_pendingPollEvents.size() is not a constant-time operation
        LOG.debug("onEvent: Received event: {} uei: {}, dbid: {}, pendingEventCount: {}", event, event.getUei(), event.getDbid(), m_pendingPollEvents.size());
    }
    for (final PendingPollEvent pollEvent : m_pendingPollEvents) {
        LOG.trace("onEvent: comparing event to pollEvent: {}", pollEvent);
        // identical.
        if (event.equals(pollEvent.getEvent())) {
            LOG.trace("onEvent: found matching pollEvent, completing pollEvent: {}", pollEvent);
            // Thread-safe and idempotent
            pollEvent.complete(event);
        // TODO: Can we break here? I think there should only be one 
        // instance of any given event in m_pendingPollEvents
        // break;
        }
    }
    for (final Iterator<PendingPollEvent> it = m_pendingPollEvents.iterator(); it.hasNext(); ) {
        final PendingPollEvent pollEvent = it.next();
        LOG.trace("onEvent: determining if pollEvent is pending: {}", pollEvent);
        if (!pollEvent.isPending()) {
            try {
                // Thread-safe and idempotent
                processPending(pollEvent);
            } catch (Throwable e) {
                LOG.error("Unexpected exception while processing pollEvent: " + pollEvent, e);
            }
            // TODO: Should we remove the task before processing it? This would
            // reduce the chances that two threads could process the same event
            // simultaneously, although since the call is now thread-safe and
            // idempotent, that's not really a problem.
            it.remove();
            continue;
        }
    // If the event was not completed and it is still pending, then don't do anything to it
    }
    LOG.debug("onEvent: Finished processing event: {} uei: {}, dbid: {}", event, event.getUei(), event.getDbid());
}
Also used : PendingPollEvent(org.opennms.netmgt.poller.pollables.PendingPollEvent)

Example 2 with PendingPollEvent

use of org.opennms.netmgt.poller.pollables.PendingPollEvent in project opennms by OpenNMS.

the class MockPollContext method onEvent.

@Override
public synchronized void onEvent(Event e) {
    synchronized (m_pendingPollEvents) {
        for (PendingPollEvent pollEvent : m_pendingPollEvents) {
            if (e.equals(pollEvent.getEvent())) {
                pollEvent.complete(e);
            }
        }
        for (Iterator<PendingPollEvent> it = m_pendingPollEvents.iterator(); it.hasNext(); ) {
            PendingPollEvent pollEvent = it.next();
            if (pollEvent.isPending()) {
                break;
            }
            pollEvent.processPending();
            it.remove();
        }
    }
}
Also used : PendingPollEvent(org.opennms.netmgt.poller.pollables.PendingPollEvent)

Example 3 with PendingPollEvent

use of org.opennms.netmgt.poller.pollables.PendingPollEvent in project opennms by OpenNMS.

the class DefaultPollContext method sendEvent.

/* (non-Javadoc)
     * @see org.opennms.netmgt.poller.pollables.PollContext#sendEvent(org.opennms.netmgt.xml.event.Event)
     */
/** {@inheritDoc} */
@Override
public PollEvent sendEvent(Event event) {
    if (!m_listenerAdded) {
        getEventManager().addEventListener(this, Arrays.asList(UEIS));
        m_listenerAdded = true;
    }
    PendingPollEvent pollEvent = new PendingPollEvent(event);
    m_pendingPollEvents.add(pollEvent);
    //log().info("Sending "+event.getUei()+" for element "+event.getNodeid()+":"+event.getInterface()+":"+event.getService(), new Exception("StackTrace"));
    getEventManager().sendNow(event);
    return pollEvent;
}
Also used : PendingPollEvent(org.opennms.netmgt.poller.pollables.PendingPollEvent)

Example 4 with PendingPollEvent

use of org.opennms.netmgt.poller.pollables.PendingPollEvent in project opennms by OpenNMS.

the class MockPollContext method sendEvent.

@Override
public PollEvent sendEvent(Event event) {
    PendingPollEvent pollEvent = new PendingPollEvent(event);
    synchronized (this) {
        m_pendingPollEvents.add(pollEvent);
    }
    m_eventMgr.sendNow(event);
    return pollEvent;
}
Also used : PendingPollEvent(org.opennms.netmgt.poller.pollables.PendingPollEvent)

Aggregations

PendingPollEvent (org.opennms.netmgt.poller.pollables.PendingPollEvent)4