mirror of
https://github.com/OpenLiberty/liberty-bikes.git
synced 2025-01-18 10:23:58 +08:00
Add MP Fault Tolerance to game-service and align features with MP 2.0
This commit is contained in:
parent
6dc84d209b
commit
dd79e08bbb
@ -17,6 +17,7 @@ import javax.websocket.Session;
|
||||
import javax.websocket.server.PathParam;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import org.eclipse.microprofile.faulttolerance.Retry;
|
||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||
import org.libertybikes.game.core.GameRound;
|
||||
import org.libertybikes.game.core.GameRound.State;
|
||||
@ -65,7 +66,7 @@ public class GameRoundWebsocket {
|
||||
log(roundId, "[onMessage] Received message for round that did not exist or has completed. Closing this websocket connection.");
|
||||
if (round == null)
|
||||
sendToClient(session, new OutboundMessage.ErrorEvent("Round " + roundId + " did not exist."));
|
||||
// don't immediately boot out players that may keep sending messages a few seconds after the game is done
|
||||
// don't boot out players that may keep sending messages a few seconds after the game is done
|
||||
else if (!round.isPlayer(session))
|
||||
sendToClient(session, new OutboundMessage.ErrorEvent("Round " + roundId + " has already completed."));
|
||||
session.close();
|
||||
@ -78,7 +79,7 @@ public class GameRoundWebsocket {
|
||||
} else if (msg.direction != null) {
|
||||
round.updatePlayerDirection(session, msg);
|
||||
} else if (msg.playerJoinedId != null) {
|
||||
org.libertybikes.restclient.Player playerResponse = playerSvc.getPlayerById(msg.playerJoinedId);
|
||||
org.libertybikes.restclient.Player playerResponse = getPlayer(msg.playerJoinedId);
|
||||
if (!round.addPlayer(session, msg.playerJoinedId, playerResponse.name, msg.hasGameBoard))
|
||||
sendToClient(session, new OutboundMessage.ErrorEvent("Unable to add player " + playerResponse.name
|
||||
+ " to game. This is probably because someone else with the same name is already in the game."));
|
||||
@ -115,4 +116,12 @@ public class GameRoundWebsocket {
|
||||
System.out.println("[websocket-" + roundId + "] " + msg);
|
||||
}
|
||||
|
||||
// We need to specify an extra helper method here because MP Rest Client does not
|
||||
// yet allow MP Fault Tolerance annotations directly on rest client interfaces
|
||||
// see: https://github.com/eclipse/microprofile-rest-client/issues/5
|
||||
@Retry(maxRetries = 3)
|
||||
private org.libertybikes.restclient.Player getPlayer(String id) {
|
||||
return playerSvc.getPlayerById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.libertybikes.restclient;
|
||||
|
||||
import javax.enterprise.context.Dependent;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.POST;
|
||||
@ -13,7 +12,6 @@ import javax.ws.rs.core.MediaType;
|
||||
import org.eclipse.microprofile.openapi.annotations.Operation;
|
||||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
||||
|
||||
@Dependent
|
||||
@RegisterRestClient
|
||||
@Path("/")
|
||||
public interface PlayerService {
|
||||
|
@ -6,9 +6,9 @@
|
||||
<feature>jaxrs-2.1</feature>
|
||||
<feature>jndi-1.0</feature>
|
||||
<feature>jsonb-1.0</feature>
|
||||
<feature>mpConfig-1.2</feature>
|
||||
<feature>mpRestClient-1.0</feature>
|
||||
<feature>mpJwt-1.0</feature>
|
||||
<feature>mpConfig-1.3</feature>
|
||||
<feature>mpFaultTolerance-1.1</feature>
|
||||
<feature>mpRestClient-1.1</feature>
|
||||
<feature>mpOpenAPI-1.0</feature>
|
||||
<feature>websocket-1.1</feature>
|
||||
</featureManager>
|
||||
@ -19,11 +19,13 @@
|
||||
<jndiEntry jndiName="round/gameSpeed" value="50"/> <!-- Default = 50(ms) -->
|
||||
<jndiEntry jndiName="round/map" value="-1"/> <!-- Default = -1 (random map) -->
|
||||
<jndiEntry jndiName="round/autoStartCooldown" value="20"/> <!-- Default = 20(sec) -->
|
||||
<jndiEntry jndiName="jwtKeyStore" value="${server.config.dir}resources/security/validationKeystore.jks"/>
|
||||
<jndiEntry jndiName="jwtKeyStorePassword" value="secret"/>
|
||||
|
||||
<variable name="jwtKeyStore" value="${server.config.dir}resources/security/validationKeystore.jks"/>
|
||||
<variable name="jwtKeyStorePassword" value="secret"/>
|
||||
<jndiEntry jndiName="jwtKeyStore" value="${jwtKeyStore}"/>
|
||||
<jndiEntry jndiName="jwtKeyStorePassword" value="${jwtKeyStorePassword}"/>
|
||||
<jndiEntry jndiName="jwtKeyStoreAlias" value="bike"/>
|
||||
|
||||
|
||||
<applicationManager autoExpand="true"/>
|
||||
|
||||
<sslDefault sslRef="RpSSLConfig" />
|
||||
@ -31,9 +33,9 @@
|
||||
keyStoreRef="validationKeystore"
|
||||
trustStoreRef="validationKeystore" />
|
||||
<keyStore id="validationKeystore"
|
||||
password="secret"
|
||||
password="${jwtKeyStorePassword}"
|
||||
type="jks"
|
||||
location="${server.config.dir}resources/security/validationKeystore.jks" />
|
||||
location="${jwtKeyStore}" />
|
||||
|
||||
<keyStore id="defaultKeyStore" password="secret" />
|
||||
<quickStartSecurity userName="admin" userPassword="admin"/>
|
||||
|
Loading…
Reference in New Issue
Block a user