1

I'm pretty confused about the infinispan subsystem under Wildfly and am not able to get a pre-configured cache from an existing cache container. To visualize the problem I've created a minimal sample project shared on Github: infinispan-wildfly-test

The test setup creates a cache container (TEST) with two caches (x,y), setting x to be the default. When I now get the EmbeddedCacheManager through resource lookup I get the container I'm expecting:

@Resource(lookup = "java:jboss/infinispan/container/TEST")
private EmbeddedCacheManager cacheManager;

But then, when trying to get a Cache (x or y) I always get a freshly created one whose configuration does not match the one that I have created using the CLI, the cache is totally unconfigured!

The point is I can be sure that the EmbeddedCacheManager is the correct container since it delivers me Cache x as the default one (but unconfigured) but what am I missing here? How can one get the pre-configured caches of a cache container?

All samples that are out there don't address this issue and I'm not sure whether these people are aware of the fact that they get an unconfigured cache instead. Samples always only show the resource lookup of the container an getting the default cache instance. There is no check of configuration ...

So is there anyone out there (maybe a contributor of infinispan) who knows the answer? Thanks and many appreciation in advance ;)

shillner
  • 1,806
  • 15
  • 24

1 Answers1

5

Injected your caches directly.

@Resource(lookup = "java:jboss/infinispan/cache/TEST/x")
private Cache<?, ?> cacheX;
@Resource(lookup = "java:jboss/infinispan/cache/TEST/y")
private Cache<?, ?> cacheY;
Paul Ferraro
  • 326
  • 1
  • 3
  • But is there a way to retrieve the cache programmatically from the injected CM? – Radim Vansa May 23 '16 at 07:30
  • Hi, I have tried this previously and wasn't able to get the caches using programmatic lookup through the context. Injecting the caches is no option since at the point where I need the caches the names are only known at runtime which excludes the static resource lookup approach. – shillner May 23 '16 at 08:41
  • I have tried your approach and it works as expected but it shows a bit of a strange behavior: When I use InitialContext.lookup("java:jboss/infinispan/cache/TEST/x") the name is not found! But when I add the resource injection to my servlet as you said, I can also use the context lookup for this cache. So is there a programmatic approach for the resource lookup concept? – shillner May 24 '16 at 06:55
  • 1
    Sorry for the late response - you would need to establish a resource-ref in your deployment descriptor. This will make sure that the target service is available to a vanilla JNDI lookup. – Paul Ferraro May 24 '17 at 18:32