Search in sources :

Example 1 with TCPHydraSession

use of de.datasecs.hydra.shared.handler.impl.TCPHydraSession in project Hydra by DataSecs.

the class HydraChannelInitializer method initChannel.

@Override
protected void initChannel(C channel) {
    ChannelPipeline pipeline = channel.pipeline();
    // In
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    pipeline.addLast(new PacketDecoder(protocol));
    // Out
    pipeline.addLast(new LengthFieldPrepender(4));
    pipeline.addLast(new PacketEncoder(protocol));
    /*
        if (!useUDP) {
            TCPHydraSession session = new TCPHydraSession(channel, protocol);
            pipeline.addLast(session);
        } else {
            UDPHydraSession session = new UDPHydraSession(channel, protocol);
            pipeline.addLast(session);
        }
         */
    HydraSession session = new HydraSession(channel, protocol);
    pipeline.addLast(session);
    // Add sessions to protocol, to keep track of them
    if (isServer) {
        protocol.addSession(session);
    } else {
        protocol.setClientSession(session);
    }
    if (!useUDP) {
        if (protocol.getSessionListener() != null) {
            // Inform SessionListener about new session
            protocol.callSessionListener(true, session);
        } else if (protocol.getSessionConsumer() != null) {
            // Inform SessionConsumer about new session
            protocol.callSessionConsumer(true, session);
        }
    }
}
Also used : PacketEncoder(de.datasecs.hydra.shared.protocol.packets.serialization.PacketEncoder) TCPHydraSession(de.datasecs.hydra.shared.handler.impl.TCPHydraSession) HydraSession(de.datasecs.hydra.shared.handler.impl.HydraSession) UDPHydraSession(de.datasecs.hydra.shared.handler.impl.UDPHydraSession) PacketDecoder(de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

HydraSession (de.datasecs.hydra.shared.handler.impl.HydraSession)1 TCPHydraSession (de.datasecs.hydra.shared.handler.impl.TCPHydraSession)1 UDPHydraSession (de.datasecs.hydra.shared.handler.impl.UDPHydraSession)1 PacketDecoder (de.datasecs.hydra.shared.protocol.packets.serialization.PacketDecoder)1 PacketEncoder (de.datasecs.hydra.shared.protocol.packets.serialization.PacketEncoder)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)1 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)1