Class PluginTaskAbortRegistry

java.lang.Object
com.xebialabs.xlrelease.domain.tasks.plugin.PluginTaskAbortRegistry

@Component public class PluginTaskAbortRegistry extends Object
Routes a release author's abort to the running plugin-task execution it belongs to: flips TaskExecutionContext.isAborted() true, and calls the extension's TaskExecutorExtension.onAbort(com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext) so it can release whatever it is holding.

Deliberately not ScriptLifeCycle, which is the equivalent hook for Jython. That class aborts by interrupting the thread it captured, which suits an interpreter that polls between opcodes but is the wrong primitive for a Java extension:

  • The published isAborted() contract is a cooperative flag - "the host cannot interrupt a loop inside an extension", "once true it stays true", "thread-safe". An interrupt satisfies none of those: it is invisible to a thread the extension started itself, and any catch (InterruptedException) along the way clears it, so the flag would flip back to false.
  • Interrupting a thread doing NIO closes the channel it is on (ClosedByInterruptException), which can permanently poison a pooled HTTP client held inside the bundle and break every later task that reuses it. Classic blocking socket reads, meanwhile, ignore the interrupt entirely - so the risk is real and the benefit is not.

TaskExecutorExtension.onAbort(com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext) is this class's answer to the same problem without that risk: instead of the host reaching into the extension's thread, the extension itself is asked to close what it owns, on a thread of the host's choosing - never inline on the caller of abort(java.lang.String), which is the release actor's own thread and must not be blocked by plugin code. The task itself is failed/aborted immediately either way, by ScalaExecutionService.abortTask; an extension that also implements onAbort meaningfully and/or polls isAborted() additionally releases the worker thread and whatever it is holding, instead of leaving both pinned until execute eventually returns on its own.

Keyed by executionId rather than task id: one task can be entered repeatedly across suspend/resume cycles, and only the execution that is actually running should be signalled.

  • Constructor Details

    • PluginTaskAbortRegistry

      public PluginTaskAbortRegistry(@Qualifier("auxiliary") ExecutorService auxiliaryExecutor)
  • Method Details

    • register

      public void register(String executionId, DefaultTaskExecutionContext context, com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutorExtension extension)
      Registers a context/extension pair for the span of one execute call. A null executionId is ignored, as in abort(java.lang.String): a task reloaded after complete or fail cleared its id has nothing an abort could name, and ConcurrentHashMap throws on a null key.
    • unregister

      public void unregister(String executionId)
      Removes the registration. Must run in a finally: an entry left behind pins the context, its task and, through it, the plugin's own classloader. A null executionId is ignored, as in register(java.lang.String, com.xebialabs.xlrelease.domain.tasks.plugin.DefaultTaskExecutionContext, com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutorExtension).
    • abort

      public boolean abort(String executionId)
      Marks the identified execution aborted, if it is still running here, and dispatches the extension's onAbort to run off the caller's thread. A no-op for every task kind that is not a plugin task, and for a plugin task that already finished - the abort path is shared by all of them and cannot know which is which.

      executionId is null for a task that never started executing, which is an ordinary thing to abort. ScriptLifeCycle absorbs that in a plain HashMap lookup; ConcurrentHashMap throws on a null key, so it is rejected explicitly here.