本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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();
}
示例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();
}
示例11: inTransaction
import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction inTransaction() {
return curator.inTransaction();
}
示例12: getTransaction
import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@VisibleForTesting
CuratorTransaction getTransaction() {
return transaction;
}
示例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();
}
示例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();
}
示例15: inTransaction
import org.apache.curator.framework.api.transaction.CuratorTransaction; //导入依赖的package包/类
@Override
public CuratorTransaction inTransaction() {
return new MockCuratorTransactionFinal();
}