Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic Ranger for TokenRing

  • Loading branch information...
commit 5d3f1a90d497fe03fbe068206a7174947295973d 1 parent 6a5b1e9
@pksunkara authored
Showing with 62 additions and 10 deletions.
  1. +1 −10 LamportClock/Ranger.java
  2. +61 −0 TokenRing/Ranger.java
View
11 LamportClock/Ranger.java
@@ -10,8 +10,8 @@
private static Clock clock;
private static Socket pentagonSocket;
- private static ObjectInputStream pentagonInput;
private static ObjectOutputStream pentagonOutput;
+ private static ObjectInputStream pentagonInput;
private static OtherClient otherClientList[] = new OtherClient[2];
private static OtherClientThread otherClientThreadList[] = new OtherClientThread[2];
@@ -83,15 +83,6 @@ private static void requestQueueInsert(Request r) {
requestQueue = tmp;
}
-// private static void printRequestQueue() {
-// System.out.println("RQ:");
-// for(int i=0; i<3; i++) {
-// if(requestQueue[i]!=null) {
-// System.out.println("\t"+i+" "+requestQueue[i].nodePort+" "+requestQueue[i].timeStamp);
-// }
-// }
-// }
-
private static void requestQueueRelease(int n) {
Request tmp[] = new Request[3];
for(int i=0, j=0; i<3; i++) {
View
61 TokenRing/Ranger.java
@@ -0,0 +1,61 @@
+import java.io.*;
+import java.util.*;
+import java.net.*;
+
+public class Ranger {
+ private static String nodeName;
+ private static String port;
+ private static FileWriter fileStream;
+
+ private static Socket pentagonSocket;
+ private static ObjectOutputStream pentagonOutput;
+ private static ObjectInputStream pentagonInput;
+
+ private static OtherClient otherClientList[] = new OtherClient[2];
+ private static OtherClientThread otherClientThreadList[] = new OtherClientThread[2];
+
+ public static void main(String[] args) throws Exception {
+ if(args.length!=3) {
+ System.out.println("Usage: Ranger <codename> <host> <port>");
+ System.exit(1);
+ }
+ nodeName = args[0];
+ port = args[2];
+
+ pentagonSocket = new Socket(args[1], 5000);
+ pentagonOutput = new ObjectOutputStream(pentagonSocket.getOutputStream());
+ pentagonInput = new ObjectInputStream(pentagonSocket.getInputStream());
+
+ pentagonOutput.writeObject("Ranger " + nodeName + " ready to proceed.");
+ pentagonOutput.writeObject(port);
+
+ 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("Agent " + nodeName + " reporting, Mission Accomplished.");
+ pentagonInput.readObject();
+
+ pentagonInput.close();
+ pentagonOutput.close();
+ pentagonSocket.close();
+ }
+
+ private static void report(String msg) throws Exception {
+ fileStream = new FileWriter("report", true);
+ 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();
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.