Ok bu the event just tells me if the key was read correct? I need to keep a
count of how many times each key was read globally.

The other way I was thinking of doing it is by having a cache as
Cache<String, MyTuple> and then use cache.invoke(...., new
CounterEntryProcessor())

And then in the EntryProcessor...

MyTuple is just a a value class that holds 2 values, one being the counter.

class CounterEntryProcessor implements EntryProcessor<String, MyTuple,
Integer> {
    @Override public Integer process(MutableEntry<String, MyTuple> e,
Object... args) {


      MyTuple newVal = e.getValue();
      newVal.counter++

      // Update cache.
      e.setValue(newVal);

      return newVal.counter;
    }
  }

And then check if cache.invoke(...., new CounterEntryProcessor()) >= 3
remove the entry from cache.


On Tue, 21 Apr 2020 at 16:28, akorensh <alexanderko...@gmail.com> wrote:

> Hi,
>
> You can use Events:https://apacheignite.readme.io/docs/events
> In Particular: EVT_CACHE_OBJECT_READ
> see:
>
> https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/events/EventsExample.java
>
>
>
> Here is an example: (modified localListen() fn in the above example)
>  private static void localListen() throws IgniteException,
> InterruptedException {
>         System.out.println(">>> Local event listener example.");
>
>         Ignite ignite = Ignition.ignite();
>
>         IgnitePredicate<CacheEvent> lsnr = evt -> {
>             System.out.println("Received task event [evt=" + evt.name() +
> ",
> keyName=" + evt.key() + ']');
>
>             return true; // Return true to continue listening.
>         };
>
>         ignite.events().localListen(lsnr, EVT_CACHE_OBJECT_READ);
>
>         ignite.getOrCreateCache("test").put("a", "a");
>         ignite.getOrCreateCache("test").put("b", "b");
>
>         for (int i = 0; i < 100 ; i++) {
>             if(i %2 ==0 ) ignite.getOrCreateCache("test").get("a");
>             else ignite.getOrCreateCache("test").get("b");
>             Thread.sleep(1000);
>             System.out.println("sleeping..");
>         }
>
>         // Unsubscribe local task event listener.
>         ignite.events().stopLocalListen(lsnr);
>     }
>
>
> You can also use continuous queries to listen for updates:
> https://apacheignite.readme.io/docs/continuous-queries  for
> updates/inserts
>
>
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Reply via email to