.of(t.getConstructors()) .min((o1, o2) -> o2.getParameterCount() - o1.getParameterCount())) .map(t -> services.getServices().computeIfAbsent(t.getDeclaringClass(), k -> { try { return t .newInstance(reflections .parameterFactory(t, services.getServices(), null) .apply(emptyMap())); } catch (final InstantiationException | IllegalAccessException e) {
final AllServices allServices = new AllServices(services); container.set(AllServices.class, allServices);
.get() .get(ComponentManager.AllServices.class) .getServices()); processor.onElement(dataInputFactory, dataOutputFactory); dataOutputFactory.getOutputs().forEach((branch, data) -> data.forEach(item -> {
.cast(container .get(AllServices.class) .getServices() .get(LocalConfiguration.class)))), invoker);
final List<ParameterMeta> parameterMetas = parameterModelService .buildParameterMetas(constructor, getPackage(type), new BaseParameterEnricher.Context( LocalConfiguration.class.cast(services.getServices().get(LocalConfiguration.class)))); addProcessorsBuiltInParameters(type, parameterMetas); final Function<Map<String, String>, Object[]> parameterFactory = createParametersFactory(plugin, constructor, services.getServices(), parameterMetas); final String name = of(processor.name()).filter(n -> !n.isEmpty()).orElseGet(type::getName); final ComponentFamilyMeta component = getOrCreateComponent(processor.family());
@Override public void onPartitionMapper(final Class<?> type, final PartitionMapper partitionMapper) { final Constructor<?> constructor = findConstructor(type); final List<ParameterMeta> parameterMetas = parameterModelService .buildParameterMetas(constructor, getPackage(type), new BaseParameterEnricher.Context( LocalConfiguration.class.cast(services.getServices().get(LocalConfiguration.class)))); final Function<Map<String, String>, Object[]> parameterFactory = createParametersFactory(plugin, constructor, services.getServices(), parameterMetas); final String name = of(partitionMapper.name()).filter(n -> !n.isEmpty()).orElseGet(type::getName); final ComponentFamilyMeta component = getOrCreateComponent(partitionMapper.family()); final Function<Map<String, String>, Mapper> instantiator = context.getOwningExtension() != null && context.getOwningExtension().supports(Mapper.class) ? config -> executeInContainer(plugin, () -> context .getOwningExtension() .convert(new ComponentInstanceImpl( doInvoke(constructor, parameterFactory.apply(config)), plugin, component.getName(), name), Mapper.class)) : config -> new PartitionMapperImpl(component.getName(), name, null, plugin, partitionMapper.infinite(), doInvoke(constructor, parameterFactory.apply(config))); component .getPartitionMappers() .put(name, new ComponentFamilyMeta.PartitionMapperMeta(component, name, findIcon(type), findVersion(type), type, parameterMetas, instantiator, migrationHandlerFactory.findMigrationHandler(parameterMetas, type, services), !context.isNoValidation())); }
@Override public void onEmitter(final Class<?> type, final Emitter emitter) { final Constructor<?> constructor = findConstructor(type); final List<ParameterMeta> parameterMetas = parameterModelService .buildParameterMetas(constructor, getPackage(type), new BaseParameterEnricher.Context( LocalConfiguration.class.cast(services.getServices().get(LocalConfiguration.class)))); final Function<Map<String, String>, Object[]> parameterFactory = createParametersFactory(plugin, constructor, services.getServices(), parameterMetas); final String name = of(emitter.name()).filter(n -> !n.isEmpty()).orElseGet(type::getName); final ComponentFamilyMeta component = getOrCreateComponent(emitter.family()); final Function<Map<String, String>, Mapper> instantiator = context.getOwningExtension() != null && context.getOwningExtension().supports(Mapper.class) ? config -> executeInContainer(plugin, () -> context .getOwningExtension() .convert(new ComponentInstanceImpl( doInvoke(constructor, parameterFactory.apply(config)), plugin, component.getName(), name), Mapper.class)) : config -> new LocalPartitionMapper(component.getName(), name, plugin, doInvoke(constructor, parameterFactory.apply(config))); component .getPartitionMappers() .put(name, new ComponentFamilyMeta.PartitionMapperMeta(component, name, findIcon(type), findVersion(type), type, parameterMetas, instantiator, migrationHandlerFactory.findMigrationHandler(parameterMetas, type, services), !context.isNoValidation())); }
@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); } }); }
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 <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)); }