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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations