本文整理汇总了Java中org.infinispan.Cache.get方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.get方法的具体用法?Java Cache.get怎么用?Java Cache.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.infinispan.Cache
的用法示例。
在下文中一共展示了Cache.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import org.infinispan.Cache; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
ServiceContainer sc = CurrentServiceContainer.getServiceContainer();
// for(ServiceName sn: sc.getServiceNames()) {
// log.info("" + sn);
// }
ServiceName sn = ServiceName.of("jboss", "infinispan", "web", "repl");
ServiceController scon = sc.getService(sn);
Cache cache = (Cache)scon.getValue();
log.info("" + cache);
String path = req.getPathInfo();
Object o = null;
if ("/put".equals(path)) {
cache.put("test", "blah");
}
else if ("/get".equals(path)) {
o = cache.get("test");
}
res.setContentType("text/html");
PrintWriter out = res.getWriter();
if (o != null) {
out.println(o);
}
}
示例2: timeout
import org.infinispan.Cache; //导入方法依赖的package包/类
@Timeout
public void timeout(Timer timer) {
final Cache<String, ExecutionControl> cache = GlobalCache.get().getExecutionControls();
String info = (String) timer.getInfo();
try {
int n = info.indexOf(' ');
String execCtrlName = info.substring(0, n);
int cycleNum = Integer.parseInt(info.substring(n + 1));
ExecutionControl execCtrl = cache.get(execCtrlName);
if (execCtrl != null)
execCtrl.onTimeout(cycleNum);
else
logger.log(Level.WARNING, "ExecutionControl " + execCtrlName + " not found.");
} catch (ConcurrentAccessTimeoutException ex) {
logger.warning(ex.getMessage());
}
}
示例3: printInfo
import org.infinispan.Cache; //导入方法依赖的package包/类
/**
* Queue에 들어있는 데이터 출력
*
* @param cache
*/
public void printInfo(Cache<String, Object> cache) {
System.out.println("========= Queue Info =========");
System.out.println("Queue Size=" + (Integer) cache.get(QUEUE_SIZE));
String headKey = (String) cache.get(QUEUE_HEAD);
System.out.println("Queue Head=" + headKey);
System.out.println("Queue Tail=" + cache.get(QUEUE_TAIL));
InfinispanQueueElement element = new InfinispanQueueElement();
while(true) {
element = (InfinispanQueueElement) cache.get(headKey);
if( element == null ) {
break;
}
System.out.println("Queue> " + element);
headKey = element.getNextId();
}
System.out.println("========= Queue END =========");
}
示例4: read
import org.infinispan.Cache; //导入方法依赖的package包/类
public int read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
Map<String, String> row;
if (clustered) {
row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false);
} else {
Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
row = cache.get(key);
}
if (row != null) {
result.clear();
if (fields == null || fields.isEmpty()) {
StringByteIterator.putAllAsByteIterators(result, row);
} else {
for (String field : fields) result.put(field, new StringByteIterator(row.get(field)));
}
}
return OK;
} catch (Exception e) {
return ERROR;
}
}
示例5: main
import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager("config/beosbank-infinispan.xml");
// Obtain the default cache
Cache<Long, MoneyTransfert> cache = cacheManager.getCache("beosbank-dist");
// Obtain the remote cache
cache.addListener(new DatagridListener());
// Create a Money Transfer Object from XML Message using BeaoIO API
try {
BeosBankCacheUtils.loadEntries(cache,inputFileNames);
// Inspect the cache .
System.out.println(cache.size());
Thread.sleep(2000);
cache.get(5l);
System.out.println("Cache content after 2 sec");
//Current node content
printCacheContent(cache);
Thread.sleep(1000);
System.out.println("Cache content after 3 sec");
printCacheContent(cache);
Thread.sleep(3000);
System.out.println("Cache content after 6 sec");
printCacheContent(cache);
// Stop the cache
cache.stop();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例6: testEmptyHASession
import org.infinispan.Cache; //导入方法依赖的package包/类
@Test
public void testEmptyHASession() {
LOGGER.info("Start test empty HASessionID");
System.setProperty("grid.buffer", "10");
RulesConfigurationTestImpl rulesConfigurationTest = RulesTestBuilder.buildV1();
rulesConfigurationTest.registerChannel("additions", additionsChannel, replayChannel);
RulesManager rulesManager = new RulesManager(rulesConfigurationTest);
rulesManager.start(null, null, null);
Cache<String, Object> cache1 = startNodes(2, rulesManager).getCache();
Cache<String, Object> cache2 = startNodes(2, rulesManager).getCache();
reset(replayChannel);
String key = "1";
HAKieSession session1 = new HAKieSession(rulesManager, executorService);
cache1.put(key, session1);
HAKieSession serializedSessionCopy = (HAKieSession) cache2.get(key);
Assert.assertNotNull(serializedSessionCopy);
Assert.assertTrue(serializedSessionCopy.isSerialized());
reset(replayChannel, additionsChannel);
HAKieSession session2 = ((HAKieSerializedSession) serializedSessionCopy).rebuild();
Assert.assertNotNull(session2);
LOGGER.info("End test empty HASessionID");
rulesManager.stop();
}
示例7: get
import org.infinispan.Cache; //导入方法依赖的package包/类
@GET
@Produces("text/plain")
public String get() throws Exception {
EmbeddedCacheManager cacheContainer
= (EmbeddedCacheManager) new InitialContext().lookup("java:jboss/infinispan/container/server");
Cache<String,String> cache = cacheContainer.getCache("server");
if (cache.keySet().contains(key)) {
return (String) cache.get(key);
}
String result = UUID.randomUUID().toString();
cache.put(key, result);
return result;
}
示例8: getPaths
import org.infinispan.Cache; //导入方法依赖的package包/类
@Override
public List<String> getPaths(String kind, String type, String specification, Optional<byte[]> exemplar) {
Cache<String, List<String>> cache = caches.getCache(CACHE_NAME);
if (cache.containsKey(type)) {
return cache.get(type);
}
List<String> paths = getPathsForJavaClassName("", type, new ArrayList<>());
cache.put(type, paths);
return paths;
}
示例9: performKeySearch
import org.infinispan.Cache; //导入方法依赖的package包/类
@Override
public Object performKeySearch(String cacheName, String columnNameInSource, Object value, ObjectConnection connection) throws TranslatorException {
LogManager.logTrace(LogConstants.CTX_CONNECTOR,
"Perform Lucene KeySearch."); //$NON-NLS-1$
Cache<?,?> c = (Cache<?, ?>) connection.getCacheContainer().getCache(cacheName);
return c.get(String.valueOf(value));
}
示例10: viewChanged
import org.infinispan.Cache; //导入方法依赖的package包/类
@ViewChanged
public void viewChanged(ViewChangedEvent event) {
final Cache<String, ExecutionControl> cache = GlobalCache.get().getExecutionControls();
Set<String> allExecCtrls = new HashSet<>(cache.keySet());
for (String name : allExecCtrls) {
ExecutionControl ctrl = cache.get(name);
if (ctrl != null)
ctrl.onTimeout(-1);
}
}
示例11: initialize
import org.infinispan.Cache; //导入方法依赖的package包/类
/**
* Queue 포인터 초기화
*
* @param cache
*/
public void initialize(Cache<String, Object> cache) {
String key = UUIDFactory.generateGuid();
if( cache.get(QUEUE_TAIL) == null )
cache.put(QUEUE_TAIL, key);
if( cache.get(QUEUE_HEAD) == null )
cache.put(QUEUE_HEAD, key);
if( cache.get(QUEUE_SIZE) == null )
cache.put(QUEUE_SIZE, 0);
}
示例12: offer
import org.infinispan.Cache; //导入方法依赖的package包/类
/**
* Queue에 Element Offer
*
* @param cache
* @param element
* @return
*/
public boolean offer(Cache<String, Object> cache, InfinispanQueueElement element) {
// 다음 Queue Element를 가리킬 포인터를 생성
String nextKey = UUIDFactory.generateGuid();
element.setNextId(nextKey);
// 트랜잭션 사용
@SuppressWarnings("rawtypes")
TransactionManager tm = ((CacheImpl) cache).getAdvancedCache().getTransactionManager();
try {
tm.begin();
// Queue의 Tail에 Element 추가
String tailKey = (String) cache.get(QUEUE_TAIL);
cache.put(tailKey, element);
cache.put(QUEUE_TAIL, nextKey);
cache.put(QUEUE_SIZE, (Integer) cache.get(QUEUE_SIZE) + 1);
tm.commit();
} catch (Exception e) {
if (tm != null) {
try {
tm.rollback();
} catch (Exception e1) {}
}
}
return false;
}
示例13: poll
import org.infinispan.Cache; //导入方法依赖的package包/类
/**
* Queue의 Element Poll
*
* @param cache
* @return
*/
public InfinispanQueueElement poll(Cache<String, Object> cache) {
// 트랜잭션 사용
@SuppressWarnings("rawtypes")
TransactionManager tm = ((CacheImpl) cache).getAdvancedCache().getTransactionManager();
InfinispanQueueElement element = null;
try {
tm.begin();
// Queue의 Head의 포인터의 값을 get
String key = (String) cache.get(QUEUE_HEAD);
element = (InfinispanQueueElement) cache.get(key);
// Queue Head 포인터값 Update & 제거
if( element != null ) {
cache.put(QUEUE_HEAD, element.getNextId());
cache.put(QUEUE_SIZE, (Integer) cache.get(QUEUE_SIZE) - 1);
cache.remove(key);
}
tm.commit();
} catch (Exception e) {
if (tm != null) {
try {
tm.rollback();
} catch (Exception e1) {}
}
}
return element;
}
示例14: main
import org.infinispan.Cache; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
//Configuration
ConfigurationBuilder builder = new ConfigurationBuilder();
builder
.expiration()
.maxIdle(3l, TimeUnit.SECONDS)
.lifespan(5l, TimeUnit.SECONDS);
// Initialize the cache manager
DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
// Obtain the default cache
Cache<Long, MoneyTransfert> cache = cacheManager.getCache("beosbank-dist");
// Obtain the remote cache
cache.addListener(new DatagridListener());
// Create a Money Transfer Object from XML Message using BeaoIO API
try {
BeosBankCacheUtils.loadEntries(cache,inputFileNames);
// Inspect the cache .
System.out.println(cache.size());
Thread.sleep(2000);
cache.get(5l);
System.out.println("Cache content after 2 sec");
//Current node content
printCacheContent(cache);
Thread.sleep(1000);
System.out.println("Cache content after 3 sec");
printCacheContent(cache);
Thread.sleep(3000);
System.out.println("Cache content after 6 sec");
printCacheContent(cache);
// Stop the cache
cache.stop();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例15: testNonEmptyHASession
import org.infinispan.Cache; //导入方法依赖的package包/类
@Test
public void testNonEmptyHASession() throws IOException, URISyntaxException {
System.setProperty("grid.buffer", "10");
logger.info("Start test modified rules");
RulesConfigurationTestImpl rulesConfigurationTest = RulesTestBuilder.buildV1();
rulesConfigurationTest.registerChannel("additions", additionsChannel, replayChannel);
RulesManager rulesManager = new RulesManager(rulesConfigurationTest);
rulesManager.start(null, null, null);
Cache<String, Object> cache1 = startNodes(2, rulesManager).getCache();
Cache<String, Object> cache2 = startNodes(2, rulesManager).getCache();
String key = "2";
HAKieSession session1 = new HAKieSession(rulesManager, executorService);
cache1.put(key, session1);
session1.insert(generateFactTenSecondsAfter(1L, 10L));
cache1.put(key, session1);
session1.insert(generateFactTenSecondsAfter(1L, 20L));
cache1.put(key, session1);
verify(replayChannel, never()).send(any());
InOrder inOrder = inOrder(additionsChannel);
inOrder.verify(additionsChannel, times(1)).send(eq(10L));
inOrder.verify(additionsChannel, times(1)).send(eq(30L));
inOrder.verifyNoMoreInteractions();
// Double check on total number of calls to the method send
verify(additionsChannel, times(2)).send(any());
HAKieSession serializedSessionCopy = (HAKieSession) cache2.get(key);
Assert.assertNotNull(serializedSessionCopy);
Assert.assertTrue(serializedSessionCopy.isSerialized());
reset(replayChannel, additionsChannel);
((HAKieSerializedSession) serializedSessionCopy).createSnapshot();
((HAKieSerializedSession) serializedSessionCopy).waitForSnapshotToComplete();
inOrder = inOrder(replayChannel);
inOrder.verify(replayChannel, times(1)).send(eq(30L));
inOrder.verifyNoMoreInteractions();
reset(replayChannel, additionsChannel);
rulesConfigurationTest = RulesTestBuilder.buildV1();
rulesConfigurationTest.registerChannel("additions", otherAdditionsChannel, otherReplayChannel);
rulesManager = new RulesManager(rulesConfigurationTest);
rulesManager.start(null, null, null);
byte[] serializedSession = ((HAKieSerializedSession) serializedSessionCopy).getSerializedSession();
HAKieSession session2 = new HAKieSerializedSession(rulesManager, executorService, rulesConfigurationTest.getVersion(), serializedSession).rebuild();
String version = RulesTestBuilder.buildV2().getVersion();
rulesManager.updateToVersion(version);
session2.insert(generateFactTenSecondsAfter(1L, 30L));
verify(replayChannel, never()).send(any());
verify(additionsChannel, never()).send(any());
verify(otherReplayChannel, never()).send(any());
verify(otherAdditionsChannel, atMost(1)).send(any());
verify(otherAdditionsChannel, times(1)).send(eq(120L));
logger.info("End test modified rules");
rulesManager.stop();
}