use of com.hazelcast.jet.impl.deployment.ChildFirstClassLoader in project hazelcast by hazelcast.
the class JobClassLoaderService method createProcessorClassLoaders.
private Map<String, ClassLoader> createProcessorClassLoaders(long jobId, JobConfig jobConfig, ClassLoader parent) {
logger.fine("Create processor classloader map for job " + idToString(jobId));
String customLibDir = nodeEngine.getProperties().getString(ClusterProperty.PROCESSOR_CUSTOM_LIB_DIR);
Map<String, ClassLoader> classLoaderMap = new HashMap<>();
for (Entry<String, List<String>> entry : jobConfig.getCustomClassPaths().entrySet()) {
List<URL> list = entry.getValue().stream().map(jar -> {
try {
Path path = Paths.get(customLibDir, jar);
return path.toUri().toURL();
} catch (MalformedURLException e) {
throw new JetException(e);
}
}).collect(Collectors.toList());
URL[] urls = list.toArray(new URL[] {});
classLoaderMap.put(entry.getKey(), new ChildFirstClassLoader(urls, parent));
}
return unmodifiableMap(classLoaderMap);
}
use of com.hazelcast.jet.impl.deployment.ChildFirstClassLoader in project hazelcast by hazelcast.
the class JobClassLoaderService method tryRemoveClassloadersForJob.
/**
* Try to remove and close/shutdown job classloader and any processor
* classloaders for given job
* <p>
* We keep track of phases where the classloader is used and remove
* the classloader only if there are no more phases left.
*/
public void tryRemoveClassloadersForJob(long jobId, JobPhase phase) {
logFinest(logger, "Try remove classloaders for jobId=%s, phase=%s", idToString(jobId), phase);
classLoaders.compute(jobId, (k, jobClassLoaders) -> {
if (jobClassLoaders == null) {
logger.warning("JobClassLoaders for jobId=" + idToString(jobId) + " already removed");
return null;
}
int phaseCount = jobClassLoaders.removePhase(phase);
if (phaseCount == 0) {
logFinest(logger, "JobClassLoaders phaseCount = 0, removing classloaders for jobId=%s", idToString(jobId));
Map<String, ClassLoader> processorCls = jobClassLoaders.processorCls();
if (processorCls != null) {
for (ClassLoader cl : processorCls.values()) {
try {
((ChildFirstClassLoader) cl).close();
} catch (IOException e) {
logger.warning("Exception when closing processor classloader", e);
}
}
}
// the class loader might not have been initialized if the job failed before that
JetDelegatingClassLoader jobClassLoader = jobClassLoaders.jobClassLoader();
jobClassLoader.shutdown();
logFine(logger, "Finish JobClassLoaders phaseCount = 0," + " removing classloaders for jobId=%s", idToString(jobId));
// Removes the item from the map
return null;
} else {
logFinest(logger, "JobClassLoaders refCount > 0, NOT removing classloaders for jobId=%s", idToString(jobId));
return jobClassLoaders;
}
});
}
use of com.hazelcast.jet.impl.deployment.ChildFirstClassLoader in project hazelcast by hazelcast.
the class Hazelcast3Proxy method newHazelcastInstance.
public HazelcastInstance newHazelcastInstance(String xmlConfig) {
try {
File hazelcastJar = locateVersion("3.12.12", new File("target"), false)[HAZELCAST_JAR_INDEX];
URLClassLoader classLoader = new ChildFirstClassLoader(new URL[] { hazelcastJar.toURI().toURL() }, Hazelcast3Proxy.class.getClassLoader());
Object config = buildHz3Config(xmlConfig, classLoader);
Object hz3Instance = newHazelcast3Instance(classLoader, config);
return proxyInstance(hz3Instance, HazelcastInstance.class);
} catch (MalformedURLException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
Aggregations