Package net.yura.lobby.netty

Source Code of net.yura.lobby.netty.ProtoEncoder

package net.yura.lobby.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import java.util.logging.Level;
import net.yura.lobby.model.Message;
import net.yura.lobby.server.LobbyServer;

/**
* @author Yura Mamyrin
*/
public class ProtoEncoder extends MessageToByteEncoder<Message> {

    final LobbyServer server;

    public ProtoEncoder(LobbyServer server) {
        this.server = server;
    }

    @Override
    protected void encode(ChannelHandlerContext chc, Message message, ByteBuf bb) throws Exception {
        try {
            if (Server.DEBUG_SEND) {
                Server.logger.log(Level.FINER, "encoding "+System.identityHashCode(message)+" "+message);
            }
            server.encode(new ByteBufOutputStream(bb),message);
        }
        catch(Exception ex) {
            // TODO if i do not log this here, it does not seem to be logged
            // fields that are LAZY but we have no transaction create a error here
            LobbyServer.logger.log(Level.WARNING, "error in encode", ex);
            throw ex;
        }
        // this message has already been encoded
        //LobbyServer.logger.info("Sent "+chc+" "+message);
    }

}
TOP

Related Classes of net.yura.lobby.netty.ProtoEncoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.