本文整理汇总了Java中org.apache.jute.BinaryOutputArchive.getArchive方法的典型用法代码示例。如果您正苦于以下问题:Java BinaryOutputArchive.getArchive方法的具体用法?Java BinaryOutputArchive.getArchive怎么用?Java BinaryOutputArchive.getArchive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jute.BinaryOutputArchive
的用法示例。
在下文中一共展示了BinaryOutputArchive.getArchive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBB
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
public void createBB() {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
boa.writeInt(-1, "len"); // We'll fill this in later
if (requestHeader != null) {
requestHeader.serialize(boa, "header");
}
if (request instanceof ConnectRequest) {
request.serialize(boa, "connect");
// append "am-I-allowed-to-be-readonly" flag
boa.writeBool(readOnly, "readOnly");
} else if (request != null) {
request.serialize(boa, "request");
}
baos.close();
this.bb = ByteBuffer.wrap(baos.toByteArray());
this.bb.putInt(this.bb.capacity() - 4);
this.bb.rewind();
} catch (IOException e) {
LOG.warn("Ignoring unexpected exception", e);
}
}
示例2: send
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
private void send(DataOutputStream dout, byte[] challenge,
QuorumAuth.Status s) throws IOException {
BufferedOutputStream bufferedOutput = new BufferedOutputStream(dout);
BinaryOutputArchive boa = BinaryOutputArchive
.getArchive(bufferedOutput);
QuorumAuthPacket authPacket;
if (challenge != null && challenge.length < 0) {
throw new IOException("Response length < 0");
} else if (challenge == null && s != QuorumAuth.Status.SUCCESS) {
authPacket = QuorumAuth.createPacket(
QuorumAuth.Status.IN_PROGRESS, challenge);
} else {
authPacket = QuorumAuth.createPacket(s, challenge);
}
boa.writeRecord(authPacket, QuorumAuth.QUORUM_AUTH_MESSAGE_TAG);
bufferedOutput.flush();
}
示例3: serializeTree
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
private static void serializeTree(int depth, int width, int len)
throws InterruptedException, IOException, KeeperException.NodeExistsException, KeeperException.NoNodeException {
DataTree tree = new DataTree();
createNodes(tree, "/", depth, width, tree.getNode("/").stat.getCversion(), new byte[len]);
int count = tree.getNodeCount();
BinaryOutputArchive oa =
BinaryOutputArchive.getArchive(new NullOutputStream());
System.gc();
long start = System.nanoTime();
tree.serialize(oa, "test");
long end = System.nanoTime();
long durationms = (end - start)/1000000L;
long pernodeus = ((end - start)/1000L)/count;
LOG.info("Serialized " + count + " nodes in "
+ durationms + " ms (" + pernodeus + "us/node), depth="
+ depth + " width=" + width + " datalen=" + len);
}
示例4: newRequest
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
private Request newRequest(Record rec, int type, int sessionId, int xid)
throws IOException {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
rec.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
return new Request(null, sessionId, xid, type, bb, new ArrayList<Id>());
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:9,代码来源:CommitProcessorConcurrencyTest.java
示例5: testSerializeDeserialize
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
@Test
public void testSerializeDeserialize() throws IOException {
ReferenceCountedACLCache cache = new ReferenceCountedACLCache();
List<ACL> acl1 = createACL("one");
List<ACL> acl2 = createACL("two");
List<ACL> acl3 = createACL("three");
List<ACL> acl4 = createACL("four");
List<ACL> acl5 = createACL("five");
Long aclId1 = convertACLsNTimes(cache, acl1, 1);
Long aclId2 = convertACLsNTimes(cache, acl2, 2);
Long aclId3 = convertACLsNTimes(cache, acl3, 3);
Long aclId4 = convertACLsNTimes(cache, acl4, 4);
Long aclId5 = convertACLsNTimes(cache, acl5, 5);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive archive = BinaryOutputArchive.getArchive(baos);
cache.serialize(archive);
BinaryInputArchive inArchive = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
ReferenceCountedACLCache deserializedCache = new ReferenceCountedACLCache();
deserializedCache.deserialize(inArchive);
callAddUsageNTimes(deserializedCache, aclId1, 1);
callAddUsageNTimes(deserializedCache, aclId2, 2);
callAddUsageNTimes(deserializedCache, aclId3, 3);
callAddUsageNTimes(deserializedCache, aclId4, 4);
callAddUsageNTimes(deserializedCache, aclId5, 5);
assertCachesEqual(cache, deserializedCache);
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:32,代码来源:ReferenceCountedACLCacheTest.java
示例6: deserializeTree
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的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, tree.getNode("/").stat.getCversion(), width, 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: marshallTxnEntry
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
/**
* Serializes transaction header and transaction data into a byte buffer.
*
* @param hdr transaction header
* @param txn transaction data
* @return serialized transaction record
* @throws IOException
*/
public static byte[] marshallTxnEntry(TxnHeader hdr, Record txn)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputArchive boa = BinaryOutputArchive.getArchive(baos);
hdr.serialize(boa, "hdr");
if (txn != null) {
txn.serialize(boa, "txn");
}
return baos.toByteArray();
}
示例8: testCreatePersistent
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
/**
* When local session is enabled, leader will allow persistent node
* to be create for unknown session
*/
@Test
public void testCreatePersistent() throws Exception {
qu.enableLocalSession(true);
qu.startAll();
QuorumPeer leader = qu.getLeaderQuorumPeer();
ZooKeeper zk = ClientBase.createZKClient(qu.getConnectString(leader));
CreateRequest createRequest = new CreateRequest("/success",
new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT.toFlag());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
createRequest.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
// Mimic sessionId generated by follower's local session tracker
long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer()
.getServerId();
long locallSession = (sid << 56) + 1;
LOG.info("Local session Id: " + Long.toHexString(locallSession));
Request request = new Request(null, locallSession, 0, OpCode.create,
bb, new ArrayList<Id>());
// Submit request directly to leader
leader.getActiveServer().submitRequest(request);
// Make sure that previous request is finished
zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Stat stat = zk.exists("/success", null);
Assert.assertTrue("Request from local sesson failed", stat != null);
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:42,代码来源:LeaderSessionTrackerTest.java
示例9: sendResponse
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
@Override
public void sendResponse(ReplyHeader h, Record r, String tag)
throws IOException {
if (closingChannel || !channel.isOpen()) {
return;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Make space for length
BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
try {
baos.write(fourBytes);
bos.writeRecord(h, "header");
if (r != null) {
bos.writeRecord(r, tag);
}
baos.close();
} catch (IOException e) {
LOG.error("Error serializing response");
}
byte b[] = baos.toByteArray();
ByteBuffer bb = ByteBuffer.wrap(b);
bb.putInt(b.length - 4).rewind();
sendBuffer(bb);
if (h.getXid() > 0) {
// zks cannot be null otherwise we would not have gotten here!
if (!zkServer.shouldThrottle(outstandingCount.decrementAndGet())) {
enableRecv();
}
}
}
示例10: testPathTrieClearOnDeserialize
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testPathTrieClearOnDeserialize() throws Exception {
//Create a DataTree with quota nodes so PathTrie get updated
DataTree dserTree = new DataTree();
dserTree.createNode("/bug", new byte[20], null, -1, 1, 1, 1);
dserTree.createNode(Quotas.quotaZookeeper+"/bug", null, null, -1, 1, 1, 1);
dserTree.createNode(Quotas.quotaPath("/bug"), new byte[20], null, -1, 1, 1, 1);
dserTree.createNode(Quotas.statPath("/bug"), new byte[20], null, -1, 1, 1, 1);
//deserialize a DataTree; this should clear the old /bug nodes and pathTrie
DataTree tree = new DataTree();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
tree.serialize(oa, "test");
baos.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
BinaryInputArchive ia = BinaryInputArchive.getArchive(bais);
dserTree.deserialize(ia, "test");
Field pfield = DataTree.class.getDeclaredField("pTrie");
pfield.setAccessible(true);
PathTrie pTrie = (PathTrie)pfield.get(dserTree);
//Check that the node path is removed from pTrie
Assert.assertEquals("/bug is still in pTrie", "", pTrie.findMaxPrefix("/bug"));
}
示例11: sendResponse
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
@Override
public void sendResponse(ReplyHeader h, Record r, String tag)
throws IOException {
if (!channel.isOpen()) {
return;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Make space for length
BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
try {
baos.write(fourBytes);
bos.writeRecord(h, "header");
if (r != null) {
bos.writeRecord(r, tag);
}
baos.close();
} catch (IOException e) {
LOG.error("Error serializing response");
}
byte b[] = baos.toByteArray();
ByteBuffer bb = ByteBuffer.wrap(b);
bb.putInt(b.length - 4).rewind();
sendBuffer(bb);
if (h.getXid() > 0) {
// zks cannot be null otherwise we would not have gotten here!
if (!zkServer.shouldThrottle(outstandingCount.decrementAndGet())) {
enableRecv();
}
}
}
示例12: codeDecode
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
private MultiResponse codeDecode(MultiResponse request) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
request.serialize(boa, "result");
baos.close();
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
bb.rewind();
BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb));
MultiResponse decodedRequest = new MultiResponse();
decodedRequest.deserialize(bia, "result");
return decodedRequest;
}
示例13: createRequest
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
private Request createRequest(Record record, int opCode) throws IOException {
// encoding
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
record.serialize(boa, "request");
baos.close();
// Id
List<Id> ids = Arrays.asList(Ids.ANYONE_ID_UNSAFE);
return new Request(null, 1l, 0, opCode, ByteBuffer.wrap(baos.toByteArray()), ids);
}
示例14: propose
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
/**
* create a proposal and send it out to all the members
*
* @param request
* @return the proposal that is queued to send to all the members
*/
public Proposal propose(Request request) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
try {
request.hdr.serialize(boa, "hdr");
if (request.txn != null) {
request.txn.serialize(boa, "txn");
}
baos.close();
} catch (IOException e) {
LOG.warn("This really should be impossible", e);
}
QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid,
baos.toByteArray(), null);
Proposal p = new Proposal();
p.packet = pp;
p.request = request;
synchronized (this) {
if (LOG.isDebugEnabled()) {
LOG.debug("Proposing:: " + request);
}
lastProposed = p.packet.getZxid();
outstandingProposals.put(lastProposed, p);
sendPacket(pp);
}
return p;
}
示例15: addCommittedProposal
import org.apache.jute.BinaryOutputArchive; //导入方法依赖的package包/类
/**
* maintains a list of last <i>committedLog</i>
* or so committed requests. This is used for
* fast follower synchronization.
* @param request committed request
*/
public void addCommittedProposal(Request request) {
WriteLock wl = logLock.writeLock();
try {
wl.lock();
if (committedLog.size() > commitLogCount) {
committedLog.removeFirst();
minCommittedLog = committedLog.getFirst().packet.getZxid();
}
if (committedLog.isEmpty()) {
minCommittedLog = request.zxid;
maxCommittedLog = request.zxid;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
try {
request.getHdr().serialize(boa, "hdr");
if (request.getTxn() != null) {
request.getTxn().serialize(boa, "txn");
}
baos.close();
} catch (IOException e) {
LOG.error("This really should be impossible", e);
}
QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid,
baos.toByteArray(), null);
Proposal p = new Proposal();
p.packet = pp;
p.request = request;
committedLog.add(p);
maxCommittedLog = p.packet.getZxid();
} finally {
wl.unlock();
}
}