当前位置: 首页>>代码示例>>Java>>正文


Java SerializeUtils类代码示例

本文整理汇总了Java中org.apache.zookeeper.server.util.SerializeUtils的典型用法代码示例。如果您正苦于以下问题:Java SerializeUtils类的具体用法?Java SerializeUtils怎么用?Java SerializeUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SerializeUtils类属于org.apache.zookeeper.server.util包,在下文中一共展示了SerializeUtils类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readSnapshotLog

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
private static void readSnapshotLog(String snapshotPath) throws Exception {
  FileInputStream fis = new FileInputStream(snapshotPath);
  BinaryInputArchive ia = BinaryInputArchive.getArchive(fis);
  Map<Long, Integer> sessions = new HashMap<Long, Integer>();
  DataTree dt = new DataTree();
  FileHeader header = new FileHeader();
  header.deserialize(ia, "fileheader");
  if (header.getMagic() != FileSnap.SNAP_MAGIC) {
    throw new IOException("mismatching magic headers " + header.getMagic() + " !=  "
        + FileSnap.SNAP_MAGIC);
  }
  SerializeUtils.deserializeSnapshot(dt, ia, sessions);

  if (bw != null) {
    bw.write(sessions.toString());
    bw.newLine();
  } else {
    System.out.println(sessions);
  }
  traverse(dt, 1, "/");

}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:ZKLogFormatter.java

示例2: processPacket

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * Controls the response of an observer to the receipt of a quorumpacket
 * @param qp
 * @throws IOException
 */
