@Override public void removeClientListener(Object listener) { delegate.removeClientListener(listener); }
@Override protected void removeListener(AbstractJCacheListenerAdapter<K, V> listenerAdapter) { cache.removeClientListener(listenerAdapter); }
@Override protected void doStop() throws Exception { this.cache.removeClientListener(this); if (this.version != null) { this.cache.removeWithVersion(lockKey, this.version); } if (future != null) { future.cancel(true); future = null; } }
@Override public void unregisterListener() { ((RemoteCache<?, ?>) eventSource.getNativeCache()).removeClientListener(this); }
@Override public void stop(InfinispanConsumer consumer) { InfinispanUtil.asRemote(consumer.getCache()).removeClientListener(consumer.getListener()); }
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()); }
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); } }
expectElementsInQueue(listener.modifyEvents, 2); remoteCache.removeClientListener(listener);
@Test public void testCustomFilterEvents() { final FilterCustomEventLogListener eventListener = new FilterCustomEventLogListener(); remoteCache.addClientListener(eventListener, new Object[]{3}, null); try { eventListener.expectNoEvents(); remoteCache.put(1, "one"); eventListener.expectSingleCustomEvent(1, "one"); remoteCache.put(1, "uno"); eventListener.expectSingleCustomEvent(1, "uno"); remoteCache.put(2, "two"); eventListener.expectSingleCustomEvent(2, "two"); remoteCache.put(2, "dos"); eventListener.expectSingleCustomEvent(2, "dos"); remoteCache.put(3, "three"); eventListener.expectSingleCustomEvent(3, null); remoteCache.put(3, "tres"); eventListener.expectSingleCustomEvent(3, null); remoteCache.remove(1); eventListener.expectSingleCustomEvent(1, null); remoteCache.remove(2); eventListener.expectSingleCustomEvent(2, null); remoteCache.remove(3); eventListener.expectSingleCustomEvent(3, null); } finally { remoteCache.removeClientListener(eventListener); } }
@Test public void testEventReceiveConditional() { final EventLogListener eventListener = new EventLogListener(); remoteCache.addClientListener(eventListener); try { expectNoEvents(eventListener); // Put if absent remoteCache.putIfAbsent(1, "one"); expectOnlyCreatedEvent(1, eventListener); remoteCache.putIfAbsent(1, "again"); expectNoEvents(eventListener); // Replace remoteCache.replace(1, "newone"); expectOnlyModifiedEvent(1, eventListener); // Replace with version remoteCache.replaceWithVersion(1, "one", 0); expectNoEvents(eventListener); VersionedValue<String> versioned = remoteCache.getVersioned(1); remoteCache.replaceWithVersion(1, "one", versioned.getVersion()); expectOnlyModifiedEvent(1, eventListener); // Remove with version remoteCache.removeWithVersion(1, 0); expectNoEvents(eventListener); versioned = remoteCache.getVersioned(1); remoteCache.removeWithVersion(1, versioned.getVersion()); expectOnlyRemovedEvent(1, 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); } }
eventListener.expectOnlyRemovedEvent(3); } finally { remote.removeClientListener(eventListener);
@Test public void testCustomFilterEventsCustomPojo() { final CustomPojoFilterCustomEventLogListener eventListener = new CustomPojoFilterCustomEventLogListener(); remoteCache.addClientListener(eventListener, new Object[]{new Id(3)}, null); try { eventListener.expectNoEvents(); remoteCache.put(new Id(1), new Person("one")); eventListener.expectSingleCustomEvent(new Id(1), new Person("one")); remoteCache.put(new Id(1), new Person("uno")); eventListener.expectSingleCustomEvent(new Id(1), new Person("uno")); remoteCache.put(new Id(2), new Person("two")); eventListener.expectSingleCustomEvent(new Id(2), new Person("two")); remoteCache.put(new Id(2), new Person("dos")); eventListener.expectSingleCustomEvent(new Id(2), new Person("dos")); remoteCache.put(new Id(3), new Person("three")); eventListener.expectSingleCustomEvent(new Id(3), null); remoteCache.put(new Id(3), new Person("tres")); eventListener.expectSingleCustomEvent(new Id(3), null); remoteCache.remove(new Id(1)); eventListener.expectSingleCustomEvent(new Id(1), null); remoteCache.remove(new Id(2)); eventListener.expectSingleCustomEvent(new Id(2), null); remoteCache.remove(new Id(3)); eventListener.expectSingleCustomEvent(new Id(3), null); } finally { remoteCache.removeClientListener(eventListener); } }