Sequencer Command Service
The SequencerCommandService provides the ability to send a Sequence of commands to a running Sequencer. A future value of SubmitResponse is returned on execution of the provided Sequence.
Dependencies
To use the SequencerCommandService, add this to your build.sbt file:
- sbt
-
libraryDependencies += "com.github.tmtsoftware.csw" %% "csw-command" % "3.0.0-RC1"
Creating SequencerCommandService
To create SequencerCommandService, you need to resolve the AkkaLocation of the Sequencer using the Location Service. Pass the resolved location to the SequencerCommandServiceImpl, which will return the handle of a SequencerCommandService.
- Scala
-
private val connection = AkkaConnection(ComponentId(Prefix(Subsystem.CSW, "sequencer"), ComponentType.Sequencer)) private val location: AkkaLocation = Await.result(locationService.resolve(connection, 5.seconds), 5.seconds).get val sequencerCommandService: SequencerCommandService = new SequencerCommandServiceImpl(location)
Submitting Sequence to a Sequencer
To submit a Sequence to a Sequencer, SequencerCommandService provides a submit API which takes a Sequence and returns a Future[SubmitResponse].
If the sequencer is idle, the provided sequence is loaded in the sequencer and execution of the sequence starts immediately, and a Started response is returned. If the sequencer is already running another sequence, an Invalid response is returned.
- Scala
-
val sequence: Sequence = Sequence(Setup(Prefix("test.move"), CommandName("command-1"), None)) implicit val timeout: Timeout = Timeout(10.seconds) private val initialResponse: SubmitResponse = Await.result(sequencerCommandService.submit(sequence), 5.seconds) private val queryResponse: SubmitResponse = Await.result(sequencerCommandService.query(initialResponse.runId), 5.seconds) private val queryFinalResponse: SubmitResponse = Await.result(sequencerCommandService.queryFinal(initialResponse.runId), 5.seconds)
query or queryFinal Apis, as shown above, could be used to query for the sequence result after the sequence is submitted. query returns the current response which could be either final response (eg. Completed) or intermediate response (eg. Started). Whereas queryFinal will wait for the final response of the sequence for the given timeout. This Api will never return an intermediate response.
If you are not interested in initial/intermediate response but only in final response, you can use the submitAndWait api which submits the sequence and waits for the final response if the sequence was successfully Started.