// Path: cn.ctodb.push.sdk/src/main/java/cn/ctodb/push/client/ClientHandler.java
// @Sharable
// public class ClientHandler extends ChannelInboundHandlerAdapter {
//     private PacketReceiver packetReceiver;
// 
//     public ClientHandler(PacketReceiver packetReceiver) {
//         this.packetReceiver = packetReceiver;
//     }
// 
//     /**
//      * tcp链路简历成功后调用
//      */
//     @Override
//     public void channelActive(ChannelHandlerContext ctx) throws Exception {
//         System.out.println("成功连接服务器");
//         // TextMessage message = new TextMessage();
//         // message.setMessage("test");
//         // sendMsg(message);
//     }
// 
//     /**
//      * 收到消息后调用
//      *
//      * @throws IOException
//      */
//     @Override
//     public void channelRead(ChannelHandlerContext ctx, Object msg) throws IOException {
//         Packet packet = (Packet) msg;
//         Connection connection = new Connection();
//         connection.setChc(ctx);
//         packetReceiver.onReceive(packet, connection);
//     }
// 
//     /**
//      * 发生异常时调用
//      */
//     @Override
//     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
//         System.err.println("与服务器断开连接:" + cause);
//         ctx.close();
//     }
// 
// }
// 
// Path: cn.ctodb.push.sdk/src/main/java/cn/ctodb/push/client/handler/HandshakeHandler.java
// public class HandshakeHandler extends AbstractHandler<HandshakeResp> {
// 
//     @Override
//     public Command cmd() {
//         return Command.HANDSHAKE_RESP;
//     }
// 
//     @Override
//     public Class<HandshakeResp> getType() {
//         return HandshakeResp.class;
//     }
// 
//     @Override
//     public void handle(HandshakeResp message, Connection connection) {
//         logger.debug("握手成功:{}", message.sessionId);
//         ClientInfo.setSessionId(message.sessionId);
//     }
// }
// 
// Path: cn.ctodb.push.core/src/main/java/cn/ctodb/push/core/PacketReceiver.java
// public final class PacketReceiver {
// 
//     private static final Logger logger = LoggerFactory.getLogger(PacketReceiver.class);
//     private static List<Filter> filterList = new ArrayList<>();
//     private static final Map<Command, PacketHandler> handlers = new HashMap<>();
// 
//     public void addHandler(PacketHandler handler) {
//         logger.debug("register : {}", handler.cmd().name());
//         handlers.put(handler.cmd(), handler);
//     }
// 
//     public void addFilter(Filter filter) {
//         logger.debug("filter : {}", filter.getClass());
//         filterList.add(filter);
//     }
// 
//     public void onReceive(Packet packet, Connection connection) {
//         Command command = Command.toCMD(packet.getCmd());
//         PacketHandler handler = handlers.get(command);
//         logger.debug("new packet : {}", command);
//         if (handler == null) return;
//         for (Filter filter : filterList) {
//             if (filter.exec(packet, connection).equals(FilterResult.END)) return;
//         }
//         try {
//             handler.handle(packet, connection);
//         } catch (Throwable e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: cn.ctodb.push.core/src/main/java/cn/ctodb/push/handler/ErrorHandler.java
// public final class ErrorHandler extends AbstractHandler<Error> {
// 
//     @Override
//     public Command cmd() {
//         return Command.ERROR;
//     }
// 
//     @Override
//     public Class<Error> getType() {
//         return Error.class;
//     }
// 
//     @Override
//     public void handle(Error message, Connection connection) {
//         logger.debug("error : {}", message.getErrorCode());
//     }
// 
// }


import cn.ctodb.push.client.ClientHandler;
import cn.ctodb.push.client.handler.HandshakeHandler;
import cn.ctodb.push.core.PacketReceiver;
import cn.ctodb.push.handler.ErrorHandler;
package cn.ctodb.push.client.conf;


/**
 * Created by cc on 2017/8/21.
 */
public class ClientConfiguration {

    private static PacketReceiver packetReceiver;

    static {
        init();
    }

