-
1. Re: Programatic creation of cache inside AS7
pferraro Jul 2, 2012 1:46 PM (in response to will.tatam)1 of 1 people found this helpfule.g.
{code}@Resource(lookup="java:jboss/infinispan/container/mycontainer")
private final EmbeddedCacheManager manager;
private Cache cache;
private final String cacheName = "...";
@PostConstruct
public void init() {
ConfigurationBuilder builder = new ConfigurationBuilder();
// configure builder ...
this.manager.defineConfiguration(this.cacheName, builder.install());
this.cache = this.manager.getCache(this.cacheName);
}{code}
-
2. Re: Programatic creation of cache inside AS7
will.tatam Jul 4, 2012 5:46 AM (in response to pferraro)What is java:jboss/
infinispan/container/mycontainer ? Is that an example or is "mycontainer" the name of the CacheManager in AS7 ?
-
3. Re: Programatic creation of cache inside AS7
pferraro Jul 5, 2012 11:35 AM (in response to will.tatam)1 of 1 people found this helpful"mycontainer" is just an example. All cache containers can be summoned via jndi, using the value specified by the <cache-container jndi-name="..."/> attribute; or, if undefined, via the default name: java:jboss/infinispan/container/[container-name]
-
4. Re: Programatic creation of cache inside AS7
will.tatam Jul 5, 2012 12:07 PM (in response to pferraro)So we just create our own cache inside one of the exisitng containers? Where can I find out more about cache-containers ?
-
5. Re: Programatic creation of cache inside AS7
pferraro Jul 5, 2012 12:26 PM (in response to will.tatam)Yes - although you aren't limited to one of the default cache-containers; feel free to add your own within the infinispan subsystem configuration (see standalone[-ha].xml or domain.xml). The AS creates an EmbeddedCacheManager (on demand) for every <cache-container/> listed in the infinispan subsystem configuration.
-
6. Re: Programatic creation of cache inside AS7
will.tatam Jul 5, 2012 12:50 PM (in response to pferraro)javax.annotation.Resource does not contain lookup
-
8. Re: Programatic creation of cache inside AS7
will.tatam Jul 11, 2012 7:33 AM (in response to pferraro)Thanks, sounds like I must have an EE5 version of Resource leaking into my classpath from somewhere, despite using the recommended BOMs
-
9. Re: Programatic creation of cache inside AS7
will.tatam Jul 13, 2012 5:49 AM (in response to will.tatam)I tried to work around the issue with @Resource by doing an old fashioned JNDI lookup, but it says "service service jboss.naming.context.java.jboss.infinispan.container.cluster is not started"
-
10. Re: Programatic creation of cache inside AS7
will.tatam Jul 13, 2012 7:53 AM (in response to will.tatam)Found the issue with @Resource(lookup=""), see http://java-abwaschbar.blogspot.co.uk/2011/01/resource-annotation-and-lookup.html
-
11. Re: Programatic creation of cache inside AS7
will.tatam Jul 13, 2012 8:00 AM (in response to pferraro)Caused by: java.lang.IllegalArgumentException: Can not set org.infinispan.manager.EmbeddedCacheManager field mypackagename.myclassname.cacheManager to org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager
I tried changing to the following, but still see the same error weirdly
@Resource(lookup="java:jboss/infinispan/container/cluster")
DefaultEmbeddedCacheManager cacheManager;
-
12. Re: Programatic creation of cache inside AS7
pferraro Jul 18, 2012 11:37 AM (in response to will.tatam)Smells like a classloader issue. Are you, by any chance, packaging the infinispan jar with your application? If so, you should remove it. The infinispan classes should be loaded from the org.infinispan module bundled with AS7. Your application should define an explicit dependency on this non-public module via an entry in your MANIFEST.MF:
Dependencies: org.infinispan
For more about classloading in AS7:
https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7