Search in sources :

Example 6 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project flink by apache.

the class NettyClient method connect.

// ------------------------------------------------------------------------
// Client connections
// ------------------------------------------------------------------------
ChannelFuture connect(final InetSocketAddress serverSocketAddress) {
    checkState(bootstrap != null, "Client has not been initialized yet.");
    // --------------------------------------------------------------------
    // Child channel pipeline for accepted connections
    // --------------------------------------------------------------------
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel channel) throws Exception {
            // SSL handler should be added first in the pipeline
            if (clientSSLFactory != null) {
                SslHandler sslHandler = clientSSLFactory.createNettySSLHandler(channel.alloc(), serverSocketAddress.getAddress().getCanonicalHostName(), serverSocketAddress.getPort());
                channel.pipeline().addLast("ssl", sslHandler);
            }
            channel.pipeline().addLast(protocol.getClientChannelHandlers());
        }
    });
    try {
        return bootstrap.connect(serverSocketAddress);
    } catch (ChannelException e) {
        if ((e.getCause() instanceof java.net.SocketException && e.getCause().getMessage().equals("Too many open files")) || (e.getCause() instanceof ChannelException && e.getCause().getCause() instanceof java.net.SocketException && e.getCause().getCause().getMessage().equals("Too many open files"))) {
            throw new ChannelException("The operating system does not offer enough file handles to open the network connection. " + "Please increase the number of available file handles.", e.getCause());
        } else {
            throw e;
        }
    }
}
Also used : EpollSocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.epoll.EpollSocketChannel) NioSocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.SocketChannel) IOException(java.io.IOException) ChannelException(org.apache.flink.shaded.netty4.io.netty.channel.ChannelException) SslHandler(org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler) ChannelException(org.apache.flink.shaded.netty4.io.netty.channel.ChannelException)

Example 7 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class LocalChannelRegistry method register.

static LocalAddress register(Channel channel, LocalAddress oldLocalAddress, SocketAddress localAddress) {
    if (oldLocalAddress != null) {
        throw new ChannelException("already bound");
    }
    if (!(localAddress instanceof LocalAddress)) {
        throw new ChannelException("unsupported address type: " + StringUtil.simpleClassName(localAddress));
    }
    LocalAddress addr = (LocalAddress) localAddress;
    if (LocalAddress.ANY.equals(addr)) {
        addr = new LocalAddress(channel);
    }
    Channel boundChannel = boundChannels.putIfAbsent(addr, channel);
    if (boundChannel != null) {
        throw new ChannelException("address already in use by: " + boundChannel);
    }
    return addr;
}
Also used : Channel(io.netty.channel.Channel) ChannelException(io.netty.channel.ChannelException)

Example 8 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class DiskAttribute method replace.

@Override
public Attribute replace(ByteBuf content) {
    DiskAttribute attr = new DiskAttribute(getName(), baseDir, deleteOnExit);
    attr.setCharset(getCharset());
    if (content != null) {
        try {
            attr.setContent(content);
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
    return attr;
}
Also used : IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException)

Example 9 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class MemoryAttribute method replace.

@Override
public Attribute replace(ByteBuf content) {
    MemoryAttribute attr = new MemoryAttribute(getName());
    attr.setCharset(getCharset());
    if (content != null) {
        try {
            attr.setContent(content);
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
    return attr;
}
Also used : IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException)

Example 10 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class NioUdtMessageConnectorChannel method doReadMessages.

@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    final int maximumMessageSize = config.getReceiveBufferSize();
    final ByteBuf byteBuf = config.getAllocator().directBuffer(maximumMessageSize);
    final int receivedMessageSize = byteBuf.writeBytes(javaChannel(), maximumMessageSize);
    if (receivedMessageSize <= 0) {
        byteBuf.release();
        return 0;
    }
    if (receivedMessageSize >= maximumMessageSize) {
        javaChannel().close();
        throw new ChannelException("Invalid config : increase receive buffer size to avoid message truncation");
    }
    // delivers a message
    buf.add(new UdtMessage(byteBuf));
    return 1;
}
Also used : UdtMessage(io.netty.channel.udt.UdtMessage) ByteBuf(io.netty.buffer.ByteBuf) ChannelException(io.netty.channel.ChannelException)

Aggregations

ChannelException (io.netty.channel.ChannelException)23 IOException (java.io.IOException)10 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)4 ClosedChannelException (java.nio.channels.ClosedChannelException)4 JSONObjectDecoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectDecoder)3 JSONObjectEncoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectEncoder)3 Channel (io.netty.channel.Channel)3 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)3 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 BindException (java.net.BindException)2 InetSocketAddress (java.net.InetSocketAddress)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Send (com.github.ambry.network.Send)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SessionResumptionSslHandler (com.linkedin.r2.netty.handler.common.SessionResumptionSslHandler)1 Config (com.typesafe.config.Config)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 Connection (de.jackwhite20.japs.server.network.Connection)1