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


Java AdvancedCache类代码示例

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


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

示例1: initSchema

import org.infinispan.AdvancedCache; //导入依赖的package包/类
private void initSchema() {
    AtomicReference<Integer> replicationFactor = new AtomicReference<>();
    try {
        replicationFactor.set(Integer.parseInt(replicationFactorProp));
    } catch (NumberFormatException e) {
        log.warnf("Invalid value [%s] for Cassandra replication_factor. Using default value of 1",
                replicationFactorProp);
        replicationFactor.set(1);
    }

    AdvancedCache<String, String> cache = locksCache.getAdvancedCache();
    DistributedLock schemaLock = new DistributedLock(cache, "cassalog");
    schemaLock.lockAndThen(30000, () -> {
        SchemaService schemaService = new SchemaService();
        schemaService.run(session, keyspace, Boolean.parseBoolean(resetDb), replicationFactor.get());
        session.execute("USE " + keyspace);
        logReplicationFactor();
    });
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:20,代码来源:MetricsServiceLifecycle.java

示例2: getCache

import org.infinispan.AdvancedCache; //导入依赖的package包/类
/**
 *
 * Get embedded Infinispan cache which acts as an underlying store for JSON documents.
 *
 * Look into global map for registered cache. Avoiding multiple asking CacheManager.
 * <p/>
 * If there is no cache with the given name, get it from CacheManager and put.
 *
 * @param cacheName -- name of cache, AdvancedCache is returned.
 * @return AdvancedCache instance in dependence on a given name.
 */
private AdvancedCache getCache(String cacheName) {
    if (caches.get(cacheName) != null) {
        return this.caches.get(cacheName);
    } else {
        try {
            defaultCacheManager.startCache(cacheName);
            Cache cache = defaultCacheManager.getCache(cacheName);
            this.caches.put(cacheName, cache.getAdvancedCache());
            return cache.getAdvancedCache();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("ERROR DURING STARTING CACHE " + cacheName, e);
        }
    }
    return this.caches.get(cacheName);
}
 
开发者ID:tsykora,项目名称:infinispan-odata-server,代码行数:28,代码来源:InfinispanProducer.java

示例3: runTask

import org.infinispan.AdvancedCache; //导入依赖的package包/类
@Override
public void runTask() {
	// wait for a message from coordinator to try to lock keys A and B
	// post a message TimeoutException if lock cannot be acquired
	// post a message LockSuccess if lock is successful
	getCacheManager().getCache(TestConstants.CACHE_MESSAGE).addListener(new NodeMessageListener<String>() {
		@Override
		public void onMessage(Message<String> value) {
			LOGGER.debug("message received");
			if (value.getAddress().equals(getCacheManager().getCoordinator())) {
				LOGGER.debug("message received from coordinator");
				if ("tryLock".equals(value.getMessage())) {
					LOGGER.debug("received tryLock message");
					AdvancedCache<String, Object> cache =
							getCacheManager().<String, Object>getCache(TestConstants.CACHE_DEFAULT).getAdvancedCache();
					LOGGER.debug("batch started");
					cache.startBatch();
					boolean successful = false;
					Address address = getCacheManager().getAddress();
					try {
						LOGGER.debug("try A, B locks");
						cache.lock("A", "B");
						LOGGER.debug("lock successful");
						successful = true;
						LOGGER.debug("send success message");
						getCacheManager().<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE)
							.put("messageBus", Message.from(address, LOCK_SUCCESS));
					} catch (TimeoutException e) {
						LOGGER.debug("send failure message");
						getCacheManager().<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE)
							.put("messageBus", Message.from(address, TIMEOUT_EXCEPTION));
					} finally {
						cache.endBatch(successful);
						LOGGER.debug("batch ended");
					}
				}
			}
		}
	});
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:41,代码来源:LockTask.java

示例4: findAll

