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


Java SerializeUtils.deserializeTxn方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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();
        BinaryInputArchive ia = BinaryInputArchive
                .getArchive(new ByteArrayInputStream(qp.getData()));
        Record txn = SerializeUtils.deserializeTxn(ia, 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:prodigeni,项目名称:zookeeper.dsc,代码行数:41,代码来源:Observer.java

示例5: 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();
        BinaryInputArchive ia = BinaryInputArchive
        .getArchive(new ByteArrayInputStream(qp.getData()));
        Record txn = SerializeUtils.deserializeTxn(ia, 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:prodigeni,项目名称:zookeeper.dsc,代码行数:39,代码来源:Follower.java

示例6: 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;
        InputArchive iab = BinaryInputArchive
                            .getArchive(new ByteArrayInputStream(bytes));
        hdr = new TxnHeader();
        record = SerializeUtils.deserializeTxn(iab, hdr);
    } catch (EOFException e) {
        LOG.debug("EOF excepton " + e);
        inputStream.close();
        inputStream = null;
        ia = null;
        hdr = null;
        // thsi 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:prodigeni,项目名称:zookeeper.dsc,代码行数:44,代码来源:FileTxnLog.java

示例7: playLog

import org.apache.zookeeper.server.util.SerializeUtils; //导入方法依赖的package包/类
/**
 * play the log from this logstream into the datatree
 * @param logStream
 * @return
 * @throws IOException
 */
public long playLog(InputArchive logStream) throws IOException {
    long highestZxid = 0;
    try {
        while (true) {
            byte[] bytes = logStream.readBuffer("txnEntry");
            if (bytes.length == 0) {
                // Since we preallocate, we define EOF to be an
                // empty transaction
                throw new EOFException();
            }
            TxnHeader hdr = new TxnHeader();
            Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
            if (logStream.readByte("EOR") != 'B') {
                LOG.warn("Last transaction was partial.");
                throw new EOFException("Last transaction was partial.");
            }
            if (hdr.getZxid() <= highestZxid && highestZxid != 0) {
                LOG.error(highestZxid + "(higestZxid) >= "
                        + hdr.getZxid() + "(next log) for type "
                        + hdr.getType());
            } else {
                highestZxid = hdr.getZxid();
            }
            switch (hdr.getType()) {
            case OpCode.createSession:
                sessionsWithTimeouts.put(hdr.getClientId(),
                        ((CreateSessionTxn) txn).getTimeOut());
                if (LOG.isTraceEnabled()) {
                    ZooTrace.logTraceMessage(LOG,
                                             ZooTrace.SESSION_TRACE_MASK,
                            "playLog --- create session in log: 0x"
                                    + Long.toHexString(hdr.getClientId())
                                    + " with timeout: "
                                    + ((CreateSessionTxn) txn).getTimeOut());
                }
                // give dataTree a chance to sync its lastProcessedZxid
                oldDataTree.processTxn(hdr, txn);
                break;
            case OpCode.closeSession:
                sessionsWithTimeouts.remove(hdr.getClientId());
                if (LOG.isTraceEnabled()) {
                    ZooTrace.logTraceMessage(LOG,
                            ZooTrace.SESSION_TRACE_MASK,
                            "playLog --- close session in log: 0x"
                                    + Long.toHexString(hdr.getClientId()));
                }
                oldDataTree.processTxn(hdr, txn);
                break;
            default:
                oldDataTree.processTxn(hdr, txn);
            }
            Request r = new Request(null, 0, hdr.getCxid(), hdr.getType(),
                    null, null);
            r.txn = txn;
            r.hdr = hdr;
            r.zxid = hdr.getZxid();
        }
    } catch (EOFException e) {
        // expected in some cases - see comments in try block
    }
    return highestZxid;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:69,代码来源:UpgradeSnapShotV1.java

示例8: main

import org.apache.zookeeper.server.util.SerializeUtils; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("USAGE: LogFormatter log_file");
        System.exit(2);
    }
    FileInputStream fis = new FileInputStream(args[0]);
    BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");

    if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
        System.err.println("Invalid magic number for " + args[0]);
        System.exit(2);
    }
    System.out.println("ZooKeeper Transactional Log File with dbid "
            + fhdr.getDbid() + " txnlog format version "
            + fhdr.getVersion());

    int count = 0;
    while (true) {
        long crcValue;
        byte[] bytes;
        try {
            crcValue = logStream.readLong("crcvalue");

            bytes = logStream.readBuffer("txnEntry");
        } catch (EOFException e) {
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        Checksum crc = new Adler32();
        crc.update(bytes, 0, bytes.length);
        if (crcValue != crc.getValue()) {
            throw new IOException("CRC doesn't match " + crcValue +
                    " vs " + crc.getValue());
        }
        TxnHeader hdr = new TxnHeader();
        Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
        System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(hdr.getTime()))
                + " session 0x"
                + Long.toHexString(hdr.getClientId())
                + " cxid 0x"
                + Long.toHexString(hdr.getCxid())
                + " zxid 0x"
                + Long.toHexString(hdr.getZxid())
                + " " + TraceFormatter.op2String(hdr.getType()) + " " + txn);
        if (logStream.readByte("EOR") != 'B') {
            LOG.error("Last transaction was partial.");
            throw new EOFException("Last transaction was partial.");
        }
        count++;
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:64,代码来源:LogFormatter.java

示例9: TxnLogSource

import org.apache.zookeeper.server.util.SerializeUtils; //导入方法依赖的package包/类
public TxnLogSource(String file) throws IOException {
this.file = file;

skiplist = new LogSkipList();

RandomAccessFileReader reader = new RandomAccessFileReader(new File(file));
try {
    BinaryInputArchive logStream = new BinaryInputArchive(reader);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");
    
    byte[] bytes = null;
    while (true) {
	long lastFp = reader.getPosition();

	long crcValue;

	try {
	    crcValue = logStream.readLong("crcvalue");
	    bytes = logStream.readBuffer("txnEntry");
	} catch (EOFException e) {
	    break;
	}
	
	if (bytes.length == 0) {
	    break;
	}
	Checksum crc = new Adler32();
	crc.update(bytes, 0, bytes.length);
	if (crcValue != crc.getValue()) {
	    throw new IOException("CRC doesn't match " + crcValue +
				  " vs " + crc.getValue());
	}
	if (logStream.readByte("EOR") != 'B') {
	    throw new EOFException("Last transaction was partial.");
	}
	TxnHeader hdr = new TxnHeader();
	Record r = SerializeUtils.deserializeTxn(bytes, hdr);
	
	if (starttime == 0) {
	    starttime = hdr.getTime();
	}
	endtime = hdr.getTime();

	if (size % skipN == 0) {
	    skiplist.addMark(hdr.getTime(), lastFp, size);
	}
	size++;
    }
    if (bytes == null) {
	throw new IOException("Nothing read from ("+file+")");
    }
} finally {
    reader.close();
}
   }
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:57,代码来源:TxnLogSource.java

示例10: readTransactionLog

import org.apache.zookeeper.server.util.SerializeUtils; //导入方法依赖的package包/类
private static void readTransactionLog(String logfilepath) throws FileNotFoundException,
    IOException, EOFException {
  FileInputStream fis = new FileInputStream(logfilepath);
  BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
  FileHeader fhdr = new FileHeader();
  fhdr.deserialize(logStream, "fileheader");

  if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
    System.err.println("Invalid magic number for " + logfilepath);
    System.exit(2);
  }

  if (bw != null) {
    bw.write("ZooKeeper Transactional Log File with dbid " + fhdr.getDbid()
        + " txnlog format version " + fhdr.getVersion());
    bw.newLine();
  } else {
    System.out.println("ZooKeeper Transactional Log File with dbid " + fhdr.getDbid()
        + " txnlog format version " + fhdr.getVersion());
  }

  int count = 0;
  while (true) {
    long crcValue;
    byte[] bytes;
    try {
      crcValue = logStream.readLong("crcvalue");

      bytes = logStream.readBuffer("txnEntry");
    } catch (EOFException e) {
      if (bw != null) {
        bw.write("EOF reached after " + count + " txns.");
        bw.newLine();
      } else {
        System.out.println("EOF reached after " + count + " txns.");
      }

      break;
    }
    if (bytes.length == 0) {
      // Since we preallocate, we define EOF to be an
      // empty transaction
      if (bw != null) {
        bw.write("EOF reached after " + count + " txns.");
        bw.newLine();
      } else {
        System.out.println("EOF reached after " + count + " txns.");
      }

      return;
    }
    Checksum crc = new Adler32();
    crc.update(bytes, 0, bytes.length);
    if (crcValue != crc.getValue()) {
      throw new IOException("CRC doesn't match " + crcValue + " vs " + crc.getValue());
    }
    TxnHeader hdr = new TxnHeader();
    Record txn = SerializeUtils.deserializeTxn(bytes, hdr);
    if (bw != null) {
      bw.write(formatTransaction(hdr, txn));
      bw.newLine();
    } else {
      System.out.println(formatTransaction(hdr, txn));
    }

    if (logStream.readByte("EOR") != 'B') {
      LOG.error("Last transaction was partial.");
      throw new EOFException("Last transaction was partial.");
    }
    count++;
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:73,代码来源:ZKLogFormatter.java

示例11: playLog

import org.apache.zookeeper.server.util.SerializeUtils; //导入方法依赖的package包/类
/**
 * play the log from this logstream into the datatree
 * @param logStream
 * @return
 * @throws IOException
 */
public long playLog(InputArchive logStream) throws IOException {
    long highestZxid = 0;
    try {
        while (true) {
            byte[] bytes = logStream.readBuffer("txnEntry");
            if (bytes.length == 0) {
                // Since we preallocate, we define EOF to be an
                // empty transaction
                throw new EOFException();
            }
            InputArchive ia = BinaryInputArchive
                    .getArchive(new ByteArrayInputStream(bytes));
            TxnHeader hdr = new TxnHeader();
            Record txn = SerializeUtils.deserializeTxn(ia, hdr);
            if (logStream.readByte("EOR") != 'B') {
                LOG.warn("Last transaction was partial.");
                throw new EOFException("Last transaction was partial.");
            }
            if (hdr.getZxid() <= highestZxid && highestZxid != 0) {
                LOG.error(highestZxid + "(higestZxid) >= "
                        + hdr.getZxid() + "(next log) for type "
                        + hdr.getType());
            } else {
                highestZxid = hdr.getZxid();
            }
            switch (hdr.getType()) {
            case OpCode.createSession:
                sessionsWithTimeouts.put(hdr.getClientId(),
                        ((CreateSessionTxn) txn).getTimeOut());
                if (LOG.isTraceEnabled()) {
                    ZooTrace.logTraceMessage(LOG,
                                             ZooTrace.SESSION_TRACE_MASK,
                            "playLog --- create session in log: 0x"
                                    + Long.toHexString(hdr.getClientId())
                                    + " with timeout: "
                                    + ((CreateSessionTxn) txn).getTimeOut());
                }
                // give dataTree a chance to sync its lastProcessedZxid
                oldDataTree.processTxn(hdr, txn);
                break;
            case OpCode.closeSession:
                sessionsWithTimeouts.remove(hdr.getClientId());
                if (LOG.isTraceEnabled()) {
                    ZooTrace.logTraceMessage(LOG,
                            ZooTrace.SESSION_TRACE_MASK,
                            "playLog --- close session in log: 0x"
                                    + Long.toHexString(hdr.getClientId()));
                }
                oldDataTree.processTxn(hdr, txn);
                break;
            default:
                oldDataTree.processTxn(hdr, txn);
            }
            Request r = new Request(null, 0, hdr.getCxid(), hdr.getType(),
                    null, null);
            r.txn = txn;
            r.hdr = hdr;
            r.zxid = hdr.getZxid();
        }
    } catch (EOFException e) {
        // expected in some cases - see comments in try block
    }
    return highestZxid;
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:71,代码来源:UpgradeSnapShotV1.java

示例12: main

import org.apache.zookeeper.server.util.SerializeUtils; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("USAGE: LogFormatter log_file");
        System.exit(2);
    }
    FileInputStream fis = new FileInputStream(args[0]);
    BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
    FileHeader fhdr = new FileHeader();
    fhdr.deserialize(logStream, "fileheader");

    if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) {
        System.err.println("Invalid magic number for " + args[0]);
        System.exit(2);
    }
    System.out.println("ZooKeeper Transactional Log File with dbid "
            + fhdr.getDbid() + " txnlog format version "
            + fhdr.getVersion());

    int count = 0;
    while (true) {
        long crcValue;
        byte[] bytes;
        try {
            crcValue = logStream.readLong("crcvalue");

            bytes = logStream.readBuffer("txnEntry");
        } catch (EOFException e) {
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        if (bytes.length == 0) {
            // Since we preallocate, we define EOF to be an
            // empty transaction
            System.out.println("EOF reached after " + count + " txns.");
            return;
        }
        Checksum crc = new Adler32();
        crc.update(bytes, 0, bytes.length);
        if (crcValue != crc.getValue()) {
            throw new IOException("CRC doesn't match " + crcValue +
                    " vs " + crc.getValue());
        }
        InputArchive iab = BinaryInputArchive
                            .getArchive(new ByteArrayInputStream(bytes));
        TxnHeader hdr = new TxnHeader();
        SerializeUtils.deserializeTxn(iab, hdr);
        System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
                DateFormat.LONG).format(new Date(hdr.getTime()))
                + " session 0x"
                + Long.toHexString(hdr.getClientId())
                + " cxid 0x"
                + Long.toHexString(hdr.getCxid())
                + " zxid 0x"
                + Long.toHexString(hdr.getZxid())
                + " " + TraceFormatter.op2String(hdr.getType()));
        if (logStream.readByte("EOR") != 'B') {
            LOG.error("Last transaction was partial.");
            throw new EOFException("Last transaction was partial.");
        }
        count++;
    }
}
 
开发者ID:prodigeni,项目名称:zookeeper.dsc,代码行数:66,代码来源:LogFormatter.java


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