You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by roar109 <ro...@gmail.com> on 2015/08/21 19:12:00 UTC

Cache Events Questions

Hi all,

I have been working with events for some days and I can't find in the
documentation the following questions:

1) If we can query for registered events or check if some event is
registered?. This in order to not register it again, I notice that if I have
2 nodes and each node register remote listener it registers again - but with
local works fine.
2) Can we register events tied to a specific cache? Now Im adding some logic
inside the predicates to exclude the execution of non-known Put/Remove
actions.

Thanks



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by vkulichenko <va...@gmail.com>.
Yes, that's right. If you want to listen only for newly created entries, your
filter is correct.

Remote filter is always called on the server node. If it returns true, the
event is sent to the client where the listener is called.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1253.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by roar109 <ro...@gmail.com>.
I answer my own question, I added something like:

    public boolean evaluate(
	    CacheEntryEvent<? extends String, ? extends String> event)
	    throws CacheEntryListenerException {
	return event.getEventType().equals(javax.cache.event.EventType.CREATED);
    }

In the query.setRemoteFilter and looks like is working. I notice is
executing the code in the "client" or "caller" and the "filtering" in the
nodes where the cache is distributed.

I'm correct in this assumptions?

Documentation for reference:
https://apacheignite.readme.io/docs/continuous-queries



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1252.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by roar109 <ro...@gmail.com>.
I still not get it how I will query for new inserts into cache.

I tried the Affinity.isPrimary(node, key) and works fine, but I would like
to try the Continuos Query.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1251.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by vkulichenko <va...@gmail.com>.
I still think that continuous queries fit you use case much better. It will
update you once for each update and make all this filtering automatically.
Moreover, after https://issues.apache.org/jira/browse/IGNITE-426 is
finished, it will provide consistent updates even on changing topology (will
notify from backup in case primary node crashes).

With events you can use Affinity.isPrimary(node, key) method to check if
local node is primary for the updated key, but this will work properly only
on stable topology.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1243.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by roar109 <ro...@gmail.com>.
Thanks for the answers Val.

Last question: 
I register/listener for events in some cache + 1 backup  and I have 2 nodes.
If I write it get triggered twice, checking forwards with for some tests I
did is because is wiriting in the Primary and in the other node in the
backup, is there a way to filter or detect that the event is triggered from
a backup write? I only only want to be executed once. 

Thanks



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1242.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by vkulichenko <va...@gmail.com>.
roar109 wrote
> Sure, I have a cluster of clients (2) (same WAR's) that connects to a
> cluster or Ignite nodes (2). I want to be able to register the events to
> the ignite nodes only once and gets executed in all the nodes that detect 
> a change in the cache. with what you mention I dont see a clear path maybe
> use some "flag" for example an AtomicLong or something to hold the status
> of the "registration".

Do you want to get notifications on all clients? If so, each client has to
register its own remote listener. So with 2 clients you will have 2
listeners which are completely independent. I.e., they can have different
filters and callbacks.

roar109 wrote
> Is there a way to pause the events execution? or needs to
> stopLocal/stopRemoteListener only?

You can also return false from the local listener. This will automatically
stop this listener.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1098.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by roar109 <ro...@gmail.com>.
Sure, I have a cluster of clients (2) (same WAR's) that connects to a cluster
or Ignite nodes (2). I want to be able to register the events to the ignite
nodes only once and gets executed in all the nodes that detect  a change in
the cache. with what you mention I dont see a clear path maybe use some
"flag" for example an AtomicLong or something to hold the status of the
"registration".

Is there a way to pause the events execution? or needs to
stopLocal/stopRemoteListener only?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1097.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by vkulichenko <va...@gmail.com>.
roar109 wrote
> 1) I have 2 nodes (a war with Ignite running ingite.start(cfgPath) on war
> startup), also on war start up I register Put/remove event listeners. So
> our CI tool shutdown/start one by one, after this we notice that the
> listeneres were executed several times. I manually shutdown/start nodes to
> see if it register again, and yes it register again if is remote listener,
> so on an event it rises many times, many times as I bounce or register the
> event in remote mode. 

The behavior is correct, because each node registers its own listener that
is supposed to notify this particular node about the events that happened
throughout the topology. I.e., if only one node does that, the second node
will never get any notifications. In case of local event listener you, on
the other hand, listen only for events that happened locally, but not on
remote nodes.

So local and remote listeners are separate pieces of functionality and you
should use the one that fits your use case. Can you describe it in more
details?

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1096.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by roar109 <ro...@gmail.com>.
Thanks for the answerd Val.

1) I have 2 nodes (a war with Ignite running ingite.start(cfgPath) on war
startup), also on war start up I register Put/remove event listeners. So our
CI tool shutdown/start one by one, after this we notice that the listeneres
were executed several times. I manually shutdown/start nodes to see if it
register again, and yes it register again if is remote listener, so on an
event it rises many times, many times as I bounce or register the event in
remote mode. 

Right now because each node has this code I'm just registering "local" to
avoid duplicating this calls. But eventually I have some clients that will
register new events and want to know if this behavior is correct.

2) Thanks let me take a look.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1093.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Cache Events Questions

Posted by vkulichenko <va...@gmail.com>.
Hi,

1. If you register two remote listeners from two different nodes, they are
registered separately, because they have to notify different nodes. So this
behavior is correct and I'm not sure I completely understand your
expectations here. Can you please clarify?
2. You're using this correctly. Events API is generic and is not tied to
cache or any other component, so you should filter CacheEvent by cacheName
yourself. If you're looking into listening for updates in a particular
cache, I would recommend to use continuous queries instead:
https://apacheignite.readme.io/docs/continuous-queries

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-Events-Questions-tp1090p1092.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.