@Override public void addClientListener(Object listener, Object[] filterFactoryParams, Object[] converterFactoryParams) { delegate.addClientListener(listener, filterFactoryParams, converterFactoryParams); }
@Override protected void addListener(AbstractJCacheListenerAdapter<K, V> listenerAdapter) { cache.addClientListener(listenerAdapter); }
@Override public void addClientListener(Object listener) { delegate.addClientListener(listener); }
@Override protected void doStart() throws Exception { this.future = executorService.scheduleAtFixedRate(this::run, 0, lifespan / 2, lifespanTimeUnit); this.cache.addClientListener(this); }
@Override protected void registerListener() { ((RemoteCache<?, ?>) eventSource.getNativeCache()).addClientListener(this, null, new Object[]{Boolean.TRUE}); }
private static void addSsoCacheCrossDcListener(Cache<String, String[]> ssoCache, SsoSessionCacheListener listener) { if (ssoCache.getCacheConfiguration().persistence() == null) { return; } final Set<RemoteStore> stores = getRemoteStores(ssoCache); if (stores == null || stores.isEmpty()) { return; } LOG.infov("Listening for events on remote stores configured for cache {0}", ssoCache.getName()); for (RemoteStore store : stores) { store.getRemoteCache().addClientListener(listener); } }
private <K, V extends SessionEntity> boolean checkRemoteCache(KeycloakSession session, Cache<K, SessionEntityWrapper<V>> ispnCache, RemoteCacheInvoker.MaxIdleTimeLoader maxIdleLoader) { Set<RemoteStore> remoteStores = InfinispanUtil.getRemoteStores(ispnCache); if (remoteStores.isEmpty()) { log.debugf("No remote store configured for cache '%s'", ispnCache.getName()); return false; } else { log.infof("Remote store configured for cache '%s'", ispnCache.getName()); RemoteCache<K, SessionEntityWrapper<V>> remoteCache = (RemoteCache) remoteStores.iterator().next().getRemoteCache(); if (remoteCache == null) { throw new IllegalStateException("No remote cache available for the infinispan cache: " + ispnCache.getName()); } remoteCacheInvoker.addRemoteCache(ispnCache.getName(), remoteCache, maxIdleLoader); RemoteCacheSessionListener hotrodListener = RemoteCacheSessionListener.createListener(session, ispnCache, remoteCache); remoteCache.addClientListener(hotrodListener); return true; } }
public static void testAddGetClientListener(RemoteCache<String, String> remoteCache) { remoteCache.addClientListener(new NoopEventListener()); Set<Object> s = remoteCache.getListeners(); assertTrue(s.size() > 0); }
public static InfinispanNotificationsManager create(KeycloakSession session, Cache<String, Serializable> workCache, String myAddress, String mySite, Set<RemoteStore> remoteStores) { RemoteCache workRemoteCache = null; if (!remoteStores.isEmpty()) { RemoteStore remoteStore = remoteStores.iterator().next(); workRemoteCache = remoteStore.getRemoteCache(); if (mySite == null) { throw new IllegalStateException("Multiple datacenters available, but site name is not configured! Check your configuration"); } } ExecutorService listenersExecutor = workRemoteCache==null ? null : session.getProvider(ExecutorsProvider.class).getExecutor("work-cache-event-listener"); InfinispanNotificationsManager manager = new InfinispanNotificationsManager(workCache, workRemoteCache, myAddress, mySite, listenersExecutor); // We need CacheEntryListener for communication within current DC workCache.addListener(manager.new CacheEntryListener()); logger.debugf("Added listener for infinispan cache: %s", workCache.getName()); // Added listener for remoteCache to notify other DCs if (workRemoteCache != null) { workRemoteCache.addClientListener(manager.new HotRodListener(workRemoteCache)); logger.debugf("Added listener for HotRod remoteStore cache: %s", workRemoteCache.getName()); } return manager; }
public static void testRemoveClientListener(RemoteCache<String, String> remoteCache) { NoopEventListener c = new NoopEventListener(); int initialListenerCount = remoteCache.getListeners().size(); remoteCache.addClientListener(c); assertEquals(initialListenerCount + 1, remoteCache.getListeners().size()); remoteCache.removeClientListener(c); assertEquals(initialListenerCount, remoteCache.getListeners().size()); }
@Override public InfinispanEventListener start(InfinispanConsumer consumer) { if (consumer.getConfiguration().isSync()) { throw new UnsupportedOperationException("Sync listeners not supported for remote caches."); } RemoteCache<?, ?> remoteCache = InfinispanUtil.asRemote(consumer.getCache()); InfinispanConfiguration configuration = consumer.getConfiguration(); InfinispanEventListener listener; if (configuration.hasCustomListener()) { listener = configuration.getCustomListener(); listener.setInfinispanConsumer(consumer); } else { listener = new InfinispanRemoteEventListener(consumer, configuration.getEventTypes()); } remoteCache.addClientListener(listener); listener.setCacheName(remoteCache.getName()); return listener; }
public static void main(String[] args) throws InterruptedException { // Create a configuration for a locally-running server ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT); // Connect to the server RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build()); // Obtain the remote cache RemoteCache<String, String> cache = cacheManager.getCache(); // Register a listener MyListener listener = new MyListener(); cache.addClientListener(listener); // Store some values cache.put("key1", "value1"); cache.put("key2", "value2"); cache.put("key1", "newValue"); // Remote events are asynchronous, so wait a bit Thread.sleep(1000); // Remove listener cache.removeClientListener(listener); // Stop the cache manager and release all resources cacheManager.stop(); }
@Test public void testCustomEventsDynamic() { final DynamicCustomEventLogListener eventListener = new DynamicCustomEventLogListener(); remoteCache.addClientListener(eventListener, null, new Object[]{2}); try { eventListener.expectNoEvents(); remoteCache.put(1, "one"); eventListener.expectSingleCustomEvent(1, "one"); remoteCache.put(2, "two"); eventListener.expectSingleCustomEvent(2, null); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testCustomEvents() { final StaticCustomEventLogListener eventListener = new StaticCustomEventLogListener(); remoteCache.addClientListener(eventListener); try { eventListener.expectNoEvents(); remoteCache.put(1, "one"); eventListener.expectSingleCustomEvent(1, "one"); remoteCache.put(1, "newone"); eventListener.expectSingleCustomEvent(1, "newone"); remoteCache.remove(1); eventListener.expectSingleCustomEvent(1, null); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testCustomEventsCustomPojo() { final CustomPojoCustomEventLogListener eventListener = new CustomPojoCustomEventLogListener(); remoteCache.addClientListener(eventListener, null, new Object[]{new Person("two")}); try { eventListener.expectNoEvents(); remoteCache.put(1, new Person("one")); eventListener.expectSingleCustomEvent(1, new Person("one")); remoteCache.put(2, new Person("two")); eventListener.expectSingleCustomEvent(2, null); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testEventFilteringStatic() { final StaticFilteredEventLogListener eventListener = new StaticFilteredEventLogListener(); remoteCache.addClientListener(eventListener); try { expectNoEvents(eventListener); remoteCache.put(1, "one"); expectNoEvents(eventListener); remoteCache.put(2, "two"); expectOnlyCreatedEvent(2, eventListener); remoteCache.remove(1); expectNoEvents(eventListener); remoteCache.remove(2); expectOnlyRemovedEvent(2, eventListener); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testEventReceiveBasic() { final EventLogListener eventListener = new EventLogListener(); remoteCache.addClientListener(eventListener); try { expectNoEvents(eventListener); // Created events remoteCache.put(1, "one"); expectOnlyCreatedEvent(1, eventListener); remoteCache.put(2, "two"); expectOnlyCreatedEvent(2, eventListener); // Modified events remoteCache.put(1, "newone"); expectOnlyModifiedEvent(1, eventListener); // Remove events remoteCache.remove(1); expectOnlyRemovedEvent(1, eventListener); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testEventFilteringCustomPojo() { final CustomPojoFilteredEventLogListener eventListener = new CustomPojoFilteredEventLogListener(); remoteCache.addClientListener(eventListener, new Object[]{"two"}, null); try { expectNoEvents(eventListener); remoteCache.put(1, new Person("one")); expectNoEvents(eventListener); remoteCache.put(2, new Person("two")); expectOnlyCreatedEvent(2, eventListener); remoteCache.remove(1); expectNoEvents(eventListener); remoteCache.remove(2); expectOnlyRemovedEvent(2, eventListener); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testEventFilteringDynamic() { final DynamicFilteredEventLogListener eventListener = new DynamicFilteredEventLogListener(); remoteCache.addClientListener(eventListener, new Object[]{3}, null); try { expectNoEvents(eventListener); remoteCache.put(1, "one"); expectNoEvents(eventListener); remoteCache.put(2, "two"); expectNoEvents(eventListener); remoteCache.put(3, "three"); expectOnlyCreatedEvent(3, eventListener); remoteCache.replace(1, "new-one"); expectNoEvents(eventListener); remoteCache.replace(2, "new-two"); expectNoEvents(eventListener); remoteCache.replace(3, "new-three"); expectOnlyModifiedEvent(3, eventListener); remoteCache.remove(1); expectNoEvents(eventListener); remoteCache.remove(2); expectNoEvents(eventListener); remoteCache.remove(3); expectOnlyRemovedEvent(3, eventListener); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testEventReceiveBasic() { final IdEventListener eventListener = new IdEventListener(); remoteCache.addClientListener(eventListener); try { // Created events remoteCache.put(new Id(1), new Id(11)); ClientCacheEntryCreatedEvent<Id> created = eventListener.pollEvent(); assertEquals(new Id(1), created.getKey()); remoteCache.put(new Id(2), new Id(22)); created = eventListener.pollEvent(); assertEquals(new Id(2), created.getKey()); // Modified events remoteCache.put(new Id(1), new Id(111)); ClientCacheEntryModifiedEvent<Id> modified = eventListener.pollEvent(); assertEquals(new Id(1), modified.getKey()); // Remove events remoteCache.remove(new Id(1)); ClientCacheEntryRemovedEvent<Id> removed = eventListener.pollEvent(); assertEquals(new Id(1), removed.getKey()); remoteCache.remove(new Id(2)); removed = eventListener.pollEvent(); assertEquals(new Id(2), removed.getKey()); } finally { remoteCache.removeClientListener(eventListener); } }