提交 6da808a0 编写于 作者: L liquidsnake@sapo.pt

In this commit, it was fixed a bug on the comuniation system that would make...

In this commit, it was fixed a bug on the comuniation system that would make the clients freeze  after the removal of a replica
上级 fed574db
......@@ -209,6 +209,7 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
//if (!(e.getCause() instanceof ClosedChannelException) && !(e.getCause() instanceof ConnectException)) {
System.out.println("Excepção no CS (client side)!");
e.getCause().printStackTrace();
//}
}
......@@ -257,17 +258,24 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
// Set up the default event pipeline.
bootstrap.setPipelineFactory(new NettyClientPipelineFactory(this, true, sessionTable, authKey, macDummy.getMacLength(), manager, rl, TOMUtil.getSignatureSize(manager), new ReentrantLock()));
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(manager.getRemoteAddress(ncss.getReplicaId()));
//******* EDUARDO END **************//
if (manager.getRemoteAddress(ncss.getReplicaId()) != null) {
ChannelFuture future = bootstrap.connect(manager.getRemoteAddress(ncss.getReplicaId()));
//******* EDUARDO END **************//
//creates MAC stuff
Mac macSend = ncss.getMacSend();
Mac macReceive = ncss.getMacReceive();
NettyClientServerSession cs = new NettyClientServerSession(future.getChannel(), macSend, macReceive, ncss.getReplicaId(), manager.getStaticConf().getRSAPublicKey(ncss.getReplicaId()), new ReentrantLock());
sessionTable.remove(ncss.getReplicaId());
sessionTable.put(ncss.getReplicaId(), cs);
//System.out.println("RE-Connecting to replica "+ncss.getReplicaId()+" at " + conf.getRemoteAddress(ncss.getReplicaId()));
//creates MAC stuff
Mac macSend = ncss.getMacSend();
Mac macReceive = ncss.getMacReceive();
NettyClientServerSession cs = new NettyClientServerSession(future.getChannel(), macSend, macReceive, ncss.getReplicaId(), manager.getStaticConf().getRSAPublicKey(ncss.getReplicaId()), new ReentrantLock());
sessionTable.remove(ncss.getReplicaId());
sessionTable.put(ncss.getReplicaId(), cs);
//System.out.println("RE-Connecting to replica "+ncss.getReplicaId()+" at " + conf.getRemoteAddress(ncss.getReplicaId()));
} else {
// This cleans an olde server from the session table
sessionTable.remove(ncss.getReplicaId());
}
} catch (NoSuchAlgorithmException ex) {
}
}
......
......@@ -149,6 +149,7 @@ public class NettyClientServerCommunicationSystemServerSide extends SimpleChanne
public void exceptionCaught(
ChannelHandlerContext ctx, ExceptionEvent e) {
//if (!(e.getCause() instanceof ClosedChannelException))
System.out.println("Excepção no CS (server side)!");
e.getCause().printStackTrace();
}
......
......@@ -13,6 +13,7 @@ import java.io.ObjectOutputStream;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -160,7 +161,25 @@ public class TTP {
}
System.out.println("ola");
Scanner scan = new Scanner(System.in);
String str = null;
do {
str = scan.nextLine();
StringTokenizer token = new StringTokenizer(str);
String cmd = token.nextToken();
int arg = Integer.parseInt(token.nextToken());
if (cmd.equals("add")) {
int port = (arg * 10) + 11000;
ttp.addServer(arg, "127.0.0.1", port);
}
else if (cmd.equals("rem")) {
ttp.removeServer(arg);
}
ttp.executeUpdates();
} while(!str.equals("exit"));
System.exit(0);
ttp.addServer(4, "127.0.0.1", 11040);
ttp.executeUpdates();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册