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)); }
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); }
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()); }
private Runnable postDeploy(final Container plugin) { final Collection<String> componentIds = plugin .get(ContainerComponentRegistry.class) .getComponents() .values() .stream() .getComponents() .values() .stream()
.map(file -> { final String id = addPlugin(file.getAbsolutePath()); if (container.find(id).get().get(ContainerComponentRegistry.class).getComponents().isEmpty()) { removePlugin(id); return null;
@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); } }); }
@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();
registry.getComponents().computeIfAbsent(c.getName(), n -> c); if (componentFamilyMeta != c) { if (componentFamilyMeta
.getComponents() .values() .stream()