use of org.talend.sdk.component.runtime.serialization.LightContainer in project component-runtime by Talend.
the class InterceptorTest method run.
@Test
void run(final TemporaryFolder temporaryFolder) throws Exception {
final File pluginFolder = new File(temporaryFolder.getRoot(), "test-plugins_" + UUID.randomUUID().toString());
pluginFolder.mkdirs();
final File plugin = pluginGenerator.createChainPlugin(pluginFolder, "plugin.jar");
try (final ComponentManager manager = new ComponentManager(new File("target/test-dependencies"), "META-INF/test/dependencies", "org.talend.test:type=plugin,value=%s")) {
manager.addPlugin(plugin.getAbsolutePath());
final List<Object> collect = manager.find(c -> c.get(ComponentManager.AllServices.class).getServices().values().stream()).filter(c -> c.getClass().getName().endsWith("SuperService$$TalendServiceProxy")).collect(toList());
assertEquals(1, collect.size());
final Object instance = collect.iterator().next();
final Method method = instance.getClass().getMethod("canBeLong", int.class);
assertEquals("exec_1/1", method.invoke(instance, 1));
assertEquals("exec_1/1", method.invoke(instance, 1));
sleep(450);
assertEquals("exec_1/2", method.invoke(instance, 1));
assertEquals("exec_3/3", method.invoke(instance, 3));
assertEquals("exec_4/4", method.invoke(instance, 4));
final LightContainer container = manager.find(c -> Stream.of(c.get(LightContainer.class))).findFirst().get();
DynamicContainerFinder.LOADERS.put("plugin", container.classloader());
DynamicContainerFinder.SERVICES.put(instance.getClass().getSuperclass(), instance);
final Object roundTrip = roundTrip(instance);
assertEquals(roundTrip, instance);
} finally {
// clean temp files
DynamicContainerFinder.LOADERS.clear();
DynamicContainerFinder.SERVICES.clear();
}
}
use of org.talend.sdk.component.runtime.serialization.LightContainer in project component-runtime by Talend.
the class StandaloneContainerFinder method find.
// IMPORTANT: don't abuse of lambdas here, it is on the runtime codepath
@Override
public LightContainer find(final String plugin) {
final ComponentManager manager = ComponentManager.instance();
Optional<Container> optionalContainer = manager.findPlugin(plugin);
if (!optionalContainer.isPresent()) {
log.info("Didn't find plugin " + plugin + ", had: " + manager.availablePlugins());
// nested in current jar.
try {
optionalContainer = manager.findPlugin(manager.addPlugin(plugin));
} catch (final IllegalArgumentException iae) {
// concurrent request?
optionalContainer = manager.findPlugin(plugin);
}
}
if (optionalContainer.isPresent()) {
final LightContainer lightContainer = optionalContainer.get().get(LightContainer.class);
if (lightContainer != null) {
return lightContainer;
}
}
// TCCL
return super.find(plugin);
}
Aggregations