Refine search
public ActorBaseTest() { ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance(); serviceLocator = factory.create(UUID.randomUUID().toString()); ServiceLocatorUtilities.addOneConstant(serviceLocator, fakeSync); }
@Before public void before() { String testName = TEST_NAME + RANDOM.nextInt(); habitat = ServiceLocatorFactory.getInstance().create(testName); DynamicConfigurationService dcs = habitat.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); new ConfigModule(habitat).configure(config); config.commit(); parseDomainXml(); }
@Test public void testEnableConfigUtilities() { ServiceLocator locator = ServiceLocatorFactory.getInstance().create(null); Assert.assertNull(locator.getService(ConfigSupport.class)); Assert.assertNull(locator.getService(ConfigurationPopulator.class)); Assert.assertNull(locator.getService(Transactions.class)); Assert.assertNull(locator.getService(ConfigInstanceListener.class)); HK2DomConfigUtilities.enableHK2DomConfiguration(locator); // Twice to check idempotence HK2DomConfigUtilities.enableHK2DomConfiguration(locator); Assert.assertEquals(1, locator.getAllServices(ConfigSupport.class).size()); Assert.assertEquals(1, locator.getAllServices(ConfigurationPopulator.class).size()); Assert.assertEquals(1, locator.getAllServices(Transactions.class).size()); Assert.assertEquals(1, locator.getAllServices(ConfigInstanceListener.class).size()); }
public static ServiceLocator getNewServiceLocator(String name) { ServiceLocator habitat = null; if (ServiceLocatorFactory.getInstance().find(name) == null) { ServiceLocator serviceLocator = ServiceLocatorFactory.getInstance() .create(name); DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); config.commit(); habitat = ServiceLocatorFactory.getInstance().create(name); try { HK2Populator.populate(serviceLocator, new ClasspathDescriptorFileFinder(Utils.class.getClassLoader()), null); } catch (IOException e) { e.printStackTrace(); } } return (habitat != null) ? habitat : ServiceLocatorFactory.getInstance().create(name); }
@Override public void initialize(NotDuplicateTargetName constraintAnnotation) { ServiceLocator locator = ServiceLocatorFactory.getInstance().find("default"); if (locator == null) return; ConfigBeansUtilities cbu = locator.getService(ConfigBeansUtilities.class); if (cbu == null) return; domain = cbu.getDomain(); }
ServiceLocator locator = factory.create("SimpleServiceLocator"); GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class); guiceBridge.bridgeGuiceInjector(injector); HK2Service service = locator.getService(HK2Service.class); service.printMessage("peeskillet");
@After public void after() { ServiceLocatorFactory.getInstance().destroy(habitat); habitat = null; }
/** * This method will create or find a ServiceLocator with the given name and * bind all of the binders given together in a single config transaction. * * @param name The non-null name of the locator to use for the configuration action * @param binders The non-null list of binders to be added to the locator * @return The service locator that was either found or created * @throws MultiException if any error was encountered while binding services */ public static ServiceLocator bind(String name, Binder... binders) { ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance(); ServiceLocator locator = factory.create(name); bind(locator, binders); return locator; }
/** * This can be used to configure the name of the service locator * to use * * @param name The name to be used. If null an anonymous service * locator will be used */ public synchronized void setServiceLocatorName(String name) { locator = ServiceLocatorFactory.getInstance().create(name); }
private void createServiceLocator() { String locatorName = APP_SERVICE_LOCATOR_PREFIX + name; ServiceLocatorFactory slf = ServiceLocatorFactory.getInstance(); if (slf.find(locatorName) != null) { slf.destroy(locatorName); } appServiceLocator = slf.create(locatorName); deploymentFailedListener = new DeploymentFailedListener(source); events.register(deploymentFailedListener); }
locator = ServiceLocatorFactory.getInstance().create(null, parent); ServiceLocatorUtilities.bind(locator, bootstraps.toArray(new Binder[bootstraps.size()])); return (Verticle) locator.createAndInitialize(clazz);
/** * Ensures that even the non-standard format of metadata from the hk2-config subsystem can * be read from the service in addClasses. addClasses will now read both forms, if the * documented form fails, it'll try the hk2-config form */ @Test public void testAddClassOfInjector() { ServiceLocator locator = ServiceLocatorFactory.getInstance().create(null); List<ActiveDescriptor<?>> added = ServiceLocatorUtilities.addClasses(locator, EjbContainerAvailabilityInjector.class); ActiveDescriptor<?> descriptor = added.get(0); Assert.assertEquals("org.jvnet.hk2.config.test.EjbContainerAvailability", ServiceLocatorUtilities.getOneMetadataField(descriptor, "target")); }
/** * Creates a new {@link ServiceLocator} instance from static {@link ServiceLocatorFactory} and adds the provided parent * locator if the instance is not null. * * @param parentLocator parent locator, can be {@code null}. * @return new instance of injection manager. */ private static ServiceLocator createLocator(ServiceLocator parentLocator) { ServiceLocator result = factory.create(null, parentLocator, null, ServiceLocatorFactory.CreatePolicy.DESTROY); result.setNeutralContextClassLoader(false); ServiceLocatorUtilities.enablePerThreadScope(result); return result; }
locator = ServiceLocatorFactory.getInstance().create(null); return (Verticle) locator.createAndInitialize(clazz);
/** * @see ServiceLocatorFactory */ private static synchronized GuiceServiceLocatorFactory getOrCreateFactory() { ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance(); if (factory instanceof GuiceServiceLocatorFactory) { return (GuiceServiceLocatorFactory)factory; } if (LOG.isInfoEnabled()) { LOG.info("Attempting to install (using relfection) a Guice-aware ServiceLocatorFactory..."); } try { GuiceServiceLocatorFactory guiceServiceLocatorFactory = new GuiceServiceLocatorFactory(factory); Class<?> clazz = ServiceLocatorFactory.class; Field field = clazz.getDeclaredField("INSTANCE"); set(field, null, guiceServiceLocatorFactory); return guiceServiceLocatorFactory; } catch (Exception err) {err.printStackTrace(); LOG.error("Exception", err); } return null; }
serviceLocator = locatorFactory.create("TestLocator"); ServiceLocatorUtilities.bind(serviceLocator, new EntityManagerProvider()); serviceLocator.inject(task); Future<String> f = backgroundService.submit(task); System.out.println("Background task submitted"); serviceLocator.inject(task); System.out.println("Background task instantiated");
ServiceLocatorFactory locatorFactory = ServiceLocatorFactory.getInstance(); ServiceLocator serviceLocator = locatorFactory.create("TestLocator"); ServiceLocatorUtilities.bind(serviceLocator, new EntityManagerProvider());
@Override public void destroy(ServiceLocator locator) { factory.destroy(locator); }
@Override public ServiceLocator find(String name) { return factory.find(name); }