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


Java CreateMode.isSequential方法代码示例

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


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

示例1: create

import org.apache.zookeeper.CreateMode; //导入方法依赖的package包/类
/**
 * <pre>
 * 1. 使用zookeeper过程,针对出现ConnectionLoss异常,比如进行create/setData/delete,操作可能已经在zookeeper server上进行应用
 * 2. 针对SelectStageListener进行processId创建时,会以最后一次创建的processId做为调度id. 如果进行retry,之前成功的processId就会被遗漏了
 * </pre>
 * 
 * @see org.apache.zookeeper.ZooKeeper#create(String path, byte[] path, List acl, CreateMode mode)
 */
public String create(final String path, final byte[] data, final CreateMode mode) throws KeeperException,
                                                                                 InterruptedException {
    if (mode.isSequential()) {
        return zookeeper.create(path, data, acl, mode);
    } else {
        return retryOperation(new ZooKeeperOperation<String>() {

            public String execute() throws KeeperException, InterruptedException {
                return zookeeper.create(path, data, acl, mode);
            }
        });
    }

}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:23,代码来源:ZooKeeperx.java

示例2: pRequest2TxnCreate

import org.apache.zookeeper.CreateMode; //导入方法依赖的package包/类
private void pRequest2TxnCreate(int type, Request request, Record record, boolean deserialize) throws IOException, KeeperException {
    if (deserialize) {
        ByteBufferInputStream.byteBuffer2Record(request.request, record);
    }

    int flags;
    String path;
    List<ACL> acl;
    byte[] data;
    long ttl;
    if (type == OpCode.createTTL) {
        CreateTTLRequest createTtlRequest = (CreateTTLRequest)record;
        flags = createTtlRequest.getFlags();
        path = createTtlRequest.getPath();
        acl = createTtlRequest.getAcl();
        data = createTtlRequest.getData();
        ttl = createTtlRequest.getTtl();
    } else {
        CreateRequest createRequest = (CreateRequest)record;
        flags = createRequest.getFlags();
        path = createRequest.getPath();
        acl = createRequest.getAcl();
        data = createRequest.getData();
        ttl = -1;
    }
    CreateMode createMode = CreateMode.fromFlag(flags);
    validateCreateRequest(path, createMode, request, ttl);
    String parentPath = validatePathForCreate(path, request.sessionId);

    List<ACL> listACL = fixupACL(path, request.authInfo, acl);
    ChangeRecord parentRecord = getRecordForPath(parentPath);

    checkACL(zks, request.cnxn, parentRecord.acl, ZooDefs.Perms.CREATE, request.authInfo, path, listACL);
    int parentCVersion = parentRecord.stat.getCversion();
    if (createMode.isSequential()) {
        path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion);
    }
    validatePath(path, request.sessionId);
    try {
        if (getRecordForPath(path) != null) {
            throw new KeeperException.NodeExistsException(path);
        }
    } catch (KeeperException.NoNodeException e) {
        // ignore this one
    }
    boolean ephemeralParent = EphemeralType.get(parentRecord.stat.getEphemeralOwner()) == EphemeralType.NORMAL;
    if (ephemeralParent) {
        throw new KeeperException.NoChildrenForEphemeralsException(path);
    }
    int newCversion = parentRecord.stat.getCversion()+1;
    if (type == OpCode.createContainer) {
        request.setTxn(new CreateContainerTxn(path, data, listACL, newCversion));
    } else if (type == OpCode.createTTL) {
        request.setTxn(new CreateTTLTxn(path, data, listACL, newCversion, ttl));
    } else {
        request.setTxn(new CreateTxn(path, data, listACL, createMode.isEphemeral(),
                newCversion));
    }
    StatPersisted s = new StatPersisted();
    if (createMode.isEphemeral()) {
        s.setEphemeralOwner(request.sessionId);
    }
    parentRecord = parentRecord.duplicate(request.getHdr().getZxid());
    parentRecord.childCount++;
    parentRecord.stat.setCversion(newCversion);
    addChangeRecord(parentRecord);
    addChangeRecord(new ChangeRecord(request.getHdr().getZxid(), path, s, 0, listACL));
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:69,代码来源:PrepRequestProcessor.java


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