public AbstractPacket getProcessingPacket(AbstractPacket packet) {
   if (packet == null) {
     return null;
   } else if (PacketStatus.PROCESSED.equals(packet.getStatus())) {
     return packet;
   } else {
     return getProcessingPacket(packet.getResponse());
   }
 }
  public void processWrite() throws ClosedChannelException {

    AbstractPacket packet = getProcessingPacket(client.getLastQuery());
    int interestOps = 0;
    if (packet == null) {
      interestOps = updateClientFileList();
    } else if (packet instanceof AbstractResponse) {
      packetHandler.handleWrite(packet, getBuffer());
      interestOps = packet.updateStatus(getChannel());
    }
    setOps(interestOps);
  }
 public int recognizePacket() {
   byte settings = getBuffer().get();
   AbstractPacket packet = determineFromAction(settings);
   int interestOps = 0;
   if (packet != null) {
     addPacket(packet);
     getBuffer().rewind();
     packetHandler.handleRead(packet, getBuffer());
     interestOps = packet.updateStatus(getChannel());
   }
   return interestOps;
 }
  public void processRead() throws IOException {

    SocketChannel socketChannel = getChannel();
    if (socketChannel.read(getBuffer()) <= 0) {
      updateClientStatus(ClientStatus.OFFLINE);
      return;
    }

    getBuffer().flip();

    AbstractPacket packet = getProcessingPacket(client.getLastQuery());
    int interestOps = 0;
    if (packet == null) {
      interestOps = recognizePacket();
    } else if (packet instanceof AbstractQuery) {
      packetHandler.handleRead(packet, getBuffer());
      interestOps = packet.updateStatus(getChannel());
    }
    setOps(interestOps);
  }