org.apache.zookeeper.server.quorum.QuorumPacket.setData()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(72)

本文整理了Java中org.apache.zookeeper.server.quorum.QuorumPacket.setData方法的一些代码示例,展示了QuorumPacket.setData的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QuorumPacket.setData方法的具体详情如下:
包路径:org.apache.zookeeper.server.quorum.QuorumPacket
类名称:QuorumPacket
方法名:setData

QuorumPacket.setData介绍

暂无

代码示例

代码示例来源:origin: apache/zookeeper

protected void ping(QuorumPacket qp) throws IOException {
  // Send back the ping with our session data
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  Map<Long, Integer> touchTable = zk.getTouchSnapshot();
  for (Entry<Long, Integer> entry : touchTable.entrySet()) {
    dos.writeLong(entry.getKey());
    dos.writeInt(entry.getValue());
  }
  qp.setData(bos.toByteArray());
  writePacket(qp, true);
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

protected void ping(QuorumPacket qp) throws IOException {
  // Send back the ping with our session data
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  HashMap<Long, Integer> touchTable = zk
      .getTouchSnapshot();
  for (Entry<Long, Integer> entry : touchTable.entrySet()) {
    dos.writeLong(entry.getKey());
    dos.writeInt(entry.getValue());
  }
  qp.setData(bos.toByteArray());
  writePacket(qp, true);
}

代码示例来源:origin: apache/zookeeper

@Override
public void revalidateSession(QuorumPacket qp, LearnerHandler learnerHandler) throws IOException {
  ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
  DataInputStream dis = new DataInputStream(bis);
  long id = dis.readLong();
  int to = dis.readInt();
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  dos.writeLong(id);
  boolean valid = zk.checkIfValidGlobalSession(id, to);
  if (valid) {
    try {
      // set the session owner as the follower that owns the session
      zk.setOwner(id, learnerHandler);
    } catch (KeeperException.SessionExpiredException e) {
      LOG.error("Somehow session " + Long.toHexString(id) + " expired right after being renewed! (impossible)", e);
    }
  }
  if (LOG.isTraceEnabled()) {
    ZooTrace.logTraceMessage(LOG,
        ZooTrace.SESSION_TRACE_MASK,
        "Session 0x" + Long.toHexString(id)
            + " is valid: "+ valid);
  }
  dos.writeBoolean(valid);
  qp.setData(bos.toByteArray());
  learnerHandler.queuePacket(qp);
}

代码示例来源:origin: apache/zookeeper

/**
 * Forge an invalid session packet as a LEADER do
 *
 * @param valid <code>true</code> to create a valid session message
 *
 * @throws Exception
 */
private QuorumPacket createValidateSessionPacketResponse(boolean valid) throws Exception {
  QuorumPacket qp = createValidateSessionPacket();
  ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
  DataInputStream dis = new DataInputStream(bis);
  long id = dis.readLong();
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  dos.writeLong(id);
  // false means that the session has expired
  dos.writeBoolean(valid);
  qp.setData(bos.toByteArray());
  return qp;
}

代码示例来源:origin: apache/zookeeper

private void proposeSetData(QuorumPacket qp, long zxid, String data, int version) throws IOException {
    qp.setType(Leader.PROPOSAL);
    qp.setZxid(zxid);
    TxnHeader hdr = new TxnHeader(4, 1414, qp.getZxid(), 55, ZooDefs.OpCode.setData);
    SetDataTxn sdt = new SetDataTxn("/foo", data.getBytes(), version);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OutputArchive boa = BinaryOutputArchive.getArchive(baos);
    boa.writeRecord(hdr, null);
    boa.writeRecord(sdt, null);
    qp.setData(baos.toByteArray());
  }
});

代码示例来源:origin: apache/zookeeper

