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


Java CuratorTransaction类代码示例

本文整理汇总了Java中org.apache.curator.framework.api.transaction.CuratorTransaction的典型用法代码示例。如果您正苦于以下问题:Java CuratorTransaction类的具体用法?Java CuratorTransaction怎么用?Java CuratorTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: transation

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
/**
 * Curator支持事务,一组crud操作同生同灭
 * @param client
 */
private static void transation(CuratorFramework client) {
    try {
        // 开启事务
        CuratorTransaction transaction = client.inTransaction();
        Collection<CuratorTransactionResult> results = transaction.create()
                .forPath("/root/transation", "transation".getBytes()).and().create()
                .forPath("/root/transation2", "transation2".getBytes()).and()
                .delete().forPath("/root/transation").and()
                .delete().forPath("/root/transation2").and().commit();
        for (CuratorTransactionResult result : results) {
            System.out.println(result.getForPath() + " - " + result.getType());
        }
    }catch (Exception e){
        log.error("transation exception ", e);
    }
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:21,代码来源:CrudDemo.java

示例2: delete

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public void delete(String path) throws DataSourceConnectorException {
    String error = "Can't delete data for path: " + path + " in transaction";
    transaction = executeOrFailWithError(
        () -> {
            CuratorTransaction resultingTransaction = (transaction == null) ? getConnectedClientOrFailFast().inTransaction() : transaction;
            return resultingTransaction.delete().forPath(path).and();
        },
        error);
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:11,代码来源:ZookeeperConnector.java

示例3: saveInTransaction

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
private CuratorTransaction saveInTransaction(CuratorTransaction transaction, byte[] data, String path) throws Exception {
    CuratorTransaction resultingTransaction = (transaction == null) ? getConnectedClientOrFailFast().inTransaction() : transaction;
    if (isNodeExistsInternal(path)) {
        resultingTransaction = resultingTransaction.setData().forPath(path, data).and();
    } else {
        String parentPath = StringUtils.substringBeforeLast(path, "/");
        if (!isNodeExistsInternal(parentPath)) {
            resultingTransaction = resultingTransaction.create().forPath(parentPath).and();
        }
        resultingTransaction = resultingTransaction.create().forPath(path, data).and();
    }
    return resultingTransaction;
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:14,代码来源:ZookeeperConnector.java

示例4: SafeTransaction

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
SafeTransaction() throws Exception {
  CuratorTransaction transaction = curatorFramework.inTransaction();
  transactionFinal =
      transaction.create()
          .withMode(CreateMode.PERSISTENT).withACL(zkAcl)
          .forPath(fencingNodePath, new byte[0]).and();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:8,代码来源:ZKRMStateStore.java

示例5: doWriteChangeLogPartitionMapping

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
protected void doWriteChangeLogPartitionMapping(Map<TaskName, Integer> mapping) throws Exception {

        CuratorTransaction transaction = curator.inTransaction();
        boolean needTransaction = false;

        for (Map.Entry<TaskName, Integer> entry : mapping.entrySet()) {

            Integer partitionNumber = entry.getValue();
            TaskName tn = entry.getKey();

            String clpnPath = getChangelogPartitionNumberPath(tn);
            byte[] data = intToBytes(partitionNumber);

            boolean created = createChangeLogPartitionPathIfNecessary(clpnPath, data);

            if (!created) {//create would have written with the data, but since we didn't create, we have to set it now:
                transaction.setData().forPath(clpnPath, data);
                needTransaction = true;
                log.debug("Appended changelog partition mapping {}={} to current transaction.", tn, partitionNumber);
            }
        }

        if (needTransaction) {
            ((CuratorTransactionFinal) transaction).commit();
        }

        log.info("Wrote changelog partition mappings {}", mapping);
    }
 
开发者ID:stormpath,项目名称:samza-spring-boot-starter,代码行数:29,代码来源:ZookeeperCheckpointManager.java

示例6: and

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction and(CuratorTransaction transaction) throws Exception {
    if (data.isPresent()) {
        return transaction.create().forPath(path, data.get()).and();
    } else {
        return transaction.create().forPath(path).and();
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:9,代码来源:CuratorCreateOperation.java

示例7: createAtomically

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
/**
 * Creates all the given paths in a single transaction. Any paths which already exists are ignored.
 */
public void createAtomically(Path... paths) {
    try {
        CuratorTransaction transaction = framework().inTransaction();
        for (Path path : paths) {
            if ( ! exists(path)) {
                transaction = transaction.create().forPath(path.getAbsolute(), new byte[0]).and();
            }
        }
        ((CuratorTransactionFinal)transaction).commit();
    } catch (Exception e) {
        throw new RuntimeException("Could not create " + Arrays.toString(paths), e);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:17,代码来源:Curator.java

示例8: inTransaction

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction inTransaction()
{
    Preconditions.checkState(getState() == CuratorFrameworkState.STARTED, "instance must be started before calling this method");

    return new CuratorTransactionImpl(this);
}
 
开发者ID:apache,项目名称:curator,代码行数:8,代码来源:CuratorFrameworkImpl.java

示例9: complete

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
public void complete(List<Long> txIds) throws Exception {
    Iterator<Long> iterator = txIds.iterator();
    CuratorTransaction transaction = curatorFramework.inTransaction();
    while (iterator.hasNext()) {
        Long txId = iterator.next();
        transaction = transaction.delete().forPath(LIMBO_PATH + "/" + txId)
                .and().create().forPath(COMPLETED_PATH + "/" + txId).and();
    }
    CuratorTransactionFinal tx = (CuratorTransactionFinal) transaction;
    tx.commit();
}
 
开发者ID:jfmwz,项目名称:storm-example,代码行数:12,代码来源:DruidBatchStatus.java

示例10: complete

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
public void complete(List<String> partitionIds) throws Exception {
    Iterator<String> iterator = partitionIds.iterator();
    CuratorTransaction transaction = curatorFramework.inTransaction();
    while (iterator.hasNext()) {
        String partitionId = iterator.next();
        transaction = transaction.delete().forPath(LIMBO_PATH + "/" + partitionId)
                .and().create().forPath(COMPLETED_PATH + "/" + partitionId).and();
    }
    CuratorTransactionFinal tx = (CuratorTransactionFinal) transaction;
    tx.commit();
}
 
开发者ID:jfmwz,项目名称:storm-example,代码行数:12,代码来源:DruidPartitionStatus.java

示例11: inTransaction

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction inTransaction() {
    return curator.inTransaction();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:5,代码来源:RedirectorCuratorFramework.java

示例12: getTransaction

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@VisibleForTesting
CuratorTransaction getTransaction() {
    return transaction;
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:5,代码来源:ZookeeperConnector.java

示例13: and

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction and(CuratorTransaction transaction) throws Exception {
    return transaction.setData().forPath(path, data).and();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:5,代码来源:CuratorSetDataOperation.java

示例14: and

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction and(CuratorTransaction transaction) throws Exception {
    return transaction.delete().forPath(path).and();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:5,代码来源:CuratorDeleteOperation.java

示例15: inTransaction

import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction inTransaction() {
    return new MockCuratorTransactionFinal();
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:5,代码来源:MockCurator.java


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