本文整理汇总了Java中org.apache.jute.InputArchive类的典型用法代码示例。如果您正苦于以下问题:Java InputArchive类的具体用法?Java InputArchive怎么用?Java InputArchive使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InputArchive类属于org.apache.jute包,在下文中一共展示了InputArchive类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.apache.jute.InputArchive; //导入依赖的package包/类
public void deserialize(InputArchive archive, String tag)
throws IOException {
archive.startRecord("node");
data = archive.readBuffer("data");
Index i = archive.startVector("acl");
if (i != null) {
acl = new ArrayList<ACL>();
while (!i.done()) {
ACL a = new ACL();
a.deserialize(archive, "aclEntry");
acl.add(a);
i.incr();
}
}
archive.endVector("acl");
stat = new StatPersistedV1();
stat.deserialize(archive, "stat");
archive.endRecord("node");
}
示例2: deserializeSnapshot
import org.apache.jute.InputArchive; //导入依赖的package包/类
/**
* deseriluize from an inputarchive
* @param oldTree the tree to be created
* @param ia the input archive to be read from
* @param sessions the sessions to be created
* @throws IOException
*/
private void deserializeSnapshot(DataTreeV1 oldTree, InputArchive ia,
Map<Long, Integer> sessions) throws IOException {
int count = ia.readInt("count");
while (count > 0) {
long id = ia.readLong("id");
int to = ia.readInt("timeout");
sessions.put(id, to);
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK,
"loadData --- session in archive: " + id
+ " with timeout: " + to);
}
count--;
}
oldTree.deserialize(ia, "tree");
}
示例3: loadThisSnapShot
import org.apache.jute.InputArchive; //导入依赖的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);
}
}
示例4: readTxnBytes
import org.apache.jute.InputArchive; //导入依赖的package包/类
/**
* Reads a transaction entry from the input archive.
* @param ia archive to read from
* @return null if the entry is corrupted or EOF has been reached; a buffer
* (possible empty) containing serialized transaction record.
* @throws IOException
*/
public static byte[] readTxnBytes(InputArchive ia) throws IOException {
try{
byte[] bytes = ia.readBuffer("txtEntry");
// Since we preallocate, we define EOF to be an
// empty transaction
if (bytes.length == 0)
return bytes;
if (ia.readByte("EOF") != 'B') {
LOG.error("Last transaction was partial.");
return null;
}
return bytes;
}catch(EOFException e){}
return null;
}
示例5: deserialize
import org.apache.jute.InputArchive; //导入依赖的package包/类
public synchronized void deserialize(InputArchive ia) throws IOException {
clear();
int i = ia.readInt("map");
while (i > 0) {
Long val = ia.readLong("long");
if (aclIndex < val) {
aclIndex = val;
}
List<ACL> aclList = new ArrayList<ACL>();
Index j = ia.startVector("acls");
while (!j.done()) {
ACL acl = new ACL();
acl.deserialize(ia, "acl");
aclList.add(acl);
j.incr();
}
longKeyMap.put(val, aclList);
aclKeyMap.put(aclList, val);
referenceCounter.put(val, new AtomicLongWithEquals(0));
i--;
}
}
示例6: deserializeSnapshot
import org.apache.jute.InputArchive; //导入依赖的package包/类
public static void deserializeSnapshot(DataTree dt,InputArchive ia,
Map<Long, Integer> sessions) throws IOException {
int count = ia.readInt("count");
while (count > 0) {
long id = ia.readLong("id");
int to = ia.readInt("timeout");
sessions.put(id, to);
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK,
"loadData --- session in archive: " + id
+ " with timeout: " + to);
}
count--;
}
dt.deserialize(ia, "tree");
}
示例7: testAbandonBeforeACKEpoch
import org.apache.jute.InputArchive; //导入依赖的package包/类
/**
* Tests that when a quorum of followers send LearnerInfo but do not ack the epoch (which is sent
* by the leader upon receipt of LearnerInfo from a quorum), the leader does not start using this epoch
* as it would in the normal case (when a quorum do ack the epoch). This tests ZK-1192
* @throws Exception
*/
@Test
public void testAbandonBeforeACKEpoch() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException, InterruptedException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000);
byte liBytes[] = new byte[12];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Thread.sleep(l.self.getInitLimit()*l.self.getTickTime() + 5000);
// The leader didn't get a quorum of acks - make sure that leader's current epoch is not advanced
Assert.assertEquals(0, l.self.getCurrentEpoch());
}
});
}
示例8: getCheckSum
import org.apache.jute.InputArchive; //导入依赖的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);
}
示例9: testAbandonBeforeACKEpoch
import org.apache.jute.InputArchive; //导入依赖的package包/类
/**
* Tests that when a quorum of followers send LearnerInfo but do not ack the epoch (which is sent
* by the leader upon receipt of LearnerInfo from a quorum), the leader does not start using this epoch
* as it would in the normal case (when a quorum do ack the epoch). This tests ZK-1192
* @throws Exception
*/
@Test
public void testAbandonBeforeACKEpoch() throws Exception {
testLeaderConversation(new LeaderConversation() {
public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
throws IOException, InterruptedException {
/* we test a normal run. everything should work out well. */
LearnerInfo li = new LearnerInfo(1, 0x10000, 0);
byte liBytes[] = new byte[20];
ByteBufferOutputStream.record2ByteBuffer(li,
ByteBuffer.wrap(liBytes));
QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
liBytes, null);
oa.writeRecord(qp, null);
readPacketSkippingPing(ia, qp);
Assert.assertEquals(Leader.LEADERINFO, qp.getType());
Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
0x10000);
Thread.sleep(l.self.getInitLimit()*l.self.getTickTime() + 5000);
// The leader didn't get a quorum of acks - make sure that leader's current epoch is not advanced
Assert.assertEquals(0, l.self.getCurrentEpoch());
}
});
}
示例10: readHeader
import org.apache.jute.InputArchive; //导入依赖的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);
}
}
}
示例11: deserializeSnapshot
import org.apache.jute.InputArchive; //导入依赖的package包/类
public static void deserializeSnapshot(DataTree dt,InputArchive ia,
Map<Long, Integer> sessions) throws IOException {
// 读取session个数
int count = ia.readInt("count");
while (count > 0) {
// session id
long id = ia.readLong("id");
// session超时时间
int to = ia.readInt("timeout");
// 解析session集合
sessions.put(id, to);
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK,
"loadData --- session in archive: " + id
+ " with timeout: " + to);
}
count--;
}
// 反序列化tree
dt.deserialize(ia, "tree");
}
示例12: deserializeList
import org.apache.jute.InputArchive; //导入依赖的package包/类
private void deserializeList(Map<Long, List<ACL>> longKeyMap,
InputArchive ia) throws IOException {
int i = ia.readInt("map");
while (i > 0) {
Long val = ia.readLong("long");
if (aclIndex < val) {
aclIndex = val;
}
List<ACL> aclList = new ArrayList<ACL>();
Index j = ia.startVector("acls");
while (!j.done()) {
ACL acl = new ACL();
acl.deserialize(ia, "acl");
aclList.add(acl);
j.incr();
}
longKeyMap.put(val, aclList);
aclKeyMap.put(aclList, val);
i--;
}
}
示例13: deserializeList
import org.apache.jute.InputArchive; //导入依赖的package包/类
private void deserializeList(Map<Long, List<ACL>> longKeyMap,
InputArchive ia) throws IOException {
int i = ia.readInt("map");
while (i > 0) {
Long val = ia.readLong("long");
if (aclIndex < val) {
aclIndex = val;
}
List<ACL> aclList = new ArrayList<ACL>();
Index j = ia.startVector("acls");
while (!j.done()) {
ACL acl = new ACL();
acl.deserialize(ia, "acl");
aclList.add(acl);
j.incr();
}
longKeyMap.put(val, aclList);
aclKeyMap.put(aclList, val);
i--;
}
}
示例14: deserializeList
import org.apache.jute.InputArchive; //导入依赖的package包/类
private void deserializeList(Map<Long, List<ACL>> longKeyMap,
InputArchive ia) throws IOException {
// longKey数量
int i = ia.readInt("map");
while (i > 0) {
Long val = ia.readLong("long");
if (aclIndex < val) {
aclIndex = val;
}
List<ACL> aclList = new ArrayList<ACL>();
// acl列表数量
Index j = ia.startVector("acls");
while (!j.done()) {
ACL acl = new ACL();
// 反序列化acl
acl.deserialize(ia, "acl");
aclList.add(acl);
j.incr();
}
longKeyMap.put(val, aclList);
aclKeyMap.put(aclList, val);
i--;
}
}