private void proposeSetData(QuorumPacket qp, String path,
      long zxid, String data, int version) throws IOException {
    qp.setType(Leader.PROPOSAL);
    qp.setZxid(zxid);
    TxnHeader hdr = new TxnHeader(4, 1414, qp.getZxid(), 55,
        ZooDefs.OpCode.setData);
    SetDataTxn sdt = new SetDataTxn(path, data.getBytes(), version);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OutputArchive boa = BinaryOutputArchive.getArchive(baos);
    boa.writeRecord(hdr, null);
    boa.writeRecord(sdt, null);
    qp.setData(baos.toByteArray());
  }
});

代码示例来源:origin: apache/zookeeper

private void proposeNewSession(QuorumPacket qp, long zxid, long sessionId) throws IOException {
    qp.setType(Leader.PROPOSAL);
    qp.setZxid(zxid);
    TxnHeader hdr = new TxnHeader(4, 1414, qp.getZxid(), 55, ZooDefs.OpCode.createSession);
    CreateSessionTxn cst = new CreateSessionTxn(30000);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OutputArchive boa = BinaryOutputArchive.getArchive(baos);
    boa.writeRecord(hdr, null);
    boa.writeRecord(cst, null);
    qp.setData(baos.toByteArray());
  }
});

代码示例来源:origin: apache/zookeeper

BinaryOutputArchive boa = BinaryOutputArchive.getArchive(bsid);
boa.writeRecord(li, "LearnerInfo");
qp.setData(bsid.toByteArray());

代码示例来源:origin: org.apache.zookeeper/zookeeper

qp.setData(bos.toByteArray());
queuedPackets.add(qp);
break;

代码示例来源:origin: org.apache.zookeeper/zookeeper

BinaryOutputArchive boa = BinaryOutputArchive.getArchive(bsid);
boa.writeRecord(li, "LearnerInfo");
qp.setData(bsid.toByteArray());

代码示例来源:origin: apache/zookeeper

byte protoBytes[] = new byte[4];
ByteBuffer.wrap(protoBytes).putInt(0x10000);
qp.setData(protoBytes);
oa.writeRecord(qp, null);
qp.setData(new byte[0]);
qp.setZxid(zkDb.getDataTreeLastProcessedZxid());
oa.writeRecord(qp, null);
qp.setType(Leader.NEWLEADER);
qp.setZxid(ZxidUtils.makeZxid(1, 0));
qp.setData(null);
oa.writeRecord(qp, null);
qp.setType(Leader.UPTODATE);

代码示例来源:origin: apache/zookeeper

byte protoBytes[] = new byte[4];
ByteBuffer.wrap(protoBytes).putInt(0x10000);
qp.setData(protoBytes);
oa.writeRecord(qp, null);
qp.setData(new byte[0]);
qp.setZxid(zkDb.getDataTreeLastProcessedZxid());
oa.writeRecord(qp, null);

代码示例来源:origin: apache/zookeeper

byte protoBytes[] = new byte[4];
ByteBuffer.wrap(protoBytes).putInt(0x10000);
qp.setData(protoBytes);
oa.writeRecord(qp, null);
qp.setData(new byte[0]);
qp.setZxid(zkDb.getDataTreeLastProcessedZxid());
oa.writeRecord(qp, null);

代码示例来源:origin: org.apache.hadoop/zookeeper

protected void ping(QuorumPacket qp) throws IOException {
  // Send back the ping with our session data
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  HashMap<Long, Integer> touchTable = zk
      .getTouchSnapshot();
  for (Entry<Long, Integer> entry : touchTable.entrySet()) {
    dos.writeLong(entry.getKey());
    dos.writeInt(entry.getValue());
  }
  qp.setData(bos.toByteArray());
  writePacket(qp, true);
}

代码示例来源:origin: org.apache.hadoop/zookeeper

DataOutputStream dsid = new DataOutputStream(bsid);
dsid.writeLong(self.getId());
qp.setData(bsid.toByteArray());

代码示例来源:origin: org.apache.hadoop/zookeeper

qp.setData(bos.toByteArray());
queuedPackets.add(qp);
break;

相关文章