Esempio n. 1
0
 protected void reconnect() {
   if (retries <= 0) {
     Flog.log("Giving up!");
     context.shutdown();
     return;
   }
   delay = Math.min(10000, Math.round((float) 1.5 * delay));
   Flog.log("Connection lost. Reconnecting in %sms", delay);
   context.setTimeout(
       delay,
       new Runnable() {
         @Override
         public void run() {
           Flog.log("Attempting to reconnect.");
           connect();
         }
       });
 }
Esempio n. 2
0
  protected void _connect(String host, int port) {
    Bootstrap b = new Bootstrap();

    if (!context.addGroup(b)) {
      Flog.warn("no loopgroup, will not reconnect");
      return;
    }
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 15 * 1000);
    b.handler(new FlooChannelInitializer(this));

    try {
      ChannelFuture connect = b.connect(host, port);
      channel = connect.channel();
    } catch (RejectedExecutionException e) {
      context.errorMessage("Can not connect to floobits!");
      context.shutdown();
    } catch (Throwable e) {
      Flog.error(e);
      reconnect();
    }
  }