/**
  * We both log the packet summary to console and write it back to client.
  *
  * <p>Override super method
  *
  * @see org.apache.niolex.network.IPacketHandler#handlePacket(PacketData, IPacketWriter)
  */
 @Override
 public void handlePacket(PacketData sc, IPacketWriter wt) {
   StringBuilder sb = new StringBuilder();
   sb.append("---------------------Packet Summary:----------------------\ncode\t");
   sb.append(sc.getCode()).append("\nversion\t").append(sc.getVersion());
   sb.append("\nlength\t").append(sc.getLength());
   sb.append("\nreceived at\t").append(DateTimeUtil.formatDate2DateTimeStr());
   sb.append("\nfrom\t").append(wt.getRemoteName());
   sb.append("\n--------------------------------------------------------\n");
   PacketData bc = new PacketData(sc.getCode(), sb.toString());
   wt.handleWrite(bc);
   LOG.debug("summary sent to remote.\n{}", sb);
 }
예제 #2
0
 /**
  * Override super method
  *
  * @see org.apache.niolex.network.IPacketHandler#handlePacket(PacketData, IPacketWriter)
  */
 @Override
 public void handlePacket(PacketData sc, IPacketWriter wt) {
   // Dispatch package according to packet code.
   switch (sc.getCode()) {
       // Server published address list.
     case Config.CODE_NAME_DATA:
       List<String> list = transformer.getDataObject(sc);
       // Let sub classes to deal with it.
       handleRefresh(list);
       break;
       // Server published new address record.
     case Config.CODE_NAME_DIFF:
       AddressRecord bean = transformer.getDataObject(sc);
       // Let sub classes to deal with it.
       handleDiff(bean);
       break;
     default:
       LOG.warn("Packet received for code [{}] have no handler, just ignored.", sc.getCode());
       break;
   }
 }
 /**
  * Override super method
  *
  * @see
  *     org.apache.niolex.network.IPacketHandler#handlePacket(org.apache.niolex.network.PacketData,
  *     org.apache.niolex.network.IPacketWriter)
  */
 @Override
 public void handlePacket(PacketData sc, IPacketWriter wt) {
   String groupName = StringUtil.utf8ByteToStr(sc.getData());
   groupService.svrSendGroup(groupName);
 }