Interface ComputationManager
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DockerLocalComputationManager
,LazyCreatedComputationManager
,LocalComputationManager
public interface ComputationManager extends AutoCloseable
Computation managers have the ability to execute commands provided through anExecutionHandler
.Typically, they are used to execute expensive computations through external processes. According to the computation manager implementation, those processes may then be executed on the local host or on a dedicated computation infrastructure which may have better performance or scaling capabilities. Commands will be executed asynchronously and results accessible through the
CompletableFuture
returned by one of theexecute(com.powsybl.computation.ExecutionEnvironment, com.powsybl.computation.ExecutionHandler<R>)
method variants. IfCompletableFuture.cancel(boolean)
is called, the computation manager should try as much as possible to free computation resources used for the underlying commands execution.The computation manager must provide a temporary working directory for each submitted execution, where data may be written to (in particular before the execution) and read from (in particular after the execution). A prefix for this directory may be provided through the
ExecutionEnvironment
. Typically, the prefix will be appended with a UUID to ensure working directory uniqueness. IfExecutionEnvironment.isDebug()
is true, that working directory will not be discarded, otherwise it may be discarded to ensure a sustainable use of the execution environment.Execution handlers define a list of
CommandExecution
s to be executed. Those command executions must be executed sequentially. However, when a command execution has an execution number greater than one, the corresponding executions may be executed in parallel.The interface extends
AutoCloseable
, since it may require some resource cleanup on closing, for instance deleting working directories or closing connections to remote infrastructure.- Author:
- Geoffroy Jamgotchian
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
<R> CompletableFuture<R>
execute(ExecutionEnvironment environment, ExecutionHandler<R> handler)
Submits for execution commands defined by the specifiedExecutionHandler
, using the specifiedExecutionEnvironment
.default <R> CompletableFuture<R>
execute(ExecutionEnvironment environment, ExecutionHandler<R> handler, ComputationParameters parameters)
Submits for execution commands defined by the specifiedExecutionHandler
, using the specifiedExecutionEnvironment
.Executor
getExecutor()
An executor which may be used to perform expensive processing inside this JVM.Path
getLocalDir()
ComputationResourcesStatus
getResourcesStatus()
String
getVersion()
OutputStream
newCommonFile(String fileName)
-
-
-
Method Detail
-
getVersion
String getVersion()
-
newCommonFile
OutputStream newCommonFile(String fileName) throws IOException
- Throws:
IOException
-
execute
<R> CompletableFuture<R> execute(ExecutionEnvironment environment, ExecutionHandler<R> handler)
Submits for execution commands defined by the specifiedExecutionHandler
, using the specifiedExecutionEnvironment
.The result of type
ComputationManager
will be provided asynchronously through the returnedCompletableFuture
.- Type Parameters:
R
- the type of the result expected from the commands execution.- Parameters:
environment
- specifies environment details such as the working directory prefix and environment variables.handler
- defines the commands to be executed together with preprocessing and postprocessing.- Returns:
- the result of the commands execution, as provided by the execution handler.
-
execute
default <R> CompletableFuture<R> execute(ExecutionEnvironment environment, ExecutionHandler<R> handler, ComputationParameters parameters)
Submits for execution commands defined by the specifiedExecutionHandler
, using the specifiedExecutionEnvironment
.The result of type
ComputationManager
will be provided asynchronously through the returnedCompletableFuture
.Additional technical parameters may be provided through the
ComputationParameters
.- Type Parameters:
R
- the type of the result expected from the commands execution.- Parameters:
environment
- specifies environment details such as the working directory prefix and environment variables.handler
- defines the commands to be executed together with preprocessing and postprocessing.parameters
- defines additional technical parameters- Returns:
- the result of the commands execution, as provided by the execution handler.
-
getResourcesStatus
ComputationResourcesStatus getResourcesStatus()
-
getExecutor
Executor getExecutor()
An executor which may be used to perform expensive processing inside this JVM.- Returns:
- an executor which may be used to perform expensive processing inside this JVM.
-
getLocalDir
Path getLocalDir()
-
close
void close()
- Specified by:
close
in interfaceAutoCloseable
-
-