trytrysin
trytrysin

Reputation: 11

How to identify the path of the infinispan configuration xml file

I am a newbie to infinispan and would like to seek help about issue below.

I tried to start a infinispan cache on an ejb, such that it should be shared among several applications.

@Singleton  
public class CSysAppCacheServiceImpl implements CSysAppCacheService {  

private DefaultCacheManager cacheManager;  

private Cache testingCache;  

@EJB(name = "postService")  
private CSysPostDao postService;  

@EJB(name = "roleService")  
private CSysRoleDao roleService;  


protected Map<String, List<CSysRole>> sysRoleMap;  
protected Map<String, List<CSysPost>> sysPostMap;  
protected List<CSysRole> sysRoleList;  
protected List<CSysPost> sysPostList;  


@PostConstruct  
public void init() {  
        // perform some initialization logic  
        try {  
            System.out.println("init CacheManager start");  
            cacheManager = new DefaultCacheManager("/demo-infinispan.xml");  
            System.out.println("init CacheManager end");  
        } catch (IOException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  



        testingCache = cacheManager.getCache("testingCache");  
        preloadCache();  

}  


// Pre-load cache when server startup  
public void preloadCache() {  
    for (CacheKey ck : CacheKey.values()) {  
        resetCache(ck);  
    }  
}  




public void resetCache(CacheKey key) {  
    if (key == null) {  
        for (CacheKey ck : CacheKey.values()) {  
            resetCache(ck);  
        }  
    } else if (key.equals(CacheKey.SYS_ROLE_LIST)) {  
        this.sysRoleList = roleService.findAllRole();  
        setupCacheList(CacheKey.SYS_ROLE_LIST, sysRoleList);  
    } else if (key.equals(CacheKey.SYS_POST_LIST)) {  
        this.sysPostList = postService.findAllPost();  
        setupCacheList(CacheKey.SYS_POST_LIST, sysPostList);  
    }  
}  


protected <T> void setupCacheList(CacheKey key, List<T> list) {  
    testingCache.put(key, list);  
}  

public List<Object> getCacheList(CacheKey key) {  
    return (List<Object>) testingCache.get(key);  
}  

public List<Object> getCacheList(String keyString) {  
    return (List<Object>) testingCache.get(keyString);  
}  


@SuppressWarnings("unchecked")  
public <K, V> Map<K, V> getCacheMap(CacheKey key) {  
    return (Map<K, V>) testingCache.get(key);  
}  


public Map<String, List<CSysRole>> getCSysRoleMap() {  
    sysRoleMap = getCacheMap(CacheKey.SYS_ROLE_LIST);  
    if (MapUtils.isEmpty(sysRoleMap)) {  
        resetCache(CacheKey.SYS_ROLE_LIST);  
    }  
    return sysRoleMap;  
}  


public Map<String, List<CSysPost>> getCSysPostMap() {  
    sysRoleMap = getCacheMap(CacheKey.SYS_POST_LIST);  
    if (MapUtils.isEmpty(sysPostMap)) {  
        resetCache(CacheKey.SYS_POST_LIST);  
    }  
    return sysPostMap;  
}  
}  

The ejb is init via following class

@ViewScoped  
@Named  
public class CacheView implements Serializable {  


private static final long serialVersionUID = 1L;  


private static final Logger logger = LogManager.getLogger(CacheView.class);  


public static final String FNCT_ID = "SAMPLCACH";  


private List<String> cacheKeyList;  

// private Map<K, V> selectedMap;  
private CacheKey selectedKey;  
private List<Object> selectedList;  


@EJB CSysAppCacheService appScopeCache;  

@PostConstruct  
public void init() {  
        appScopeCache.init();  

}  

...  

}}}}

But when the application start, following exception raised

Caused by: java.lang.NoClassDefFoundError: org/jboss/marshalling/ClassResolver  
at org.infinispan.configuration.global.SerializationConfiguration.<clinit>(SerializationConfiguration.java:16)  
at org.infinispan.configuration.global.SerializationConfigurationBuilder.<init>(SerializationConfigurationBuilder.java:27)  
at org.infinispan.configuration.global.GlobalConfigurationBuilder.<init>(GlobalConfigurationBuilder.java:43)  
at org.infinispan.configuration.parsing.ConfigurationBuilderHolder.<init>(ConfigurationBuilderHolder.java:25)  
at org.infinispan.configuration.parsing.ParserRegistry.parse(ParserRegistry.java:122)  
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:311)  
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:286)  
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:274)  
at CSysAppCacheServiceImpl.init(CSysAppCacheServiceImpl.java:58)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:122)  
at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:111)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)  
at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:72)  
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:89)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:112)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:112)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:105)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)  
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)  
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:237)  
... 150 more  

The problem should be at line

cacheManager = new DefaultCacheManager("/demo-infinispan.xml");

the xml is just a simple standlone cache as below

<?xml version="1.0" encoding="UTF-8"?>  
<infinispan  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="urn:infinispan:config:9.0 http://www.infinispan.org/schemas/infinispan-config-9.0.xsd"  
      xmlns="urn:infinispan:config:9.0">  

      <cache-container name="testing" default-cache="default">  
          <local-cache name="default">  
          <eviction max-entries="5000" strategy="LIRS" />  
    </local-cache>  
      </cache-container>  
</infinispan>  

I tried to put the demo-infinispan.xml in either of the following path, but still exception raised

1) same folder of the java bean

2) src folder of the package

3) same folder of the view bean

Would anyone advise where the xml should I put?

Thanks.

Best Regards,

Upvotes: 0

Views: 392

Answers (1)

trytrysin
trytrysin

Reputation: 11

The issue is solved due to missing libraries

Upvotes: 1

Related Questions