-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for outbound HTTP API to send timer updates to "Conduct…
…or" by creating a "Composite Adapter" for the Broadcaster used by the timer. Only the configuration has changed, other changes are just whitespace.
- Loading branch information
Showing
7 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# API for Conductor | ||
|
||
## Outbound HTTP API to Conductor | ||
|
||
Configuration: base URL | ||
|
||
* Sync Timer | ||
* PUT /timers/:name: | ||
* { | ||
"state": | ||
WAITING_TO_START -> "Waiting" | ||
RUNNING -> "Running" | ||
PAUSED -> "Paused" | ||
FINISHED -> "Finished", | ||
"driver": "name", | ||
"navigator": "name", | ||
"nextDriver": "name", | ||
"restOfParticipants": ["name1", "name2"], | ||
"timeRemainingSeconds": 99 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/jitterted/mobreg/adapter/out/CompositeBroadcaster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.jitterted.mobreg.adapter.out; | ||
|
||
import com.jitterted.mobreg.application.port.Broadcaster; | ||
import com.jitterted.mobreg.domain.EnsembleTimer; | ||
|
||
import java.util.List; | ||
|
||
public class CompositeBroadcaster implements Broadcaster { | ||
|
||
private final List<Broadcaster> broadcasters; | ||
|
||
public CompositeBroadcaster(List<Broadcaster> broadcasters) { | ||
this.broadcasters = broadcasters; | ||
} | ||
|
||
@Override | ||
public void sendCurrentTimer(EnsembleTimer ensembleTimer) { | ||
broadcasters.forEach(broadcaster -> broadcaster.sendCurrentTimer(ensembleTimer)); | ||
} | ||
|
||
@Override | ||
public void sendEvent(EnsembleTimer.TimerEvent timerEvent) { | ||
broadcasters.forEach(broadcaster -> broadcaster.sendEvent(timerEvent)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/jitterted/mobreg/adapter/out/conductor/ConductorHttpBroadcaster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.jitterted.mobreg.adapter.out.conductor; | ||
|
||
import com.jitterted.mobreg.application.port.Broadcaster; | ||
import com.jitterted.mobreg.domain.CountdownTimer; | ||
import com.jitterted.mobreg.domain.EnsembleTimer; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestClient; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
|
||
@Component | ||
public class ConductorHttpBroadcaster implements Broadcaster { | ||
private final RestClient restClient = RestClient.create(); | ||
|
||
@Override | ||
public void sendCurrentTimer(EnsembleTimer ensembleTimer) { | ||
|
||
if (ensembleTimer.state() == CountdownTimer.TimerState.WAITING_TO_START) { | ||
CreateTimerRequest createTimerRequest = new CreateTimerRequest( | ||
ensembleTimer.ensembleName(), | ||
ensembleTimer.timeRemaining() | ||
.minutes() * 60); | ||
try { | ||
ResponseEntity<Void> responseEntity = | ||
restClient.post() | ||
.uri("https://conductor-service-ld5mdxm4za-ey.a.run.app/timers") | ||
.contentType(APPLICATION_JSON) | ||
.body(createTimerRequest) | ||
.retrieve() | ||
.toBodilessEntity(); | ||
System.out.println("POST response: " + responseEntity); | ||
} catch (HttpClientErrorException e) { | ||
System.err.println(e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void sendEvent(EnsembleTimer.TimerEvent timerEvent) { | ||
} | ||
|
||
record CreateTimerRequest(String name, int durationSeconds) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters