本文整理汇总了Java中org.apache.jute.BinaryInputArchive类的典型用法代码示例。如果您正苦于以下问题:Java BinaryInputArchive类的具体用法?Java BinaryInputArchive怎么用?Java BinaryInputArchive使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryInputArchive类属于org.apache.jute包,在下文中一共展示了BinaryInputArchive类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadThisSnapShot
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/**
* create the old snapshot database
* apply logs to it and create the final
* database
* @throws IOException
*/
private void loadThisSnapShot() throws IOException {
// pick the most recent snapshot
File snapshot = findMostRecentSnapshot();
if (snapshot == null) {
throw new IOException("Invalid snapshots " +
"or not snapshots in " + snapShotDir);
}
InputStream inputstream = new BufferedInputStream(
new FileInputStream(snapshot));
InputArchive ia = BinaryInputArchive.getArchive(inputstream);
deserializeSnapshot(oldDataTree, ia, sessionsWithTimeouts);
//ok done with the snapshot
// now apply the logs
long snapshotZxid = oldDataTree.lastProcessedZxid;
File[] files = FileTxnLog.getLogFiles(
dataDir.listFiles(), snapshotZxid);
long zxid = processLogFiles(oldDataTree, files);
//check for this zxid to be sane
if (zxid != oldDataTree.lastProcessedZxid) {
LOG.error("Zxids not equal " + " log zxid " +
zxid + " datatree processed " + oldDataTree.lastProcessedZxid);
}
}
示例2: readLength
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/** Reads the first 4 bytes of lenBuffer, which could be true length or
* four letter word.
*
* @param k selection key
* @return true if length read, otw false (wasn't really the length)
* @throws IOException if buffer size exceeds maxBuffer size
*/
private boolean readLength(SelectionKey k) throws IOException {
// Read the length, now get the buffer
int len = lenBuffer.getInt();
if (!initialized && checkFourLetterWord(sk, len)) {
return false;
}
if (len < 0 || len > BinaryInputArchive.maxBuffer) {
throw new IOException("Len error " + len);
}
if (zkServer == null) {
throw new IOException("ZooKeeperServer not running");
}
incomingBuffer = ByteBuffer.allocate(len);
return true;
}
示例3: getCheckSum
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
DataTree dt = new DataTree();
Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
InputStream snapIS = new BufferedInputStream(new FileInputStream(
snapFile));
CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
InputArchive ia = BinaryInputArchive.getArchive(crcIn);
try {
snap.deserialize(dt, sessions, ia);
} catch (IOException ie) {
// we failed on the most recent snapshot
// must be incomplete
// try reading the next one
// after corrupting
snapIS.close();
crcIn.close();
throw ie;
}
long checksum = crcIn.getChecksum().getValue();
long val = ia.readLong("val");
snapIS.close();
crcIn.close();
return (val != checksum);
}
示例4: testPad
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/**
* Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
* fixes it.
*/
@Test
public void testPad() throws Exception {
File tmpDir = ClientBase.createTmpDir();
FileTxnLog txnLog = new FileTxnLog(tmpDir);
TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
System.currentTimeMillis(), OpCode.create);
Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
txnLog.append(txnHeader, txn);
FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
Long.toHexString(txnHeader.getZxid()));
BinaryInputArchive ia = BinaryInputArchive.getArchive(in);
FileHeader header = new FileHeader();
header.deserialize(ia, "fileheader");
LOG.info("Received magic : " + header.getMagic() +
" Expected : " + FileTxnLog.TXNLOG_MAGIC);
Assert.assertTrue("Missing magic number ",
header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
示例5: readLength
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/** Reads the first 4 bytes of lenBuffer, which could be true length or
* four letter word.
*
* @param k selection key
* @return true if length read, otw false (wasn't really the length)
* @throws IOException if buffer size exceeds maxBuffer size
*/
private boolean readLength(SelectionKey k) throws IOException {
// Read the length, now get the buffer
int len = lenBuffer.getInt();
if (!initialized && checkFourLetterWord(sk, len)) {
return false;
}
if (len < 0 || len > BinaryInputArchive.maxBuffer) {
throw new IOException("Len error " + len);
}
if (!isZKServerRunning()) {
throw new IOException("ZooKeeperServer not running");
}
incomingBuffer = ByteBuffer.allocate(len);
return true;
}
示例6: deserializeTree
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
private static void deserializeTree(int depth, int width, int len)
throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
BinaryInputArchive ia;
int count;
{
DataTree tree = new DataTree();
SerializationPerfTest.createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]);
count = tree.getNodeCount();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
tree.serialize(oa, "test");
baos.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ia = BinaryInputArchive.getArchive(bais);
}
DataTree dserTree = new DataTree();
System.gc();
long start = System.nanoTime();
dserTree.deserialize(ia, "test");
long end = System.nanoTime();
long durationms = (end - start) / 1000000L;
long pernodeus = ((end - start) / 1000L) / count;
Assert.assertEquals(count, dserTree.getNodeCount());
LOG.info("Deserialized " + count + " nodes in " + durationms
+ " ms (" + pernodeus + "us/node), depth=" + depth + " width="
+ width + " datalen=" + len);
}
示例7: testPad
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/**
* Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
* fixes it.
*/
@Test
public void testPad() throws Exception {
File tmpDir = ClientBase.createTmpDir();
FileTxnLog txnLog = new FileTxnLog(tmpDir);
TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
Time.currentElapsedTime(), OpCode.create);
Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
txnLog.append(txnHeader, txn);
FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
Long.toHexString(txnHeader.getZxid()));
BinaryInputArchive ia = BinaryInputArchive.getArchive(in);
FileHeader header = new FileHeader();
header.deserialize(ia, "fileheader");
LOG.info("Received magic : " + header.getMagic() +
" Expected : " + FileTxnLog.TXNLOG_MAGIC);
Assert.assertTrue("Missing magic number ",
header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
示例8: readHeader
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/**
* read the header of the transaction file
* @param file the transaction file to read
* @return header that was read fomr the file
* @throws IOException
*/
private static FileHeader readHeader(File file) throws IOException {
InputStream is =null;
try {
is = new BufferedInputStream(new FileInputStream(file));
InputArchive ia=BinaryInputArchive.getArchive(is);
FileHeader hdr = new FileHeader();
hdr.deserialize(ia, "fileheader");
return hdr;
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
LOG.warn("Ignoring exception during close", e);
}
}
}
示例9: testPad
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/**
* Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
* fixes it.
*/
@Test
public void testPad() throws Exception {
File tmpDir = ClientBase.createTmpDir();
FileTxnLog txnLog = new FileTxnLog(tmpDir);
TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
System.currentTimeMillis(), OpCode.create);
Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
txnLog.append(txnHeader, txn);
FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
Long.toHexString(txnHeader.getZxid()));
BinaryInputArchive ia = BinaryInputArchive.getArchive(in);
FileHeader header = new FileHeader();
header.deserialize(ia, "fileheader");
LOG.info("Expected header :" + header.getMagic() +
" Received : " + FileTxnLog.TXNLOG_MAGIC);
Assert.assertTrue("Missing magic number ",
header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
示例10: readConnectResult
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
void readConnectResult() throws IOException {
if (LOG.isTraceEnabled()) {
StringBuilder buf = new StringBuilder("0x[");
for (byte b : incomingBuffer.array()) {
buf.append(Integer.toHexString(b) + ",");
}
buf.append("]");
LOG.trace("readConnectResult " + incomingBuffer.remaining() + " "
+ buf.toString());
}
ByteBufferInputStream bbis = new ByteBufferInputStream(incomingBuffer);
BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis);
ConnectResponse conRsp = new ConnectResponse();
conRsp.deserialize(bbia, "connect");
// read "is read-only" flag
boolean isRO = false;
try {
isRO = bbia.readBool("readOnly");
} catch (IOException e) {
// this is ok -- just a packet from an old server which
// doesn't contain readOnly field
LOG.warn("Connected to an old server; r-o mode will be unavailable");
}
this.sessionId = conRsp.getSessionId();
sendThread.onConnected(conRsp.getTimeOut(), this.sessionId,
conRsp.getPasswd(), isRO);
}
示例11: processLogFiles
import org.apache.jute.BinaryInputArchive; //导入依赖的package包/类
/**
* apply the log files to the datatree
* @param oldTree the datatreee to apply the logs to
* @param logFiles the logs to be applied
* @throws IOException
*/
private long processLogFiles(DataTreeV1 oldTree,
File[] logFiles) throws IOException {
long zxid = 0;
for (File f: logFiles) {
LOG.info("Processing log file: " + f);
InputStream logIs =
new BufferedInputStream(new FileInputStream(f));
zxid = playLog(BinaryInputArchive.getArchive(logIs));
logIs.close();
}
return zxid;
}