Commit 10313d83 authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

Back to Java 1.8

parent d2e991fd
...@@ -11,6 +11,4 @@ service GameServerService { ...@@ -11,6 +11,4 @@ service GameServerService {
i32 createGame(i32 numberOfPlayers) i32 createGame(i32 numberOfPlayers)
i32 join(i32 gameId, JoinRequest request) throws (1:common.GameNotFound e) i32 join(i32 gameId, JoinRequest request) throws (1:common.GameNotFound e)
void start(i32 gameId) throws (1:common.GameNotFound e)
} }
...@@ -22,7 +22,6 @@ par ...@@ -22,7 +22,6 @@ par
player5 -> game : playerId := join(id, five) player5 -> game : playerId := join(id, five)
player6 -> game : playerId := join(id, six) player6 -> game : playerId := join(id, six)
end end
game -> game : start()
.... ....
.Questions ouveres (à faire) .Questions ouveres (à faire)
...@@ -35,6 +34,5 @@ game -> game : start() ...@@ -35,6 +34,5 @@ game -> game : start()
interface GameServer { interface GameServer {
createGame(numberOfPlayers : Integer): Integer createGame(numberOfPlayers : Integer): Integer
join(gameId : Integer): Integer join(gameId : Integer): Integer
satrt()
} }
.... ....
...@@ -9,16 +9,14 @@ ...@@ -9,16 +9,14 @@
interface GameServer { interface GameServer {
createGame(numberOfPlayers : Integer): Integer createGame(numberOfPlayers : Integer): Integer
join(gameId : Integer): Integer join(gameId : Integer): Integer
start()
} }
package game { package game {
class "GameServerController" as controller { class "GameServerController" as controller {
createGame(numberOfPlayers : Integer): Integer createGame(numberOfPlayers : Integer): Integer
join(gameId : Integer): Integer join(gameId : Integer): Integer
start()
} }
class "Game" as game { class "Game \n[Thread]" as game {
id : Integer {id} id : Integer {id}
numberOfPlayers : Integer numberOfPlayers : Integer
} }
...@@ -27,7 +25,7 @@ package game { ...@@ -27,7 +25,7 @@ package game {
} }
GameServer <|-- controller GameServer <|-- controller
controller *- "[*] games" game : \t\t\t controller *- "[*] games" game : \t\t\t
controller *-- "[0..7] players" player game *-- "[0..7] players" player
} }
note right of game: Uncompleted! note right of game: Uncompleted!
.... ....
...@@ -71,7 +69,7 @@ post: ...@@ -71,7 +69,7 @@ post:
.Start Game .Start Game
[plantuml] [plantuml]
---- ----
partition GameServerController::start() { partition Game::run() {
start start
while (enough players?) while (enough players?)
:JoinRequest< :JoinRequest<
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
<name>Not Alone Server</name> <name>Not Alone Server</name>
<description>Spring Boot Not Alone server</description> <description>Spring Boot Not Alone server</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>fr.univnantes.alma</groupId> <groupId>fr.univnantes.alma</groupId>
......
...@@ -20,5 +20,4 @@ public interface GameService { ...@@ -20,5 +20,4 @@ public interface GameService {
*/ */
int join(int gameId, GameJoinRequest request); int join(int gameId, GameJoinRequest request);
void start(int gameId) throws InterruptedException;
} }
...@@ -20,9 +20,14 @@ public class Game { ...@@ -20,9 +20,14 @@ public class Game {
private final AtomicInteger expectedPlayers; private final AtomicInteger expectedPlayers;
private Thread play;
public Game(int expectedPlayers) { public Game(int expectedPlayers) {
this.expectedPlayers = new AtomicInteger(expectedPlayers); this.expectedPlayers = new AtomicInteger(expectedPlayers);
this.requests = new ArrayBlockingQueue<GameJoinRequest>(expectedPlayers); this.requests = new ArrayBlockingQueue<GameJoinRequest>(expectedPlayers);
play = new Thread(() -> this.start());
play.start();
} }
public int join(GameJoinRequest request) { public int join(GameJoinRequest request) {
...@@ -31,13 +36,10 @@ public class Game { ...@@ -31,13 +36,10 @@ public class Game {
return id; return id;
} }
public void start() { private void start() {
Thread t = new Thread(() -> { this.waitForPlayers();
this.waitForPlayers(); Log.info("We can start !");
Log.info("We can start !");
}
);
t.start();
} }
private void waitForPlayers() { private void waitForPlayers() {
......
...@@ -34,10 +34,4 @@ public class GameServiceController implements GameService { ...@@ -34,10 +34,4 @@ public class GameServiceController implements GameService {
return game.join(request); return game.join(request);
} }
@Override
public void start(int gameId) throws InterruptedException {
Game game = games.get(gameId);
game.start();
}
} }
...@@ -22,16 +22,8 @@ public class GameServiceHandler implements GameServerService.Iface { ...@@ -22,16 +22,8 @@ public class GameServiceHandler implements GameServerService.Iface {
@Override @Override
public int join(int gameId, JoinRequest request) throws TException { public int join(int gameId, JoinRequest request) throws TException {
//TODO: translate JoinRequest into GameJoinRequest
return service.join(gameId, new GameJoinRequest()); return service.join(gameId, new GameJoinRequest());
} }
@Override
public void start(int gameId) throws GameNotFound, TException {
try {
service.start(gameId);
} catch (InterruptedException e) {
throw new GameNotFound();
}
}
} }
...@@ -50,7 +50,7 @@ class NotAloneApplicationTest { ...@@ -50,7 +50,7 @@ class NotAloneApplicationTest {
client.join(id, new JoinRequest("two")); client.join(id, new JoinRequest("two"));
client.join(id, new JoinRequest("three")); client.join(id, new JoinRequest("three"));
client.join(id, new JoinRequest("four")); client.join(id, new JoinRequest("four"));
client.start(id);
Thread.sleep(1000); Thread.sleep(1000);
} }
......
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.9</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
<commons.version>1.0.5</commons.version> <commons.version>1.0.5</commons.version>
</properties> </properties>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment