/** * Execute the given function with the {@link #getValue() } as its parameters. * * @param <R> function return type * @param function the function * @return the result of executing the function */ default <R> R query(Function<T, R> function) { return function.apply(getValue()); }
void addInstances(Queue<Instance<?>> instances, DefaultListableBeanFactory beanFactory) { //add new instances instances.forEach(instance -> { Object value = instance.getValue(); String name = instance.getName(); Class contract = value.getClass(); if (name == null) { beanFactory.registerSingleton(contract.getSimpleName(), value); } else { beanFactory.registerSingleton(name, value); } }); }
@Override protected void configure() { while (instances.peek() != null) { Instance constant = instances.poll(); Object instance = constant.getValue(); Class instanceType = instance.getClass(); String name = constant.getName(); Class contract = constant.getContract(); if (name != null && contract != null) { bind(instanceType).annotatedWith(Names.named(name)).toInstance(instance); bind(contract).annotatedWith(Names.named(name)).toInstance(instance); bind(contract).toInstance(instance); } else if (name != null) { bind(instanceType).annotatedWith(Names.named(name)).toInstance(instance); } else if (contract != null) { bind(contract).toInstance(instance); } else { for (Class instanceInterface : instanceType.getInterfaces()) { bind(instanceInterface).toInstance(instance); } } bind(instanceType).toInstance(instance); } }
void removeInstances(ServiceLocator serviceLocator, ConcurrentLinkedDeque<Instance<?>> instances) { instances.forEach(instance -> { String name = instance.getName(); Class contract = instance.getContract(); Class instanceType = instance.getClass(); IndexedFilter filter = BuilderHelper.createContractFilter(instanceType .getTypeName()); removeFilter(serviceLocator, filter, true); if (name != null && contract != null) { removeFilter(serviceLocator, createNameAndContractFilter(contract.getName(), name), true); removeFilter(serviceLocator, createNameFilter(name), true); removeFilter(serviceLocator, createContractFilter(contract.getName()), true); } else if (name != null) { removeFilter(serviceLocator, createNameFilter(name), true); } else if (contract != null) { removeFilter(serviceLocator, createContractFilter(contract.getName()), true); } }); }
ClientInstance clientInstance = foundClientInstance.get(); Instance<Object> client = clientInstance.getClient(); String clientName = client.getName(); Class<?> clientContract = client.getContract(); sutValue = client.getValue(); String clientSupplierName = clientSupplier.getName(); Class<?> clientSupplierContract = clientSupplier.getContract();
void removeInstances(InjectionManager injectionManager, ConcurrentLinkedDeque<Instance<?>> instances) { ServiceLocator serviceLocator = ((ImmediateHk2InjectionManager) injectionManager) .getServiceLocator(); instances.forEach(instance -> { String name = instance.getName(); Class contract = instance.getContract(); Class instanceType = instance.getClass(); IndexedFilter filter = BuilderHelper.createContractFilter(instanceType .getTypeName()); removeFilter(serviceLocator, filter, true); if (name != null && contract != null) { removeFilter(serviceLocator, createNameAndContractFilter(contract.getName(), name), true); removeFilter(serviceLocator, createNameFilter(name), true); removeFilter(serviceLocator, createContractFilter(contract.getName()), true); } else if (name != null) { removeFilter(serviceLocator, createNameFilter(name), true); } else if (contract != null) { removeFilter(serviceLocator, createContractFilter(contract.getName()), true); } }); }
@Override protected void configure() { while (constants.peek() != null) { Instance constant = constants.poll(); Object instance = constant.getValue(); Class instanceType = instance.getClass(); String name = constant.getName(); Class contract = constant.getContract(); if (name != null && contract != null) { bind(instance).named(name).to(contract); bind(instance).to(contract); } else if (name != null) { bind(instance).named(name).to(instanceType); } else if (contract != null) { bind(instance).to(contract); } else { for (Class instanceInterface : instanceType.getInterfaces()) { bind(instance).to(instanceInterface); } } bind(instance).to(instanceType); } }
/** * Execute a function with the {@link #getValue() } as its parameters. * * @param consumer the consumer function */ default void command(Consumer<T> consumer) { consumer.accept(getValue()); }
void removeInstances(Queue<Instance<?>> instances, DefaultListableBeanFactory beanFactory) { String name = instance.getName(); Class contract = instance.getContract();
@Override protected void configure() { while (constants.peek() != null) { Instance constant = constants.poll(); Object instance = constant.getValue(); Class instanceType = instance.getClass(); String name = constant.getName(); Class contract = constant.getContract(); if (name != null && contract != null) { bind(instance).named(name).to(contract); bind(instance).to(contract); } else if (name != null) { bind(instance).named(name).to(instanceType); } else if (contract != null) { bind(instance).to(contract); } else { for (Class instanceInterface : instanceType.getInterfaces()) { bind(instance).to(instanceInterface); } } bind(instance).to(instanceType); } }
/** * Atomically execute the given function with the {@link #getValue() } as its parameters. * * @param <R> function return type * @param function the function * @return the result of executing the function */ default <R> R operation(Function<T, R> function) { synchronized (this) { return function.apply(getValue()); } }
/** * Execute the given consumer function with the {@link #getClient()} value and * {@link #getClientSupplier()} value as its parameters. If client supplier is not present * {@code null} will passed in as client supplier value. * * @param consumer the consumer function */ default void command(BiConsumer<C, P> consumer) { consumer.accept( getClient().getValue(), getClientSupplier().map(Instance::getValue).orElse(null) ); } }
/** * Execute the given function with the {@link #getServer()} value and {@link #getBaseURI()} * as its parameters. * * @param <R> function return type * @param function the function * @return the result of executing the function */ default <R> R query(BiFunction<T, URI, R> function) { return function.apply(getServer().getValue(), getBaseURI()); }
/** * Execute the given function with the {@link #getClient()} value and * {@link #getClientSupplier()} value as its parameters. If client supplier is not present * {@code null} will passed in as client supplier value. * * @param <R> function return type * @param function the function * @return the result of executing the function */ default <R> R query(BiFunction<C, P, R> function) { return function.apply( getClient().getValue(), getClientSupplier().map(Instance::getValue).orElse(null) ); }
/** * Execute the given consumer function with the {@link #getServer()} value and * {@link #getBaseURI()} as its parameters. * * @param consumer the consumer function */ default void command(BiConsumer<T, URI> consumer) { consumer.accept(getServer().getValue(), getBaseURI()); }
@Override public void stop(ServerInstance<Undertow> serverInstance) { if (serverInstance != null) { LoggingUtil.INSTANCE.debug("Stopping Undertow server"); serverInstance.getServer().getValue().stop(); } applicationProvider.stop(); }
void createClient(TestContext testContext, TestConfigurer testConfigurer, ClientProvider clientProvider, Application application) { URI baseURI = testContext.getProperty(TestContextProperties.SERVER_BASE_URI); //configure and create the client Object clientConfig = clientProvider.configure(testContext, application, baseURI); clientConfig = testConfigurer.configure(testContext, clientConfig); ClientInstance<Object, Object> clientInstance = clientProvider.create(testContext, application, baseURI, clientConfig); testContext .addProperty(TestContextProperties.CLIENT_INSTANCE, clientInstance) .addProperty(clientInstance.getFqn(), clientInstance.getProperties()) .addProperty(TestContextProperties.CLIENT, clientInstance .getClient().getValue()); clientInstance.getClientSupplier() .map(Instance::getValue) .ifPresent(value -> { testContext.addProperty(TestContextProperties.CLIENT_SUPPLIER, value); }); }
void createServer(TestContext testContext, TestConfigurer testConfigurer, ServerProvider serverProvider, Application application) throws Exception { //configure and start the server Object serverConfig = serverProvider.configure(testContext); serverConfig = testConfigurer.configure(testContext, serverConfig); ServerInstance serverInstance = serverProvider.start(testContext, application, serverConfig); testContext .addProperty(TestContextProperties.SERVER_INSTANCE, serverInstance) .addProperty(serverInstance.getFqn(), serverInstance.getProperties()) .addProperty(TestContextProperties.SERVER_BASE_URI, serverInstance.getBaseURI()) .addProperty(TestContextProperties.SERVER, serverInstance .getServer().getValue()); }