码迷,mamicode.com
首页 > 编程语言 > 详细

Java Code Examples for io.netty.util.concurrent.GlobalEventExecutor

时间:2017-05-05 10:38:04      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:override   ddl   aos   elf   nat   href   void   hadoop   protect   

Example 1
Project: lettuce   File: FuturesTest.java View source code 6 votes 技术分享 技术分享
@Test
public void regularUse() throws Exception {
    final DefaultPromise<Boolean> target = new DefaultPromise<Boolean>(GlobalEventExecutor.INSTANCE);
    Futures.PromiseAggregator<Boolean, Promise<Boolean>> sut = new Futures.PromiseAggregator<Boolean, Promise<Boolean>>(
            target);

    sut.expectMore(1);
    sut.arm();
    DefaultPromise<Boolean> part = new DefaultPromise<Boolean>(GlobalEventExecutor.INSTANCE);
    sut.add(part);

    assertThat(target.isDone()).isFalse();

    part.setSuccess(true);

    WaitFor.waitOrTimeout(new Condition() {
        @Override
        public boolean isSatisfied() {
            return target.isDone();
        }
    }, timeout(seconds(5)));

    assertThat(target.isDone()).isTrue();
}

Example 2
Project: usc   File: UscNetconfClientDispatcherImpl.java View source code 6 votes 技术分享 技术分享
private Future<Void> createReconnectingSshClient(final NetconfReconnectingClientConfiguration currentConfiguration) {
    LOG.debug("Creating reconnecting SSH client with configuration: {}", currentConfiguration);
    LOG.warn("UscNetconfClientDispatcherImpl createReconnectingSshClient");

    final Bootstrap b = new Bootstrap();
    b.group(group);
    b.channel(LocalChannel.class);

    final ReconnectPromise p = new ReconnectPromise(GlobalEventExecutor.INSTANCE, this,
            currentConfiguration.getAddress(), currentConfiguration.getConnectStrategyFactory(), b,
            new PipelineInitializer<NetconfClientSession>() {
                @Override
                public void initializeChannel(final Channel ch, final Promise<NetconfClientSession> promise) {
                    new NetconfSshClientChannelInitializer(currentConfiguration.getAuthHandler(),
                            getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener())
                            .initialize(ch, promise);
                }
            });

    p.connect();
    return p;
}

Example 3
Project: netty4.0.27Learn   File: EpollSocketChannel.java View source code 6 votes 技术分享 技术分享
@Override
protected Executor closeExecutor() {
    if (config().getSoLinger() > 0) {
        return GlobalEventExecutor.INSTANCE;
    }
    return null;
}

Example 4
Project: JgFramework   File: BaseArea.java View source code 6 votes 技术分享 技术分享
public BaseArea(String name, BasePosition entrancePosition, IBaseMap map) {
    this.id = hashCode();
    this.name = name;
    this.map = map;
    this.entrancePosition = entrancePosition;
    this.channelGroup = new DefaultChannelGroup(name, GlobalEventExecutor.INSTANCE);
}

Example 5
Project: glowroot   File: HttpServerHandler.java View source code 6 votes 技术分享 技术分享
HttpServerHandler(LayoutService layoutService, Map<Pattern, HttpService> httpServices,
        HttpSessionManager httpSessionManager, List<Object> jsonServices) {
    this.layoutService = layoutService;
    this.httpServices = ImmutableMap.copyOf(httpServices);
    this.httpSessionManager = httpSessionManager;
    List<JsonServiceMapping> jsonServiceMappings = Lists.newArrayList();
    for (Object jsonService : jsonServices) {
        for (Method method : jsonService.getClass().getDeclaredMethods()) {
            GET annotationGET = method.getAnnotation(GET.class);
            if (annotationGET != null) {
                jsonServiceMappings.add(ImmutableJsonServiceMapping.builder()
                        .httpMethod(HttpMethod.GET)
                        .path(annotationGET.value())
                        .service(jsonService)
                        .methodName(method.getName())
                        .build());
            }
            POST annotationPOST = method.getAnnotation(POST.class);
            if (annotationPOST != null) {
                jsonServiceMappings.add(ImmutableJsonServiceMapping.builder()
                        .httpMethod(HttpMethod.POST)
                        .path(annotationPOST.value())
                        .service(jsonService)
                        .methodName(method.getName())
                        .build());
            }
        }
    }
    this.jsonServiceMappings = ImmutableList.copyOf(jsonServiceMappings);
    allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
}

