10000 LinkageError -> Cannot resolve cache2k core implementation · Issue #198 · cache2k/cache2k · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

LinkageError -> Cannot resolve cache2k core implementation #198

New issue
8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
puppetmaster- opened this issue Dec 15, 2022 · 2 comments
Open

LinkageError -> Cannot resolve cache2k core implementation #198

puppetmaster- opened this issue Dec 15, 2022 · 2 comments

Comments

@puppetmaster-
Copy link

Error

I am trying to use the cache for the first time. But unfortunately I get the following message on the server

15:13:11,642 ERROR [ch.coop.workflow.component.hrservices.cache.AbstractWorkforceIdKeyCache] (default task-30) Error: java.lang.LinkageError: Cannot resolve cache2k core implementation
        at org.cache2k.CacheManager.<clinit>(CacheManager.java:64)
        at org.cache2k.Cache2kBuilder.cfg(Cache2kBuilder.java:186)
        at org.cache2k.Cache2kBuilder.name(Cache2kBuilder.java:342)
        at ch.coop.workflow.component.hrservices.cache.AbstractWorkforceIdKeyCache.initCache(AbstractWorkforceIdKeyCache.java:29)
        at ch.coop.workflow.component.hrservices.cache.AbstractWorkforceIdKeyCache.getCache(AbstractWorkforceIdKeyCache.java:22)
        at ch.coop.workflow.component.hrservices.cache.MaOrgDatCache.getDocument(MaOrgDatCache.java:24)
        at ch.coop.workflow.component.hrservices.HRServicesService.zHRGetMitarbeiterOrgDat(HRServicesService.java:173)

Setting

  • SLES 12
  • Adobe AEM J2EE Forms 6.5
  • JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14)
  • Java 1.8
  • Maven 3.6.3
  • Eclipse IDE

pom.xml

<properties>
	<jdk-version>1.8</jdk-version>
	<cache2k-version>2.6.1.Final</cache2k-version>
</properties>
<dependencies>
	<!-- CACHE -->
	<dependency>
		<groupId>org.cache2k</groupId>
		<artifactId>cache2k-api</artifactId>
		<version>${cache2k-version}</version>
	</dependency>
	<dependency>
		<groupId>org.cache2k</groupId>
		<artifactId>cache2k-core</artifactId>
		<version>${cache2k-version}</version>
		<scope>runtime</scope>
	</dependency>
</dependencies>

implementation

package ch.coop.workflow.component.hrservices.cache;

import java.util.concurrent.TimeUnit;

import org.cache2k.Cache;
import org.cache2k.Cache2kBuilder;
import org.cache2k.io.CacheLoader;
import org.w3c.dom.Document;

import ch.coop.workflow.component.hrservices.cache.functions.WorkforceIdKeyFunction;
import ch.coop.workflow.component.hrservices.cache.keys.WorkforceIdKey;

public abstract class AbstractWorkforceIdKeyCache {

	protected AbstractWorkforceIdKeyCache() {
	}

	protected static Cache<WorkforceIdKey, Document> getCache(WorkforceIdKeyFunction fn, String cacheName) {
		return initCache(fn, cacheName);
	}

	private static Cache<WorkforceIdKey, Document> initCache(WorkforceIdKeyFunction fn, String cacheName) {
		return new Cache2kBuilder<WorkforceIdKey, Document>() {
		}
				.name(cacheName)
				.entryCapacity(1000)
				.refreshAhead(true)
				.loaderThreadCount(3)
				.expireAfterWrite(60, TimeUnit.MINUTES)
				.loader(new CacheLoader<WorkforceIdKey, Document>() {

					@Override
					public Document load(WorkforceIdKey key) throws Exception {
						return fn.reload(key);
					}

				})
				.build();
	}
}
package ch.coop.workflow.component.hrservices.cache;

import org.apache.log4j.Logger;
import org.cache2k.Cache;
import org.w3c.dom.Document;

import ch.coop.workflow.common.exception.SystemException;
import ch.coop.workflow.component.hrservices.cache.keys.WorkforceIdKey;
import ch.coop.workflow.component.hrservices.dao.SAPModuleDAO;

public class MaOrgDatCache extends AbstractWorkforceIdKeyCache {

	private static final Logger LOGGER = Logger.getLogger(MaOrgDatCache.class);

	private static SAPModuleDAO sapDAO;
	private static Cache<WorkforceIdKey, Document> cache;

	private MaOrgDatCache() {
	}

	public static Document getDocument(WorkforceIdKey key, SAPModuleDAO service) {
		sapDAO = service;
		if (cache == null) {
			cache = getCache(MaOrgDatCache::reload, "MaOrgDatCache");
		}
		try {
			return cache.get(key);
		} catch (Exception e) {
			String message = String.format("error loading Z_HR_GET_MITARBEITER_ORG_DAT with %s", key);
			LOGGER.error(message, e);
			throw new SystemException(message);
		}
	}

	protected static Document reload(WorkforceIdKey key) {
		Document doc = sapDAO.zHRGetMitarbeiterOrgDat(key.getXmlDate(), key.getWorkforceId());
		if (doc == null) {
			String message = "document is null";
			throw new SystemException(message);
		}
		return doc;
	}
}

I do not get any error in Eclipse during execution of the test cases.
Do I need to implement/use the cache differently?

@cruftex
Copy link
Member
cruftex commented Dec 16, 2022

Hi @puppetmaster-,

everything looks quite good to me. Try remove:

		<scope>runtime</scope>

I don't see what kind of packaging you use, maybe the scope isn't interpreted as intended.

Another thing:

		try {
			return cache.get(key);
		} catch (Exception e) {
			String message = String.format("error loading Z_HR_GET_MITARBEITER_ORG_DAT with %s", key);
			LOGGER.error(message, e);
			throw new SystemException(message);
		}

cache2k is optimized for high performance. I consider a try { cache.get(xy); } catch (Exception e) .... as an anti pattern, because the try/catch needs (very little) extra cycles on every cache access. If you want to wrap exceptions on interface boundaries, do it within the CacheLoader. cache2k will wrap exceptions from the loader in turn into CacheLoaderException, however, you can change that with a different ExceptionPropagator. Anyhow, hope you get it working at all, first!

@puppetmaster-
Copy link
Author

Thank you for your answer.
I only included the try catch to better analyze the location of the problem.

Removing the scope did not help.
To take the pressure off the projects I switched to another cache at the moment.

I'll try to set up a smaller POC project as soon as I can.
This gives me more time for in-depth analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0