private <T> ComponentFamilyMeta.BaseMeta<? extends Lifecycle> findMeta(final Class<T> componentType) { return asManager() .find(c -> c.get(ContainerComponentRegistry.class).getComponents().values().stream()) .flatMap(f -> Stream .concat(f.getProcessors().values().stream(), f.getPartitionMappers().values().stream())) .filter(m -> m.getType().getName().equals(componentType.getName())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("No component " + componentType)); }
@Override public void onClose(final Container container) { // ensure we don't keep any data/ref after the classloader of the container is // released ofNullable(container.get(ContainerComponentRegistry.class)).ifPresent(r -> { final ContainerComponentRegistry registry = container.remove(ContainerComponentRegistry.class); registry.getComponents().clear(); registry .getServices() .stream() .filter(i -> !Proxy.isProxyClass(i.getInstance().getClass())) .forEach(s -> doInvoke(container.getId(), s.getInstance(), PreDestroy.class)); registry.getServices().clear(); }); ofNullable(container.get(AllServices.class)) .map(s -> s.getServices().get(Jsonb.class)) .map(Jsonb.class::cast) .ifPresent(jsonb -> { try { jsonb.close(); } catch (final Exception e) { log.warn(e.getMessage(), e); } }); }
final ContainerComponentRegistry registry = new ContainerComponentRegistry(); container.set(ContainerComponentRegistry.class, registry); internationalizationServiceFactory.create(proxy, container.getLoader())); services.put(proxy, instance); registry.getServices().add(new ServiceMeta(instance, emptyList())); }); finder HttpClientFactory.class.cast(services.get(HttpClientFactory.class)).create(proxy, null); services.put(proxy, instance); registry.getServices().add(new ServiceMeta(instance, emptyList())); }); final Map<Class<?>, Object> userServices = finder services.put(service, instance); registry .getServices() .add(new ServiceMeta(instance, Stream .of(service.getMethods()) registry.getComponents().computeIfAbsent(c.getName(), n -> c); if (componentFamilyMeta != c) { if (componentFamilyMeta
private Collection<ActionReference> findActions(final String family, final Set<ActionReference> actions, final Container container, final Locale locale, final FamilyBundle familyBundle) { final ContainerComponentRegistry registry = container.get(ContainerComponentRegistry.class); return registry .getServices() .stream() .flatMap(s -> s.getActions().stream()) .filter(s -> s.getFamily().equals(family)) .filter(s -> actions .stream() .anyMatch(e -> s.getFamily().equals(e.getFamily()) && s.getType().equals(e.getType()) && s.getAction().equals(e.getName()))) .map(s -> new ActionReference(s.getFamily(), s.getAction(), s.getType(), familyBundle.actionDisplayName(s.getType(), s.getAction()).orElse(s.getAction()), propertiesService .buildProperties(s.getParameters(), container.getLoader(), locale, null) .collect(toList()))) .collect(toList()); }
.find(c -> c .get(ContainerComponentRegistry.class) .getServices() .stream() .map(s -> s.getActions().stream())
public Optional<Object> createComponent(final String plugin, final String name, final ComponentType componentType, final int version, final Map<String, String> configuration) { final String familyName = container.buildAutoIdFromName(plugin); return find(pluginContainer -> Stream.of(pluginContainer.get(ContainerComponentRegistry.class))) .filter(Objects::nonNull) .map(r -> r.getComponents().get(familyName)) .filter(Objects::nonNull) .map(component -> ofNullable(componentType.findMeta(component).get(name)) .map(comp -> comp .getInstantiator() .apply(configuration == null ? null : comp.getMigrationHandler().migrate(version, configuration)))) .findFirst() .flatMap(identity()) // unwrap to access the actual instance which is the desired one .map(i -> Delegated.class.isInstance(i) ? Delegated.class.cast(i).getDelegate() : i); }
private Runnable postDeploy(final Container plugin) { final Collection<String> componentIds = plugin .get(ContainerComponentRegistry.class) .getComponents() .values() .stream() .getServices() .stream() .flatMap(c -> c.getActions().stream()) .getComponents() .values() .stream()
public Optional<Mapper> findMapper(final String plugin, final String name, final int version, final Map<String, String> configuration) { return find(pluginContainer -> Stream .of(pluginContainer .get(ContainerComponentRegistry.class) .getComponents() .get(container.buildAutoIdFromName(plugin)))) .filter(Objects::nonNull) .map(component -> ofNullable(component.getPartitionMappers().get(name)) .map(mapper -> mapper .getInstantiator() .apply(configuration == null ? null : mapper.getMigrationHandler().migrate(version, configuration))) .map(Mapper.class::cast)) .findFirst() .flatMap(identity()); }
public Optional<org.talend.sdk.component.runtime.output.Processor> findProcessor(final String plugin, final String name, final int version, final Map<String, String> configuration) { return find(pluginContainer -> Stream .of(pluginContainer .get(ContainerComponentRegistry.class) .getComponents() .get(container.buildAutoIdFromName(plugin)))) .filter(Objects::nonNull) .map(component -> ofNullable(component.getProcessors().get(name)) .map(proc -> proc .getInstantiator() .apply(configuration == null ? null : proc.getMigrationHandler().migrate(version, configuration))) .map(org.talend.sdk.component.runtime.output.Processor.class::cast)) .findFirst() .flatMap(identity()); }
.map(file -> { final String id = addPlugin(file.getAbsolutePath()); if (container.find(id).get().get(ContainerComponentRegistry.class).getComponents().isEmpty()) { removePlugin(id); return null;
@Override protected void doExecute() throws MojoExecutionException, MojoFailureException { if (!classes.exists()) { throw new MojoExecutionException("No " + classes); } try (final ComponentManager manager = new ComponentManager(repository, "TALEND-INF/dependencies.txt", "org.talend.sdk.component:type=component,value=%s") { { addPlugin(artifactId, classes.getAbsolutePath()); } }) { final Container container = manager.findPlugin(artifactId).get(); final ContainerComponentRegistry registry = container.get(ContainerComponentRegistry.class); registry.getComponents().values().forEach(c -> { c .getPartitionMappers() .forEach((k, p) -> getLog().info("Found component " + c.getName() + "#" + p.getName())); c .getProcessors() .forEach((k, p) -> getLog().info("Found component " + c.getName() + "#" + p.getName())); }); doWork(manager, container, registry); } }
.find(c -> c .execute( () -> c.get(ContainerComponentRegistry.class).getComponents().values().stream()) .flatMap(component -> Stream .concat(component
.map(value -> ofNullable(container.get(ContainerComponentRegistry.class)) .flatMap(r -> r .getComponents() .values() .stream()
final Collection<ComponentFamilyMeta> componentFamilyMetas = componentRegistry.getComponents().values();
.getComponents() .values() .stream()