/**
  * read a packet from the leader
  *
  * @param pp the packet to be instantiated
  * @throws IOException
  */
 void readPacket(QuorumPacket pp) throws IOException {
   synchronized (leaderIs) {
     leaderIs.readRecord(pp, "packet");
   }
   long traceMask = ZooTrace.SERVER_PACKET_TRACE_MASK;
   if (pp.getType() == Leader.PING) {
     traceMask = ZooTrace.SERVER_PING_TRACE_MASK;
   }
   if (LOG.isTraceEnabled()) {
     ZooTrace.logQuorumPacket(LOG, traceMask, 'i', pp);
   }
 }
 /**
  * validate a session for a client
  *
  * @param clientId the client to be revalidated
  * @param timeout the timeout for which the session is valid
  * @return
  * @throws IOException
  */
 void validateSession(ServerCnxn cnxn, long clientId, int timeout) throws IOException {
   LOG.info("Revalidating client: 0x" + Long.toHexString(clientId));
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   DataOutputStream dos = new DataOutputStream(baos);
   dos.writeLong(clientId);
   dos.writeInt(timeout);
   dos.close();
   QuorumPacket qp = new QuorumPacket(Leader.REVALIDATE, -1, baos.toByteArray());
   pendingRevalidations.put(clientId, cnxn);
   if (LOG.isTraceEnabled()) {
     ZooTrace.logTraceMessage(
         LOG, ZooTrace.SESSION_TRACE_MASK, "To validate session 0x" + Long.toHexString(clientId));
   }
   writePacket(qp, true);
 }
 protected void revalidate(QuorumPacket qp) throws IOException {
   ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
   DataInputStream dis = new DataInputStream(bis);
   long sessionId = dis.readLong();
   boolean valid = dis.readBoolean();
   ServerCnxn cnxn = pendingRevalidations.remove(sessionId);
   if (cnxn == null) {
     LOG.warn("Missing session 0x" + Long.toHexString(sessionId) + " for validation");
   } else {
     zk.finishSessionInit(cnxn, valid);
   }
   if (LOG.isTraceEnabled()) {
     ZooTrace.logTraceMessage(
         LOG,
         ZooTrace.SESSION_TRACE_MASK,
         "Session 0x" + Long.toHexString(sessionId) + " is valid: " + valid);
   }
 }