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);
}
}
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);
}
}
});
}
}
}
Aggregations