Search in sources :

Example 1 with ChannelId

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);
}
Also used : MessagePacket(io.dingodb.net.netty.packet.impl.MessagePacket) SimpleChannelId(io.dingodb.net.netty.channel.impl.SimpleChannelId) ChannelId(io.dingodb.net.netty.channel.ChannelId)

Example 2 with ChannelId

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);
}
Also used : ChannelId(io.dingodb.net.netty.channel.ChannelId) NetServiceConnectionSubChannel(io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel)

Example 3 with ChannelId

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());
    }
}
Also used : PacketMode(io.dingodb.net.netty.packet.PacketMode) Packet(io.dingodb.net.netty.packet.Packet) PacketType(io.dingodb.net.netty.packet.PacketType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message(io.dingodb.net.Message) TimeoutException(java.util.concurrent.TimeoutException) ErrorMessage(io.dingodb.net.netty.packet.message.ErrorMessage) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Slf4j(lombok.extern.slf4j.Slf4j) Future(java.util.concurrent.Future) MessagePacket(io.dingodb.net.netty.packet.impl.MessagePacket) MessageDispatcher(io.dingodb.net.netty.handler.MessageDispatcher) AutoService(com.google.auto.service.AutoService) Map(java.util.Map) Optional(io.dingodb.common.util.Optional) ConnectionSubChannel(io.dingodb.net.netty.channel.ConnectionSubChannel) MessageHandler(io.dingodb.net.netty.handler.MessageHandler) Logs(io.dingodb.net.netty.utils.Logs) ChannelId(io.dingodb.net.netty.channel.ChannelId) Connection(io.dingodb.net.netty.connection.Connection) Message(io.dingodb.net.Message) ErrorMessage(io.dingodb.net.netty.packet.message.ErrorMessage) ErrorMessage(io.dingodb.net.netty.packet.message.ErrorMessage) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with ChannelId

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);
}
Also used : SimpleChannelId(io.dingodb.net.netty.channel.impl.SimpleChannelId) ChannelId(io.dingodb.net.netty.channel.ChannelId) NetServiceConnectionSubChannel(io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel)

Aggregations

ChannelId (io.dingodb.net.netty.channel.ChannelId)4 NetServiceConnectionSubChannel (io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel)2 SimpleChannelId (io.dingodb.net.netty.channel.impl.SimpleChannelId)2 MessagePacket (io.dingodb.net.netty.packet.impl.MessagePacket)2 AutoService (com.google.auto.service.AutoService)1 Optional (io.dingodb.common.util.Optional)1 Message (io.dingodb.net.Message)1 ConnectionSubChannel (io.dingodb.net.netty.channel.ConnectionSubChannel)1 Connection (io.dingodb.net.netty.connection.Connection)1 MessageDispatcher (io.dingodb.net.netty.handler.MessageDispatcher)1 MessageHandler (io.dingodb.net.netty.handler.MessageHandler)1 Packet (io.dingodb.net.netty.packet.Packet)1 PacketMode (io.dingodb.net.netty.packet.PacketMode)1 PacketType (io.dingodb.net.netty.packet.PacketType)1 ErrorMessage (io.dingodb.net.netty.packet.message.ErrorMessage)1 Logs (io.dingodb.net.netty.utils.Logs)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1