@Retention(value=RUNTIME) @Target(value=TYPE) public @interface IgniteAsyncCallback
Currently this annotation is supported for:
ContinuousQuery - CacheEntryUpdatedListener and CacheEntryEventFilter.
For example, if filter or CacheEntryListener
has the annotation then callbacks will be executing to asyncCallback thread pool. It allows to use cache API
in a callbacks. This thread pool can be configured by IgniteConfiguration.setAsyncCallbackPoolSize(int).
'Person' objects and we need
to query all persons with salary above then 1000. Also remote filter will update some entries.
Here is the Person class:
public class Person {
// Name.
private String name;
// Salary.
private double salary;
...
}
Here is the ExampleCacheEntryFilter class:
@IgniteAsyncCallback
public class ExampleCacheEntryFilter implements CacheEntryEventFilter<Integer, Person> {
@IgniteInstanceResource
private Ignite ignite;
// Continuous listener will be notified for persons with salary above 1000.
// Filter increases salary for some person on 100. Without @IgniteAsyncCallback annotation
// this operation is not safe.
public boolean evaluate(CacheEntryEvent<? extends K, ? extends V> evt) throws CacheEntryListenerException {
Person p = evt.getValue();
if (p.getSalary() > 1000)
return true;
ignite.cache("Person").put(evt.getKey(), new Person(p.getName(), p.getSalary() + 100));
return false;
}
}
Query with asynchronous callback execute as usually:
// Create new continuous query.
ContinuousQuery<Long, Person> qry = new ContinuousQuery<>();
// Callback that is called locally when update notifications are received.
// It simply prints out information about all created persons.
qry.setLocalListener((evts) -> {
for (CacheEntryEvent<? extends Long, ? extends Person> e : evts) {
Person p = e.getValue();
System.out.println(p.getFirstName() + " " + p.getLastName() + "'s salary is " + p.getSalary());
}
});
// Sets remote filter.
qry.setRemoteFilterFactory(() -> new ExampleCacheEntryFilter());
// Execute query.
QueryCursor<Cache.Entry<Long, Person>> cur = cache.query(qry);
GridGain In-Memory Computing Platform : ver. 8.9.26 Release Date : October 16 2025