Search in sources :

Example 1 with MonitoringException

use of org.talend.esb.sam.common.event.MonitoringException in project tesb-rt-se by Talend.

the class MonitoringServiceWrapper method putEvents.

/**
 * Sends all events to the web service. Events will be transformed with mapper before sending.
 *
 * @param events the events
 */
public void putEvents(List<Event> events) {
    Exception lastException;
    List<EventType> eventTypes = new ArrayList<EventType>();
    for (Event event : events) {
        EventType eventType = EventMapper.map(event);
        eventTypes.add(eventType);
    }
    int i = 0;
    lastException = null;
    while (i < numberOfRetries) {
        try {
            monitoringService.putEvents(eventTypes);
            break;
        } catch (Exception e) {
            lastException = e;
            i++;
        }
        if (i < numberOfRetries) {
            try {
                Thread.sleep(delayBetweenRetry);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
    if (i == numberOfRetries) {
        throw new MonitoringException("1104", "Could not send events to monitoring service after " + numberOfRetries + " retries.", lastException, events);
    }
}
Also used : EventType(org.talend.esb.sam._2011._03.common.EventType) MonitoringException(org.talend.esb.sam.common.event.MonitoringException) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event) MonitoringException(org.talend.esb.sam.common.event.MonitoringException)

Example 2 with MonitoringException

use of org.talend.esb.sam.common.event.MonitoringException in project tesb-rt-se by Talend.

the class EventCollector method sendEventsFromQueue.

/**
 * Method will be executed asynchronously.
 */
public void sendEventsFromQueue() {
    if (null == queue || stopSending) {
        return;
    }
    LOG.fine("Scheduler called for sending events");
    int packageSize = getEventsPerMessageCall();
    while (!queue.isEmpty()) {
        final List<Event> list = new ArrayList<Event>();
        int i = 0;
        while (i < packageSize && !queue.isEmpty()) {
            Event event = queue.remove();
            if (event != null && !filter(event)) {
                list.add(event);
                i++;
            }
        }
        if (list.size() > 0) {
            executor.execute(new Runnable() {

                public void run() {
                    try {
                        sendEvents(list);
                    } catch (MonitoringException e) {
                        e.logException(Level.SEVERE);
                    }
                }
            });
        }
    }
}
Also used : MonitoringException(org.talend.esb.sam.common.event.MonitoringException) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event)

Aggregations

ArrayList (java.util.ArrayList)2 Event (org.talend.esb.sam.common.event.Event)2 MonitoringException (org.talend.esb.sam.common.event.MonitoringException)2 EventType (org.talend.esb.sam._2011._03.common.EventType)1