    public static void init() {
// Path: cn.ctodb.push.sdk/src/main/java/cn/ctodb/push/client/ClientHandler.java
// @Sharable
// public class ClientHandler extends ChannelInboundHandlerAdapter {
//     private PacketReceiver packetReceiver;
// 
//     public ClientHandler(PacketReceiver packetReceiver) {
//         this.packetReceiver = packetReceiver;
//     }
// 
//     /**
//      * tcp链路简历成功后调用
//      */
//     @Override
//     public void channelActive(ChannelHandlerContext ctx) throws Exception {
//         System.out.println("成功连接服务器");
//         // TextMessage message = new TextMessage();
//         // message.setMessage("test");
//         // sendMsg(message);
//     }
// 
//     /**
//      * 收到消息后调用
//      *
//      * @throws IOException
//      */
//     @Override
//     public void channelRead(ChannelHandlerContext ctx, Object msg) throws IOException {
//         Packet packet = (Packet) msg;
//         Connection connection = new Connection();
//         connection.setChc(ctx);
//         packetReceiver.onReceive(packet, connection);
//     }
// 
//     /**
//      * 发生异常时调用
//      */
//     @Override
//     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
//         System.err.println("与服务器断开连接:" + cause);
//         ctx.close();
//     }
// 
// }
// 
// Path: cn.ctodb.push.sdk/src/main/java/cn/ctodb/push/client/handler/HandshakeHandler.java
// public class HandshakeHandler extends AbstractHandler<HandshakeResp> {
// 
//     @Override
//     public Command cmd() {
//         return Command.HANDSHAKE_RESP;
//     }
// 
//     @Override
//     public Class<HandshakeResp> getType() {
//         return HandshakeResp.class;
//     }
// 
//     @Override
//     public void handle(HandshakeResp message, Connection connection) {
//         logger.debug("握手成功:{}", message.sessionId);
//         ClientInfo.setSessionId(message.sessionId);
//     }
// }
// 
// Path: cn.ctodb.push.core/src/main/java/cn/ctodb/push/core/PacketReceiver.java
// public final class PacketReceiver {
// 
//     private static final Logger logger = LoggerFactory.getLogger(PacketReceiver.class);
//     private static List<Filter> filterList = new ArrayList<>();
//     private static final Map<Command, PacketHandler> handlers = new HashMap<>();
// 
//     public void addHandler(PacketHandler handler) {
//         logger.debug("register : {}", handler.cmd().name());
//         handlers.put(handler.cmd(), handler);
//     }
// 
//     public void addFilter(Filter filter) {
//         logger.debug("filter : {}", filter.getClass());
//         filterList.add(filter);
//     }
// 
//     public void onReceive(Packet packet, Connection connection) {
//         Command command = Command.toCMD(packet.getCmd());
//         PacketHandler handler = handlers.get(command);
//         logger.debug("new packet : {}", command);
//         if (handler == null) return;
//         for (Filter filter : filterList) {
//             if (filter.exec(packet, connection).equals(FilterResult.END)) return;
//         }
//         try {
//             handler.handle(packet, connection);
//         } catch (Throwable e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: cn.ctodb.push.core/src/main/java/cn/ctodb/push/handler/ErrorHandler.java
// public final class ErrorHandler extends AbstractHandler<Error> {
// 
//     @Override
//     public Command cmd() {
//         return Command.ERROR;
//     }
// 
//     @Override
//     public Class<Error> getType() {
//         return Error.class;
//     }
// 
//     @Override
//     public void handle(Error message, Connection connection) {
//         logger.debug("error : {}", message.getErrorCode());
//     }
// 
// }


// Path: cn.ctodb.push.sdk/src/main/java/cn/ctodb/push/client/conf/ClientConfiguration.java
import cn.ctodb.push.client.ClientHandler;
import cn.ctodb.push.client.handler.HandshakeHandler;
import cn.ctodb.push.core.PacketReceiver;
import cn.ctodb.push.handler.ErrorHandler;

package cn.ctodb.push.client.conf;


/**
 * Created by cc on 2017/8/21.
 */
public class ClientConfiguration {

    private static PacketReceiver packetReceiver;

    static {
        init();
    }

    public static void init() {
        packetReceiver = new PacketReceiver();