use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class KieContainerImpl method reinitModifiedClasses.
private Collection<Class<?>> reinitModifiedClasses(InternalKieModule newKM, List<String> modifiedClasses, ClassLoader classLoader, boolean modifyingUsedClass) {
if (modifiedClasses.isEmpty() || !(classLoader instanceof ProjectClassLoader)) {
return Collections.emptyList();
}
Set<String> reloadedClasses = new HashSet<>(modifiedClasses);
ProjectClassLoader projectClassLoader = (ProjectClassLoader) classLoader;
projectClassLoader.clearStore();
if (modifyingUsedClass) {
reloadedClasses.addAll(projectClassLoader.reinitTypes().stream().map(ClassUtils::convertClassToResourcePath).collect(toList()));
}
List<Class<?>> classes = new ArrayList<Class<?>>();
for (String resourceName : reloadedClasses) {
String className = convertResourceToClassName(resourceName);
byte[] bytes = newKM.getBytes(resourceName);
if (bytes != null) {
Class<?> clazz = projectClassLoader.defineClass(className, resourceName, bytes);
classes.add(clazz);
}
}
return classes;
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class CanonicalKieModule method createKieBase.
@Override
public InternalKnowledgeBase createKieBase(KieBaseModelImpl kBaseModel, KieProject kieProject, BuildContext buildContext, KieBaseConfiguration conf) {
this.moduleClassLoader = ((ProjectClassLoader) kieProject.getClassLoader());
if (generatedClassNames == null) {
generatedClassNames = findGeneratedClassNamesWithDependencies();
}
moduleClassLoader.setGeneratedClassNames(generatedClassNames);
KieBaseConfiguration kBaseConf = getKieBaseConfiguration(kBaseModel, moduleClassLoader, conf);
CanonicalKiePackages kpkgs = pkgsInKbase.computeIfAbsent(kBaseModel.getName(), k -> createKiePackages(kieProject, kBaseModel, buildContext, kBaseConf));
checkStreamMode(kBaseModel, conf, kpkgs.getKiePackages());
InternalKnowledgeBase kieBase = new KieBaseBuilder(kBaseModel, kBaseConf).createKieBase(kpkgs);
registerNonNativeResources(kBaseModel, kieProject, kieBase, buildContext);
return kieBase;
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class ClassLoaderTest method testParallelClassLoading.
@Test(timeout = 20000)
public void testParallelClassLoading() {
final Integer THREAD_COUNT = 100;
final ClassLoader projectClassLoader = ProjectClassLoader.createProjectClassLoader();
final ClassLoader internalTypesClassLoader = (ClassLoader) ((ProjectClassLoader) projectClassLoader).makeClassLoader();
((ProjectClassLoader) projectClassLoader).setInternalClassLoader((ProjectClassLoader.InternalTypesClassLoader) internalTypesClassLoader);
final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
try {
final List<Future> futures = new ArrayList<>();
for (int i = 0; i < THREAD_COUNT; i++) {
if (i % 2 == 0) {
futures.add(executorService.submit(() -> {
try {
Class.forName("nonexistant", true, projectClassLoader);
} catch (ClassNotFoundException e) {
//
}
}));
} else {
futures.add(executorService.submit(() -> {
try {
Class.forName("nonexistant", true, internalTypesClassLoader);
} catch (ClassNotFoundException e) {
//
}
}));
}
}
for (int i = 1; i <= THREAD_COUNT; i++) {
try {
futures.get(i - 1).get();
} catch (final InterruptedException | ExecutionException e) {
// Nothing
}
}
} finally {
executorService.shutdownNow();
}
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class HasKnowledgeBuilderImplTest method getClassLoader.
@Test
public void getClassLoader() {
ClassLoader retrieved = hasKnowledgeBuilder.getClassLoader();
assertNotNull(retrieved);
assertEquals(knowledgeBuilder.getRootClassLoader(), retrieved);
assertTrue(retrieved instanceof ProjectClassLoader);
}
use of org.drools.wiring.api.classloader.ProjectClassLoader in project drools by kiegroup.
the class StandaloneTest method init.
@Before
public void init() {
ProjectClassLoader loader = ProjectClassLoader.createProjectClassLoader();
factory = createStandaloneTraitFactory();
}
Aggregations