protected void processPacket(QuorumPacket qp) throws IOException{
    switch (qp.getType()) {
    case Leader.PING:
        ping(qp);
        break;
    case Leader.PROPOSAL:
        LOG.warn("Ignoring proposal");
        break;
    case Leader.COMMIT:
        LOG.warn("Ignoring commit");            
        break;            
    case Leader.UPTODATE:
        LOG.error("Received an UPTODATE message after Observer started");
        break;
    case Leader.REVALIDATE:
        revalidate(qp);
        break;
    case Leader.SYNC:
        ((ObserverZooKeeperServer)zk).sync();
        break;
    case Leader.INFORM:            
        TxnHeader hdr = new TxnHeader();
        Record txn = SerializeUtils.deserializeTxn(qp.getData(), hdr);
        Request request = new Request (null, hdr.getClientId(), 
                                       hdr.getCxid(),
                                       hdr.getType(), null, null);
        request.txn = txn;
        request.hdr = hdr;
        ObserverZooKeeperServer obs = (ObserverZooKeeperServer)zk;
        obs.commitRequest(request);            
        break;
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:39,代码来源:Observer.java

示例3: processPacket

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * Examine the packet received in qp and dispatch based on its contents.
 * @param qp
 * @throws IOException
 */
protected void processPacket(QuorumPacket qp) throws IOException{
    switch (qp.getType()) {
    case Leader.PING:            
        ping(qp);            
        break;
    case Leader.PROPOSAL:            
        TxnHeader hdr = new TxnHeader();
        Record txn = SerializeUtils.deserializeTxn(qp.getData(), hdr);
        if (hdr.getZxid() != lastQueued + 1) {
            LOG.warn("Got zxid 0x"
                    + Long.toHexString(hdr.getZxid())
                    + " expected 0x"
                    + Long.toHexString(lastQueued + 1));
        }
        lastQueued = hdr.getZxid();
        fzk.logRequest(hdr, txn);
        break;
    case Leader.COMMIT:
        fzk.commit(qp.getZxid());
        break;
    case Leader.UPTODATE:
        LOG.error("Received an UPTODATE message after Follower started");
        break;
    case Leader.REVALIDATE:
        revalidate(qp);
        break;
    case Leader.SYNC:
        fzk.sync();
        break;
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:37,代码来源:Follower.java

示例4: deserialize

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * deserialize the datatree from an inputarchive
 * @param dt the datatree to be serialized into
 * @param sessions the sessions to be filled up
 * @param ia the input archive to restore from
 * @throws IOException
 */
public void deserialize(DataTree dt, Map<Long, Integer> sessions,
        InputArchive ia) throws IOException {
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    if (header.getMagic() != SNAP_MAGIC) {
        throw new IOException("mismatching magic headers "
                + header.getMagic() + 
                " !=  " + FileSnap.SNAP_MAGIC);
    }
    SerializeUtils.deserializeSnapshot(dt,ia,sessions);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:FileSnap.java

示例5: serialize

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * serialize the datatree and sessions
 * @param dt the datatree to be serialized
 * @param sessions the sessions to be serialized
 * @param oa the output archive to serialize into
 * @param header the header of this snapshot
 * @throws IOException
 */
protected void serialize(DataTree dt,Map<Long, Integer> sessions,
        OutputArchive oa, FileHeader header) throws IOException {
    // this is really a programmatic error and not something that can
    // happen at runtime
    if(header==null)
        throw new IllegalStateException(
                "Snapshot's not open for writing: uninitialized header");
    header.serialize(oa, "fileheader");
    SerializeUtils.serializeSnapshot(dt,oa,sessions);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:19,代码来源:FileSnap.java

示例6: deserialize

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * deserialize the datatree from an inputarchive
 * @param dt the datatree to be serialized into
 * @param sessions the sessions to be filled up
 * @param ia the input archive to restore from
 * @throws IOException
 */
public void deserialize(DataTree dt, Map<Long, Integer> sessions,
        InputArchive ia) throws IOException {
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    if (header.getMagic() != SNAP_MAGIC) {
        throw new IOException("mismatching magic headers "
                + header.getMagic() +
                " !=  " + FileSnap.SNAP_MAGIC);
    }
    SerializeUtils.deserializeSnapshot(dt,ia,sessions);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:19,代码来源:FileSnap.java

示例7: next

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * the iterator that moves to the next transaction
 * @return true if there is more transactions to be read
 * false if not.
 */
public boolean next() throws IOException {
    if (ia == null) {
        return false;
    }
    try {
        long crcValue = ia.readLong("crcvalue");
        byte[] bytes = Util.readTxnBytes(ia);
        // Since we preallocate, we define EOF to be an
        if (bytes == null || bytes.length==0) {
            throw new EOFException("Failed to read " + logFile);
        }
        // EOF or corrupted record
        // validate CRC
        Checksum crc = makeChecksumAlgorithm();
        crc.update(bytes, 0, bytes.length);
        if (crcValue != crc.getValue())
            throw new IOException(CRC_ERROR);
        if (bytes == null || bytes.length == 0)
            return false;
        hdr = new TxnHeader();
        record = SerializeUtils.deserializeTxn(bytes, hdr);
    } catch (EOFException e) {
        LOG.debug("EOF excepton " + e);
        inputStream.close();
        inputStream = null;
        ia = null;
        hdr = null;
        // this means that the file has ended
        // we should go to the next file
        if (!goToNextLog()) {
            return false;
        }
        // if we went to the next log file, we should call next() again
        return next();
    }
    return true;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:43,代码来源:FileTxnLog.java

示例8: next

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * the iterator that moves to the next transaction
 * @return true if there is more transactions to be read
 * false if not.
 */
public boolean next() throws IOException {
    if (ia == null) {
        return false;
    }
    try {
        long crcValue = ia.readLong("crcvalue");
        byte[] bytes = Util.readTxnBytes(ia);
        // Since we preallocate, we define EOF to be an
        if (bytes == null || bytes.length==0)
           throw new EOFException("Failed to read");
        // EOF or corrupted record
        // validate CRC
        Checksum crc = makeChecksumAlgorithm();
        crc.update(bytes, 0, bytes.length);
        if (crcValue != crc.getValue())
            throw new IOException(CRC_ERROR);
        if (bytes == null || bytes.length == 0)
            return false;
        hdr = new TxnHeader();
        record = SerializeUtils.deserializeTxn(bytes, hdr);
    } catch (EOFException e) {
        LOG.debug("EOF excepton " + e);
        inputStream.close();
        inputStream = null;
        ia = null;
        hdr = null;
        // this means that the file has ended
        // we shoud go to the next file
        if (!goToNextLog()) {
            return false;
        }
        // if we went to the next log file, we should call next() again
        return next();
    }
    return true;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:42,代码来源:FileTxnLog.java

示例9: deserialize

import org.apache.zookeeper.server.util.SerializeUtils; //导入依赖的package包/类
/**
 * deserialize the datatree from an inputarchive
 * @param dt the datatree to be serialized into
 * @param sessions the sessions to be filled up
 * @param ia the input archive to restore from
 * @throws IOException
 */
public void deserialize(DataTree dt, Map<Long, Integer> sessions,
        InputArchive ia) throws IOException {
    FileHeader header = new FileHeader();
    // 反序列化fileheader
    header.deserialize(ia, "fileheader");
    // 校验魔数
    if (header.getMagic() != SNAP_MAGIC) {
        throw new IOException("mismatching magic headers "
                + header.getMagic() + 
                " !=  " + FileSnap.SNAP_MAGIC);
    }
    // 反序列化内存快照
    SerializeUtils.deserializeSnapshot(dt,ia,sessions);
}
 
开发者ID:txazo,项目名称:zookeeper,代码行数:22,代码来源:FileSnap.java


注:本文中的org.apache.zookeeper.server.util.SerializeUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。