• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TransactionOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getFreeResources

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
public Set<ResourceAllocation> getFreeResources(Link link) {
    TransactionOptions opt = new TransactionOptions();
    // read-only and will never be commited, thus does not need durability
    opt.setTransactionType(TransactionType.LOCAL);
    TransactionContext tx = theInstance.newTransactionContext(opt);
    tx.beginTransaction();
    try {
        Map<ResourceType, Set<? extends ResourceAllocation>> freeResources = getFreeResourcesEx(tx, link);
        Set<ResourceAllocation> allFree = new HashSet<>();
        for (Set<? extends ResourceAllocation> r : freeResources.values()) {
            allFree.addAll(r);
        }
        return allFree;
    } finally {
        tx.rollbackTransaction();
    }

}
 
开发者ID:ravikumaran2015,项目名称:ravikumaran201504,代码行数:20,代码来源:HazelcastLinkResourceStore.java


示例2: getAllocations

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
public LinkResourceAllocations getAllocations(IntentId intentId) {
    checkNotNull(intentId);
    TransactionOptions opt = new TransactionOptions();
    // read-only and will never be commited, thus does not need durability
    opt.setTransactionType(TransactionType.LOCAL);
    TransactionContext tx = theInstance.newTransactionContext(opt);
    tx.beginTransaction();
    try {
        STxMap<IntentId, LinkResourceAllocations> intentAllocs = getIntentAllocs(tx);
        return intentAllocs.get(intentId);
    } finally {
        tx.rollbackTransaction();
    }
}
 
开发者ID:ravikumaran2015,项目名称:ravikumaran201504,代码行数:16,代码来源:HazelcastLinkResourceStore.java


