Exemplo n.º 1
0
            protected internal override ChannelContext create()
            {
                _outerInstance.msgLog.info(threadInfo() + "Trying to open a new channel from " + _outerInstance.origin + " to " + _outerInstance.destination);
                // We must specify the origin address in case the server has multiple IPs per interface
                ChannelFuture channelFuture = _outerInstance.bootstrap.connect(_outerInstance.destination, _outerInstance.origin);

                channelFuture.awaitUninterruptibly(5, TimeUnit.SECONDS);
                if (channelFuture.Success)
                {
                    _outerInstance.msgLog.info(threadInfo() + "Opened a new channel from " + channelFuture.Channel.LocalAddress + " to " + channelFuture.Channel.RemoteAddress);

                    return(new ChannelContext(channelFuture.Channel, ChannelBuffers.dynamicBuffer(), ByteBuffer.allocate(1024 * 1024)));
                }

                Exception cause = channelFuture.Cause;
                string    msg   = _outerInstance.GetType().Name + " could not connect from " + _outerInstance.origin + " to " + _outerInstance.destination;

                _outerInstance.msgLog.debug(msg);
                throw outerInstance.traceComException(new ComException(msg, cause), "Client.start");
            }
Exemplo n.º 2
0
        private Channel OpenChannel(URI clusterUri)
        {
            SocketAddress destination = new InetSocketAddress(clusterUri.Host, clusterUri.Port == -1 ? _config.defaultPort() : clusterUri.Port);
            // We must specify the origin address in case the server has multiple IPs per interface
            SocketAddress origin = new InetSocketAddress(_me.Host, 0);

            _msgLog.info("Attempting to connect from " + origin + " to " + destination);
            ChannelFuture channelFuture = _clientBootstrap.connect(destination, origin);

            channelFuture.awaitUninterruptibly(5, TimeUnit.SECONDS);

            if (channelFuture.Success)
            {
                Channel channel = channelFuture.Channel;
                _msgLog.info("Connected from " + channel.LocalAddress + " to " + channel.RemoteAddress);
                return(channel);
            }

            Exception cause = channelFuture.Cause;

            _msgLog.info("Failed to connect to " + destination + " due to: " + cause);

            throw new ChannelOpenFailedException(cause);
        }