Search in sources :

Example 1 with NetServiceConnectionSubChannel

use of io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel 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 2 with NetServiceConnectionSubChannel

use of io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel in project dingo by dingodb.

the class NetServiceNettyConnection method openSubChannel.

@Override
public ConnectionSubChannel<Message> openSubChannel(ChannelId targetChannelId) {
    NetServiceConnectionSubChannel channel = subChannels.computeIfAbsent(generateChannelId(), cid -> new NetServiceConnectionSubChannel(cid, targetChannelId, this));
    if (log.isDebugEnabled()) {
        log.debug("Open channel from [{}] channel [{}], this channel: [{}], caller: [{}]", remoteAddress(), targetChannelId, channel.channelId(), log.isTraceEnabled() ? stackTrace() : stack(3));
    }
    channel.start();
    return channel;
}
Also used : NetServiceConnectionSubChannel(io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel)

Example 3 with NetServiceConnectionSubChannel

use of io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel 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)

Example 4 with NetServiceConnectionSubChannel

use of io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel in project dingo by dingodb.

the class NetServiceLocalConnection method closeSubChannel.

@Override
public void closeSubChannel(ChannelId channelId) {
    NetServiceConnectionSubChannel subChannel = subChannels.remove(channelId);
    if (subChannel == null || subChannel.status() == Channel.Status.CLOSE) {
        return;
    }
    subChannel.status(Channel.Status.CLOSE);
    subChannel.close();
}
Also used : NetServiceConnectionSubChannel(io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel)

Example 5 with NetServiceConnectionSubChannel

use of io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel in project dingo by dingodb.

the class NetServiceNettyConnection method openSubChannel.

@Override
public NetServiceConnectionSubChannel openSubChannel() {
    NetServiceConnectionSubChannel channel = subChannels.computeIfAbsent(generateChannelId(), cid -> new NetServiceConnectionSubChannel(cid, null, this));
    Future<Packet<Message>> ack = GenericMessageHandler.instance().waitAck(this, channel.channelId());
    channel.send(MessagePacket.connectRemoteChannel(channel.channelId(), channel.nextSeq()));
    try {
        channel.targetChannelId(ack.get(heartbeat, TimeUnit.SECONDS).header().targetChannelId());
    } catch (InterruptedException e) {
        closeSubChannel(channel.channelId());
        NetError.OPEN_CHANNEL_INTERRUPT.throwFormatError();
    } catch (ExecutionException e) {
        closeSubChannel(channel.channelId());
        log.error("Open channel error, channel id: [{}], caller: [{}]", channel.channelId(), stack(2));
        NetError.UNKNOWN.throwFormatError(e.getMessage());
    } catch (TimeoutException e) {
        closeSubChannel(channel.channelId());
        OPEN_CHANNEL_TIME_OUT.throwFormatError();
    }
    if (log.isDebugEnabled()) {
        log.debug("Open channel to [{}] channel [{}], this channel: [{}], caller: [{}]", remoteAddress(), channel.targetChannelId(), channel.channelId(), log.isTraceEnabled() ? stackTrace() : stack(3));
    }
    channel.start();
    return channel;
}
Also used : HandshakeMessage.handshakePacket(io.dingodb.net.netty.packet.message.HandshakeMessage.handshakePacket) MessagePacket(io.dingodb.net.netty.packet.impl.MessagePacket) Packet(io.dingodb.net.netty.packet.Packet) NetServiceConnectionSubChannel(io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

NetServiceConnectionSubChannel (io.dingodb.net.netty.channel.impl.NetServiceConnectionSubChannel)6 ChannelId (io.dingodb.net.netty.channel.ChannelId)2 SimpleChannelId (io.dingodb.net.netty.channel.impl.SimpleChannelId)1 Packet (io.dingodb.net.netty.packet.Packet)1 MessagePacket (io.dingodb.net.netty.packet.impl.MessagePacket)1 HandshakeMessage.handshakePacket (io.dingodb.net.netty.packet.message.HandshakeMessage.handshakePacket)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1