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


Java OpCode.create方法代码示例

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


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

示例1: testPad

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的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);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:23,代码来源:LoadFromLogTest.java

示例2: testPad

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的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);
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:23,代码来源:LoadFromLogTest.java

示例3: needCommit

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
protected boolean needCommit(Request request) {
    switch (request.type) {
        case OpCode.create:
        case OpCode.create2:
        case OpCode.createContainer:
        case OpCode.delete:
        case OpCode.deleteContainer:
        case OpCode.setData:
        case OpCode.reconfig:
        case OpCode.multi:
        case OpCode.setACL:
            return true;
        case OpCode.sync:
            return matchSyncs;    
        case OpCode.createSession:
        case OpCode.closeSession:
            return !request.isLocalSession();
        default:
            return false;
    }
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:22,代码来源:CommitProcessor.java

示例4: op2String

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
static String op2String(int op) {
    switch (op) {
    case OpCode.notification:
        return "notification";
    case OpCode.create:
        return "create";
    case OpCode.delete:
        return "delete";
    case OpCode.exists:
        return "exists";
    case OpCode.getData:
        return "getDate";
    case OpCode.setData:
        return "setData";
    case OpCode.multi:
        return "multi";
    case OpCode.getACL:
        return "getACL";
    case OpCode.setACL:
        return "setACL";
    case OpCode.getChildren:
        return "getChildren";
    case OpCode.getChildren2:
        return "getChildren2";
    case OpCode.ping:
        return "ping";
    case OpCode.createSession:
        return "createSession";
    case OpCode.closeSession:
        return "closeSession";
    case OpCode.error:
        return "error";
    default:
        return "unknown " + op;
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:37,代码来源:TraceFormatter.java

示例5: isValid

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
/**
 * is the packet type a valid packet in zookeeper
 * 
 * @param type
 *                the type of the packet
 * @return true if a valid packet, false if not
 */
static boolean isValid(int type) {
    // make sure this is always synchronized with Zoodefs!!
    switch (type) {
    case OpCode.notification:
        return false;
    case OpCode.create:
    case OpCode.delete:
    case OpCode.createSession:
    case OpCode.exists:
    case OpCode.getData:
    case OpCode.check:
    case OpCode.multi:
    case OpCode.setData:
    case OpCode.sync:
    case OpCode.getACL:
    case OpCode.setACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.ping:
    case OpCode.closeSession:
    case OpCode.setWatches:
        return true;
    default:
        return false;
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:34,代码来源:Request.java

示例6: testPRequest

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
@Test
public void testPRequest() throws Exception {
    pLatch = new CountDownLatch(1);
    processor = new PrepRequestProcessor(zks, new MyRequestProcessor());
    Request foo = new Request(null, 1l, 1, OpCode.create, ByteBuffer.allocate(3), null);
    processor.pRequest(foo);

    Assert.assertEquals("Request should have marshalling error", new ErrorTxn(KeeperException.Code.MARSHALLINGERROR.intValue()),
            outcome.txn);
    Assert.assertTrue("request hasn't been processed in chain", pLatch.await(5, TimeUnit.SECONDS));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:12,代码来源:PrepRequestProcessorTest.java

示例7: testCreatePersistent

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的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

示例8: isValid

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
/**
 * is the packet type a valid packet in zookeeper
 *
 * @param type
 *                the type of the packet
 * @return true if a valid packet, false if not
 */
static boolean isValid(int type) {
    // make sure this is always synchronized with Zoodefs!!
    switch (type) {
    case OpCode.notification:
        return false;
    case OpCode.check:
    case OpCode.closeSession:
    case OpCode.create:
    case OpCode.create2:
    case OpCode.createTTL:
    case OpCode.createContainer:
    case OpCode.createSession:
    case OpCode.delete:
    case OpCode.deleteContainer:
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
    case OpCode.multi:
    case OpCode.ping:
    case OpCode.reconfig:
    case OpCode.setACL:
    case OpCode.setData:
    case OpCode.setWatches:
    case OpCode.sync:
    case OpCode.checkWatches:
    case OpCode.removeWatches:
        return true;
    default:
        return false;
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:41,代码来源:Request.java

示例9: isQuorum

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
public boolean isQuorum() {
    switch (this.type) {
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
        return false;
    case OpCode.create:
    case OpCode.create2:
    case OpCode.createTTL:
    case OpCode.createContainer:
    case OpCode.error:
    case OpCode.delete:
    case OpCode.deleteContainer:
    case OpCode.setACL:
    case OpCode.setData:
    case OpCode.check:
    case OpCode.multi:
    case OpCode.reconfig:
        return true;
    case OpCode.closeSession:
    case OpCode.createSession:
        return !this.isLocalSession;
    default:
        return false;
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:29,代码来源:Request.java

示例10: sendWriteRequest

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
public void sendWriteRequest() throws Exception {
    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
    CreateRequest createReq = new CreateRequest(
        "/session" + Long.toHexString(sessionId) + "-" + (++nodeId),
        new byte[0], Ids.OPEN_ACL_UNSAFE, 1);
    createReq.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
    Request req = new Request(null, sessionId, ++cxid, OpCode.create,
                              bb, new ArrayList<Id>());
    zks.getFirstProcessor().processRequest(req);

}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:14,代码来源:CommitProcessorTest.java

示例11: isQuorum

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
public boolean isQuorum() {
    switch (this.type) {
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
        return false;
    case OpCode.create:
    case OpCode.create2:
    case OpCode.createContainer:
    case OpCode.error:
    case OpCode.delete:
    case OpCode.deleteContainer:
    case OpCode.setACL:
    case OpCode.setData:
    case OpCode.check:
    case OpCode.multi:
    case OpCode.reconfig:
        return true;
    case OpCode.closeSession:
    case OpCode.createSession:
        return !this.isLocalSession;
    default:
        return false;
    }
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:28,代码来源:Request.java

示例12: checkUpgradeSession

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
public Request checkUpgradeSession(Request request)
        throws IOException, KeeperException {
    // If this is a request for a local session and it is to
    // create an ephemeral node, then upgrade the session and return
    // a new session request for the leader.
    // This is called by the request processor thread (either follower
    // or observer request processor), which is unique to a learner.
    // So will not be called concurrently by two threads.
    if (request.type != OpCode.create ||
        !upgradeableSessionTracker.isLocalSession(request.sessionId)) {
        return null;
    }
    CreateRequest createRequest = new CreateRequest();
    request.request.rewind();
    ByteBufferInputStream.byteBuffer2Record(request.request, createRequest);
    request.request.rewind();
    CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags());
    if (!createMode.isEphemeral()) {
        return null;
    }
    // Uh oh.  We need to upgrade before we can proceed.
    if (!self.isLocalSessionsUpgradingEnabled()) {
        throw new KeeperException.EphemeralOnLocalSessionException();
    }

    return makeUpgradeRequest(request.sessionId);
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:28,代码来源:QuorumZooKeeperServer.java

示例13: op2String

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
static String op2String(int op) {
    switch (op) {
    case OpCode.notification:
        return "notification";
    case OpCode.create:
        return "create";
    case OpCode.setWatches:
        return "setWatches";
    case OpCode.delete:
        return "delete";
    case OpCode.exists:
        return "exists";
    case OpCode.getData:
        return "getData";
    case OpCode.setData:
        return "setData";
    case OpCode.sync:
          return "sync:";
    case OpCode.getACL:
        return "getACL";
    case OpCode.setACL:
        return "setACL";
    case OpCode.getChildren:
        return "getChildren";
    case OpCode.getChildren2:
        return "getChildren2";
    case OpCode.ping:
        return "ping";
    case OpCode.createSession:
        return "createSession";
    case OpCode.closeSession:
        return "closeSession";
    case OpCode.error:
        return "error";
    default:
        return "unknown " + op;
    }
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:39,代码来源:Request.java

示例14: run

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        while (!finished) {
            Request request = queuedRequests.take();
            if (LOG.isTraceEnabled()) {
                ZooTrace.logRequest(LOG, ZooTrace.CLIENT_REQUEST_TRACE_MASK,
                        'F', request, "");
            }
            if (request == Request.requestOfDeath) {
                break;
            }
            // We want to queue the request to be processed before we submit
            // the request to the leader so that we are ready to receive
            // the response
            nextProcessor.processRequest(request);
            
            // We now ship the request to the leader. As with all
            // other quorum operations, sync also follows this code
            // path, but different from others, we need to keep track
            // of the sync operations this follower has pending, so we
            // add it to pendingSyncs.
            switch (request.type) {
            case OpCode.sync:
                zks.pendingSyncs.add(request);
                zks.getFollower().request(request);
                break;
            case OpCode.create:
            case OpCode.delete:
            case OpCode.setData:
            case OpCode.setACL:
            case OpCode.createSession:
            case OpCode.closeSession:
            case OpCode.multi:
                zks.getFollower().request(request);
                break;
            }
        }
    } catch (Exception e) {
        handleException(this.getName(), e);
    }
    LOG.info("FollowerRequestProcessor exited loop!");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:44,代码来源:FollowerRequestProcessor.java

示例15: run

import org.apache.zookeeper.ZooDefs.OpCode; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        while (!finished) {
            Request request = queuedRequests.take();
            if (LOG.isTraceEnabled()) {
                ZooTrace.logRequest(LOG, ZooTrace.CLIENT_REQUEST_TRACE_MASK,
                        'F', request, "");
            }
            if (request == Request.requestOfDeath) {
                break;
            }
            // We want to queue the request to be processed before we submit
            // the request to the leader so that we are ready to receive
            // the response
            nextProcessor.processRequest(request);
            
            // We now ship the request to the leader. As with all
            // other quorum operations, sync also follows this code
            // path, but different from others, we need to keep track
            // of the sync operations this Observer has pending, so we
            // add it to pendingSyncs.
            switch (request.type) {
            case OpCode.sync:
                zks.pendingSyncs.add(request);
                zks.getObserver().request(request);
                break;
            case OpCode.create:
            case OpCode.delete:
            case OpCode.setData:
            case OpCode.setACL:
            case OpCode.createSession:
            case OpCode.closeSession:
            case OpCode.multi:
                zks.getObserver().request(request);
                break;
            }
        }
    } catch (Exception e) {
        handleException(this.getName(), e);
    }
    LOG.info("ObserverRequestProcessor exited loop!");
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:44,代码来源:ObserverRequestProcessor.java


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