Example 6
Project: vibe-java-platform   File: NettyServerHttpExchangeTest.java View source code 6 votes 技术分享 技术分享
@Override
protected void startServer() {
    bossGroup = new NioEventLoopGroup();
    workerGroup = new NioEventLoopGroup();
    channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(bossGroup, workerGroup)
    .channel(NioServerSocketChannel.class)
    .childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            channels.add(ctx.channel());
        }

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new HttpServerCodec())
            .addLast(new VibeServerCodec() {
                @Override
                protected boolean accept(HttpRequest req) {
                    return URI.create(req.getUri()).getPath().equals("/test");
                }
            }
            .onhttp(performer.serverAction()));
        }
    });
    channels.add(bootstrap.bind(port).channel());
}

Example 7
Project: termd   File: NettyIoAcceptor.java View source code 6 votes 技术分享 技术分享
public NettyIoAcceptor(NettyIoServiceFactory factory, IoHandler handler) {
  this.factory = factory;
  this.handler = handler;
  channelGroup = new DefaultChannelGroup("sshd-acceptor-channels", GlobalEventExecutor.INSTANCE);;
  bootstrap.group(factory.eventLoopGroup)
      .channel(NioServerSocketChannel.class)
      .option(ChannelOption.SO_BACKLOG, 100)
      .handler(new LoggingHandler(LogLevel.INFO))
      .childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
          ChannelPipeline p = ch.pipeline();
          p.addLast(new NettyIoSession(NettyIoAcceptor.this, handler).adapter);
        }
      });
}

Example 8
Project: rest.li   File: HttpNettyClient.java View source code 6 votes 技术分享 技术分享
HttpNettyClient(ChannelPoolFactory factory,
                ScheduledExecutorService executor,
                int requestTimeout,
                int shutdownTimeout,
                int maxResponseSize)
{
  _maxResponseSize = maxResponseSize;
  _channelPoolManager = new ChannelPoolManager(factory);
  _scheduler = executor;
  _callbackExecutors = new DefaultEventExecutorGroup(1);
  _requestTimeout = requestTimeout;
  _shutdownTimeout = shutdownTimeout;
  _requestTimeoutMessage = "Exceeded request timeout of " + _requestTimeout + "ms";
  _jmxManager = AbstractJmxManager.NULL_JMX_MANAGER;
  _jmxManager.onProviderCreate(_channelPoolManager);
  _maxHeaderSize = 8192;
  _maxChunkSize = 8192;
  _maxConcurrentConnections = Integer.MAX_VALUE;
  _allChannels = new DefaultChannelGroup("R2 client channels", GlobalEventExecutor.INSTANCE);
}

Example 9
Project: tajo   File: HttpFileServer.java View source code 6 votes 技术分享 技术分享
public HttpFileServer(final InetSocketAddress addr) {
  this.addr = addr;
  this.eventloopGroup = new NioEventLoopGroup(2, Executors.defaultThreadFactory());

  // Configure the server.
  this.bootstrap = new ServerBootstrap();
  this.bootstrap.childHandler(new HttpFileServerChannelInitializer())
        .group(eventloopGroup)
        .option(ChannelOption.TCP_NODELAY, true)
        .channel(NioServerSocketChannel.class);
  this.channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
}

Example 10
Project: hadoop   File: WebImageViewer.java View source code 6 votes 技术分享 技术分享
public WebImageViewer(InetSocketAddress address) {
  this.address = address;
  this.bossGroup = new NioEventLoopGroup();
  this.workerGroup = new NioEventLoopGroup();
  this.allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
  this.bootstrap = new ServerBootstrap()
    .group(bossGroup, workerGroup)
    .channel(NioServerSocketChannel.class);
}

