Package io.molr.mole.core.local
Class LocalSuperMole
- java.lang.Object
-
- io.molr.mole.core.local.LocalSuperMole
-
- All Implemented Interfaces:
Mole
public class LocalSuperMole extends java.lang.Object implements Mole
This is probably the most simple agency possible: it is employing several moles, instantiating a mission on the first one who can do itThis agency is threadsafe by delegating all the methods execution to a separate thread. All the methods that return
Flux
orMono
are asynchronous.
-
-
Constructor Summary
Constructors Constructor Description LocalSuperMole(java.lang.Iterable<Mole> moles)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description reactor.core.publisher.Mono<io.molr.commons.domain.MissionHandle>
instantiate(io.molr.commons.domain.Mission mission, java.util.Map<java.lang.String,java.lang.Object> params)
Instantiates the given mission with the given parameters (Currently only string and integer parameters are supported).void
instruct(io.molr.commons.domain.MissionHandle handle, io.molr.commons.domain.MissionCommand command)
Instruct the mole to execute a mission related command.void
instruct(io.molr.commons.domain.MissionHandle handle, io.molr.commons.domain.Strand strand, io.molr.commons.domain.StrandCommand command)
Instructs the mission instance identified by the given handle to execute the given command on the given strand.void
instructBlock(io.molr.commons.domain.MissionHandle handle, java.lang.String blockId, io.molr.commons.domain.BlockCommand command)
Instruct the mole to execute a block related command.void
instructRoot(io.molr.commons.domain.MissionHandle handle, io.molr.commons.domain.StrandCommand command)
Instructs the root strand of the mission identified by the given handle to execute a given command.reactor.core.publisher.Flux<io.molr.commons.domain.MissionOutput>
outputsFor(io.molr.commons.domain.MissionHandle handle)
Retrieves a stream of the actual output of one mission instance.reactor.core.publisher.Mono<io.molr.commons.domain.MissionParameterDescription>
parameterDescriptionOf(io.molr.commons.domain.Mission mission)
Retrieves information on what parameters a mission expects (name, type, optional or mandatory).reactor.core.publisher.Mono<io.molr.commons.domain.MissionRepresentation>
representationOf(io.molr.commons.domain.Mission mission)
Retrieves the initial (!) representation of a mission, meaning when the mission is not instantiated/running.reactor.core.publisher.Flux<io.molr.commons.domain.MissionRepresentation>
representationsFor(io.molr.commons.domain.MissionHandle handle)
Delivers updates of the representation of the mission.reactor.core.publisher.Flux<io.molr.commons.domain.AgencyState>
states()
Retrieves a stream of the actualAgencyState
.reactor.core.publisher.Flux<io.molr.commons.domain.MissionState>
statesFor(io.molr.commons.domain.MissionHandle handle)
Retrieves a stream emitting new items anytime the state of the mission instance changes.
-
-
-
Constructor Detail
-
LocalSuperMole
public LocalSuperMole(java.lang.Iterable<Mole> moles)
-
-
Method Detail
-
states
public reactor.core.publisher.Flux<io.molr.commons.domain.AgencyState> states()
Description copied from interface:Mole
Retrieves a stream of the actualAgencyState
. This state contains information about all the available missions and those which are currently instantiated. The stream shall emit a new item whenever the state changes and shall be long-living, so basically never complete during the lifetime of the agency.
-
representationOf
public reactor.core.publisher.Mono<io.molr.commons.domain.MissionRepresentation> representationOf(io.molr.commons.domain.Mission mission)
Description copied from interface:Mole
Retrieves the initial (!) representation of a mission, meaning when the mission is not instantiated/running. This representation contains for example the tree structure of the mission. In many (or even most) cases, this information will be static (so not change over the lifecycle of a mission). So, for specific clients - when they know that the structure does not change - it might be sufficient to use this method only to determine the structure. However, for the general case (imagine for example a mission like a parametrized junit test), it is recommended to use this method only to get the initial representation (when no handle exists yet), and then subscribe to the stream providedMole.representationsFor(MissionHandle)
, to be notified of any changes in the representation.- Specified by:
representationOf
in interfaceMole
- Parameters:
mission
- the mission for which to retrieve the initial (!) representation- Returns:
- a mono, emitting the initial representation as soon as it is available (usually instantly).
-
parameterDescriptionOf
public reactor.core.publisher.Mono<io.molr.commons.domain.MissionParameterDescription> parameterDescriptionOf(io.molr.commons.domain.Mission mission)
Description copied from interface:Mole
Retrieves information on what parameters a mission expects (name, type, optional or mandatory). For interactive clients it is recommended to use this information to help the user to input only valid values.- Specified by:
parameterDescriptionOf
in interfaceMole
- Parameters:
mission
- the mission for which the information shall be queried.- Returns:
- a stream emitting the information about expected parameters as soon as it is available (usually instantly).
-
instantiate
public reactor.core.publisher.Mono<io.molr.commons.domain.MissionHandle> instantiate(io.molr.commons.domain.Mission mission, java.util.Map<java.lang.String,java.lang.Object> params)
Description copied from interface:Mole
Instantiates the given mission with the given parameters (Currently only string and integer parameters are supported). The returned mono shall only emit, as soon as the mission is available and more detailed states can be retrieved by other methods of the agency, if queried with the given handle. As soon as the mission is instantiated (the returned mono emits), then the mission instance shall be in a paused state with the cursor of the rootStrand
on its first (or only)Block
.At this point in time, commands can be sent to the mission instance through the
Mole.instruct(MissionHandle, Strand, StrandCommand)
method (non-allowed commands shall be ignored by the agency and the underlying moles). The allowed commands (and other information) can be queried through theMole.statesFor(MissionHandle)
method.- Specified by:
instantiate
in interfaceMole
- Parameters:
mission
- the mission which shall be instantiatedparams
- a map from parameter name to parameter value to instantiate the mission- Returns:
- a mono of a new handle (unique throughout the lifetime of the agency), representing the instance of the mission and being emitted as soon as the mission instance is ready to receive commands.
-
statesFor
public reactor.core.publisher.Flux<io.molr.commons.domain.MissionState> statesFor(io.molr.commons.domain.MissionHandle handle)
Description copied from interface:Mole
Retrieves a stream emitting new items anytime the state of the mission instance changes. Agency implementations (and underlying moles) shall guarantee that the stream emits at least once on new subscriptions. The mission state contains runtime information of the mission instance (for example, strands, cursor positions, run states of each strand and block).- Specified by:
statesFor
in interfaceMole
- Parameters:
handle
- a handle representing the mission instance for which the states shall be retrieved- Returns:
- a stream of mission states, emitting each time when the state changes and being completed only at the end of the lifecycle of the mission instance.
-
outputsFor
public reactor.core.publisher.Flux<io.molr.commons.domain.MissionOutput> outputsFor(io.molr.commons.domain.MissionHandle handle)
Description copied from interface:Mole
Retrieves a stream of the actual output of one mission instance. The items in the stream represent a 'snapshot' of the actually available output of the whole mission. The returned stream shall emit each time the output changes and at least once on subscription. An output basically contains a map of output values per block.- Specified by:
outputsFor
in interfaceMole
- Parameters:
handle
- a handle representing the mission instance for which the output shall be queried.- Returns:
- a stream of the actually available output for the mission instance.
-
representationsFor
public reactor.core.publisher.Flux<io.molr.commons.domain.MissionRepresentation> representationsFor(io.molr.commons.domain.MissionHandle handle)
Description copied from interface:Mole
Delivers updates of the representation of the mission. Implementations of the agency (and underlying moles) shall guarantee that the returned stream emits at least once for a newly subscribed client.- Specified by:
representationsFor
in interfaceMole
- Parameters:
handle
- the handle of the mission for which to retrieve representation updates- Returns:
- a stream emitting whenever the representation changes, and at least once on subscription.
-
instruct
public void instruct(io.molr.commons.domain.MissionHandle handle, io.molr.commons.domain.Strand strand, io.molr.commons.domain.StrandCommand command)
Description copied from interface:Mole
Instructs the mission instance identified by the given handle to execute the given command on the given strand. The allowed commands can be 'guessed' by using the information fromMole.statesFor(MissionHandle)
. However, due to the asynchronous nature of the whole framework, it can never be guaranteed that the command is still allowed when sent. For that reason, non-allowed commands shall be ignored by the implementations of an agency and underlying moles.
-
instructRoot
public void instructRoot(io.molr.commons.domain.MissionHandle handle, io.molr.commons.domain.StrandCommand command)
Description copied from interface:Mole
Instructs the root strand of the mission identified by the given handle to execute a given command. This is mainly a convenience method to execute commands without knowing the actual strand structure, as there has to be always to be a root strand. This is e.g. useful if missions simply have to be run without any GUI interaction. This can be accomplished by sending a resume command through this method. The rest of the behaviour shall be identical to theMole.instruct(MissionHandle, Strand, StrandCommand)
method.- Specified by:
instructRoot
in interfaceMole
- Parameters:
handle
- a handle representing the mission instance on which the command shall be executedcommand
- the command to execute.
-
instructBlock
public void instructBlock(io.molr.commons.domain.MissionHandle handle, java.lang.String blockId, io.molr.commons.domain.BlockCommand command)
Description copied from interface:Mole
Instruct the mole to execute a block related command.- Specified by:
instructBlock
in interfaceMole
- Parameters:
handle
- representing the mission instanceblockId
- the id of the target blockcommand
- the command to execute
-
instruct
public void instruct(io.molr.commons.domain.MissionHandle handle, io.molr.commons.domain.MissionCommand command)
Description copied from interface:Mole
Instruct the mole to execute a mission related command.
-
-