Skip to content

Commit

Permalink
This worked 3 times with you servers
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosv5 committed Dec 2, 2017
1 parent 6d06729 commit 7840df4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
27 changes: 7 additions & 20 deletions BankClient/src/es/upm/dit/cnvr/server/Barrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,16 @@ boolean enter() throws KeeperException, InterruptedException{
List<String> list = zk.getChildren(root, true);
System.out.println(size);
System.out.println(list.size());
List<String> boperationList = null;
boperationList = zk.getChildren(root+"leave", true);
if (list.size() < size && boperationList.size()==0) {
System.out.println("Cuantos somos en la barrera enter: " + list.size());
if (list.size() < size ) {
synchronized (mutexBarrier) {
System.out.println("While antes del wait barrier.java");
System.out.println("He hecho wait con el mutexBarrier: " + System.identityHashCode(mutexBarrier));
mutexBarrier.wait();
mutexBarrier.wait(1000);
System.out.println("While tras el wait barrier.java");
}
} else {
System.out.println("ESTADO T: " + boperationList.size());
boperationList = zk.getChildren(root+"leave", true);
if (boperationList.size()==0) {
System.out.println("*********************** SE ESTA CREANDO EL NODO LEAVE **************");
zk.create(root+"leave/nodo", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.EPHEMERAL);
}
System.out.println("Enter");
return true;
}
}
Expand All @@ -134,22 +127,16 @@ boolean leave() throws KeeperException, InterruptedException{
System.out.println("Start leave barrier");
zk.delete(nodoB, 0);
System.out.println("He borrado el nodoB: " + nodoB);
List<String> boperationList = zk.getChildren(root+"leave", true);
System.out.println("Leave");
System.out.println("La lista de "+ root+"leave"+" es: " + boperationList);
System.out.println("El size de boperationleave es: " + boperationList.size());
while (true) {
List<String> list = zk.getChildren(root, true);
System.out.println("Cuantos somos en la barrera leave: " + list.size());

if (list.size() > 0) {
synchronized (mutexBarrier) {
mutexBarrier.wait();
mutexBarrier.wait(1000);
}
} else {
if (boperationList.size()>0) {
System.out.println("DELETING AUXILIAR NODE");
zk.delete(root+"leave/nodo", 0);
}
System.out.println("Leave");
return true;
}
}
Expand Down
5 changes: 2 additions & 3 deletions BankClient/src/es/upm/dit/cnvr/server/ProcessBarrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ProcessBarrier extends Thread {

private List<String> listBarriersP = null;
private int npBarriers = 0;
private String rootBarrier = "/b1";
private String rootBarrier = "/boperation";
private ZooKeeper zk;
private Watcher barrierWatcherP;
private Integer mutex;
Expand All @@ -35,9 +35,8 @@ public void run() {
synchronized (mutex) {
mutex.wait();
}
System.out.println("Recargando el watcher del barrier cuando ha saltado");
listBarriersP = zk.getChildren(rootBarrier, barrierWatcherP, s);
npBarriers ++;
//System.out.println("Process Barrier. NBarriers: " + npBarriers);
} catch (Exception e) {
System.out.println("Unexpected Exception process barrier");
break;
Expand Down
6 changes: 1 addition & 5 deletions BankClient/src/es/upm/dit/cnvr/server/ZookeeperObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ public void configure() {
getZk().create(rootBarrier, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
}
Stat sp = getZk().exists("/boperationleave", false);
if (sp == null) {
getZk().create("/boperationleave", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
}

// getZk().create(rootBarrier, new byte[0],
// Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
Expand Down Expand Up @@ -310,6 +305,7 @@ else if (event.getPath().equals(rootBarrier)) {
synchronized (mutexBarrier) {
nBarriers ++;
System.out.println("BW: NBarriers: " + nBarriers);
Thread.sleep(6000);
mutexBarrier.notifyAll();
System.out.println("He hecho notify con el mutexBarrier: " + System.identityHashCode(mutexBarrier));
}
Expand Down

0 comments on commit 7840df4

Please sign in to comment.