Search in sources :

Example 1 with ExecutableTask

use of org.dkpro.lab.task.ExecutableTask in project dkpro-lab by dkpro.

the class ExecutableTaskEngine method run.

@Override
public String run(Task aConfiguration) throws ExecutionException, LifeCycleException {
    if (!(aConfiguration instanceof ExecutableTask)) {
        throw new ExecutionException("This engine can only execute [" + ExecutableTask.class.getName() + "]");
    }
    // Create persistence service for injection into analysis components
    TaskContext ctx = null;
    try {
        ctx = contextFactory.createContext(aConfiguration);
        // Now the setup is complete
        ctx.getLifeCycleManager().initialize(ctx, aConfiguration);
        // Start recording
        ctx.getLifeCycleManager().begin(ctx, aConfiguration);
        try {
            ((ExecutableTask) aConfiguration).execute(ctx);
        } catch (LifeCycleException e) {
            ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
            throw e;
        } catch (UnresolvedImportException e) {
            // HACK - pass unresolved import exceptions up to the outer batch task
            ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
            throw e;
        } catch (Throwable e) {
            ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
            throw new ExecutionException(e);
        }
        aConfiguration.markExecuted();
        // End recording (here the reports will nbe done)
        ctx.getLifeCycleManager().complete(ctx, aConfiguration);
        return ctx.getId();
    } finally {
        if (ctx != null) {
            ctx.getLifeCycleManager().destroy(ctx, aConfiguration);
        }
    }
}
Also used : UnresolvedImportException(org.dkpro.lab.storage.UnresolvedImportException) TaskContext(org.dkpro.lab.engine.TaskContext) LifeCycleException(org.dkpro.lab.engine.LifeCycleException) ExecutableTask(org.dkpro.lab.task.ExecutableTask) ExecutionException(org.dkpro.lab.engine.ExecutionException)

Aggregations

ExecutionException (org.dkpro.lab.engine.ExecutionException)1 LifeCycleException (org.dkpro.lab.engine.LifeCycleException)1 TaskContext (org.dkpro.lab.engine.TaskContext)1 UnresolvedImportException (org.dkpro.lab.storage.UnresolvedImportException)1 ExecutableTask (org.dkpro.lab.task.ExecutableTask)1