/** * Attempts a new connection with the current {@code "remoteAddress"} and * {@code "localAddress"} option. If the {@code "localAddress"} option is * not set, the local address of a new channel is determined automatically. * This method is similar to the following code: * * <pre> * {@link ClientBootstrap} b = ...; * b.connect(b.getOption("remoteAddress"), b.getOption("localAddress")); * </pre> * * @return a future object which notifies when this connection attempt * succeeds or fails * * @throws IllegalStateException * if {@code "remoteAddress"} option was not set * @throws ClassCastException * if {@code "remoteAddress"} or {@code "localAddress"} option's * value is neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect() { SocketAddress remoteAddress = (SocketAddress) getOption("remoteAddress"); if (remoteAddress == null) { throw new IllegalStateException("remoteAddress option is not set."); } return connect(remoteAddress); }
/** * Reconnect to the remote address that the closed channel was connected to. * This creates a new {@link ChannelPipeline} with the same handler instances * contained in the old channel's pipeline. * * @param timeout Timer task handle. * * @throws Exception when reconnection fails. */ @Override public void run(Timeout timeout) throws Exception { ChannelPipeline old = channel.getPipeline(); CommandHandler<?, ?> handler = old.get(CommandHandler.class); RedisAsyncConnection<?, ?> connection = old.get(RedisAsyncConnection.class); ChannelPipeline pipeline = Channels.pipeline(this, handler, connection); Channel c = bootstrap.getFactory().newChannel(pipeline); c.getConfig().setOptions(bootstrap.getOptions()); c.connect((SocketAddress) bootstrap.getOption("remoteAddress")); } }
/** * Attempts a new connection with the specified {@code remoteAddress} and * the current {@code "localAddress"} option. If the {@code "localAddress"} * option is not set, the local address of a new channel is determined * automatically. This method is identical with the following code: * * <pre> * {@link ClientBootstrap} b = ...; * b.connect(remoteAddress, b.getOption("localAddress")); * </pre> * * @return a future object which notifies when this connection attempt * succeeds or fails * * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect(SocketAddress remoteAddress) { if (remoteAddress == null) { throw new NullPointerException("remoteAddress"); } SocketAddress localAddress = (SocketAddress) getOption("localAddress"); return connect(remoteAddress, localAddress); }
/** * Reconnect to the remote address that the closed channel was connected to. * This creates a new {@link ChannelPipeline} with the same handler instances * contained in the old channel's pipeline. * * @param timeout Timer task handle. * * @throws Exception when reconnection fails. */ @Override public void run(Timeout timeout) throws Exception { ChannelPipeline old = channel.getPipeline(); CommandHandler<?, ?> handler = old.get(CommandHandler.class); RedisAsyncConnection<?, ?> connection = old.get(RedisAsyncConnection.class); ChannelPipeline pipeline = Channels.pipeline(this, handler, connection); Channel c = bootstrap.getFactory().newChannel(pipeline); c.getConfig().setOptions(bootstrap.getOptions()); c.connect((SocketAddress) bootstrap.getOption("remoteAddress")); } }
private InetSocketAddress getRemoteAddress() { return (InetSocketAddress) bootstrap.getOption("remoteAddress"); }
private InetSocketAddress getRemoteAddress() { return (InetSocketAddress) bootstrap.getOption("remoteAddress"); }
InetSocketAddress getRemoteAddress() { return (InetSocketAddress) bootstrap.getOption("remoteAddress"); }
/** * Attempts a new connection with the specified {@code remoteAddress} and * the current {@code "localAddress"} option. If the {@code "localAddress"} * option is not set, the local address of a new channel is determined * automatically. This method is identical with the following code: * * <pre> * {@link ClientBootstrap} b = ...; * b.connect(remoteAddress, b.getOption("localAddress")); * </pre> * * @return a future object which notifies when this connection attempt * succeeds or fails * * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect(SocketAddress remoteAddress) { if (remoteAddress == null) { throw new NullPointerException("remoteAddress"); } SocketAddress localAddress = (SocketAddress) getOption("localAddress"); return connect(remoteAddress, localAddress); }
/** * Attempts a new connection with the current {@code "remoteAddress"} and * {@code "localAddress"} option. If the {@code "localAddress"} option is * not set, the local address of a new channel is determined automatically. * This method is similar to the following code: * * <pre> * {@link ClientBootstrap} b = ...; * b.connect(b.getOption("remoteAddress"), b.getOption("localAddress")); * </pre> * * @return a future object which notifies when this connection attempt * succeeds or fails * * @throws IllegalStateException * if {@code "remoteAddress"} option was not set * @throws ClassCastException * if {@code "remoteAddress"} or {@code "localAddress"} option's * value is neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect() { SocketAddress remoteAddress = (SocketAddress) getOption("remoteAddress"); if (remoteAddress == null) { throw new IllegalStateException("remoteAddress option is not set."); } return connect(remoteAddress); }
@Override public void run(final Timeout timeout) throws Exception { final InetSocketAddress remoteAddr = (InetSocketAddress) ReconnectHandler.this.bootstrap .getOption("remoteAddress"); final ChannelFuture cf = ReconnectHandler.this.bootstrap.connect(); cf.addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture e) throws Exception { if (e.isSuccess()) { ReconnectTimeoutTask.this.sw.setChannel(e.getChannel()); ReconnectTimeoutTask.this.cg.add(e.getChannel()); } else { ReconnectHandler.this.log .error("Failed to connect to controller {} for switch {}", remoteAddr, ReconnectTimeoutTask.this.sw .getSwitchName()); } } }); } }
@Override public void channelClosed(final ChannelHandlerContext ctx, final ChannelStateEvent e) { if (!this.sw.isActive()) { return; } this.sw.removeChannel(e.getChannel()); final int retry = this.sw.incrementBackOff(); final Integer backOffTime = Math.min(1 << retry, this.maxBackOff); this.timeout = this.timer.newTimeout(new ReconnectTimeoutTask(this.sw, this.cg), backOffTime, TimeUnit.SECONDS); this.log.error("Backing off {} for controller {}", backOffTime, this.bootstrap.getOption("remoteAddress")); ctx.sendUpstream(e); }
private <K, V, T extends RedisAsyncConnection<K, V>> T connect(CommandHandler<K, V> handler, T connection) { try { ConnectionWatchdog watchdog = new ConnectionWatchdog(bootstrap, channels, timer); ChannelPipeline pipeline = Channels.pipeline(watchdog, handler, connection); Channel channel = bootstrap.getFactory().newChannel(pipeline); ChannelFuture future = channel.connect((SocketAddress) bootstrap.getOption("remoteAddress")); future.await(); if (!future.isSuccess()) { throw future.getCause(); } watchdog.setReconnect(true); return connection; } catch (Throwable e) { throw new RedisException("Unable to connect", e); } }
private <K, V, T extends RedisAsyncConnection<K, V>> T connect(CommandHandler<K, V> handler, T connection) { try { ConnectionWatchdog watchdog = new ConnectionWatchdog(bootstrap, channels, timer); ChannelPipeline pipeline = Channels.pipeline(watchdog, handler, connection); Channel channel = bootstrap.getFactory().newChannel(pipeline); ChannelFuture future = channel.connect((SocketAddress) bootstrap.getOption("remoteAddress")); future.await(); if (!future.isSuccess()) { throw future.getCause(); } watchdog.setReconnect(true); return connection; } catch (Throwable e) { throw new RedisException("Unable to connect", e); } }