public static void main(String[] args) throws Exception { final int totalServiceDefinitions = Integer.parseInt(args[0]); final int threadPoolSize = Integer.parseInt(args[1]); final ServiceContainer container = ServiceContainer.Factory.create(); final ThreadPoolExecutor executor = new ThreadPoolExecutor( threadPoolSize, threadPoolSize, 1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); container.setExecutor(executor); BatchBuilder batch = container.batchBuilder(); final LatchedFinishListener listener = new LatchedFinishListener(); final Value<Field> testFieldValue = new CachedValue<Field>( new LookupFieldValue(new ImmediateValue<Class<?>>(TestObject.class), "test")); final List<Value<Class<?>>> params = Collections.singletonList((Value<Class<?>>) new ImmediateValue<Class<?>>(TestObject.class)); final List<Value<Method>> setterMethodValues = new ArrayList<Value<Method>>(5); for (int i = 0; i < 5; i++) setterMethodValues.add( new CachedValue<Method>( new LookupMethodValue( new ImmediateValue<Class<?>>(TestObject.class), "setOther" + (i), params))); for (int i = 0; i < totalServiceDefinitions; i++) { final TestObject testObject = new TestObject("test" + i); final TestObjectService service = new TestObjectService(testObject); final ServiceBuilder<TestObject> builder = batch.addService(ServiceName.of(("test" + i).intern()), service).addListener(listener); final Object injectedValue = new Object(); // builder.addInjection(injectedValue).toFieldValue(testFieldValue); int nextDivByFive = (5 - (i % 5)) + i; int numDeps = Math.min(nextDivByFive - i, totalServiceDefinitions - i - 1); for (int j = 0; j < numDeps; j++) { int depId = i + j + 1; if (depId % 5 == 0) continue; // builder.addDependency(ServiceName.of(("test" + // depId).intern())).toMethodValue(setterMethodValues.get(j), // Collections.singletonList(Values.injectedValue())); } } batch.install(); listener.await(); System.out.println(totalServiceDefinitions + " : " + listener.getElapsedTime() / 1000.0); container.shutdown(); executor.shutdown(); }
private ServiceContainer register() { Runtime.getRuntime().addShutdownHook(this); synchronized (this) { if (!down) { container = ServiceContainer.Factory.create("host-controller", false); return container; } else { throw new IllegalStateException(); } } }
/** * Create a new controller with the passed in operations. * * @param additionalInit Additional initialization that should be done to the parsers, controller * and service container before initializing our extension * @param bootOperations the operations */ protected KernelServices installInController( AdditionalInitialization additionalInit, List<ModelNode> bootOperations) throws Exception { if (additionalInit == null) { additionalInit = new AdditionalInitialization(); } ControllerInitializer controllerInitializer = additionalInit.createControllerInitializer(); additionalInit.setupController(controllerInitializer); // Initialize the controller ServiceContainer container = ServiceContainer.Factory.create("test" + counter.incrementAndGet()); ServiceTarget target = container.subTarget(); ControlledProcessState processState = new ControlledProcessState(true); List<ModelNode> extraOps = controllerInitializer.initializeBootOperations(); List<ModelNode> allOps = new ArrayList<ModelNode>(); if (extraOps != null) { allOps.addAll(extraOps); } allOps.addAll(bootOperations); StringConfigurationPersister persister = new StringConfigurationPersister(allOps, testParser); ModelControllerService svc = new ModelControllerService( additionalInit.getType(), mainExtension, controllerInitializer, additionalInit, processState, persister, additionalInit.isValidateOperations()); ServiceBuilder<ModelController> builder = target.addService(ServiceName.of("ModelController"), svc); builder.install(); additionalInit.addExtraServices(target); // sharedState = svc.state; svc.latch.await(); ModelController controller = svc.getValue(); ModelNode setup = Util.getEmptyOperation("setup", new ModelNode()); controller.execute(setup, null, null, null); processState.setRunning(); KernelServices kernelServices = new KernelServices( container, controller, persister, new OperationValidator(svc.rootRegistration)); this.kernelServices.add(kernelServices); if (svc.error != null) { throw svc.error; } return kernelServices; }
@Override public void initPlugin() { serviceContainer = ServiceContainer.Factory.create(); eventsPlugin = getPlugin(FrameworkEventsPlugin.class); packageAdmin = getPlugin(PackageAdminPlugin.class); }
@Before public void setupServiceContainer() { serviceContainer = ServiceContainer.Factory.create("test"); }
private LiveOakFactory(File configDir, File applicationsDir, Vertx vertx, String bindAddress) { this(configDir, applicationsDir, vertx, bindAddress, ServiceContainer.Factory.create()); }