Search in sources :

Example 1 with ChannelException

use of 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 2 with ChannelException

use of 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());
    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 3 with ChannelException

use of 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 4 with ChannelException

use of 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)

Example 5 with ChannelException

use of io.netty.channel.ChannelException in project netty by netty.

the class EpollChannelConfig method setEpollMode.

/**
     * Set the {@link EpollMode} used. Default is
     * {@link EpollMode#EDGE_TRIGGERED}. If you want to use {@link #isAutoRead()} {@code false} or
     * {@link #getMaxMessagesPerRead()} and have an accurate behaviour you should use
     * {@link EpollMode#LEVEL_TRIGGERED}.
     *
     * <strong>Be aware this config setting can only be adjusted before the channel was registered.</strong>
     */
public EpollChannelConfig setEpollMode(EpollMode mode) {
    if (mode == null) {
        throw new NullPointerException("mode");
    }
    try {
        switch(mode) {
            case EDGE_TRIGGERED:
                checkChannelNotRegistered();
                channel.setFlag(Native.EPOLLET);
                break;
            case LEVEL_TRIGGERED:
                checkChannelNotRegistered();
                channel.clearFlag(Native.EPOLLET);
                break;
            default:
                throw new Error();
        }
    } catch (IOException e) {
        throw new ChannelException(e);
    }
    return this;
}
Also used : IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException)

Aggregations

ChannelException (io.netty.channel.ChannelException)8 IOException (java.io.IOException)4 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 EventLoopException (io.netty.channel.EventLoopException)1 UdtMessage (io.netty.channel.udt.UdtMessage)1 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)1 Field (java.lang.reflect.Field)1 CancelledKeyException (java.nio.channels.CancelledKeyException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 LegacyPingHandler (net.glowstone.net.handler.legacyping.LegacyPingHandler)1