@Test public void testOnce() throws ExecutionException, InterruptedException { emitter.once(testEventName, listener); Future f = emitter.emit(testEventName, event1); f.get(); Assert.assertEquals(store.size(), 1); store.clear(); emitter.emit(testEventName, event2); Assert.assertEquals(store.size(), 0); }
@Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; }
RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } }
RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting  RollupEventEmitter(ExecutorService executor); }
RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting  RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); }
RollupEventEmitter extends Emitter<RollupEvent> { @Override public Future emit(final String event, final RollupEvent... eventPayload) { Future emitFuture = null; if(eventPayload[0].getRollup() instanceof BasicRollup && super.hasListeners(ROLLUP_EVENT_NAME)) { emitFuture = eventExecutors.submit(new Callable() { @Override public Future call() { if (Util.shouldUseESForUnits()) { final DiscoveryIO discoveryIO = (DiscoveryIO) ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Lists.transform(Arrays.asList(eventPayload), new Function<RollupEvent, RollupEvent>() { @Override public RollupEvent apply(RollupEvent event) { String unit; try { unit = discoveryIO.search(event.getLocator().getTenantId(), event.getLocator().getMetricName()).get(0).getUnit(); } catch (Exception e) { log.warn("Exception encountered while getting units out of ES : %s", e.getMessage()); unit = Util.UNKNOWN; } event.setUnit(unit); return event; } }); } return RollupEventEmitter.super.emit(event, eventPayload); } }); } return emitFuture; } RollupEventEmitter(); @VisibleForTesting  RollupEventEmitter(ExecutorService executor); static RollupEventEmitter getInstance(); @Override Future emit(final String event, final RollupEvent... eventPayload); static final String ROLLUP_EVENT_NAME; }