Skip to content

Commit

Permalink
fix master config
Browse files Browse the repository at this point in the history
  • Loading branch information
LotfiYacine committed May 17, 2019
1 parent ee9db6b commit e3910c8
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 56 deletions.
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
sudo: required

language: java

jdk:
- openjdk8

env:
DOCKER_COMPOSE_VERSION: 1.20.1
DOCKER_COMPOSE_VERSION: 1.24.0

services:
- docker
- docker

script:
- cd serveur && docker build -f Dockerfile -t serveur .
- cd ../joueur && docker build -f Dockerfile -t joueur .
- docker-compose up -d
- docker-compose ps
- cd serveur && docker build -f Dockerfile -t serveur .
- cd ../joueur && docker build -f Dockerfile -t joueur .
- docker-compose ps
- docker-compose up -d
15 changes: 11 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
version: '3'
version: '3.3'
services:

serveur:
image: serveur
restart: always
ports:
- "8080:8080"
- "8080:8080"
networks:
- network1


joueur:
image: joueur
restart: always
ports:
- "8081:8081"

- "8081:8081"
depends_on:
- serveur
networks:
- network1

networks:
network1:
18 changes: 0 additions & 18 deletions joueur/src/main/java/joueur/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@ public class Controller {
@Autowired
IAPanda iaPanda;

/*
private LinkedHashMap<Integer, LinkedHashMap<Integer, IAPanda>> listPlayer = new LinkedHashMap<>();
@RequestMapping(path = "/newPlayer")
public String launch() {
IAPanda iaPanda = new IAPanda();
int[] tab = iaPanda.connect();
System.out.println("new player connecté à la partie num : " + tab[0] + " en tant que joueur : " + tab[1]);
if (listPlayer.get(tab[0]) != null) {
listPlayer.get(tab[0]).put(tab[1], iaPanda);
} else {
listPlayer.put(tab[0], new LinkedHashMap<>());
listPlayer.get(tab[0]).put(tab[1], iaPanda);
}
iaPanda.launch();
return "done";
}
*/
@PostMapping(value = "/{id}/{idPlayer}/Joue")
public String Joue(@PathVariable(value = "id") int id, @PathVariable(value = "idPlayer") int idPlayer) {
//listPlayer.get(id).get(idPlayer).joue();
Expand Down
9 changes: 6 additions & 3 deletions joueur/src/main/java/joueur/ia/IAPanda.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
Expand All @@ -36,15 +37,17 @@ public IAPanda() {
LOGGER.setLevel(Level.OFF);
}


/**
* Cet événement est exécuté le plus tard possible pour indiquer
* que l'application est prête à repondre aux demandes.
*/
@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {
int[] tab = connect("127.0.0.1", "8080", "127.0.0.1", "8081");
System.out.println("new player connecté à la partie num : " + tab[0] + " en tant que joueur : " + tab[1]);
try {
int[] tab = connect("172.18.0.2", "8080", InetAddress.getLocalHost().getHostAddress(), "8081");
System.out.println("new player connecté à la partie num : " + tab[0] + " en tant que joueur : " + tab[1]);
} catch (Exception e) {
}
launch();
}

Expand Down
4 changes: 1 addition & 3 deletions joueur/src/main/java/joueur/service/impl/ClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
@Service
public class ClientService implements IClientService {

// private String REST_SERVICE_URI = "http://192.168.99.100:8080";

private String REST_SERVICE_URI = "http://";

private RestTemplate restTemplate = new RestTemplate();

private String REST_SERVICE_URI_ID_JOUEUR = "http://";
//private String REST_SERVICE_URI_ID_JOUEUR = "http://192.168.99.100:8080";

@Override
public ArrayList<Parcelle> piocher() {
return restTemplate.exchange(
Expand Down
19 changes: 17 additions & 2 deletions joueur/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
server.address=127.0.0.1
server.port= 8081
server.port=8081
#The maximum queue length for incoming connection requests when all possible request
#processing threads are in use. Any requests received when the queue is full will be refused.
#The default value is 100.
server.tomcat.accept-count=10000
#The maximum number of request processing threads to be created by this Connector,
#which therefore determines the maximum number of simultaneous requests that can be handled.
#If not specified, this attribute is set to 200.
server.tomcat.max-threads=10000
#The number of request processing threads that will be created when this Connector is first started.
#The connector will also make sure it has the specified number of idle processing threads available.
#This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.
server.tomcat.min-spare-threads=50
# number of I/O threads to create for the worker
server.undertow.io-threads=8
# number of worker threads = io * 8
server.undertow.worker-threads=64
31 changes: 13 additions & 18 deletions serveur/src/main/java/serveur/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,27 @@

@RestController
public class Controller {
int nbjoueur=1;

private LinkedHashMap<Integer, Takenoko> listParti = new LinkedHashMap<>();
int nbjoueur = 2;

@GetMapping(value = "/init")
public String init() {
listParti.clear();
listParti.put(0, new Takenoko());
listParti.get(0).initPartie();
listParti.get(0).getListPlayer().add(new StatistiqueJoueur(0, 0, 0, 0, "joueurTest","http://localhost:8080"));
listParti.get(0).getListPlayer().add(new StatistiqueJoueur(0, 0, 0, 0, "joueurTest", "http://localhost:8080"));
return "init done";
}

@GetMapping(value = "/{joueurHost}/{joueurPort}/{namePlayer}/Connect")
public int[] connect(@PathVariable(value = "joueurHost") String joueurHost,@PathVariable(value = "joueurPort") String joueurPort,@PathVariable(value = "namePlayer") String namePlayer) {
public int[] connect(@PathVariable(value = "joueurHost") String joueurHost, @PathVariable(value = "joueurPort") String joueurPort, @PathVariable(value = "namePlayer") String namePlayer) {
synchronized (listParti) {
int[] tab = new int[2];
if (listParti.isEmpty()) {
int numGame;
do {
numGame = new Random().nextInt(5000);

} while (listParti.get(numGame) != null);
int numGame = listParti.size() + 1;
int numPlayer = 0;
listParti.put(numGame, new Takenoko());
listParti.get(numGame).getListPlayer().add(new StatistiqueJoueur(numPlayer, 0, 0, 0, namePlayer,"http://"+joueurHost+":"+joueurPort));
listParti.get(numGame).getListPlayer().add(new StatistiqueJoueur(numPlayer, 0, 0, 0, namePlayer, "http://" + joueurHost + ":" + joueurPort));
System.out.println("new Game");
System.out.println("ID partie | id joueur | nom joueur");
System.out.println(numGame + " | " + numPlayer + " | " + namePlayer);
Expand All @@ -54,7 +49,7 @@ public int[] connect(@PathVariable(value = "joueurHost") String joueurHost,@Path
Integer numGame = entry.getKey();
if (game.getListPlayer().size() < nbjoueur) {
int numPlayer = game.getListPlayer().size();
game.getListPlayer().add(new StatistiqueJoueur(numPlayer, 0, 0, 0, namePlayer,"http://"+joueurHost+":"+joueurPort));
game.getListPlayer().add(new StatistiqueJoueur(numPlayer, 0, 0, 0, namePlayer, "http://" + joueurHost + ":" + joueurPort));
System.out.println(numGame + " | " + numPlayer + " | " + namePlayer);
tab[0] = numGame;
tab[1] = numPlayer;
Expand All @@ -64,14 +59,10 @@ public int[] connect(@PathVariable(value = "joueurHost") String joueurHost,@Path
}
}
if (noGame) {
int numGame;
do {
numGame = new Random().nextInt(5000);

} while (listParti.get(numGame) != null);
int numGame = listParti.size() + 1;
int numPlayer = 0;
listParti.put(numGame, new Takenoko());
listParti.get(numGame).getListPlayer().add(new StatistiqueJoueur(numPlayer, 0, 0, 0, namePlayer,"http://"+joueurHost+":"+joueurPort));
listParti.get(numGame).getListPlayer().add(new StatistiqueJoueur(numPlayer, 0, 0, 0, namePlayer, "http://" + joueurHost + ":" + joueurPort));
System.out.println("new Game");
System.out.println("ID partie | id joueur | nom joueur");
System.out.println(numGame + " | " + numPlayer + " | " + namePlayer);
Expand All @@ -86,12 +77,16 @@ public int[] connect(@PathVariable(value = "joueurHost") String joueurHost,@Path

@PostMapping(path = "/{id}/launch")
public void launch(@PathVariable(value = "id") int id) {
boolean start = false;
synchronized (listParti) {
if (listParti.get(id).getListPlayer().size() == nbjoueur && !listParti.get(id).getDejaLancer()) {
listParti.get(id).setDejaLancer(true);
listParti.get(id).lancerParti(listParti.get(id).getListPlayer(), id);
start = true;
}
}
if (start) {
listParti.get(id).lancerParti(listParti.get(id).getListPlayer(), id);
}
}

@GetMapping(value = "/{id}/GetZoneJouee")
Expand Down
19 changes: 17 additions & 2 deletions serveur/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
server.address=127.0.0.1
server.port= 8080
server.port=8080
#The maximum queue length for incoming connection requests when all possible request
#processing threads are in use. Any requests received when the queue is full will be refused.
#The default value is 100.
server.tomcat.accept-count=10000
#The maximum number of request processing threads to be created by this Connector,
#which therefore determines the maximum number of simultaneous requests that can be handled.
#If not specified, this attribute is set to 200.
server.tomcat.max-threads=10000
#The number of request processing threads that will be created when this Connector is first started.
#The connector will also make sure it has the specified number of idle processing threads available.
#This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.
server.tomcat.min-spare-threads=50
# number of I/O threads to create for the worker
server.undertow.io-threads=8
# number of worker threads = io * 8
server.undertow.worker-threads=64

0 comments on commit e3910c8

Please sign in to comment.