@Override public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { JsonObject obj = (JsonObject) new JsonParser().parse(msg); JsonElement name = obj.get("name"); if (name == null) { Flog.warn("No name for receive, ignoring"); return; } String requestName = name.getAsString(); retries = MAX_RETRIES; delay = INITIAL_RECONNECT_DELAY; handler.on_data(requestName, obj); }
protected void connect() { if (retries <= 0) { Flog.error("I give up connecting."); return; } retries -= 1; FlooUrl flooUrl = handler.getUrl(); final String host; final int port; if (flooUrl.host.equals(Constants.floobitsDomain) && retries % 4 == 0) { host = Constants.OUTBOUND_FILTER_PROXY_HOST; port = Constants.OUTBOUND_FILTER_PROXY_PORT; } else { host = flooUrl.host; port = flooUrl.port; } if (channel == null) { _connect(host, port); return; } try { channel .close() .addListener( new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { channel = null; _connect(host, port); } }); } catch (Throwable e) { Flog.error(e); reconnect(); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { Flog.log("Connected to %s", ctx.channel().remoteAddress()); handler.on_connect(); }