All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openlca.ipc.handlers.HandlerContext Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package org.openlca.ipc.handlers;

import java.util.UUID;

import org.openlca.core.database.IDatabase;
import org.openlca.core.library.LibraryDir;
import org.openlca.core.services.JsonResultService;
import org.openlca.core.services.ServerConfig;
import org.openlca.ipc.Cache;
import org.openlca.ipc.Server;

public record HandlerContext(
	Server server,
	ServerConfig config,
	JsonResultService results,
	Cache cache) {

	public Object getCached(String id) {
		return cache.get(id);
	}

	public IDatabase db() {
		return config.db();
	}

	public LibraryDir libDir() {
		return config.dataDir().getLibraryDir();
	}

	public  T getCached(Class clazz, String id) {
		var obj = cache.get(id);
		return clazz.isInstance(obj)
			? clazz.cast(obj)
			: null;
	}

	public String cache(Object object) {
		var id = UUID.randomUUID().toString();
		cache.put(id, object);
		return id;
	}

	public Object popCached(String id) {
		return cache.remove(id);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy