use of io.dingodb.net.netty.channel.ChannelId in project dingo by dingodb.
the class NetServiceLocalConnection method send.
@Override
public <S extends Packet<Message>> void send(S packet) {
ChannelId channelId = packet.header().channelId();
if (channelId == null) {
throw new UnsupportedOperationException("Send message must have sub channel.");
}
MessagePacket sendPacket = MessagePacket.builder().mode(packet.header().mode()).type(packet.header().type()).channelId(packet.header().targetChannelId()).targetChannelId(packet.header().channelId()).content(packet.content()).msgNo(packet.header().msgNo()).build();
MessageDispatcher.instance().dispatch(this, sendPacket);
}
use of io.dingodb.net.netty.channel.ChannelId in project dingo by dingodb.
the class NetServiceNettyConnection method receive.
@Override
public void receive(Packet<Message> packet) {
ChannelId channelId = packet.header().channelId();
NetServiceConnectionSubChannel channel;
if (channelId == null || (channel = subChannels.get(channelId)) == null) {
throw new RuntimeException("Not found channel for channel id: " + channelId);
}
Logs.packetDbg(false, log, this, packet);
channel.receive(packet);
}
use of io.dingodb.net.netty.channel.ChannelId in project dingo by dingodb.
the class GenericMessageHandler method handle.
@Override
public void handle(Connection<Message> connection, Packet<Message> packet) {
switch(packet.header().type()) {
case PING:
connection.genericSubChannel().send(MessagePacket.pong(0));
return;
case PONG:
break;
case CONNECT_CHANNEL:
ConnectionSubChannel<Message> channel = connection.openSubChannel(packet.header().targetChannelId());
channel.send(MessagePacket.ack(channel.channelId(), channel.targetChannelId(), channel.nextSeq()));
break;
case DIS_CONNECT_CHANNEL:
connection.closeSubChannel(packet.header().channelId());
break;
case ACK:
Optional.ofNullable(ackFuture.get(connection)).map(futureMap -> futureMap.remove(packet.header().channelId())).ifPresent(future -> future.complete(packet));
break;
case HANDSHAKE_ERROR:
ErrorMessage errorMessage = ErrorMessage.builder().build().load(packet.content().toBytes());
log.error("Handshake failed, msg is: {}", errorMessage.getDetailMessage());
try {
connection.close();
} catch (Exception e) {
log.error("Connection close error.", e);
}
break;
default:
throw new IllegalStateException("Unexpected value: " + packet.header().type());
}
}
use of io.dingodb.net.netty.channel.ChannelId in project dingo by dingodb.
the class NetServiceLocalConnection method receive.
@Override
public void receive(Packet<Message> message) {
ChannelId channelId = message.header().channelId();
NetServiceConnectionSubChannel channel;
if (channelId == null || (channel = subChannels.get(channelId)) == null) {
throw new RuntimeException("Not found channel for channel id: " + channelId);
}
channel.receive(message);
}
Aggregations