Class PluginTaskAbortRegistry
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 anycatch (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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanMarks the identified execution aborted, if it is still running here, and dispatches the extension'sonAbortto run off the caller's thread.voidregister(String executionId, DefaultTaskExecutionContext context, com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutorExtension extension) Registers a context/extension pair for the span of oneexecutecall.voidunregister(String executionId) Removes the registration.
-
Constructor Details
-
PluginTaskAbortRegistry
-
-
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 oneexecutecall. A nullexecutionIdis ignored, as inabort(java.lang.String): a task reloaded aftercompleteorfailcleared its id has nothing an abort could name, andConcurrentHashMapthrows on a null key. -
unregister
Removes the registration. Must run in afinally: an entry left behind pins the context, its task and, through it, the plugin's own classloader. A nullexecutionIdis ignored, as inregister(java.lang.String, com.xebialabs.xlrelease.domain.tasks.plugin.DefaultTaskExecutionContext, com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutorExtension). -
abort
Marks the identified execution aborted, if it is still running here, and dispatches the extension'sonAbortto 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.executionIdis null for a task that never started executing, which is an ordinary thing to abort.ScriptLifeCycleabsorbs that in a plainHashMaplookup;ConcurrentHashMapthrows on a null key, so it is rejected explicitly here.
-