Search in sources :

Example 1 with ComponentInstaller

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));
}
Also used : ComponentInstaller(org.talend.components.api.ComponentInstaller) URL(java.net.URL) Test(org.junit.Test)

Example 2 with ComponentInstaller

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;
}
Also used : ComponentInstaller(org.talend.components.api.ComponentInstaller) DefinitionRegistry(org.talend.components.api.service.common.DefinitionRegistry)

Example 3 with ComponentInstaller

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;
}
Also used : ComponentInstaller(org.talend.components.api.ComponentInstaller) URL(java.net.URL) DefinitionRegistry(org.talend.components.api.service.common.DefinitionRegistry)

Example 4 with ComponentInstaller

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;
}
Also used : ComponentInstaller(org.talend.components.api.ComponentInstaller) DefinitionRegistry(org.talend.components.api.service.common.DefinitionRegistry)

Example 5 with ComponentInstaller

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();
}
Also used : ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) ComponentInstaller(org.talend.components.api.ComponentInstaller) ServiceReference(org.osgi.framework.ServiceReference) Activate(aQute.bnd.annotation.component.Activate)

Aggregations

ComponentInstaller (org.talend.components.api.ComponentInstaller)5 DefinitionRegistry (org.talend.components.api.service.common.DefinitionRegistry)3 URL (java.net.URL)2 Activate (aQute.bnd.annotation.component.Activate)1 Test (org.junit.Test)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1