private void processRead(SelectionKey key) throws Exception {

        SocketChannel ch = (SocketChannel) key.channel();
        int bytesOp = 0, bytesTotal = 0;
        while (readBuf[0].hasRemaining())
            bytesTotal += ch.read(readBuf, 0, 1);


        if (bytesTotal > 0) {
            ProtocolHeader protocolHeader = null;
            try {
                readBuf[0].flip();
                protocolHeader = ProtocolUtils.checkHeaderIntegrity(readBuf[0]);

            } catch (Exception e) {
                log.severe("Check header integrity failed! Cause: " + e.getMessage());
            }

            readBuf[1] = ByteBuffer.allocate(ProtocolUtils.getBodySize(protocolHeader));

            while (readBuf[1].hasRemaining())
                bytesTotal += ch.read(readBuf, 1, 1);

            readBuf[1].flip();
            clientTMThreadMessagesCount.inc();
            onRead(readBuf[1]);
            readBuf[1].clear();
            readBuf[0].clear();

        } else if (bytesOp == -1) {
            log.info("peer closed read channel");
            ch.close();
        }
        clientTMThreadBytesRcv.inc(bytesTotal);
    }