コード例 #1
0
  @Override
  public void start() throws SmppChannelException {
    if (isDestroyed()) {
      throw new SmppChannelException("Unable to start: server is destroyed");
    }
    try {
      ChannelFuture f = this.serverBootstrap.bind(new InetSocketAddress(configuration.getPort()));

      // wait until the connection is made successfully
      boolean timeout = !f.await(configuration.getBindTimeout());

      if (timeout || !f.isSuccess())
        throw new SmppChannelException(
            "Can't bind to port "
                + configuration.getPort()
                + " after "
                + configuration.getBindTimeout()
                + " milliseconds");

      logger.info("{} started on SMPP port [{}]", configuration.getName(), configuration.getPort());
      serverChannel = f.channel();
    } catch (ChannelException e) {
      throw new SmppChannelException(e.getMessage(), e);
    } catch (InterruptedException e) {
      throw new SmppChannelException(e.getMessage(), e);
    }
  }
コード例 #2
0
  public static HotRodServer startHotRodServer(
      EmbeddedCacheManager cacheManager, HotRodServerConfigurationBuilder builder) {
    // TODO: This is very rudimentary!! HotRodTestingUtil needs a more robust solution where ports
    // are generated randomly and retries if already bound
    HotRodServer server = null;
    int maxTries = 10;
    int currentTries = 0;
    ChannelException lastException = null;
    while (server == null && currentTries < maxTries) {
      try {
        server =
            HotRodTestingUtil.startHotRodServer(
                cacheManager, uniquePort.incrementAndGet(), builder);
      } catch (ChannelException e) {
        if (!(e.getCause() instanceof BindException)) {
          throw e;
        } else {
          log.debug("Address already in use: [" + e.getMessage() + "], so let's try next port");
          currentTries++;
          lastException = e;
        }
      }
    }
    if (server == null && lastException != null) throw lastException;

    return server;
  }
コード例 #3
0
ファイル: NettyHttpServer.java プロジェクト: huntc/trireme
 @Override
 public void listen(String host, int port, int backlog, TLSParams tls) {
   SSLContext ssl = null;
   if (tls != null) {
     try {
       ssl = makeSSLContext(tls);
     } catch (NoSuchAlgorithmException e) {
       throw new EvaluatorException(e.toString());
     } catch (KeyManagementException e) {
       throw new EvaluatorException(e.toString());
     }
   }
   log.debug("About to listen for HTTP on {}:{}", host, port);
   if (ssl != null) {
     log.debug("Using SSLContext " + ssl);
   }
   try {
     server = NettyFactory.get().createServer(port, host, backlog, makePipeline(tls, ssl));
     log.debug("Listening on port {}", port);
   } catch (ChannelException ce) {
     stub.onError(ce.getMessage());
     stub.onClose(null, null);
   }
 }