11 Replies Latest reply on Sep 21, 2012 3:45 PM by ferwasy

    Register custom component in ComponentRegistry

    ferwasy

      Is possible to register a custom component (like CacheLoaderManagerImpl), in order to use annotations like @Start and @Stop?

      Using Infinispan 5.1.5

       

      Kind regards.

      Fernando.

        • 1. Re: Register custom component in ComponentRegistry
          mircea.markus

          If you do that after the cache has started, I think you'll need to rewire(ComponentRegistry.rewire()) the component registry in order to get these methods invoked. That's a not very orthodox though, can't you rather use @CacheStart/@CacheStop listeners instead?

          • 2. Re: Register custom component in ComponentRegistry
            ferwasy

            I need to implement a new functionality before the cache has started (prefill the cache from a database before it can receive requests) and wire dependencies using the annotation @Inject. Can i do that using @CacheStart or @CacheStop, or i must implement a new module?

            • 3. Re: Register custom component in ComponentRegistry
              galder.zamarreno

              @Mircea, registering custom components in our component registry is not really something our users should be doing...

               

              @Fernando, I've no idea why you need a custom component, but I'm pretty sure that if you explain the problem you're trying to solve, we might find another way to resolve it

              • 4. Re: Register custom component in ComponentRegistry
                galder.zamarreno

                @Fernando, implementing listeners for those annotations should work. You can even avoid that if the database has been written by persisting data in Infinispan itself. Then, you just need to enable preloading.

                • 5. Re: Register custom component in ComponentRegistry
                  ferwasy

                  Galder: thank you for your responses. Let me tell you what I have to do: I need to implement a distributed cluster based on Infinispan using a shared cache store (a single DB2 relational database instance). Given the fact that the database is shared, the idea is that at each topology change, a new consistent hash will be installed and the cache entries should be rehashed and rebalanced reading all the entries from the database and store in cache only the entries that "belong" (each node is owner) to the node, instead of rebalance entries among the nodes. This should be invoked when the topology changes, and also, could be implemented "on demand".

                  My idea is set the options "preload" and "rehashEnabled" to false and implement a new module which contains a @ViewChanged listener, a manager and other classes that implements this functionality.

                  Which I don't understand is that, if you have a shared cache store and "preload" = true, even if your clustering mode is "distribution", every noad preloads all the entries in the underlying shared cache stored.

                  Ideas are more than welcome.

                  Regards.

                  • 6. Re: Register custom component in ComponentRegistry
                    galder.zamarreno

                    But why do you need that functionality? The rebalancing function already happens if state transfer is enabled. I'm not sure about the need to re-read the entries from the cache store.

                     

                    And btw, preloading only happens when the cache starts, not when a view change happens.

                    • 7. Re: Register custom component in ComponentRegistry
                      ferwasy

                      Galder: 'stateTransfer' documentation says: "If true, this will cause the cache to ask neighboring caches for state when it starts up, so the cache starts 'warm', although it will impact startup time.".

                      'loader.fetchInMemoryState' documentation says: "Therefore, if a shared cache store is used, the cache will not allow a persistent state transfer".

                      What I need is, having a shared cache store (database) and a distributed clustering mode, the rebalancing of keys without asking to neighbours. I mean, something equals to "CacheLoaderManagerImpl.preload()" but having into account with entry belongs to each node. 

                      • 8. Re: Register custom component in ComponentRegistry
                        galder.zamarreno

                        You're explaining what you need but not why

                         

                        IOW, what is that state transfer is not giving you that you're needing to do what you want to do?

                         

                        If the caches have most of the information in memory, and some data might be in cache store due to memory eviction, I think you can easily live with state transfer rebalancing stuff and lazily retrieving what's missing in memory going to the cache store.

                        • 9. Re: Register custom component in ComponentRegistry
                          ferwasy

                          Galder: thank you for your answer. The need of implement this type of "rehashing" comes  from a client (I work for a software company) in order to have an alternative to entries redistribution when all nodes in a cluster share a single database as a cache store, reducing the number of network traffic between nodes (although network traffic to and from database increases).

                          I think that this can be seen as somthing wrong, but i really think that 'preload' configuration option in distribution clustering mode, should preload entries that belong to each node only.

                          Regards.

                          Fernando.

                          • 10. Re: Register custom component in ComponentRegistry
                            galder.zamarreno

                            Feel free to create a JIRA in http://issues.jboss.org/browse/ISPN, and if you want to contribute a patch to get preload() to work this way, even better :

                            https://docs.jboss.org/author/x/ZABG

                             

                            We'd gladly review your pull request

                            • 11. Re: Register custom component in ComponentRegistry
                              ferwasy

                              Galder: thanks for your info. I just created a JIRA [#ISPN-2334] Distributed mode and single shared cache loader - preload and state transfer - JBoss Issue Tracker

                              I've implemented the functionality in a separated Infinispan module. Let me know if it can be interested for you.

                              Kind regards.