private boolean remove(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) { SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id); try { if (!this.properties.isLockOnWrite() || (creationMetaDataCache.getAdvancedCache().getTransactionManager().getTransaction() == null) || creationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).lock(key)) { creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(key); this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(new SessionAccessMetaDataKey(id)); return true; } return false; } catch (SystemException e) { throw new CacheException(e); } }
private InfinispanSessionMetaData<L> getValue(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) { SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id); SessionCreationMetaDataEntry<L> creationMetaDataEntry = creationMetaDataCache.get(key); if (creationMetaDataEntry != null) { SessionAccessMetaData accessMetaData = this.accessMetaDataCache.get(new SessionAccessMetaDataKey(id)); if (accessMetaData != null) { return new InfinispanSessionMetaData<>(creationMetaDataEntry.getMetaData(), accessMetaData, creationMetaDataEntry.getLocalContext()); } // Purge orphaned entry, making sure not to trigger cache listener creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.SKIP_LISTENER_NOTIFICATION).remove(key); } return null; }
public Status update(String table, String key, Map<String, ByteIterator> values) { try { if (clustered) { AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key); StringByteIterator.putAllAsStrings(row, values); } else { Cache<String, Map<String, String>> cache = infinispanManager.getCache(table); Map<String, String> row = cache.get(key); if (row == null) { row = StringByteIterator.getStringMap(values); cache.put(key, row); } else { StringByteIterator.putAllAsStrings(row, values); } } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
@Override public void close() { this.cache.removeListener(this); this.cache.getCacheManager().removeListener(this); // Cleanup any unregistered listeners for (ExecutorService executor : this.listeners.values()) { PrivilegedAction<List<Runnable>> action = () -> executor.shutdownNow(); WildFlySecurityManager.doUnchecked(action); } this.listeners.clear(); }
@Override public boolean equals(Object object) { if ((object == null) || !(object instanceof InfinispanXAResourceRecovery)) return false; InfinispanXAResourceRecovery recovery = (InfinispanXAResourceRecovery) object; return this.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName().equals(recovery.cache.getCacheManager().getCacheManagerConfiguration().globalJmxStatistics().cacheManagerName()) && this.cache.getName().equals(recovery.cache.getName()); }
public CacheGroup(CacheGroupConfiguration config) { this.cache = config.getCache(); this.nodeFactory = config.getMemberFactory(); this.cache.getCacheManager().addListener(this); this.cache.addListener(this); }
public void testCancelAndGet() throws Exception { DistributedExecutorService des = createDES(getCache()); List<Address> cacheMembers = getCache().getAdvancedCache().getRpcManager().getMembers(); List<Address> members = new ArrayList<>(cacheMembers); assertEquals(caches(cacheName()).size(), members.size()); members.remove(getCache().getAdvancedCache().getRpcManager().getAddress()); DistributedTaskBuilder<Integer> tb = des.createDistributedTaskBuilder(new SleepingSimpleCallable(latchHolder)); final Future<Integer> future = des.submit(members.get(0),tb.build()); future.cancel(true); expectException(CancellationException.class, () -> future.get()); latchHolder.get().open(); }
public void test() throws Exception { MagicKey key = new MagicKey(cache(0), cache(1)); cache(2).put(key, "value"); CyclicBarrier barrier0 = new CyclicBarrier(2); cache(0).getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore( new BlockingInterceptor<>(barrier0, GetCacheEntryCommand.class, false, false), EntryWrappingInterceptor.class); Future<Object> f = fork(() -> cache(2).get(key)); barrier0.await(10, TimeUnit.SECONDS); cache(0).stop(); barrier0.await(10, TimeUnit.SECONDS); assertEquals("value", f.get(10, TimeUnit.SECONDS)); } }
public void testMemcachedPutEmbeddedGet() throws Exception { // 1. Put with Memcached for (int i = 0; i != numEntries; i++) { Future<Boolean> f = cacheFactory2.getMemcachedClient().set("k" + i, 0, "v" + i); assertTrue(f.get(60, TimeUnit.SECONDS)); } // 2. Get with Embedded from a different node for (int i = 0; i != numEntries; i++) { assertEquals("v" + i, cacheFactory1.getEmbeddedCache().get("k" + i)); cacheFactory1.getEmbeddedCache().remove("k" + i); } }
public void testInvalidation() throws Exception { assertEquals(Collections.singletonList(address(0)), advancedCache(0).getDistributionManager().locate(k0)); assertEquals(Collections.singletonList(address(0)), advancedCache(1).getDistributionManager().locate(k0)); advancedCache(1).put(k0, "k1"); assertTrue(advancedCache(1).getDataContainer().containsKey(k0)); assertTrue(advancedCache(0).getDataContainer().containsKey(k0)); tm(0).begin(); cache(0).put(k0, "v2"); tm(0).commit(); assertFalse(advancedCache(1).getDataContainer().containsKey(k0)); }
public void testRemovalOfEvictedEntry() throws Exception { Cache<String, String> testCache = cacheManager.getCache(CACHE_NAME); for (int i = 0; i < EVICTION_MAX_ENTRIES + 1; i++) { testCache.put("key" + i, "value" + i); } String evictedKey = evictionListener.getEvictedKey(); assertTrue(isEntryInStore(evictedKey)); testCache.remove(evictedKey); assertFalse(testCache.containsKey(evictedKey)); assertNull(testCache.get(evictedKey)); }
public void testLockWithTmCommit() throws Throwable { tm().begin(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); tm().commit(); assertFalse(lockManager().isLocked("k")); } }
public void testLockWithTmRollback() throws Throwable { tm().begin(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); tm().rollback(); assertFalse(lockManager().isLocked("k")); }
@Override public void call() throws Exception { Cache<Object, Object> c = cm.getCache(); if (inTran) c.getAdvancedCache().getTransactionManager().begin(); c.put("key1", new SEntity(1, "name1", "surname1")); if (inTran) c.getAdvancedCache().getTransactionManager().commit(); assertEquals(searchByName("name1", c).size(), 1, "should be 1, even repeating this"); } });
public void testFailure() throws Exception { TransactionManager transactionManager = cache.getAdvancedCache().getTransactionManager(); transactionManager.begin(); try { cache.put("k", "v"); assert false; } catch (Exception e) { log.debug("Ignoring expected exception during put", e); assertEquals(transactionManager.getTransaction().getStatus(), Status.STATUS_MARKED_ROLLBACK); } } }
public void testRemoteLoadFromCacheLoader() throws Exception { Cache<String, String> cache1 = cache(0, "clusteredCl"); Cache<String, String> cache2 = cache(1, "clusteredCl"); CacheWriter writer = TestingUtil.getFirstWriter(cache2); assertNull(cache1.get("key")); assertNull(cache2.get("key")); writer.write(new MarshalledEntryImpl("key", "value", null, cache2.getAdvancedCache().getComponentRegistry().getCacheMarshaller())); assertEquals(((CacheLoader)writer).load("key").getValue(), "value"); assertEquals(cache1.get("key"), "value"); } }
public void testKeySetIsEmptyAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertTrue(cache.keySet().isEmpty()); } finally { tm().commit(); } }
public void testValuesIsEmptyAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertTrue(cache.values().isEmpty()); } finally { tm().commit(); } }
@Override public void call() { Cache<byte[], byte[]> cache = cm.getCache(); byte[] key = "key1".getBytes(ISO_8859_1); byte[] value = new byte[]{97, 118, 105, -61, -93, 111}; // 'avião' in UTF-8 cache.put(key, value); assertEquals(cache.get(key), value); // Value as UTF-16 Cache<byte[], byte[]> utf16ValueCache = (Cache<byte[], byte[]>) cache.getAdvancedCache().withMediaType("text/plain; charset=ISO-8859-1", "text/plain; charset=UTF-16"); assertEquals(utf16ValueCache.get(key), new byte[]{-2, -1, 0, 97, 0, 118, 0, 105, 0, -29, 0, 111}); } });
public void testPreviousValueIgnored() throws Exception { cache.put("k", "init"); tm.begin(); cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put("k", "v1"); assertEquals("v1", cache.put("k", "v2")); Transaction tx = tm.suspend(); assertEquals("init", cache.put("k", "other")); tm.resume(tx); commit(); }