Permalink
Browse files

Added timestamp and change name for threadList

  • Loading branch information...
1 parent cdbe30e commit cc9a7b35a718f9485a160a7dd3a4f03a3eb84073 @pksunkara committed Sep 16, 2011
Showing with 17 additions and 6 deletions.
  1. +17 −6 LamportClock/Ranger.java
View
@@ -6,13 +6,14 @@
private static String nodeName;
private static FileWriter fileStream;
private static ServerThread serverThread;
+ private static Clock clock;
private static Socket pentagonSocket;
private static ObjectInputStream pentagonInput;
private static ObjectOutputStream pentagonOutput;
private static OtherClient otherClientList[] = new OtherClient[2];
- private static OtherClientThread otherClientListThread[] = new OtherClientThread[2];
+ private static OtherClientThread otherClientThreadList[] = new OtherClientThread[2];
public static void main(String[] args) throws Exception {
if(args.length!=2) {
@@ -33,7 +34,9 @@ public static void main(String[] args) throws Exception {
for(int i=0; i<2; i++)
otherClientList[i] = new OtherClient();
for(int i=0; i<2; i++)
- otherClientListThread[i] = new OtherClientThread(otherClientList[i]);
+ otherClientThreadList[i] = new OtherClientThread(otherClientList[i]);
+
+ clock = new Clock();
report("Initialising mission SuperSecret!");
report("Hacking the uber super computer!");
@@ -46,7 +49,7 @@ public static void main(String[] args) throws Exception {
pentagonSocket.close();
for(int i=0; i<2; i++)
- otherClientListThread[i].thread.join();
+ otherClientThreadList[i].thread.join();
serverThread.thread.join();
}
@@ -57,6 +60,14 @@ private static void report(String msg) throws Exception {
Thread.sleep(2000);
}
+ private static class Clock {
+ public synchronized int timeStamp;
+
+ public Clock() throws Exception {
+ timeStamp = 0;
+ }
+ }
+
private static class OtherClient {
private String string;
private Socket client;
@@ -138,7 +149,7 @@ private void closeStreams() throws Exception {
private ServerSocket server;
public Thread thread;
public Client clientList[] = new Client[2];
- public ClientThread clientListThread[] = new ClientThread[2];
+ public ClientThread clientThreadList[] = new ClientThread[2];
public ServerThread(String port) throws Exception {
server = new ServerSocket(Integer.parseInt(port));
@@ -154,9 +165,9 @@ public void run() {
clientList[i] = new Client(client);
}
for(int i=0; i<2; i++)
- clientListThread[i] = new ClientThread(clientList[i]);
+ clientThreadList[i] = new ClientThread(clientList[i]);
for(int i=0; i<2; i++)
- clientListThread[i].thread.join();
+ clientThreadList[i].thread.join();
server.close();
} catch (Exception e) {
e.printStackTrace();

0 comments on commit cc9a7b3

Please sign in to comment.