@Test @Ignore public void addRemoveItemListener() throws InterruptedException { HazelcastClient hClient = getHazelcastClient(); final IList<String> list = hClient.getList("addRemoveItemListenerList"); final CountDownLatch addLatch = new CountDownLatch(4); final CountDownLatch removeLatch = new CountDownLatch(4); ItemListener<String> listener = new CountDownItemListener<String>(addLatch, removeLatch); list.addItemListener(listener, true); list.add("hello"); list.add("hello"); list.remove("hello"); list.remove("hello"); list.removeItemListener(listener); list.add("hello"); list.add("hello"); list.remove("hello"); list.remove("hello"); Thread.sleep(10); assertEquals(2, addLatch.getCount()); assertEquals(2, removeLatch.getCount()); }
public void notifyListeners(Packet packet) { List<ItemListenerHolder> list = queueItemListeners.get(packet.getName()); if (list != null) { for (ItemListenerHolder listenerHolder : list) { ItemListener<Object> listener = listenerHolder.listener; Boolean added = (Boolean) toObject(packet.getValue()); if (added) { listener.itemAdded(new DataAwareItemEvent(packet.getName(), ItemEventType.ADDED, listenerHolder.includeValue ? new Data(packet.getKey()) : null, null)); } else { listener.itemRemoved(new DataAwareItemEvent(packet.getName(), ItemEventType.REMOVED, listenerHolder.includeValue ? new Data(packet.getKey()) : null, null)); } } } }
@Override @SuppressWarnings("unchecked") protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { when(hazelcastInstance.<String>getList("foo")).thenReturn(list); argument = ArgumentCaptor.forClass(ItemListener.class); when(list.addItemListener(argument.capture(), eq(true))).thenReturn("foo"); }
@Override @SuppressWarnings("unchecked") protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { when(hazelcastInstance.<String>getSet("foo")).thenReturn(set); argument = ArgumentCaptor.forClass(ItemListener.class); when(set.addItemListener(argument.capture(), eq(true))).thenReturn("foo"); }
@Override @SuppressWarnings("unchecked") protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { when(hazelcastInstance.<String>getQueue("foo")).thenReturn(queue); argument = ArgumentCaptor.forClass(ItemListener.class); when(queue.addItemListener(argument.capture(), eq(true))).thenReturn("foo"); }
public void addItemListener(ItemListener<E> listener, boolean includeValue) { check(listener); synchronized (lock) { boolean shouldCall = listenerManager().noListenerRegistered(name); listenerManager().registerListener(name, listener); if (shouldCall) { Call c = listenerManager().createNewAddItemListenerCall(proxyHelper); proxyHelper.doCall(c); } } }
public void removeItemListener(ItemListener<E> listener) { check(listener); synchronized (lock) { listenerManager().removeListener(name, listener); Packet request = proxyHelper.createRequestPacket(ClusterOperation.REMOVE_LISTENER, null, null); Call c = proxyHelper.createCall(request); proxyHelper.doCall(c); } }
public void notifyListeners(Packet packet) { List<ItemListener> list = queueItemListeners.get(packet.getName()); if (list != null) { for (ItemListener<Object> listener : list) { Boolean added = (Boolean) toObject(packet.getValue()); if (added) { listener.itemAdded(new DataAwareItemEvent(packet.getName(), ItemEventType.ADDED, new Data(packet.getKey()))); } else { listener.itemRemoved(new DataAwareItemEvent(packet.getName(), ItemEventType.ADDED, new Data(packet.getKey()))); } } } }
public <E> void removeListener(String name, ItemListener<E> listener) { if (!queueItemListeners.containsKey(name)) { return; } queueItemListeners.get(name).remove(listener); if (queueItemListeners.get(name).isEmpty()) { queueItemListeners.remove(name); } }
public <E> void registerListener(String name, ItemListener<E> listener) { List<ItemListener> newListenersList = new CopyOnWriteArrayList<ItemListener>(); List<ItemListener> listeners = queueItemListeners.putIfAbsent(name, newListenersList); if (listeners == null) { listeners = newListenersList; } listeners.add(listener); }
public synchronized void removeItemListener(ItemListener<E> listener) { check(listener); itemListenerManager().removeListener(name, listener); Packet request = proxyHelper.createRequestPacket(ClusterOperation.REMOVE_LISTENER, null, null); Call c = proxyHelper.createCall(request); proxyHelper.doCall(c); }
@Test public void addRemoveItemListener() throws InterruptedException { HazelcastClient hClient = getHazelcastClient(); final ISet<String> set = hClient.getSet("addRemoveItemListenerSet"); final CountDownLatch addLatch = new CountDownLatch(2); final CountDownLatch removeLatch = new CountDownLatch(2); ItemListener<String> listener = new CountDownItemListener<String>(addLatch, removeLatch); set.addItemListener(listener, true); set.add("hello"); set.add("hello"); set.remove("hello"); set.remove("hello"); for (int i = 0; i < 100; i++) { if (removeLatch.getCount() != 1 || addLatch.getCount() != 1) { Thread.sleep(50); } else { break; } } assertEquals(1, removeLatch.getCount()); assertEquals(1, addLatch.getCount()); set.removeItemListener(listener); set.add("hello"); set.add("hello"); set.remove("hello"); set.remove("hello"); Thread.sleep(50); assertEquals(1, addLatch.getCount()); assertEquals(1, removeLatch.getCount()); }
public void addItemListener(ItemListener<E> listener, boolean includeValue) { check(listener); synchronized (lock) { boolean shouldCall = listenerManager().noListenerRegistered(name); listenerManager().registerListener(name, listener, includeValue); if (shouldCall) { Call c = listenerManager().createNewAddItemListenerCall(proxyHelper, includeValue); proxyHelper.doCall(c); } } }
public <E> void registerListener(String name, ItemListener<E> listener, boolean includeValue) { List<ItemListenerHolder> newListenersList = new CopyOnWriteArrayList<ItemListenerHolder>(); List<ItemListenerHolder> listeners = queueItemListeners.putIfAbsent(name, newListenersList); if (listeners == null) { listeners = newListenersList; } listeners.add(new ItemListenerHolder(listener, includeValue)); }
@Override @SuppressWarnings("unchecked") protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { verify(hazelcastInstance).getList("foo"); verify(list).addItemListener(any(ItemListener.class), eq(true)); }
@Override @SuppressWarnings("unchecked") protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { verify(hazelcastInstance).getSet("foo"); verify(set).addItemListener(any(ItemListener.class), eq(true)); }
@Override @SuppressWarnings("unchecked") protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { verify(hazelcastInstance).getQueue("foo"); verify(queue).addItemListener(any(ItemListener.class), eq(true)); }
@Override public String addItemListener(ItemListener<E> itemListener, boolean b) { return list.addItemListener(itemListener, b); }
public HazelcastBuilder withListener(ItemListener listener) { this.listener = listener; return this; }
public ItemListenerConfig(ItemListener implementation, boolean includeValue) { super(implementation); this.includeValue = includeValue; }
public ItemListener getImplementation() { return (ItemListener) implementation; }
public ItemListenerConfig setImplementation(final ItemListener implementation) { super.setImplementation(implementation); return this; }
public void addItemListener(ItemListener itemListener, boolean includeValue) { factory.node.blockingQueueManager.addItemListener(name, itemListener, includeValue); }
public void removeItemListener(ItemListener itemListener) { factory.node.blockingQueueManager.removeItemListener(name, itemListener); }
public void addItemListener(ItemListener itemListener, boolean includeValue) { ensure(); base.addItemListener(itemListener, includeValue); }
public void removeItemListener(ItemListener itemListener) { ensure(); base.removeItemListener(itemListener); }
public void addItemListener(ItemListener listener, boolean includeValue) { mapProxy.addGenericListener(listener, null, includeValue, getInstanceType()); }
public void removeItemListener(ItemListener listener) { mapProxy.removeGenericListener(listener, null); }
public void addItemListener(ItemListener listener, boolean includeValue) { ensure(); qproxyReal.addItemListener(listener, includeValue); }
public void removeItemListener(ItemListener listener) { ensure(); qproxyReal.removeItemListener(listener); }
public void addItemListener(ItemListener listener, boolean includeValue) { blockingQueueManager.addItemListener(name, listener, includeValue); }
public void removeItemListener(ItemListener listener) { blockingQueueManager.removeItemListener(name, listener); }
public synchronized void addItemListener(ItemListener<E> listener, boolean includeValue) { check(listener); Call c = itemListenerManager().createNewAddListenerCall(proxyHelper, includeValue); itemListenerManager().registerListener(name, listener); proxyHelper.doCall(c); }