/** When receive a message, analyze message content and then execute the command: Draw or Clear */
  public void receive(Message msg) {
    byte[] buf = msg.getRawBuffer();
    if (buf == null) {
      System.err.println(
          "["
              + channel.getAddress()
              + "] received null buffer from "
              + msg.getSrc()
              + ", headers: "
              + msg.printHeaders());
      return;
    }

    try {
      DrawCommand comm =
          (DrawCommand)
              Util.streamableFromByteBuffer(
                  DrawCommand.class, buf, msg.getOffset(), msg.getLength());
      switch (comm.mode) {
        case DrawCommand.DRAW:
          if (drawPanel != null) drawPanel.drawPoint(comm);
          break;
        case DrawCommand.CLEAR:
          clearPanel();
        default:
          System.err.println("***** received invalid draw command " + comm.mode);
          break;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #2
0
 protected PingData deserialize(final byte[] data) {
   try {
     return (PingData) Util.streamableFromByteBuffer(PingData.class, data);
   } catch (Exception e) {
     log.error("Error", e);
     return null;
   }
 }
Example #3
0
 protected static PingData deserialize(final byte[] data) throws Exception {
   return (PingData) Util.streamableFromByteBuffer(PingData.class, data);
 }