import org.infinispan.AdvancedCache; //导入依赖的package包/类
@Override
protected Map<ID, T> findAll(Set<ID> keys) {
    AdvancedCache<ID, T> advancedCache = cache.getAdvancedCache();
    return advancedCache.getAll(keys);
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:6,代码来源:InfinispanEmbeddedDatasourceMapper.java

示例5: asAdvanced

import org.infinispan.AdvancedCache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <K, V> AdvancedCache<K, V> asAdvanced(BasicCache<K, V> cache) {
    return Cache.class.cast(cache).getAdvancedCache();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:5,代码来源:InfinispanUtil.java

示例6: main

import org.infinispan.AdvancedCache; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
   AdvancedCache<String, String> cache = cacheManager.<String, String>getCache("local").getAdvancedCache();
   FunctionalMapImpl<String, String> functionalMap = FunctionalMapImpl.create(cache);
   FunctionalMap.WriteOnlyMap<String, String> writeOnlyMap = WriteOnlyMapImpl.create(functionalMap);
   FunctionalMap.ReadOnlyMap<String, String> readOnlyMap = ReadOnlyMapImpl.create(functionalMap);

   // Execute two parallel write-only operation to store key/value pairs
   CompletableFuture<Void> writeFuture1 = writeOnlyMap.eval("key1", "value1",
      (v, writeView) -> writeView.set(v));
   CompletableFuture<Void> writeFuture2 = writeOnlyMap.eval("key2", "value2",
      (v, writeView) -> writeView.set(v));

   // When each write-only operation completes, execute a read-only operation to retrieve the value
   CompletableFuture<String> readFuture1 =
      writeFuture1.thenCompose(r -> readOnlyMap.eval("key1", EntryView.ReadEntryView::get));
   CompletableFuture<String> readFuture2 =
      writeFuture2.thenCompose(r -> readOnlyMap.eval("key2", EntryView.ReadEntryView::get));

   // When the read-only operation completes, print it out
   System.out.printf("Created entries: %n");
   CompletableFuture<Void> end = readFuture1.thenAcceptBoth(readFuture2, (v1, v2) ->
      System.out.printf("key1 = %s%nkey2 = %s%n", v1, v2));

   // Wait for this read/write combination to finish
   end.get();

   // Create a read-write map
   FunctionalMap.ReadWriteMap<String, String> readWriteMap = ReadWriteMapImpl.create(functionalMap);

   // Use read-write multi-key based operation to write new values
   // together with lifespan and return previous values
   Map<String, String> data = new HashMap<>();
   data.put("key1", "newValue1");
   data.put("key2", "newValue2");
   Traversable<String> previousValues = readWriteMap.evalMany(data, (v, readWriteView) -> {
      String prev = readWriteView.find().orElse(null);
      readWriteView.set(v, new MetaLifespan(Duration.ofHours(1).toMillis()));
      return prev;
   });

   // Use read-only multi-key operation to read current values for multiple keys
   Traversable<EntryView.ReadEntryView<String, String>> entryViews =
      readOnlyMap.evalMany(data.keySet(), readOnlyView -> readOnlyView);
   System.out.printf("Updated entries: %n");
   entryViews.forEach(view -> System.out.printf("%s%n", view));

   // Finally, print out the previous entry values
   System.out.printf("Previous entry values: %n");
   previousValues.forEach(prev -> System.out.printf("%s%n", prev));
}
 
开发者ID:infinispan,项目名称:infinispan-simple-tutorials,代码行数:53,代码来源:InfinispanFunctional.java

示例7: testBatch

import org.infinispan.AdvancedCache; //导入依赖的package包/类
/**
 * Test {@link AdvancedCache#startBatch()} (to handle concurrent read / update).
 * We lock to keys (A and B) and asks for second nodes (using message) to confirm that these keys cannot be locked
 * concurrently.
 * After keys' release, confirm that second node can now lock these keys.
 * 
 * @throws IOException
 * @throws InterruptedException
 * @throws TimeoutException
 * @throws ExecutionException
 */
@Test
public void testBatch() throws IOException, InterruptedException, TimeoutException, ExecutionException {
	// start infinispan
	final int nodeNumber = 1;
	
	// start test instance
	final EmbeddedCacheManager cacheManager = new TestCacheManagerBuilder("node main", null).build();
	this.cacheManager = cacheManager;
	
	final Object monitor = new Object();
	final Map<Address, String> messages = Maps.newConcurrentMap();
	
	cacheManager.start();
	cacheManager.getCache(TestConstants.CACHE_MESSAGE).addListener(new NodeMessageListener<String>() {
		@Override
		public void onMessage(Message<String> value) {
			messages.put(value.getAddress(), value.getMessage());
			synchronized (monitor) {
				monitor.notify();
			}
		}
	});
	// initializes two keys A and B
	cacheManager.getCache(TestConstants.CACHE_DEFAULT).put("A", "A");
	cacheManager.getCache(TestConstants.CACHE_DEFAULT).put("B", "B");
	
	// start another node that register a task that waits a message to lock A and B
	prepareCluster(nodeNumber, LockTask.class);
	
	// startBatch
	AdvancedCache<Object, Object> cache = cacheManager.<Object, Object>getCache(TestConstants.CACHE_DEFAULT).getAdvancedCache();
	cache.startBatch();
	boolean successful = false;
	final Address address = cacheManager.getAddress();
	
	Callable<Boolean> test = new Callable<Boolean>() {
		@Override
		public Boolean call() throws Exception {
			return ! address.equals(cacheManager.<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE).get(TestConstants.CACHE_KEY_MESSAGE_BUS).getAddress());
		}
	};
	
	try {
		// lock A and B
		cache.lock("A", "B");
		// send message -> second node cannot lock -> message TimeoutException
		cacheManager.getCache(TestConstants.CACHE_MESSAGE).put(TestConstants.CACHE_KEY_MESSAGE_BUS, Message.from(address, LockTask.TRY_LOCK));
		// must be set accordingly with lockAcquisitionTimeout
		waitForEvent(monitor, test, 25, TimeUnit.SECONDS);
		Assert.assertEquals(LockTask.TIMEOUT_EXCEPTION, cacheManager.<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE).get(TestConstants.CACHE_KEY_MESSAGE_BUS).getMessage());
		successful = true;
	} finally {
		// stopBatch
		cache.endBatch(successful);
	}
	// second node can lock
	cacheManager.getCache(TestConstants.CACHE_MESSAGE).put(TestConstants.CACHE_KEY_MESSAGE_BUS, Message.from(address, LockTask.TRY_LOCK));
	// must be set accordingly with lockAcquisitionTimeout
	waitForEvent(monitor, test, 25, TimeUnit.SECONDS);
	Assert.assertEquals(LockTask.LOCK_SUCCESS, cacheManager.<String, Message<String>>getCache(TestConstants.CACHE_MESSAGE).get(TestConstants.CACHE_KEY_MESSAGE_BUS).getMessage());
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:73,代码来源:TestTransaction.java

