Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-1338

Using cache on a Singleton bean

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Cannot Reproduce
    • Icon: Optional Optional
    • None
    • 5.0.0.CR8, 5.0.0.FINAL, 5.1.0.FINAL
    • CDI
    • None

      I'm trying to get the CDI examples to work on an app. so I've created this config:

      @Produces
      @ApplicationScoped
      @OverrideDefault
      public EmbeddedCacheManager getCacheManager()

      { GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault(); gc.fluent().transport().clusterName("shared-cache-cluster").addProperty("configurationFile", "jgroups-tcp.xml"); Configuration c = new Configuration().fluent().clustering().mode(CacheMode.REPL_ASYNC).build(); return new DefaultCacheManager(gc,c); }

      BTW, trying to use configuration and @Infinispan with this I get an error when CacheManager tries to get the cache, I've discussed it at http://community.jboss.org/thread/171005?tstart=0

      Well, my scenario has 2 apps one on each node. So in one node I put a value in the distributed cache, and I expect to receive an event on the other node.

      My problem is that the events for a cache are only hooked when the cache is first accessed (According to CacheManager:getAdvancedCache).

      So, in my second ear, if there's no "warm-up" of the cache, the events do not get hooked and I don't get any notification.

      So I tried to use a Singleton:

      @Singleton
      @Startup
      public class CacheWarmupBean(){

      @Inject Cache<String,String> cache;

      @PostConstruct
      void warm(){
      cache.getCacheName();
      }
      }

      Problem is that the bean gets started before the extension, and no target is found for the cache.

      I wonder, is it possible to either warmup the cache on a different way or hook the events?

            kevinpollet Kévin Pollet (Inactive)
            viniciuscarvalho_jira Vinicius Carvalho (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: