@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()); // we assume we use a fatjar created with nested-maven-repository extensions // (default nested loading) // so we have the plugin in TALEND-INF/plugins.properties and the jar located as // 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; } } return super.find(plugin); // TCCL } }
public Date findLastUpdated() { return instance .find(Stream::of) .map(Container::getLastModifiedTimestamp) .max(Date::compareTo) .orElseGet(() -> new Date(0)); }
public static Object lookup(final String type) { if (type.equals(JsonBuilderFactory.class.getName())) { return ComponentManager.instance().getJsonpBuilderFactory(); } if (type.equals(JsonReaderFactory.class.getName())) { return ComponentManager.instance().getJsonpReaderFactory(); } if (type.equals(JsonGeneratorFactory.class.getName())) { return ComponentManager.instance().getJsonpGeneratorFactory(); } if (type.equals(JsonParserFactory.class.getName())) { return ComponentManager.instance().getJsonpParserFactory(); } if (type.equals(JsonWriterFactory.class.getName())) { return ComponentManager.instance().getJsonpWriterFactory(); } if (type.equals(RecordBuilderFactory.class.getName())) { final Function<String, RecordBuilderFactory> provider = ComponentManager.instance().getRecordBuilderFactoryProvider(); return provider.apply(null); } throw new IllegalArgumentException(type + " can't be a global service, didn't you pass a null plugin?"); } }
public void undeploy(final String pluginGAV) { if (pluginGAV == null || pluginGAV.isEmpty()) { throw new IllegalArgumentException("plugin maven GAV are required to undeploy a plugin"); } String pluginID = instance .find(c -> pluginGAV.equals(c.get(ComponentManager.OriginalId.class).getValue()) ? Stream.of(c.getId()) : empty()) .findFirst() .orElseThrow(() -> new IllegalArgumentException("No plugin found using maven GAV: " + pluginGAV)); instance.removePlugin(pluginID); }
synchronized Jsonb jsonb() { if (jsonb == null) { jsonb = manager .getJsonbProvider() .create() .withProvider(new PreComputedJsonpProvider("test", manager.getJsonpProvider(), manager.getJsonpParserFactory(), manager.getJsonpWriterFactory(), manager.getJsonpBuilderFactory(), manager.getJsonpGeneratorFactory(), manager.getJsonpReaderFactory())) // reuses the same memory buffers .withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false)) .build(); } return jsonb; }
@Override public <T> T findService(final String plugin, final Class<T> serviceClass) { return serviceClass .cast(asManager() .findPlugin(plugin) .orElseThrow(() -> new IllegalArgumentException("cant find plugin '" + plugin + "'")) .get(ComponentManager.AllServices.class) .getServices() .get(serviceClass)); }
levels.values().stream().flatMap(Collection::stream).filter(Component::isSource).map(n -> { final Mapper mapper = manager .findMapper(n.getNode().getFamily(), n.getNode().getComponent(), n.getNode().getVersion(), n.getNode().getConfiguration()) .orElseThrow(() -> new IllegalStateException("No mapper found for: " + n.getNode())); .map(component -> { final Processor processor = manager .findProcessor(component.getNode().getFamily(), component.getNode().getComponent(), component.getNode().getVersion(), component.getNode().getConfiguration()) .orElseThrow(() -> new IllegalStateException( .findPlugin(processor.plugin()) .get() .get(ComponentManager.AllServices.class)
private Object map(final Object next) { if (next == null || Record.class.isInstance(next)) { // directly ok return next; } if (String.class.isInstance(next) || next.getClass().isPrimitive()) { // primitives return next; } if (jsonb == null) { synchronized (this) { if (jsonb == null) { jsonb = JsonbBuilder .create(new JsonbConfig() .withAdapters(new MultipleFormatDateAdapter()) .setProperty("johnzon.cdi.activated", false)); } } } return new RecordConverters() .toRecord(next, () -> jsonb, () -> ComponentManager.instance().getRecordBuilderFactoryProvider().apply(null)); } }
file = componentManagerService .manager() .findPlugin(component.getParent().getPlugin()) .orElseThrow(() -> new WebApplicationException(Response .status(Response.Status.NOT_FOUND) file = componentManagerService.manager().getContainer().resolve(artifact.toPath());
instance = ComponentManager.instance(); deploymentListener = new DeploymentListener(componentDao, componentFamilyDao, actionDao, configurationDao); instance.getContainer().registerListener(deploymentListener);
break; case "file": plugin = toFile(resource, url); break; case "jar": .filter(path -> !container.find(path.getName()).isPresent()) .map(file -> { final String id = addPlugin(file.getAbsolutePath()); if (container.find(id).get().get(ContainerComponentRegistry.class).getComponents().isEmpty()) { removePlugin(id); return null;
Object readResolve() throws ObjectStreamException { return instance(); } }
synchronized JsonBuilderFactory jsonBuilderFactory() { if (jsonBuilderFactory == null) { jsonBuilderFactory = manager.getJsonpBuilderFactory(); } return jsonBuilderFactory; }
public <T> T injectServices(final T instance) { if (instance == null) { return null; } final String plugin = getSinglePlugin(); final Map<Class<?>, Object> services = asManager() .findPlugin(plugin) .orElseThrow(() -> new IllegalArgumentException("cant find plugin '" + plugin + "'")) .get(ComponentManager.AllServices.class) .getServices(); Injector.class.cast(services.get(Injector.class)).inject(instance); return instance; }
@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()); // we assume we use a fatjar created with nested-maven-repository extensions // (default nested loading) // so we have the plugin in TALEND-INF/plugins.properties and the jar located as // 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; } } return super.find(plugin); // TCCL } }
.build(); final Optional<Container> plugin = manager.findPlugin(meta.getPlugin()); if (!plugin.isPresent()) { return Response
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 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); } }
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); }
final Optional<Container> plugin = manager.findPlugin(meta.getParent().getPlugin()); if (!plugin.isPresent()) { return Response