Apache Ignite cannot access cache from listener after event “EVT_CACHE_STARTED” fired









up vote
0
down vote

favorite












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:



import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.events.CacheEvent;
import org.apache.ignite.events.EventType;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@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.










share|improve this question

























    up vote
    0
    down vote

    favorite












    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:



    import org.apache.ignite.Ignite;
    import org.apache.ignite.IgniteCache;
    import org.apache.ignite.Ignition;
    import org.apache.ignite.configuration.IgniteConfiguration;
    import org.apache.ignite.events.CacheEvent;
    import org.apache.ignite.events.EventType;
    import org.apache.ignite.lang.IgnitePredicate;
    import org.apache.ignite.resources.IgniteInstanceResource;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.env.Environment;

    @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.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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:



      import org.apache.ignite.Ignite;
      import org.apache.ignite.IgniteCache;
      import org.apache.ignite.Ignition;
      import org.apache.ignite.configuration.IgniteConfiguration;
      import org.apache.ignite.events.CacheEvent;
      import org.apache.ignite.events.EventType;
      import org.apache.ignite.lang.IgnitePredicate;
      import org.apache.ignite.resources.IgniteInstanceResource;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.core.env.Environment;

      @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.










      share|improve this question













      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:



      import org.apache.ignite.Ignite;
      import org.apache.ignite.IgniteCache;
      import org.apache.ignite.Ignition;
      import org.apache.ignite.configuration.IgniteConfiguration;
      import org.apache.ignite.events.CacheEvent;
      import org.apache.ignite.events.EventType;
      import org.apache.ignite.lang.IgnitePredicate;
      import org.apache.ignite.resources.IgniteInstanceResource;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.core.env.Environment;

      @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.







      apache ignite






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 20:45









      Vadym

      1




      1






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          As a rule you should not perform cache operations, or most of other operations that block or access Ignite internals. Events should be very fast and lightweight, meaning that they are executed from inside Ignite threads and Ignite internal locks.



          Just schedule an operation in a different thread on event arrival.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233030%2fapache-ignite-cannot-access-cache-from-listener-after-event-evt-cache-started%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            As a rule you should not perform cache operations, or most of other operations that block or access Ignite internals. Events should be very fast and lightweight, meaning that they are executed from inside Ignite threads and Ignite internal locks.



            Just schedule an operation in a different thread on event arrival.






            share|improve this answer
























              up vote
              0
              down vote













              As a rule you should not perform cache operations, or most of other operations that block or access Ignite internals. Events should be very fast and lightweight, meaning that they are executed from inside Ignite threads and Ignite internal locks.



              Just schedule an operation in a different thread on event arrival.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                As a rule you should not perform cache operations, or most of other operations that block or access Ignite internals. Events should be very fast and lightweight, meaning that they are executed from inside Ignite threads and Ignite internal locks.



                Just schedule an operation in a different thread on event arrival.






                share|improve this answer












                As a rule you should not perform cache operations, or most of other operations that block or access Ignite internals. Events should be very fast and lightweight, meaning that they are executed from inside Ignite threads and Ignite internal locks.



                Just schedule an operation in a different thread on event arrival.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 9:54









                alamar

                10.5k24771




                10.5k24771



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233030%2fapache-ignite-cannot-access-cache-from-listener-after-event-evt-cache-started%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo