/** * Adds the given <code>event</code> to this report. If this report is too full, * the event will be silently rejected (i.e. an exception will not be thrown, but the * event will not be sent to the server). * * @param event the {@link Event} to be added * @param eventSource the source of the Event to be added */ public void addEvent(@NotNull Event event, @NotNull EventSource eventSource) { if (this.totalEventsInReport < this.maxEventsPerReport) { Set<Event> eventSet = getEventsForEventSource(eventSource); if (eventSet.size() < this.maxEventsPerSource) { eventSet.add(event); this.totalEventsInReport++; } else { // this event source has maxed out its allowed number of events for this report droppedEvent(eventSource); } } else { // this event report has maxed out its total allowed number of events. droppedEvent(eventSource); } return; }
public void mergeEventReport(EventReport report) { long startTime = System.currentTimeMillis(); EventManagerLocal eventManager = LookupUtil.getEventManager(); eventManager.addEventData(report.getEvents()); long elapsedTime = (System.currentTimeMillis() - startTime); if (elapsedTime >= 10000L) { log.info("Performance: event report merge [" + report.getEvents().size() + "] timing: (" + elapsedTime + ")ms"); } else if (log.isDebugEnabled()) { log.debug("Performance: event report merge [" + report.getEvents().size() + "] timing: (" + elapsedTime + ")ms"); } } }
EventReport swapReport() { this.reportLock.writeLock().lock(); try { EventReport previousReport = this.activeReport; this.activeReport = new EventReport(this.pcConfig.getEventReportMaxPerSource(), this.pcConfig .getEventReportMaxTotal()); return previousReport; } finally { this.reportLock.writeLock().unlock(); } }
/** * Sends the given Event report to the Server, if this Plugin Container has Server services that it can communicate * with. * * @param report the Event report to be sent (this report should be closed from getting any more events added to it) */ void sendEventReport(EventReport report) { if (report.addLimitWarningEvents()) { // add any limit warning events if events were dropped Map<EventSource, Integer> droppedEvents = report.getDroppedEvents(); log.warn("Begin dropped events report"); for (Map.Entry<EventSource, Integer> next : droppedEvents.entrySet()) { log.warn("There were " + next.getValue() + " dropped events for source '" + next.getKey() + "'"); } log.warn("Finish dropped events report"); } if (!report.getEvents().isEmpty() && this.pcConfig.getServerServices() != null) { try { this.pcConfig.getServerServices().getEventServerService().mergeEventReport(report); } catch (Exception e) { log.warn("Failure to report Events to Server.", e); } } }
void publishEvents(@NotNull Set<Event> events, @NotNull Resource resource) { this.reportLock.readLock().lock(); try { for (Event event : events) { EventSource eventSource = createEventSource(event, resource); this.activeReport.addEvent(event, eventSource); } } catch (Throwable t) { log.error("Failed to add Events for " + resource + " to Event report: " + events, t); } finally { this.reportLock.readLock().unlock(); } }
EventSource eventSource = entry.getKey(); Integer droppedCount = entry.getValue(); Set<Event> eventSet = getEventsForEventSource(eventSource);
public EventManager(PluginContainerConfiguration configuration) { pcConfig = configuration; activeReport = new EventReport(pcConfig.getEventReportMaxPerSource(), pcConfig.getEventReportMaxTotal()); senderThreadPool = new ScheduledThreadPoolExecutor(SENDER_THREAD_POOL_CORE_SIZE, new LoggingThreadFactory( SENDER_THREAD_POOL_NAME, true)); // Set up a thread pool for polling threads. Polling threads will be added to the pool via calls to // registerEventPoller(). pollerThreadPool = new ScheduledThreadPoolExecutor(POLLER_THREAD_POOL_CORE_SIZE, new LoggingThreadFactory( POLLER_THREAD_POOL_NAME, true)); pollerThreads = new HashMap<PollerKey, Runnable>(); }