You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by vvasyuk <vv...@gmail.com> on 2018/11/10 16:27:24 UTC
Apache Ignite cannot access cache from listener after event “EVT_CACHE_STARTED” fired
I want to be able to monitor events of cache creation in Apache Ignite.
Whenever such events happen - I want to be able to do something with those
caches, after they are created, but before anyone else could inserts
something.
So I used local listener. Below is all the code:
@Configuration
public class ServerConfig {
public ServerConfig(Environment e) throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setIncludeEventTypes(EventType.EVT_CACHE_STARTED);
Ignite ignite = Ignition.start(cfg);
String cacheName = "test";
registerCacheCreationListener(ignite);
IgniteCache<Integer, String> cache =
ignite.getOrCreateCache(cacheName);
}
private void registerCacheCreationListener(Ignite ignite){
IgnitePredicate<CacheEvent> locLsnr = new
IgnitePredicate<CacheEvent>(){
@IgniteInstanceResource
private Ignite ignite;
@Override
public boolean apply(CacheEvent evt) {
System.out.println("Received event [evt=" + evt.name() + "
cacheName=" + evt.cacheName());
IgniteCache<Integer, String > cache =
ignite.cache(evt.cacheName()); // CANNOT ACCESS evt.cacheName() -
STUCKS HERE
System.out.println("finish listener");
return true;
}
};
ignite.events().localListen(locLsnr, EventType.EVT_CACHE_STARTED);
}
}
So when I do:
ignite.cache(evt.cacheName())
inside IgnitePredicate - it is not yet available as I understand.
Please help me find out where can I be wrong. Thanks.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/