use of org.talend.components.api.ComponentInstaller in project components by Talend.
the class ExtensibleUrlClassLoaderTest method testDynamicClassLoaderService.
@Test
public void testDynamicClassLoaderService() throws MalformedURLException {
// this will check that the java service loader works on a classloader that is mutable
RuntimeUtil.registerMavenUrlHandler();
// given
ExtensibleUrlClassLoader urlClassLoader = new ExtensibleUrlClassLoader(new URL[0]);
// 2 comp installer
assertThat(ServiceLoader.load(ComponentInstaller.class, urlClassLoader), IsIterableWithSize.<ComponentInstaller>iterableWithSize(2));
// when
urlClassLoader.addURL(new URL("mvn:org.talend.components/multiple-runtime-comp/0.18.0"));
// then
// 3 comp installer
assertThat(ServiceLoader.load(ComponentInstaller.class, urlClassLoader), IsIterableWithSize.<ComponentInstaller>iterableWithSize(3));
}
use of org.talend.components.api.ComponentInstaller in project components by Talend.
the class ServiceSpiFactory method getDefinitionRegistry.
/**
* return a singleton registry of all the definition red from the java ServiceLoader
*/
public static synchronized DefinitionRegistry getDefinitionRegistry() {
if (defReg == null) {
// Create a new instance of the definition registry.
DefinitionRegistry reg = new DefinitionRegistry();
for (ComponentInstaller installer : ServiceLoader.load(ComponentInstaller.class)) {
installer.install(reg);
}
reg.lock();
// Only assign it to the singleton after being locked.
defReg = reg;
}
return defReg;
}
use of org.talend.components.api.ComponentInstaller in project components by Talend.
the class ServiceSpiFactory method createInternalDefintionRegistry.
private static void createInternalDefintionRegistry(URL[] classpath) {
// add the classpath to the classloader.
if (classpath != null && classpath.length > 0) {
for (URL url : classpath) {
extensibleClassLoader.addURL(url);
}
}
// Create a new instance of the definition registry.
DefinitionRegistry reg = new DefinitionRegistry();
for (ComponentInstaller installer : ServiceLoader.load(ComponentInstaller.class, extensibleClassLoader)) {
installer.install(reg);
}
reg.lock();
// Only assign it to the singleton after being locked.
defReg = reg;
}
use of org.talend.components.api.ComponentInstaller in project components by Talend.
the class ComponentsTestRegistrySetup method getComponentRegistry.
private DefinitionRegistry getComponentRegistry() {
if (registry == null) {
registry = new DefinitionRegistry();
Map<String, ComponentInstaller> installers = context.getBeansOfType(ComponentInstaller.class);
for (ComponentInstaller installer : installers.values()) {
installer.install(registry);
LOGGER.debug("{} installed in the registry", installer);
}
registry.lock();
}
// else registry already initialised
return registry;
}
use of org.talend.components.api.ComponentInstaller in project components by Talend.
the class DefinitionRegistryOsgi method activate.
@Activate
void activate(final BundleContext bundleContext) throws InvalidSyntaxException {
serviceTracker = new ServiceTracker<>(bundleContext, ComponentInstaller.class.getName(), new ServiceTrackerCustomizer<ComponentInstaller, ComponentInstaller>() {
@Override
public ComponentInstaller addingService(ServiceReference<ComponentInstaller> serviceRef) {
ComponentInstaller componentInstaller = bundleContext.getService(serviceRef);
// $NON-NLS-1$
Object nameProp = serviceRef.getProperty("component.name");
if (nameProp instanceof String) {
LOGGER.info(// $NON-NLS-1$//$NON-NLS-2$
"Registered the component: " + nameProp + "(" + componentInstaller.getClass().getCanonicalName() + // $NON-NLS-1$
")");
componentInstaller.install(DefinitionRegistryOsgi.this);
} else {
// no name set so issue a warning
LOGGER.warn(// $NON-NLS-1$
"Failed to register the following component because it is unnamed: " + serviceRef.getClass().getCanonicalName());
}
return componentInstaller;
}
@Override
public void modifiedService(ServiceReference<ComponentInstaller> arg0, ComponentInstaller componentInstaller) {
// not handled for now
}
@Override
public void removedService(ServiceReference<ComponentInstaller> arg0, ComponentInstaller componentInstaller) {
// No any un-install yet from the service
}
});
serviceTracker.open();
}
Aggregations