T
- as payload typepublic class ListenItemOnHazelCast<T> extends Object implements com.hazelcast.core.ItemListener<T>
IList
type structure
ListenItemOnHazelCast<TestObj> listener = new ListenItemOnHazelCast(hazelcastInstance, "tracking-data"); //Send listen on different instances (NON CLUSTERED)
final Count count = new Count();
listener.setConsumer(new Consumer<TestObj>() {
public void accept(TestObj t) {
log.info("[LISTENER] " + listener.getContainerName() + " > " + t);
count.pass++;
Assert.assertEquals("xy"+t.i, t.s); //Simply check pattern matches x<vlaue of i>
count.pass++;
}
});
listener.init(); //bind listener to HZ
SendOnHazelCast<TestObj> send = new SendOnHazelCast(hazelcastInstance, "tracking-data");
send.accept(new TestObj("x1", 1)); //Pattern of data x<vlaue of i>
send.accept(new TestObj("x2", 2));
send.accept(new TestObj("x3", 3));
SetupHazelCastInstance
Constructor and Description |
---|
ListenItemOnHazelCast() |
ListenItemOnHazelCast(com.hazelcast.core.HazelcastInstance vmInstance,
String containerName) |
ListenItemOnHazelCast(Supplier<com.hazelcast.core.HazelcastInstance> vmInstance,
String containerName) |
Modifier and Type | Method and Description |
---|---|
Consumer<T> |
getConsumer()
Consumer of the object that came from the event
|
String |
getContainerName()
Name of the Distributed List or Map
|
protected com.hazelcast.core.ICollection<T> |
getHazelCastCollection() |
Supplier<com.hazelcast.core.HazelcastInstance> |
getVmInstance()
Context
Supplier of HazelcastInstance .This allows us to pass a instance via context in a more dynamic multi instance environment or one configured directly into this instance. |
void |
init()
Bind this Listener to its Hazelcast
vmInstance |
void |
itemAdded(com.hazelcast.core.ItemEvent<T> item) |
void |
itemRemoved(com.hazelcast.core.ItemEvent<T> item) |
void |
reInit(com.hazelcast.core.HazelcastInstance vmInstance) |
void |
setConsumer(Consumer<T> consumer)
Consumer of the object that came from the event
|
void |
setContainerName(String containerName)
Name of the Distributed List or Map
|
void |
setVmInstance(Supplier<com.hazelcast.core.HazelcastInstance> vmInstance)
Context
Supplier of HazelcastInstance .This allows us to pass a instance via context in a more dynamic multi instance environment or one configured directly into this instance. |
public ListenItemOnHazelCast()
public ListenItemOnHazelCast(Supplier<com.hazelcast.core.HazelcastInstance> vmInstance, String containerName)
public ListenItemOnHazelCast(com.hazelcast.core.HazelcastInstance vmInstance, String containerName)
public void reInit(com.hazelcast.core.HazelcastInstance vmInstance)
@PostConstruct public void init()
vmInstance
public void itemAdded(com.hazelcast.core.ItemEvent<T> item)
itemAdded
in interface com.hazelcast.core.ItemListener<T>
public void itemRemoved(com.hazelcast.core.ItemEvent<T> item)
itemRemoved
in interface com.hazelcast.core.ItemListener<T>
protected com.hazelcast.core.ICollection<T> getHazelCastCollection()
public String getContainerName()
HazelcastInstance.getMap(String)
,
if Map or List will be used.
public void setContainerName(String containerName)
HazelcastInstance.getMap(String)
,
if Map or List will be used.
public void setConsumer(Consumer<T> consumer)
public Supplier<com.hazelcast.core.HazelcastInstance> getVmInstance()
Supplier
of HazelcastInstance
.Copyright © 2018. All rights reserved.