List of usage examples for io.netty.util.concurrent DefaultPromise DefaultPromise
public DefaultPromise(EventExecutor executor)
From source file:biz.paluch.spinach.support.TestEventLoopGroupProvider.java
License:Apache License
@Override public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit) {//from ww w . j av a 2 s. c o m DefaultPromise<Boolean> result = new DefaultPromise<Boolean>(ImmediateEventExecutor.INSTANCE); result.setSuccess(true); return result; }
From source file:com.addthis.hydra.query.tracker.DetailedStatusHandler.java
License:Apache License
public void handle() { if (queryEntry != null) { if (queryEntry.lastSourceInfo == null) { Promise<TaskSourceInfo[]> promise = new DefaultPromise<>(ctx.executor()); promise.addListener(this); DetailedStatusTask statusTask = new DetailedStatusTask(promise); queryEntry.trackerHandler.submitDetailedStatusTask(statusTask); } else {//w w w . j a v a 2 s . com onSuccess(queryEntry.getStat()); } } else { onFailure(new RuntimeException("query entry unexpectedly null")); } }
From source file:com.addthis.hydra.query.tracker.TrackerHandler.java
License:Apache License
@Override public void operationComplete(ChannelProgressiveFuture future) throws Exception { if (future == queryPromise) { // only care about operation progressed events for the gathering promise return;// w ww . ja v a2 s . c o m } else if (future == opPromise) { // tell aggregator about potential early termination from the op promise if (future.isSuccess()) { queryPromise.trySuccess(); } else { queryPromise.tryFailure(opPromise.cause()); } return; } // else the entire request is over; either from an error the last http write completing // tell the op processor about potential early termination (which may tell the gatherer in turn) if (future.isSuccess()) { opPromise.trySuccess(); } else { opPromise.tryFailure(future.cause()); } QueryEntry runE = queryTracker.running.remove(query.uuid()); if (runE == null) { log.warn("failed to remove running for {}", query.uuid()); } Promise<QueryEntryInfo> promise = new DefaultPromise<>(ctx.executor()); queryEntry.getDetailedQueryEntryInfo(promise); QueryEntryInfo entryInfo = promise.getNow(); if (entryInfo == null) { log.warn("Failed to get detailed status for completed query {}; defaulting to brief", query.uuid()); entryInfo = queryEntry.getStat(); } try { StringMapHelper queryLine = new StringMapHelper().put("query.path", query.getPaths()[0]) .put("query.ops", Arrays.toString(opsLog)).put("sources", query.getParameter("sources")) .put("time", System.currentTimeMillis()).put("time.run", entryInfo.runTime) .put("job.id", query.getJob()).put("job.alias", query.getParameter("track.alias")) .put("query.id", query.uuid()).put("lines", entryInfo.lines) .put("sender", query.getParameter("sender")); if (!future.isSuccess()) { Throwable queryFailure = future.cause(); queryLine.put("type", "query.error").put("error", queryFailure.getMessage()); queryTracker.queryErrors.inc(); } else { queryLine.put("type", "query.done"); queryTracker.recentlyCompleted.put(query.uuid(), entryInfo); } queryTracker.log(queryLine); queryTracker.queryMeter.update(entryInfo.runTime, TimeUnit.MILLISECONDS); } catch (Exception e) { log.error("Error while doing record keeping for a query.", e); } }
From source file:com.addthis.hydra.query.web.DetailedStatusHandler.java
License:Apache License
public void handle() { if (queryEntry != null) { Promise<QueryEntryInfo> promise = new DefaultPromise<>(ctx.executor()); promise.addListener(this); queryEntry.getDetailedQueryEntryInfo(promise); } else {/*from w w w . j a v a2 s . c om*/ onFailure(new RuntimeException("query entry unexpectedly null")); } }
From source file:com.addthis.meshy.MeshyServer.java
License:Apache License
public MeshyServer(final int port, final File rootDir, @Nullable String[] netif, final MeshyServerGroup group) throws IOException { super();//w w w .ja v a2 s . co m this.group = group; this.rootDir = rootDir; this.filesystems = loadFileSystems(rootDir); this.serverPeers = new AtomicInteger(0); bossGroup = new NioEventLoopGroup(1); ServerBootstrap bootstrap = new ServerBootstrap() .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.SO_BACKLOG, 1024).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000) .option(ChannelOption.SO_REUSEADDR, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true) .childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATERMARK) .childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATERMARK) .channel(NioServerSocketChannel.class).group(bossGroup, workerGroup) .childHandler(new ChannelInitializer<NioSocketChannel>() { @Override protected void initChannel(final NioSocketChannel ch) throws Exception { ch.pipeline().addLast(new ChannelState(MeshyServer.this, ch)); } }); /* bind to one or more interfaces, if supplied, otherwise all */ if ((netif == null) || (netif.length == 0)) { ServerSocketChannel serverChannel = (ServerSocketChannel) bootstrap.bind(new InetSocketAddress(port)) .syncUninterruptibly().channel(); serverLocal = serverChannel.localAddress(); } else { InetSocketAddress primaryServerLocal = null; for (String net : netif) { NetworkInterface nicif = NetworkInterface.getByName(net); if (nicif == null) { log.warn("missing speficied NIC: {}", net); continue; } for (InterfaceAddress addr : nicif.getInterfaceAddresses()) { InetAddress inAddr = addr.getAddress(); if (inAddr.getAddress().length != 4) { log.trace("skip non-ipV4 address: {}", inAddr); continue; } ServerSocketChannel serverChannel = (ServerSocketChannel) bootstrap .bind(new InetSocketAddress(inAddr, port)).syncUninterruptibly().channel(); if (primaryServerLocal != null) { log.info("server [{}-*] binding to extra address: {}", super.getUUID(), primaryServerLocal); } primaryServerLocal = serverChannel.localAddress(); } } if (primaryServerLocal == null) { throw new IllegalArgumentException("no valid interface / port specified"); } serverLocal = primaryServerLocal; } this.serverNetIf = NetworkInterface.getByInetAddress(serverLocal.getAddress()); this.serverPort = serverLocal.getPort(); if (serverNetIf != null) { serverUuid = super.getUUID() + "-" + serverPort + "-" + serverNetIf.getName(); } else { serverUuid = super.getUUID() + "-" + serverPort; } log.info("server [{}] on {} @ {}", getUUID(), serverLocal, rootDir); closeFuture = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); workerGroup.terminationFuture().addListener((Future<Object> workerFuture) -> { bossGroup.terminationFuture().addListener((Future<Object> bossFuture) -> { if (!workerFuture.isSuccess()) { closeFuture.tryFailure(workerFuture.cause()); } else if (!bossFuture.isSuccess()) { closeFuture.tryFailure(bossFuture.cause()); } else { closeFuture.trySuccess(null); } }); }); addMessageFileSystemPaths(); group.join(this); if (autoMesh) { startAutoMesh(serverPort, autoMeshTimeout); } }
From source file:com.barchart.netty.server.base.AbstractServer.java
License:BSD License
@Override public ChannelFuture listen(final SocketAddress address) { shutdownFuture = new DefaultPromise<T>(GlobalEventExecutor.INSTANCE); final ChannelFuture future = bootstrap().bind(address); serverChannels.add(future.channel()); return future; }
From source file:com.basho.riak.client.core.netty.RiakSecurityDecoder.java
License:Apache License
private void init(ChannelHandlerContext ctx) { state = State.TLS_WAIT;/*from w w w . j ava2 s . c o m*/ promise = new DefaultPromise<Void>(ctx.executor()); promiseLatch.countDown(); ctx.channel().writeAndFlush(new RiakMessage(RiakMessageCodes.MSG_StartTls, new byte[0])); }
From source file:com.github.milenkovicm.kafka.KafkaProducer.java
License:Apache License
public KafkaProducer(String hostname, int port, String topicName, ProducerProperties properties, EventLoopGroup workerGroup) {/*from www. j a va 2 s. c o m*/ this.properties = properties; this.hostname = hostname; this.port = port; this.topicName = topicName; this.workerGroup = workerGroup; this.kafkaTopic = new KafkaTopic(properties.get(ProducerProperties.PARTITIONER), properties, topicName); this.eventExecutor = GlobalEventExecutor.INSTANCE; this.connectPromise = new DefaultPromise<>(eventExecutor); this.disconnectPromise = new DefaultPromise<>(eventExecutor); }
From source file:com.lambdaworks.redis.resource.DefaultClientResources.java
License:Apache License
/** * Shutdown the {@link ClientResources}. * * @param quietPeriod the quiet period as described in the documentation * @param timeout the maximum amount of time to wait until the executor is shutdown regardless if a task was submitted * during the quiet period// w ww . ja va 2 s.co m * @param timeUnit the unit of {@code quietPeriod} and {@code timeout} * @return eventually the success/failure of the shutdown without errors. */ @SuppressWarnings("unchecked") public Future<Boolean> shutdown(long quietPeriod, long timeout, TimeUnit timeUnit) { shutdownCalled = true; DefaultPromise<Boolean> overall = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); DefaultPromise<Boolean> lastRelease = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); Futures.PromiseAggregator<Boolean, Promise<Boolean>> aggregator = new Futures.PromiseAggregator<>(overall); aggregator.expectMore(1); if (!sharedEventLoopGroupProvider) { aggregator.expectMore(1); } if (!sharedEventExecutor) { aggregator.expectMore(1); } aggregator.arm(); if (metricEventPublisher != null) { metricEventPublisher.shutdown(); } if (!sharedTimer) { timer.stop(); } if (!sharedEventLoopGroupProvider) { Future<Boolean> shutdown = eventLoopGroupProvider.shutdown(quietPeriod, timeout, timeUnit); if (shutdown instanceof Promise) { aggregator.add((Promise<Boolean>) shutdown); } else { aggregator.add(toBooleanPromise(shutdown)); } } if (!sharedEventExecutor) { Future<?> shutdown = eventExecutorGroup.shutdownGracefully(quietPeriod, timeout, timeUnit); aggregator.add(toBooleanPromise(shutdown)); } if (!sharedCommandLatencyCollector) { commandLatencyCollector.shutdown(); } aggregator.add(lastRelease); lastRelease.setSuccess(null); return toBooleanPromise(overall); }
From source file:com.lambdaworks.redis.resource.DefaultEventLoopGroupProvider.java
License:Apache License
@Override public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit) {//from w w w.j a va 2 s . c om Class<?> key = getKey(release(eventLoopGroup)); if ((key == null && eventLoopGroup.isShuttingDown()) || refCounter.containsKey(eventLoopGroup)) { DefaultPromise<Boolean> promise = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); promise.setSuccess(true); return promise; } if (key != null) { eventLoopGroups.remove(key); } Future<?> shutdownFuture = eventLoopGroup.shutdownGracefully(quietPeriod, timeout, unit); return toBooleanPromise(shutdownFuture); }