Java 类com.hazelcast.core.ItemListener 实例源码

项目:hazelcast-archive    文件:HazelcastClientListTest.java   
@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());
}
项目:health-and-care-developer-network    文件:QueueItemListenerManager.java   
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));
            }
        }
    }
}
项目:health-and-care-developer-network    文件:HazelcastClientListTest.java   
@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());
}
项目:Camel    文件:HazelcastListConsumerTest.java   
@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");
}
项目:Camel    文件:HazelcastSetConsumerTest.java   
@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");
}
项目:Camel    文件:HazelcastQueueConsumerTest.java   
@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");
}
项目:hazelcast-archive    文件:QueueClientProxy.java   
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);
        }
    }
}
项目:hazelcast-archive    文件:QueueClientProxy.java   
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);
    }
}
项目:hazelcast-archive    文件:QueueItemListenerManager.java   
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())));
            }
        }
    }
}
项目:hazelcast-archive    文件:QueueItemListenerManager.java   
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);
    }
}
项目:hazelcast-archive    文件:QueueItemListenerManager.java   
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);
}
项目:hazelcast-archive    文件:CollectionClientProxy.java   
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);
}
项目:hazelcast-archive    文件:HazelcastClientSetTest.java   
@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());
}
项目:health-and-care-developer-network    文件:QueueClientProxy.java   
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);
        }
    }
}
项目:health-and-care-developer-network    文件:QueueClientProxy.java   
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);
    }
}
项目:health-and-care-developer-network    文件:QueueItemListenerManager.java   
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);
    }
}
项目:health-and-care-developer-network    文件:QueueItemListenerManager.java   
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));
}
项目:health-and-care-developer-network    文件:CollectionClientProxy.java   
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);
}
项目:health-and-care-developer-network    文件:HazelcastClientSetTest.java   
@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());
}
项目:Camel    文件:HazelcastListConsumerTest.java   
@Override
@SuppressWarnings("unchecked")
protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) {
    verify(hazelcastInstance).getList("foo");
    verify(list).addItemListener(any(ItemListener.class), eq(true));
}
项目:Camel    文件:HazelcastSetConsumerTest.java   
@Override
@SuppressWarnings("unchecked")
protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) {
    verify(hazelcastInstance).getSet("foo");
    verify(set).addItemListener(any(ItemListener.class), eq(true));
}
项目:Camel    文件:HazelcastQueueConsumerTest.java   
@Override
@SuppressWarnings("unchecked")
protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) {
    verify(hazelcastInstance).getQueue("foo");
    verify(queue).addItemListener(any(ItemListener.class), eq(true));
}
项目:hazelcast-jet    文件:ListDecorator.java   
@Override
public String addItemListener(ItemListener<E> itemListener, boolean b) {
    return list.addItemListener(itemListener, b);
}
项目:microservices-sample    文件:HazelcastBuilder.java   
public HazelcastBuilder withListener(ItemListener listener) {
    this.listener = listener;
    return this;
}
项目:hazelcast-archive    文件:ItemListenerConfig.java   
public ItemListenerConfig(ItemListener implementation, boolean includeValue) {
    super(implementation);
    this.includeValue = includeValue;
}
项目:hazelcast-archive    文件:ItemListenerConfig.java   
public ItemListener getImplementation() {
    return (ItemListener) implementation;
}
项目:hazelcast-archive    文件:ItemListenerConfig.java   
public ItemListenerConfig setImplementation(final ItemListener implementation) {
    super.setImplementation(implementation);
    return this;
}
项目:hazelcast-archive    文件:ListProxyImpl.java   
public void addItemListener(ItemListener itemListener, boolean includeValue) {
    factory.node.blockingQueueManager.addItemListener(name, itemListener, includeValue);
}
项目:hazelcast-archive    文件:ListProxyImpl.java   
public void removeItemListener(ItemListener itemListener) {
    factory.node.blockingQueueManager.removeItemListener(name, itemListener);
}
项目:hazelcast-archive    文件:SetProxyImpl.java   
public void addItemListener(ItemListener itemListener, boolean includeValue) {
    ensure();
    base.addItemListener(itemListener, includeValue);
}
项目:hazelcast-archive    文件:SetProxyImpl.java   
public void removeItemListener(ItemListener itemListener) {
    ensure();
    base.removeItemListener(itemListener);
}
项目:hazelcast-archive    文件:SetProxyImpl.java   
public void addItemListener(ItemListener listener, boolean includeValue) {
    mapProxy.addGenericListener(listener, null, includeValue,
            getInstanceType());
}
项目:hazelcast-archive    文件:SetProxyImpl.java   
public void removeItemListener(ItemListener listener) {
    mapProxy.removeGenericListener(listener, null);
}
项目:hazelcast-archive    文件:QProxyImpl.java   
public void addItemListener(ItemListener listener, boolean includeValue) {
    ensure();
    qproxyReal.addItemListener(listener, includeValue);
}
项目:hazelcast-archive    文件:QProxyImpl.java   
public void removeItemListener(ItemListener listener) {
    ensure();
    qproxyReal.removeItemListener(listener);
}
项目:hazelcast-archive    文件:QProxyImpl.java   
public void addItemListener(ItemListener listener, boolean includeValue) {
    blockingQueueManager.addItemListener(name, listener, includeValue);
}
项目:hazelcast-archive    文件:QProxyImpl.java   
public void removeItemListener(ItemListener listener) {
    blockingQueueManager.removeItemListener(name, listener);
}
项目:hazelcast-archive    文件:CollectionClientProxy.java   
public synchronized void addItemListener(ItemListener<E> listener, boolean includeValue) {
    check(listener);
    Call c = itemListenerManager().createNewAddListenerCall(proxyHelper, includeValue);
    itemListenerManager().registerListener(name, listener);
    proxyHelper.doCall(c);
}
项目:health-and-care-developer-network    文件:ItemListenerConfig.java   
public ItemListenerConfig(ItemListener implementation, boolean includeValue) {
    super(implementation);
    this.includeValue = includeValue;
}
项目:health-and-care-developer-network    文件:ItemListenerConfig.java   
public ItemListener getImplementation() {
    return (ItemListener) implementation;
}