@Before public void setup() { maxRingBufferPending = new LongAccumulator(Long::max, Long.MIN_VALUE); droppedCount = new AtomicLong(0); producerExecutor = Executors.newSingleThreadExecutor(); }
public void init(@Nonnull ServerConf serverConf, @Nonnull ZkHelixPropertyStore<ZNRecord> propertyStore) throws Exception { LOGGER.info("Initializing server instance"); _serverConf = serverConf; ServerBuilder serverBuilder = new ServerBuilder(_serverConf, propertyStore); _serverMetrics = serverBuilder.getServerMetrics(); _instanceDataManager = serverBuilder.buildInstanceDataManager(); _queryExecutor = serverBuilder.buildQueryExecutor(_instanceDataManager); _latestQueryTime = new LongAccumulator(Long::max, 0); _queryScheduler = serverBuilder.buildQueryScheduler(_queryExecutor, _latestQueryTime); _requestHandler = new ScheduledRequestHandler(_queryScheduler, _serverMetrics); _nettyServer = serverBuilder.buildNettyServer(new RequestHandlerFactory() { @Override public NettyServer.RequestHandler createNewRequestHandler() { return _requestHandler; } }); LOGGER.info("Finish initializing server instance"); }
@BeforeClass public void setUp() { serverMetrics = new ServerMetrics(new MetricsRegistry()); channelHandlerContext = mock(ChannelHandlerContext.class, RETURNS_DEEP_STUBS); when(channelHandlerContext.channel().remoteAddress()) .thenAnswer((Answer<InetSocketAddress>) invocationOnMock -> new InetSocketAddress("localhost", 60000)); queryScheduler = mock(QueryScheduler.class); queryExecutor = new ServerQueryExecutorV1Impl(); latestQueryTime = new LongAccumulator(Long::max, 0); resourceManager = new UnboundedResourceManager(new PropertiesConfiguration()); }
public static TestPriorityScheduler create(Configuration conf) { ResourceManager rm = new PolicyBasedResourceManager(conf); QueryExecutor qe = new TestQueryExecutor(); groupFactory = new TestSchedulerGroupFactory(); MultiLevelPriorityQueue queue = new MultiLevelPriorityQueue(conf, rm, groupFactory, new TableBasedGroupMapper()); latestQueryTime = new LongAccumulator(Long::max, 0); return new TestPriorityScheduler(rm, qe, queue, metrics, latestQueryTime); }
private static void testAccumulate() { LongBinaryOperator op = (x, y) -> 2 * x + y; LongAccumulator accumulator = new LongAccumulator(op, 1L); ExecutorService executor = Executors.newFixedThreadPool(2); IntStream.range(0, 10) .forEach(i -> executor.submit(() -> accumulator.accumulate(i))); ConcurrentUtils.stop(executor); System.out.format("Add: %d\n", accumulator.getThenReset()); } }
IntStream istream = ... LongAccumulator acc = new LongAccumulator(Long::min, Long.MAX_VALUE); if (istream.mapToLong(i -> i).peek(acc::accumulate).allMatch(i -> i > N)) { System.out.println("min was " + acc.get()); } else { System.out.println("a value was <= " + N); }
private static void testAccumulate() { LongBinaryOperator op = (x, y) -> 2 * x + y; LongAccumulator accumulator = new LongAccumulator(op, 1L); ExecutorService executor = Executors.newFixedThreadPool(2); IntStream.range(0, 10) .forEach(i -> executor.submit(() -> accumulator.accumulate(i))); ConcurrentUtils.stop(executor); System.out.format("Add: %d\n", accumulator.getThenReset()); } }
/** * Copy the mappings stored in a {@link LocatableResolver} to the specified replica. * * @param replica The {@link LocatableResolver} to copy to. * @return A future that will complete when the copy is finished. */ public CompletableFuture<Void> copyToAsync(@Nonnull final LocatableResolver replica) { if (!replica.getDatabase().equals(runner.getDatabase())) { throw new IllegalArgumentException("copy must be within same database"); } final LongAccumulator maxAccumulator = new LongAccumulator(Long::max, 0L); final AtomicInteger counter = new AtomicInteger(); return copyInternal(replica, maxAccumulator, counter) .thenCompose(ignore -> replica.setWindow(maxAccumulator.get())); }