-
Notifications
You must be signed in to change notification settings - Fork 1
Computation Model
To create a new computation add the following dependency to your pom.xml
:
<dependency>
<groupId>org.sybila.parasim.model</groupId>
<artifactId>computation</artifactId>
<version>${parasim.version}</version>
</dependency>
Create a representation of the result produced by your computation. The result of the computation has to extend Mergeable
interface and it's a good practice define its type as an interface:
public interface MyResult extends Mergeable<MyResult> {
}
And implementation:
public class MyResultImpl extends MyResult {
MyResult merge(MyResult toMerge) {
// TODO
}
}
Now crate your own implementation of Computation
interface, you can use AbstractComputation
class. Use @Provide
and @Inject
annotations to communicate with the context:
public class MyComputation extends AbstractComputation {
@Provide
private Configuration configuration;
@Inject
private Service service;
@Inject
private ThreadId threadId;
public MyComputation(Configuration configuration) {
this.configuration = configuration;
}
@Override
public MyResult call() throws ComputationFailedException {
// TODO, e.g. service.run(configuration)
}
}
You can also use @RunWith
annotation to specify whether your computation should be executed in distributive, concurrent or sequential way:
@Override
@RunWith(executor = SharedMemoryExecutor.class)
public MyResult call() throws ComputationFailedException {
// TODO
}
To run your computation instance use Computation Lifecycle Extension, Computation Execution Extension. Add dependencies to your pom.xml
:
<dependency>
<groupId>org.sybila.parasim.extension</groupId>
<artifactId>computation-execution-impl</artifactId>
<version>${parasim.version}</version>
</dependency>
<dependency>
<groupId>org.sybila.parasim.extension</groupId>
<artifactId>computation-lifecycle-impl</artifactId>
<version>${parasim.version}</version>
</dependency>
You have to start Manager
in your program and run your computation via ComputationContainer
:
Manager manager = ManagerImpl.create();
manager.start();
...
ComputationContainer container = manager.resolve(ComputationContainer.class, Default.class, manager.getRootContext());
...
Future<MyResult> result = container.compute(myComputationInstance);
...
manager.shutdown();
There are two main scopes related to computation:
- Computation Scope - shared among all computation instances in one shared memory
- Computation Instance Scope - each computation instance has its scope