示例8: DistributedLock

import org.infinispan.AdvancedCache; //导入依赖的package包/类
/**
 * @param locksCache The cache used for locking. This class will probably refactored at some point so that the cache
 *                   can be directly injected.
 * @param key The name or value of the lock.
 */
public DistributedLock(AdvancedCache<String, String> locksCache, String key) {
    this.key = key;
    this.locksCache = locksCache;
    this.locksCache.getCacheManager().addListener(this);
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:11,代码来源:DistributedLock.java

示例9: createCacheWrapper

import org.infinispan.AdvancedCache; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
    return cache;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:6,代码来源:InfinispanRegionFactory.java

示例10: createCacheWrapper

import org.infinispan.AdvancedCache; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
    cache.start();
    return cache;
}
 
开发者ID:jipijapa,项目名称:jipijapa,代码行数:7,代码来源:SharedInfinispanRegionFactory.java

示例11: execute

import org.infinispan.AdvancedCache; //导入依赖的package包/类
@Override
public void execute() throws Exception
{
    AdvancedCache ac = (AdvancedCache)ca.getCache("SOURCE-CACHE");

    // maipulate the JTA transaction with begin/commit/rollback

    ac.lock(key);

    System.out.println("> ok");

    // maipulate the JTA transaction with begin/commit/rollback

}
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:15,代码来源:Lock.java


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