Пример #1
0
 public AbstractPacket getProcessingPacket(AbstractPacket packet) {
   if (packet == null) {
     return null;
   } else if (PacketStatus.PROCESSED.equals(packet.getStatus())) {
     return packet;
   } else {
     return getProcessingPacket(packet.getResponse());
   }
 }
Пример #2
0
  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);
  }
Пример #3
0
 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;
 }
Пример #4
0
  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);
  }