@Override public T provide() { if (beanType != null) { Supplier<T> supplier = locator.getService(beanType, beanName); T instance = supplier.get(); if (disposable) { disposableSuppliers.put(instance, (DisposableSupplier<T>) supplier); } return instance; } else { return null; } }
@Override protected void configure() { ClassAnalyzer defaultAnalyzer = serviceLocator.getService(ClassAnalyzer.class, ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME); Supplier<List<InjectionResolver>> resolvers = () -> serviceLocator.getAllServices(InjectionResolver.class); bind(new JerseyClassAnalyzer(defaultAnalyzer, resolvers)) .analyzeWith(ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME) .named(JerseyClassAnalyzer.NAME) .to(ClassAnalyzer.class); } }
@Override public void inject(Object injectMe) { getServiceLocator().inject(injectMe); }
void initRest() { InputStream is = null; try { NetworkListener nl = domain.getServerNamed("server").getConfig().getNetworkConfig() .getNetworkListener("admin-listener"); SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class); URL url = new URL( (SecureAdmin.Util.isEnabled(secureAdmin) ? "https" : "http"), nl.getAddress(), Integer.parseInt(nl.getPort()), "/management/domain"); URLConnection conn = url.openConnection(); is = conn.getInputStream(); isRestStarted = true; } catch (Exception ex) { logger.log(Level.FINE, null, ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex1) { logger.log(Level.FINE, null, ex1); } } } }
private void addDescriptorFileFinder( ServiceLocator serviceLocator, DescriptorFileFinder descriptorFileFinder) { if (descriptorFileFinder != null) { DynamicConfigurationService dcs = serviceLocator .getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); config.addActiveDescriptor(BuilderHelper .createConstantDescriptor(descriptorFileFinder)); config.commit(); } }
Context<PerThread> perThreadContext = locator.getService((new TypeLiteral<Context<PerThread>>() {}).getType()); if (perThreadContext != null) return; DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); final DescriptorImpl descriptor = BuilderHelper.link(PerThreadContext.class). to(Context.class). in(Singleton.class.getName()). descriptor.setLoader(new HK2Loader() { @Override public Class<?> loadClass(String className) throws MultiException { config.bind(descriptor, false); config.commit();
private static void bind(ServiceLocator locator, Binder binder) { DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); DynamicConfiguration dc = dcs.createDynamicConfiguration(); locator.inject(binder); binder.bind(dc); dc.commit(); }
if (locator == null) throw new IllegalArgumentException(); DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); DynamicConfiguration cd = dcs.createDynamicConfiguration(); FactoryDescriptors fds = cd.addActiveFactoryDescriptor((Class<Factory<Object>>) factoryConstant.getClass()); intermediateState.add(fds); cd = dcs.createDynamicConfiguration(); final Factory<?> constant = constants[lcv++]; Descriptor constantDescriptor = BuilderHelper.createConstantDescriptor(constant); Descriptor addProvideMethod = new DescriptorImpl(provideMethod); retVal.add(cd.bind(fdi)); cd.commit();
ServiceLocator locator = getServiceLocator(); ActiveDescriptor<?> myselfReified = locator.reifyDescriptor(this); DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); DynamicConfiguration dc = dcs.createDynamicConfiguration(); ctrs.add(myselfReified.getImplementationClass()); getImplementation(), new HashSet<Annotation>()); domDesc.setLoader(loader); domDescriptor = dc.addActiveDescriptor(domDesc, false); dc.addActiveDescriptor(alias, false); dc.addActiveDescriptor(alias, false); dc.commit(); serviceHandle = getHabitat().getServiceHandle(domDescriptor);
@BeforeClass public static void before() { DynamicConfigurationService dcs = habitat.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); new ConfigModule(habitat).configure(config); config.commit(); }
private static void atomicReplace(ServiceLocator locator, ProgramOptions options) { DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); config.addUnbindFilter(BuilderHelper.createContractFilter(ProgramOptions.class.getName())); ActiveDescriptor<ProgramOptions> desc = BuilderHelper.createConstantDescriptor( options, null, ProgramOptions.class); config.addActiveDescriptor(desc); config.commit(); }
/** * Gets {@link DynamicConfigurationService} object from {@link ServiceLocator HK2 Locator} and creates a new object of * {@link DynamicConfiguration} to bind new services. * * @param locator HK2 locator. * @return new instance of {@code DynamicConfiguration} to bind new services. */ private static DynamicConfiguration getDynamicConfiguration(ServiceLocator locator) { DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); return dcs.createDynamicConfiguration(); }
@Override public void stop() throws IOException { ServiceLocator locator = grizzlyService.getHabitat(); IndexedFilter removeFilter = BuilderHelper.createNameAndContractFilter(Mapper.class.getName(), (address.toString() + port)); DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); config.addUnbindFilter(removeFilter); config.commit(); unregisterMonitoringStatsProviders(); super.stop(); }
public void lookupConnectorServiceAndEnsureNotActive() { SimpleConnector sc = habitat.getService(SimpleConnector.class); System.out.println("[lookupConnectorService] Got sc : " + sc.getClass().getName()); ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); assert(sc != null && !inhabitant1.isActive()); }
@Override @SuppressWarnings("unchecked") public <T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contract, Annotation... qualifiers) { return getServiceLocator().getAllServiceHandles(contract, qualifiers).stream() .map(sh -> new ServiceHolderImpl<>( sh.getService(), (Class<T>) sh.getActiveDescriptor().getImplementationClass(), sh.getActiveDescriptor().getContractTypes(), sh.getActiveDescriptor().getRanking())) .collect(Collectors.toList()); }
public void getConnectorServiceAndCheckIfActive() { SimpleConnector sc = habitat.getService(SimpleConnector.class); String port = sc.getPort(); ServiceHandle inhabitant1 = habitat.getServiceHandle(ConfigInjector.class, "simple-connector"); assert(port.equals("8080")); // && inhabitant1.isActive()); }
SimpleConnector sc = habitat.getService(SimpleConnector.class); assertEquals("Extensions", 1, sc.getExtensions().size()); assertEquals("Nested children", 2, sc.getExtensions().get(0).getExtensions().size()); habitat.getDescriptors(BuilderHelper.createContractFilter(GenericContainer.class.getName())), habitat.getService(GenericContainer.class)); assertNull("GenericConfig descriptor test still has " + habitat.getDescriptors(BuilderHelper.createContractFilter(GenericConfig.class.getName())), habitat.getService(GenericConfig.class, "test")); assertNull("GenericConfig descriptor still has " + habitat.getDescriptors(BuilderHelper.createContractFilter(GenericConfig.class.getName())), habitat.getService(GenericConfig.class));
private static boolean addIfNotThere(ServiceLocator locator, DynamicConfiguration config, DescriptorImpl desc, HK2Loader loader) { IndexedFilter filter = BuilderHelper.createContractFilter(desc.getImplementation()); if (locator.getBestDescriptor(filter) != null) return false; if (loader != null) { desc.setLoader(loader); } config.bind(desc); return true; }
@Override public Object create(Context ic) throws NamingException { ActiveDescriptor<?> descriptor = habitat.getBestDescriptor( BuilderHelper.createContractFilter("javax.transaction.UserTransaction")); if (descriptor == null) return null; return habitat.getServiceHandle(descriptor).getService(); } }, false);
public Class getClassForFullName(String configBeanClassName) { ActiveDescriptor<?> descriptor = serviceLocator.getBestDescriptor(BuilderHelper.createContractFilter(configBeanClassName)); if (descriptor != null) { if (!descriptor.isReified()) { descriptor = serviceLocator.reifyDescriptor(descriptor); } return getClassFromDescriptor(descriptor); } else { descriptor = serviceLocator.getBestDescriptor(BuilderHelper.createContractFilter(configBeanClassName + "Injector")); if (!descriptor.isReified()) { descriptor = serviceLocator.reifyDescriptor(descriptor); } ConfigInjector injector = (ConfigInjector) serviceLocator.getServiceHandle(descriptor).getService(); return getClassFromInjector(injector); } }