use of org.apache.jute.InputArchive in project zookeeper by apache.
the class SnapshotFormatter method run.
public void run(String snapshotFileName) throws IOException {
InputStream is = new CheckedInputStream(new BufferedInputStream(new FileInputStream(snapshotFileName)), new Adler32());
InputArchive ia = BinaryInputArchive.getArchive(is);
FileSnap fileSnap = new FileSnap(null);
DataTree dataTree = new DataTree();
Map<Long, Integer> sessions = new HashMap<Long, Integer>();
fileSnap.deserialize(dataTree, sessions, ia);
printDetails(dataTree, sessions);
}
use of org.apache.jute.InputArchive in project zookeeper by apache.
the class Zab1_0Test method testLeaderConversation.
public void testLeaderConversation(LeaderConversation conversation) throws Exception {
Socket[] pair = getSocketPair();
Socket leaderSocket = pair[0];
Socket followerSocket = pair[1];
File tmpDir = File.createTempFile("test", "dir", testData);
tmpDir.delete();
tmpDir.mkdir();
LeadThread leadThread = null;
Leader leader = null;
try {
QuorumPeer peer = createQuorumPeer(tmpDir);
leader = createLeader(tmpDir, peer);
peer.leader = leader;
leadThread = new LeadThread(leader);
leadThread.start();
while (leader.cnxAcceptor == null || !leader.cnxAcceptor.isAlive()) {
Thread.sleep(20);
}
LearnerHandler lh = new LearnerHandler(leaderSocket, leader);
lh.start();
leaderSocket.setSoTimeout(4000);
InputArchive ia = BinaryInputArchive.getArchive(followerSocket.getInputStream());
OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket.getOutputStream());
conversation.converseWithLeader(ia, oa, leader);
} finally {
if (leader != null) {
leader.shutdown("end of test");
}
if (leadThread != null) {
leadThread.interrupt();
leadThread.join();
}
TestUtils.deleteFileRecursively(tmpDir);
}
}
use of org.apache.jute.InputArchive in project zookeeper by apache.
the class Zab1_0Test method testFollowerConversation.
public void testFollowerConversation(FollowerConversation conversation) throws Exception {
File tmpDir = File.createTempFile("test", "dir", testData);
tmpDir.delete();
tmpDir.mkdir();
Thread followerThread = null;
ConversableFollower follower = null;
QuorumPeer peer = null;
try {
peer = createQuorumPeer(tmpDir);
follower = createFollower(tmpDir, peer);
peer.follower = follower;
ServerSocket ss = new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1"));
follower.setLeaderSocketAddress((InetSocketAddress) ss.getLocalSocketAddress());
final Follower followerForThread = follower;
followerThread = new Thread() {
public void run() {
try {
followerForThread.followLeader();
} catch (InterruptedException e) {
LOG.info("Follower thread interrupted", e);
} catch (Exception e) {
LOG.warn("Unexpected exception in follower thread", e);
}
}
};
followerThread.start();
Socket leaderSocket = ss.accept();
InputArchive ia = BinaryInputArchive.getArchive(leaderSocket.getInputStream());
OutputArchive oa = BinaryOutputArchive.getArchive(leaderSocket.getOutputStream());
conversation.converseWithFollower(ia, oa, follower);
} finally {
if (follower != null) {
follower.shutdown();
}
if (followerThread != null) {
followerThread.interrupt();
followerThread.join();
}
if (peer != null) {
peer.shutdown();
}
TestUtils.deleteFileRecursively(tmpDir);
}
}
use of org.apache.jute.InputArchive in project exhibitor by soabase.
the class ZooKeeperLogParser method parse.
public void parse(LogEntryReceiver receiver) throws Exception {
if (!validHeader) {
throw new Exception("Invalid magic number for");
}
while (true) {
long crcValue;
byte[] bytes;
try {
crcValue = logStream.readLong("crcvalue");
bytes = logStream.readBuffer("txnEntry");
} catch (EOFException e) {
break;
}
if (bytes.length == 0) {
// empty transaction
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());
}
InputArchive iab = BinaryInputArchive.getArchive(new ByteArrayInputStream(bytes));
TxnHeader hdr = new TxnHeader();
Record record = useOldDeserializeMethod ? (Record) deserializeTxnMethod.invoke(null, iab, hdr) : (Record) deserializeTxnMethod.invoke(null, bytes, hdr);
if (logStream.readByte("EOR") != 'B') {
// partial transaction
break;
}
receiver.receiveEntry(hdr, record);
}
}
use of org.apache.jute.InputArchive in project zookeeper by apache.
the class SerializeUtils method deserializeTxn.
public static Record deserializeTxn(byte[] txnBytes, TxnHeader hdr) throws IOException {
final ByteArrayInputStream bais = new ByteArrayInputStream(txnBytes);
InputArchive ia = BinaryInputArchive.getArchive(bais);
hdr.deserialize(ia, "hdr");
bais.mark(bais.available());
Record txn = null;
switch(hdr.getType()) {
case OpCode.createSession:
// This isn't really an error txn; it just has the same
// format. The error represents the timeout
txn = new CreateSessionTxn();
break;
case OpCode.closeSession:
return null;
case OpCode.create:
case OpCode.create2:
txn = new CreateTxn();
break;
case OpCode.createTTL:
txn = new CreateTTLTxn();
break;
case OpCode.createContainer:
txn = new CreateContainerTxn();
break;
case OpCode.delete:
case OpCode.deleteContainer:
txn = new DeleteTxn();
break;
case OpCode.reconfig:
case OpCode.setData:
txn = new SetDataTxn();
break;
case OpCode.setACL:
txn = new SetACLTxn();
break;
case OpCode.error:
txn = new ErrorTxn();
break;
case OpCode.multi:
txn = new MultiTxn();
break;
default:
throw new IOException("Unsupported Txn with type=%d" + hdr.getType());
}
if (txn != null) {
try {
txn.deserialize(ia, "txn");
} catch (EOFException e) {
// perhaps this is a V0 Create
if (hdr.getType() == OpCode.create) {
CreateTxn create = (CreateTxn) txn;
bais.reset();
CreateTxnV0 createv0 = new CreateTxnV0();
createv0.deserialize(ia, "txn");
// cool now make it V1. a -1 parentCVersion will
// trigger fixup processing in processTxn
create.setPath(createv0.getPath());
create.setData(createv0.getData());
create.setAcl(createv0.getAcl());
create.setEphemeral(createv0.getEphemeral());
create.setParentCVersion(-1);
} else {
throw e;
}
}
}
return txn;
}
Aggregations