DSLRuntimeContextFactory implements RuntimeContextFactory { @Override public CompletableFuture<RuntimeContext> newRuntimeContext(List<URI> bundleIdentifiers) { final String moduleClassName; try { moduleClassName = moduleClassName(bundleIdentifiers); } catch (RuntimeStateProvisionException exception) { return Futures.completedExceptionally(exception); } CompletionStage<RuntimeContext> completionStage = Futures.supplyAsync(() -> { Class<?> moduleClass = moduleFactory.loadClass(Name.qualifiedName(moduleClassName)); Module<?> module = createModule(moduleClass); BareBundle bundle = moduleFactory.createBundle(module); LinkerOptions linkerOptions = new LinkerOptions.Builder() .setClassProvider( name -> Optional.of(Class.forName(name.getBinaryName().toString(), true, classLoader)) ) .setExecutableProvider(executableProvider) .build(); RuntimeRepository repository = Linker.createRepository(Collections.singletonList(bundle), linkerOptions); return new RuntimeContextImpl(repository, classLoader); }, executor); return Futures.translateException( completionStage, throwable -> new RuntimeStateProvisionException(String.format( "Failed to provide runtime context for DSL module '%s' and its dependencies.", moduleClassName ), Futures.unwrapCompletionException(throwable)) ); } private  DSLRuntimeContextFactory(Builder builder); @Override CompletableFuture<RuntimeContext> newRuntimeContext(List<URI> bundleIdentifiers);  }
@Test public void loadTest() throws Exception { assert executorService != null; DSLRuntimeContextFactory runtimeContextFactory = new DSLRuntimeContextFactory.Builder(executorService).build(); URI bundleIdentifier = new URI(Module.URI_SCHEME, Fibonacci.class.getName(), null); CompletableFuture<RuntimeContext> future = runtimeContextFactory.newRuntimeContext( Collections.singletonList(bundleIdentifier) ); try (RuntimeContext runtimeContext = future.get(5, TimeUnit.SECONDS)) { RuntimeRepository repository = runtimeContext.getRepository(); Assert.assertEquals(repository.getBundles().size(), 1); Assert.assertEquals(repository.getBundles().get(0).getBundleIdentifier(), bundleIdentifier); RuntimeSimpleModuleDeclaration binarySumDeclaration = repository.getElement( RuntimeSimpleModuleDeclaration.class, Name.qualifiedName(BinarySum.class.getName())); Assert.assertNotNull(binarySumDeclaration); Assert.assertEquals(binarySumDeclaration.getPorts().size(), 3); } }