示例3: setup

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Setup
public void setup() {
    map = targetInstance.getMap(name);
    resultList = targetInstance.getList(name + "results");

    transactionOptions = new TransactionOptions();
    transactionOptions.setTransactionType(transactionType).setDurability(durability);
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:9,代码来源:MapTransactionTest.java


示例4: timestep

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@TimeStep
public void timestep(ThreadState state) {
    int key = state.nextRandom(0, range / 2);

    TransactionOptions transactionOptions = new TransactionOptions()
            .setTransactionType(transactionType)
            .setDurability(durability);

    TransactionContext transactionContext = targetInstance.newTransactionContext(transactionOptions);

    transactionContext.beginTransaction();

    TransactionalMap<Object, Object> txMap = transactionContext.getMap("map");

    try {
        Object val = txMap.getForUpdate(key);

        if (val != null) {
            key = state.nextRandom(range / 2, range);
        }

        txMap.put(key, (long) key);

        transactionContext.commitTransaction();
    } catch (Exception e) {
        logger.fatal("----------------------tx exception -------------------------", e);

        if (failOnException) {
            throw rethrow(e);
        }

        transactionContext.rollbackTransaction();
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:35,代码来源:MapTransactionContextTest.java


示例5: beginTransaction

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
public StoreTransaction beginTransaction(StoreTxConfig txConfig) throws StorageException {
    if (transactional) {
        TransactionOptions txo = new TransactionOptions();
        txo.setTimeout(lockExpireMS, TimeUnit.MILLISECONDS);
        return new HazelCastTransaction(manager.newTransactionContext(txo), txConfig);
    } else {
        return new NoOpStoreTransaction(txConfig);
    }
}
 
开发者ID:thinkaurelius,项目名称:titan-experimental,代码行数:11,代码来源:AbstractHazelcastStoreManager.java


示例6: executeTransaction

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
public <T> T executeTransaction(TransactionOptions transactionOptions, TransactionalTask<T> transactionalTask) throws TransactionException {
    return null;
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:5,代码来源:WebConfigurerIntTest.java


示例7: newTransactionContext

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
public TransactionContext newTransactionContext(TransactionOptions transactionOptions) {
    return null;
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:5,代码来源:WebConfigurerIntTest.java


示例8: remove

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
/**
 * This method performs transactional operation on removing the {@code exchange}
 * from the operational storage and moving it into the persistent one if the {@link HazelcastAggregationRepository}
 * runs in recoverable mode and {@code optimistic} is false. It will act at <u>your own</u> risk otherwise.
 * @param camelContext   the current CamelContext
 * @param key            the correlation key
 * @param exchange       the exchange to remove
 */
@Override
public void remove(CamelContext camelContext, String key, Exchange exchange) {
    DefaultExchangeHolder holder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders);
    if (optimistic) {
        LOG.trace("Removing an exchange with ID {} for key {} in an optimistic manner.", exchange.getExchangeId(), key);
        if (!cache.remove(key, holder)) {
            LOG.error("Optimistic locking failed for exchange with key {}: IMap#remove removed no Exchanges, while it's expected to remove one.",
                    key);
            throw new OptimisticLockingException();
        }
        LOG.trace("Removed an exchange with ID {} for key {} in an optimistic manner.", exchange.getExchangeId(), key);
        if (useRecovery) {
            LOG.trace("Putting an exchange with ID {} for key {} into a recoverable storage in an optimistic manner.",
                    exchange.getExchangeId(), key);
            persistedCache.put(exchange.getExchangeId(), holder);
            LOG.trace("Put an exchange with ID {} for key {} into a recoverable storage in an optimistic manner.",
                    exchange.getExchangeId(), key);
        }
    } else {
        if (useRecovery) {
            LOG.trace("Removing an exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key);
            // The only considerable case for transaction usage is fault tolerance:
            // the transaction will be rolled back automatically (default timeout is 2 minutes)
            // if no commit occurs during the timeout. So we are still consistent whether local node crashes.
            TransactionOptions tOpts = new TransactionOptions();

            tOpts.setTransactionType(TransactionOptions.TransactionType.LOCAL);
            TransactionContext tCtx = hzInstance.newTransactionContext(tOpts);

            try {
                tCtx.beginTransaction();

                TransactionalMap<String, DefaultExchangeHolder> tCache = tCtx.getMap(cache.getName());
                TransactionalMap<String, DefaultExchangeHolder> tPersistentCache = tCtx.getMap(persistedCache.getName());

                DefaultExchangeHolder removedHolder = tCache.remove(key);
                LOG.trace("Putting an exchange with ID {} for key {} into a recoverable storage in a thread-safe manner.",
                        exchange.getExchangeId(), key);
                tPersistentCache.put(exchange.getExchangeId(), removedHolder);

                tCtx.commitTransaction();
                LOG.trace("Removed an exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key);
                LOG.trace("Put an exchange with ID {} for key {} into a recoverable storage in a thread-safe manner.",
                        exchange.getExchangeId(), key);
            } catch (Throwable throwable) {
                tCtx.rollbackTransaction();

                final String msg = String.format("Transaction with ID %s was rolled back for remove operation with a key %s and an Exchange ID %s.",
                        tCtx.getTxnId(), key, exchange.getExchangeId());
                LOG.warn(msg, throwable);
                throw new RuntimeException(msg, throwable);
            }
        } else {
            cache.remove(key);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:66,代码来源:HazelcastAggregationRepository.java


示例9: executeTransaction

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
public <T> T executeTransaction(final TransactionOptions options, final TransactionalTask<T> task) throws TransactionException {
  return getHazelcastInstance().executeTransaction(options, task);
}
 
开发者ID:Sabadios,项目名称:Cherry,代码行数:5,代码来源:HazelcastService.java


示例10: newTransactionContext

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
public TransactionContext newTransactionContext(final TransactionOptions options) {
  return getHazelcastInstance().newTransactionContext(options);
}
 
开发者ID:Sabadios,项目名称:Cherry,代码行数:5,代码来源:HazelcastService.java


示例11: run

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
@Override
@SuppressWarnings("PMD.PreserveStackTrace")
public void run() {
    TransactionOptions options = new TransactionOptions()
            .setTransactionType(transactionType)
            .setDurability(durability);

    while (!testContext.isStopped()) {
        TransactionContext context = null;

        final int key = random.nextInt(keyCount);
        final long increment = random.nextInt(100);
        try {
            context = targetInstance.newTransactionContext(options);
            context.beginTransaction();

            final TransactionalMap<Integer, Long> map = context.getMap(name);

            Long current = map.getForUpdate(key);
            Long update = current + increment;
            map.put(key, update);

            context.commitTransaction();

            // Do local increments if commit is successful, so there is no needed decrement operation
            localIncrements[key] += increment;
            count.committed++;
        } catch (Exception commitFailedException) {
            if (context != null) {
                try {
                    logger.warn(name + ": commit failed key=" + key + " inc=" + increment, commitFailedException);
                    if (rethrowAllException) {
                        throw rethrow(commitFailedException);
                    }

                    context.rollbackTransaction();
                    count.rolled++;
                } catch (Exception rollBackFailedException) {
                    logger.warn(name + ": rollback failed key=" + key + " inc=" + increment,
                            rollBackFailedException);
                    count.failedRollbacks++;

                    if (rethrowRollBackException) {
                        throw rethrow(rollBackFailedException);
                    }
                }
            }
        }
    }
    targetInstance.getList(name + "res").add(localIncrements);
    targetInstance.getList(name + "report").add(count);
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:53,代码来源:MapTransactionGetForUpdateTest.java


示例12: run

import com.hazelcast.transaction.TransactionOptions; //导入依赖的package包/类
private static void run() {

        Config config = new Config("queueTest");

        QueueConfig queueConfig = config.getQueueConfig(QNAME);

        QueueStoreConfig queueStoreConfig = new QueueStoreConfig();
        queueStoreConfig.setEnabled(true);
        queueStoreConfig.setStoreImplementation(new MockQueueStore());
        queueStoreConfig.getProperties().setProperty("memory-limit", "0");

        queueConfig.setQueueStoreConfig(queueStoreConfig);

        HazelcastInstance hzInstance = Hazelcast.newHazelcastInstance(config);

        long startTime = System.currentTimeMillis();

        int i = 0;
        while (i++ < 2000000) {
            if (i % 10000 == 0) {
                logger.info(Integer.toString(i) + "\t" + String.format("%8.3f", (double) (System.currentTimeMillis() -
                        startTime) / i));
            }

            TransactionOptions options = new TransactionOptions().setTransactionType(TransactionOptions.TransactionType.LOCAL);

            TransactionContext context = hzInstance.newTransactionContext(options);
            context.beginTransaction();

            TransactionalQueue<Integer> queue = context.getQueue(QNAME);
            queue.offer(i);

            context.commitTransaction();

        }
    }
 
开发者ID:romario13,项目名称:hz-queue,代码行数:37,代码来源:Test3.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Cas20WithoutProxyingValidationSpecification类代码示例发布时间:2022-05-23
下一篇:
Java Row类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap