SimpleExecutionEngine implements TaskExecutionEngine { @Override public String run(Task aConfiguration) throws ExecutionException, LifeCycleException { if (!(aConfiguration instanceof UimaTask)) { throw new ExecutionException("This engine can only execute [" + UimaTask.class.getName() + "]"); } UimaTask configuration = (UimaTask) aConfiguration; TaskContext ctx = contextFactory.createContext(aConfiguration); try { ResourceManager resMgr = newDefaultResourceManager(); AnalysisEngineDescription analysisDesc = configuration .getAnalysisEngineDescription(ctx); analysisDesc.resolveImports(resMgr); if (analysisDesc.getMetaData().getName() == null) { analysisDesc.getMetaData().setName("Analysis for " + aConfiguration.getType()); } bindResource(analysisDesc, TaskContext.class, TaskContextProvider.class, TaskContextProvider.PARAM_FACTORY_NAME, contextFactory.getId(), TaskContextProvider.PARAM_CONTEXT_ID, ctx.getId()); Logger logger = new UimaLoggingAdapter(ctx); UimaContextAdmin uimaCtx = newUimaContext(logger, resMgr, newConfigurationManager()); CollectionReaderDescription readerDesc = configuration .getCollectionReaderDescription(ctx); if (readerDesc.getMetaData().getName() == null) { readerDesc.getMetaData().setName("Reader for " + aConfiguration.getType()); } Map<String, Object> addReaderParam = new HashMap<String, Object>(); addReaderParam.put(Resource.PARAM_UIMA_CONTEXT, uimaCtx); addReaderParam.put(Resource.PARAM_RESOURCE_MANAGER, resMgr); CollectionReader reader = produceCollectionReader(readerDesc, resMgr, addReaderParam); AnalysisEngine engine; if (analysisDesc.isPrimitive()) { engine = new PrimitiveAnalysisEngine_impl(); } else { engine = new AggregateAnalysisEngine_impl(); } Map<String, Object> addEngineParam = new HashMap<String, Object>(); addReaderParam.put(Resource.PARAM_UIMA_CONTEXT, uimaCtx); addReaderParam.put(Resource.PARAM_RESOURCE_MANAGER, resMgr); engine.initialize(analysisDesc, addEngineParam); ctx.getLifeCycleManager().initialize(ctx, aConfiguration); ctx.getLifeCycleManager().begin(ctx, aConfiguration); List<ResourceMetaData> metaData = new ArrayList<ResourceMetaData>(); metaData.add(reader.getMetaData()); metaData.add(engine.getMetaData()); CAS cas = CasCreationUtils.createCas(metaData); while (reader.hasNext()) { reader.getNext(cas); engine.process(cas); String documentTitle = ""; Feature documentTitleFeature = cas.getDocumentAnnotation().getType() .getFeatureByBaseName("documentTitle"); if (documentTitleFeature != null) { documentTitle = cas.getDocumentAnnotation().getFeatureValueAsString( documentTitleFeature); } cas.reset(); Progress[] progresses = reader.getProgress(); if (progresses != null) { for (Progress p : progresses) { ctx.message("Progress " + readerDesc.getImplementationName() + " " + p.getCompleted() + "/" + p.getTotal() + " " + p.getUnit() + " " + "(" + documentTitle + ")"); } } } engine.collectionProcessComplete(); reader.close(); engine.destroy(); reader.destroy(); ctx.getLifeCycleManager().complete(ctx, aConfiguration); return ctx.getId(); } catch (LifeCycleException e) { ctx.getLifeCycleManager().fail(ctx, aConfiguration, e); throw e; } catch (Throwable e) { ctx.getLifeCycleManager().fail(ctx, aConfiguration, e); throw new ExecutionException(e); } finally { if (ctx != null) { ctx.getLifeCycleManager().destroy(ctx, aConfiguration); } } }  @Override String run(Task aConfiguration); @Override void setContextFactory(TaskContextFactory aContextFactory); @Override TaskContextFactory getContextFactory();  }
@Test public void testInit() throws Exception { File repo = new File("target/repository"); FileUtils.deleteDirectory(repo); ((FileSystemStorageService) storageService).setStorageRoot(repo); assertNotNull(executionService); assertNotNull(contextFactory); TypeSystemDescription tsd = createTypeSystemDescription(new String[0]); AnalysisEngineDescription desc = createEngineDescription( DummyAE.class, tsd); DefaultUimaTask cfg = new DefaultUimaTask(); cfg.setReaderDescription(createReaderDescription(TestReader.class, tsd)); cfg.setAnalysisEngineDescription(desc); TaskExecutionEngine runner = executionService.createEngine(cfg); String uuid = runner.run(cfg); System.out.println("=== Experiments in repository ==="); List<TaskContextMetadata> experiments = storageService.getContexts(); for (TaskContextMetadata e : experiments) { System.out.println(e); } final StringBuilder sb = new StringBuilder(); storageService.retrieveBinary(uuid, "test", new StreamReader() { @Override public void read(InputStream aInputStream) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Util.shoveAndClose(aInputStream, bos); sb.append(new String(bos.toByteArray(), "UTF-8")); } }); assertEquals("works", sb.toString()); }