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


Java Cache.getOrDefault方法代码示例

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


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

示例1: filterPriorityQueue

import org.infinispan.Cache; //导入方法依赖的package包/类
private void filterPriorityQueue(IPriorityQueue priorityQueue, Predicate<IAttribution> attributionPredicate) {
	Cache<IPriorityQueue, List<IAttribution>> cache = getPriorityQueuesCache();
	boolean commit = false;
	if (!cache.getAdvancedCache().startBatch()) {
		LOGGER.error("Batch attempt on {} failed", priorityQueue);
	}
	try {
		// get lock values
		if (!cache.getAdvancedCache().lock(priorityQueue)) {
			LOGGER.error("Lock attempt on {} failed", priorityQueue);
			commit = false;
			return;
		}
		List<IAttribution> values = cache.getOrDefault(priorityQueue, Lists.<IAttribution> newArrayList());
		List<IAttribution> newValues = Lists.newArrayList(Collections2.filter(values, attributionPredicate));
		cache.put(priorityQueue, newValues);
		commit = true;
	} finally {
		cache.endBatch(commit);
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:22,代码来源:InfinispanClusterServiceImpl.java

示例2: doWithLockPriority

import org.infinispan.Cache; //导入方法依赖的package包/类
@Override
public boolean doWithLockPriority(ILockRequest lockRequest, Runnable runnable) throws ExecutionException {
	if (!isClusterActive()) {
		return false;
	}
	Cache<IPriorityQueue, List<IAttribution>> cache = getPriorityQueuesCache();
	boolean commit = true;
	boolean priorityAllowed = true;
	
	if (!cache.startBatch()) {
		LOGGER.error("Batch attempt on {} failed", lockRequest.getPriorityQueue());
	}
	try {
		// get lock values
		if (!cache.getAdvancedCache().lock(lockRequest.getPriorityQueue())) {
			LOGGER.error("Lock attempt on {} failed", lockRequest.getPriorityQueue());
			commit = false;
			return false;
		}
		List<IAttribution> values = cache.getOrDefault(lockRequest.getPriorityQueue(),
				Lists.<IAttribution> newArrayList());
		// check if a slot is already kept
		boolean prioritySlotFound = false;
		for (IAttribution attribution : values) {
			if (attribution.match(getAddress())) {
				prioritySlotFound = true;
			}
		}
		
		// if no slot, add it
		if (!prioritySlotFound) {
			// get a priority slot if absent
			values.add(Attribution.from(getAddress(), new Date()));
			cache.put(lockRequest.getPriorityQueue(), values);
		}
		
		// if slot is first, we can do our job
		if (values.size() > 0 && values.get(0).match(getAddress())) {
			// priority is allowed (first slot taken)
			// allow second phase and remove priority slot
			priorityAllowed = true;
		} else {
			// priority is not allowed, retry later when it is our slot turn
			priorityAllowed = false;
		}
	} finally {
		cache.endBatch(commit);
	}

	if (priorityAllowed) {
		// return doWithLock result (true - job done ; false - job not launch)
		try {
			return doWithLock(lockRequest.getLock(), runnable);
		} finally {
			// get rid of this node slot
			filterPriorityQueue(lockRequest.getPriorityQueue(),
					new Predicate<IAttribution>() {
						@Override
						public boolean apply(IAttribution input) {
							// keep all attribution of other nodes
							return !input.match(getAddress());
						}
				
			});
		}
	} else {
		return false;
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:70,代码来源:InfinispanClusterServiceImpl.java


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