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" % "5.0.1"

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
sourceprivate 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
sourceval sequence: Sequence        = Sequence(Setup(Prefix("test.move"), CommandName("command-1"), None))
implicit val timeout: Timeout = Timeout(10.seconds)
async {
  val initialResponse: SubmitResponse             = await(sequencerCommandService.submit(sequence))
  val queryResponseF: Future[SubmitResponse]      = sequencerCommandService.query(initialResponse.runId)
  val queryFinalResponseF: Future[SubmitResponse] = sequencerCommandService.queryFinal(initialResponse.runId)
  await(queryResponseF)
  await(queryFinalResponseF)
}.map(_ => {
  // do something once all is finished
})

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.

Scala
sourcesequencerCommandService
  .submitAndWait(sequence)
  .map(finalResponse => {
    // do something with finalResponse
  })