Example 11
Project: vert.x   File: HttpServerImpl.java View source code 5 votes 技术分享 技术分享
public synchronized HttpServer listen(int port, String host, Handler<AsyncResult<HttpServer>> listenHandler) {
  if (requestStream.handler() == null && wsStream.handler() == null) {
    throw new IllegalStateException("Set request or websocket handler first");
  }
  if (listening) {
    throw new IllegalStateException("Already listening");
  }
  listenContext = vertx.getOrCreateContext();
  listening = true;
  serverOrigin = (options.isSsl() ? "https" : "http") + "://" + host + ":" + port;
  synchronized (vertx.sharedHttpServers()) {
    id = new ServerID(port, host);
    HttpServerImpl shared = vertx.sharedHttpServers().get(id);
    if (shared == null) {
      serverChannelGroup = new DefaultChannelGroup("vertx-acceptor-channels", GlobalEventExecutor.INSTANCE);
      ServerBootstrap bootstrap = new ServerBootstrap();
      bootstrap.group(vertx.getAcceptorEventLoopGroup(), availableWorkers);
      bootstrap.channelFactory(new VertxNioServerChannelFactory());
      applyConnectionOptions(bootstrap);
      sslHelper.validate(vertx);
      bootstrap.childHandler(new ChannelInitializer<Channel>() {
          @Override
          protected void initChannel(Channel ch) throws Exception {
            if (requestStream.isPaused() || wsStream.isPaused()) {
              ch.close();
              return;
            }
            ChannelPipeline pipeline = ch.pipeline();
            if (sslHelper.isSSL()) {
              pipeline.addLast("ssl", sslHelper.createSslHandler(vertx, false));
            }
            if (USE_FLASH_POLICY_HANDLER) {
              pipeline.addLast("flashpolicy", new FlashPolicyHandler());
            }
            pipeline.addLast("httpDecoder", new HttpRequestDecoder(4096, 8192, 8192, false));
            pipeline.addLast("httpEncoder", new VertxHttpResponseEncoder());
            if (options.isCompressionSupported()) {
              pipeline.addLast("deflater", new HttpChunkContentCompressor());
            }
            if (sslHelper.isSSL() || options.isCompressionSupported()) {
              // only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used.
              pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());       // For large file / sendfile support
            }
            if (options.getIdleTimeout() > 0) {
              pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout()));
            }
            pipeline.addLast("handler", new ServerHandler());
          }
      });

      addHandlers(this, listenContext);
      try {
        bindFuture = bootstrap.bind(new InetSocketAddress(InetAddress.getByName(host), port));
        Channel serverChannel = bindFuture.channel();
        serverChannelGroup.add(serverChannel);
        bindFuture.addListener(channelFuture -> {
            if (!channelFuture.isSuccess()) {
              vertx.sharedHttpServers().remove(id);
            } else {
              metrics = vertx.metricsSPI().createMetrics(this, new SocketAddressImpl(port, host), options);
            }
          });
      } catch (final Throwable t) {
        // Make sure we send the exception back through the handler (if any)
        if (listenHandler != null) {
          vertx.runOnContext(v -> listenHandler.handle(Future.failedFuture(t)));
        } else {
          // No handler - log so user can see failure
          log.error(t);
        }
        listening = false;
        return this;
      }
      vertx.sharedHttpServers().put(id, this);
      actualServer = this;
    } else {
      // Server already exists with that host/port - we will use that
      actualServer = shared;
      addHandlers(actualServer, listenContext);
      metrics = vertx.metricsSPI().createMetrics(this, new SocketAddressImpl(port, host), options);
    }
    actualServer.bindFuture.addListener(future -> {
      if (listenHandler != null) {
        final AsyncResult<HttpServer> res;
        if (future.isSuccess()) {
          res = Future.succeededFuture(HttpServerImpl.this);
        } else {
          res = Future.failedFuture(future.cause());
          listening = false;
        }
        listenContext.runOnContext((v) -> listenHandler.handle(res));
      } else if (!future.isSuccess()) {
        listening  = false;
        // No handler - log so user can see failure
        log.error(future.cause());
      }
    });
  }
  return this;
}

Java Code Examples for io.netty.util.concurrent.GlobalEventExecutor

标签:override   ddl   aos   elf   nat   href   void   hadoop   protect   

原文地址:http://www.cnblogs.com/DaTouDaddy/p/6811345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!