Permalink
Browse files

Basic Ranger.java which has no synchronisation

  • Loading branch information...
pksunkara committed Sep 15, 2011
1 parent a7348a1 commit 13aee78b4cba9917e13b08b545cbfb78c7143e30
Showing with 31 additions and 6 deletions.
  1. +0 −2 LamportClock/Agent.java
  2. +28 −1 LamportClock/Ranger.java
  3. +3 −3 LamportClock/report_agent
View
@@ -8,7 +8,6 @@
private static Socket pentagonSocket;
private static ObjectOutputStream pentagonOutput;
private static ObjectInputStream pentagonInput;
-
private static OtherClient otherClientList[] = new OtherClient[2];
public static void main(String[] args) throws Exception {
@@ -31,7 +30,6 @@ public static void main(String[] args) throws Exception {
report("Initialising mission SuperSecret!");
report("Hacking the uber super computer!");
report("Finishing mission SuperSecret!");
-
pentagonOutput.writeObject("Agent " + nodeName + " reporting, Mission Accomplished.");
pentagonInput.close();
View
@@ -5,6 +5,10 @@
public class Ranger {
private static String nodeName;
private static FileWriter fileStream;
+ private static Socket pentagonSocket;
+ private static ObjectOutputStream pentagonOutput;
+ private static ObjectInputStream pentagonInput;
+ private static OtherClient otherClientList[] = new OtherClient[2];
public static void main(String[] args) throws Exception {
if(args.length!=2) {
@@ -13,15 +17,38 @@ public static void main(String[] args) throws Exception {
}
nodeName = args[0];
+ pentagonSocket = new Socket("localhost", 5000);
+ pentagonOutput = new ObjectOutputStream(pentagonSocket.getOutputStream());
+ pentagonInput = new ObjectInputStream(pentagonSocket.getInputStream());
+
+ pentagonOutput.writeObject("Ranger " + nodeName + " ready to proceed.");
+ pentagonOutput.writeObject(args[1]);
+
+ for(int i=0; i<2; i++)
+ otherClientList[i] = new OtherClient();
+
report("Initialising mission SuperSecret!");
report("Hacking the uber super computer!");
report("Finishing mission SuperSecret!");
+ pentagonOutput.writeObject("Ranger " + nodeName + " reporting, Mission Accomplished.");
+
+ pentagonInput.close();
+ pentagonOutput.close();
+ pentagonSocket.close();
}
private static void report(String msg) throws Exception {
fileStream = new FileWriter("report", true);
- fileStream.write(nodeName + "" + msg + "\n");
+ fileStream.write("Ranger " + nodeName + "" + msg + "\n");
fileStream.close();
Thread.sleep(2000);
}
+
+ private static class OtherClient {
+ private String string;
+
+ public OtherClient() throws Exception {
+ string = (String)pentagonInput.readObject();
+ }
+ }
}
@@ -1,14 +1,14 @@
Pentagon → Agent alpha ready to proceed.
Pentagon → Agent beta ready to proceed.
Pentagon → Agent charlie ready to proceed.
-Agent beta → Initialising mission SuperSecret!
Agent charlie → Initialising mission SuperSecret!
+Agent beta → Initialising mission SuperSecret!
Agent alpha → Initialising mission SuperSecret!
-Agent beta → Hacking the uber super computer!
Agent charlie → Hacking the uber super computer!
+Agent beta → Hacking the uber super computer!
Agent alpha → Hacking the uber super computer!
-Agent beta → Finishing mission SuperSecret!
Agent charlie → Finishing mission SuperSecret!
+Agent beta → Finishing mission SuperSecret!
Agent alpha → Finishing mission SuperSecret!
Pentagon → Agent beta reporting, Mission Accomplished.
Pentagon → Agent charlie reporting, Mission Accomplished.

0 comments on commit 13aee78

Please sign in to comment.