Skip to content

Commit

Permalink
It seems to work with two servers
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosv5 committed Dec 2, 2017
1 parent 7840df4 commit 010eb7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions BankClient/src/es/upm/dit/cnvr/server/Barrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ boolean enter() throws KeeperException, InterruptedException{
System.out.println(size);
System.out.println(list.size());
System.out.println("Cuantos somos en la barrera enter: " + list.size());
if (list.size() < size ) {
System.out.println("Condicion: " + zk.exists("/boperationleave", false)!= null);
if (list.size() < size && zk.exists("/boperationleave", false)== null) {
synchronized (mutexBarrier) {
System.out.println("While antes del wait barrier.java");
System.out.println("He hecho wait con el mutexBarrier: " + System.identityHashCode(mutexBarrier));
Expand Down Expand Up @@ -130,10 +131,16 @@ boolean leave() throws KeeperException, InterruptedException{
while (true) {
List<String> list = zk.getChildren(root, true);
System.out.println("Cuantos somos en la barrera leave: " + list.size());

Stat stat = zk.exists("/boperationleave", false);
System.out.println("STAT ES: " + stat);
if (list.size() > 0) {
synchronized (mutexBarrier) {
mutexBarrier.wait(1000);
if(stat == null){
zk.create("/boperationleave", new byte[0],
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
System.out.println("SOY EL PRIMERO Y ESTOY CREANDO EL NODO DE SALIDA");
}
}
} else {
System.out.println("Leave");
Expand Down
15 changes: 15 additions & 0 deletions BankClient/src/es/upm/dit/cnvr/server/ProcessOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,28 @@ public Transaction readData(byte[] data) throws IOException, ClassNotFoundExcept
public void run() {
System.out.println("¡¡¡¡Empiezo el run en ProcessOperation.java!!!!");
Stat s = null;

while (true) {
try {
synchronized (mutex) {
System.out.println("He hecho wait con el mutexOperate (en ProcessOperation.java): " + System.identityHashCode(mutex));
mutex.wait();
System.out.println("SALE DEL wait con el mutexOperate (en ProcessOperation.java)");
}
Stat stat = null;
try {
stat = zk.exists("/boperationleave", false);
System.out.println("STAT ES: " + stat);
if(stat != null){
zk.delete("/boperationleave", 0);
}
} catch (KeeperException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("¡¡¡¡Empiezo el *WHILE* en ProcessOperation.java!!!!");
List<String> listOperation = zk.getChildren(rootOperation, false, null);
int size = listOperation.size();
Expand Down

0 comments on commit 010eb7b

Please sign in to comment.