adding README and almost done .. i hope

ajs248 [2001-12-07 09:04:49]
adding README and almost done .. i hope
Filename
GateKeeper.java
Habitat.java
README
ServiceInterface.java
Treaty.java
portal/HabitatPortal.java
services/.AmTrakServiceList
services/.NYPDServiceList
services/.TexasServiceList
services/EventService.java
services/MapService.java
services/NYCPassListService.java
services/ResidentsListService.java
diff --git a/GateKeeper.java b/GateKeeper.java
index dcf9357..352713e 100644
--- a/GateKeeper.java
+++ b/GateKeeper.java
@@ -18,17 +18,18 @@ public class GateKeeper implements Notifiable {
 	static private final Hashtable currServiceReqList = new Hashtable();
 	static private String sienaMaster = "senp://canal.psl.cs.columbia.edu:31331";
   static HierarchicalDispatcher hd = null;
+  static String myDescription = "Gatekeeper";

 	public GateKeeper(Habitat h, String sm) {
 		masterHabitat = h;
 		summits_list = new Hashtable();
 		// connect to siena
-		// Alpa : will read senp host from properties file
+    myDescription += "_" + masterHabitat.getName();
 		hd = new HierarchicalDispatcher();
     try {
       if (sm != null) sienaMaster = sm;
       hd.setMaster(sienaMaster);
-      System.out.println(": master is " + sienaMaster);
+      // masterHabitat.log(": master is " + sienaMaster);
     } catch (siena.InvalidSenderException ihe) {
       ihe.printStackTrace();
     } catch (IOException ioe) {
@@ -47,10 +48,10 @@ public class GateKeeper implements Notifiable {

   public void notify(Notification[] e) {}
   public void notify(Notification n) {
-    System.out.println("GateKeeper: recevied " + n);
+    masterHabitat.log("GateKeeper: recevied ");
     AttributeValue rav = n.getAttribute("EventType");
     if (rav == null) {
-			System.out.println("Received a null attribute for: EventType");
+			masterHabitat.log("Received a null attribute for: EventType");
 			return;
 		}

@@ -69,7 +70,7 @@ public class GateKeeper implements Notifiable {
   private static final String TOTALRETVALS = "totalRetvals";

 	public void broadcast_req(String clientService, String serverService, Hashtable h) {
-    System.out.println("GateKeeper: broadcast_req for " + serverService);
+    masterHabitat.log("GateKeeper: broadcast_req for " + serverService);
     // maintain local reference to hashTable: h
     currServiceReqList.put(clientService, h);

@@ -83,7 +84,7 @@ public class GateKeeper implements Notifiable {
 		n.putAttribute(CLIENT_S, clientService);

 		try {
-      System.out.println("GateKeeper: broadcasting: " + n);
+      masterHabitat.log("GateKeeper: broadcasting: ");
       // send out event
 			hd.publish(n);
 		} catch (siena.SienaException se) {
@@ -100,7 +101,7 @@ public class GateKeeper implements Notifiable {
 	}

   public void processServiceRequest(Notification n) {
-    System.out.println("GateKeeper: processServiceRequest " + n);
+    masterHabitat.log(myDescription + ":: processing a Service Request ");
 		// do some simple security clearance
 		// assign an ID number
 		// create a new treaty and add it to the list of sumits
@@ -125,7 +126,10 @@ public class GateKeeper implements Notifiable {
     av = n.getAttribute(TOTALRETVALS);
 		if (av != null)	totalRetvals = av.intValue(); 	// total return values

+    masterHabitat.log("Service Request for -> " + serverService + " from -> " + clientHabitat);
+    masterHabitat.localService("Security Check on " + clientHabitat);
     if(allowed(clientHabitat, clientService)) {
+      masterHabitat.localService("Security Check Cleared on " + clientHabitat);
 			// send a +ve response
 			int ID = getNextID();
 			res_notif.putAttribute("habitatName", clientHabitat);
@@ -155,6 +159,9 @@ public class GateKeeper implements Notifiable {
 				if (av != null) retvals.add(av.stringValue());
 			}

+      masterHabitat.localService("Negotiating with " + clientHabitat);
+      masterHabitat.localService("New Treaty and Summit ID created for " + clientHabitat);
+
       Treaty t = null;
       summits_list.put(new Integer(ID),
                        t = new Treaty(serverService, clientService, ID,
@@ -186,7 +193,7 @@ public class GateKeeper implements Notifiable {
 	}

   public void processResponse2ServiceRequest(Notification n) {
-    System.out.println("GateKeeper: processResponse2ServiceRequest " + n);
+    masterHabitat.log( myDescription + " :: Recieved Response2ServiceRequest");
     AttributeValue av = n.getAttribute("Access");
     int ID;
     if (av != null) {
@@ -196,6 +203,7 @@ public class GateKeeper implements Notifiable {
           ID = av.intValue();
           String clientHabService = n.getAttribute(CLIENT_S).stringValue();
           String serverHabService = n.getAttribute(SERVER_S).stringValue();
+          masterHabitat.log( myDescription + " :: Allowed access to " + serverHabService);

           Hashtable oldHash = (Hashtable) currServiceReqList.get(clientHabService);
           String serverHabitat = oldHash.get("habitatCategory") + "";
@@ -208,23 +216,26 @@ public class GateKeeper implements Notifiable {
           for (int i=1; i<=totalParams; i++) params.add(oldHash.get("params" + i));
           for (int i=1; i<=totalRetvals; i++) retvals.add(oldHash.get("retvals" + i));

+          masterHabitat.log( myDescription + " :: Creating New Treaty ");
           Treaty t = null;
           summits_list.put(new Integer(ID),
                            t = new Treaty(serverHabService, clientHabService, ID,
                                       serverHabitat, masterHabitat.getName(),
                                       params, retvals));

-t.printIPList(); t.printOPList();
+          // t.printIPList(); t.printOPList();
           // treaty created, now notify requesting habService
           Hashtable newHash
             = masterHabitat.getService(clientHabService).performService(serverHabService, null);

+          masterHabitat.log( myDescription + "Notifying Service " + clientHabService + "to start using Remote Service " + serverHabService);
+
           n = new siena.Notification();
           for (Enumeration e = newHash.keys(); e.hasMoreElements(); ) {
             String key = e.nextElement().toString();
             if (t.valid_ip_param(key) || t.valid_op_param(key))
               n.putAttribute(key, "" + newHash.get(key));
-            else System.out.println("Invalid IP");
+            else masterHabitat.log("Invalid IP");
           }
           n.putAttribute("CurrentSummitID", ID + "_" + serverHabService);

@@ -233,7 +244,7 @@ t.printIPList(); t.printOPList();
           new FilterThread(hd, f1, new SummitHandler(serverHabService, clientHabService, t, this)).start();

           try {
-            System.out.println("GateKeeper: publishing: " + n);
+            masterHabitat.log("GateKeeper: publishing: ");
             // send out to server
             hd.publish(n);
           } catch (SienaException se) {
@@ -242,7 +253,7 @@ t.printIPList(); t.printOPList();

         } else { /* nothing */ }
       } else {
-        System.out.println("Access Denied");
+        masterHabitat.log("Access Denied");
         // masterHabitat.notifyService(); .. wake up the service waiting for this failure notification
       }
       // response to the service request
@@ -250,7 +261,7 @@ t.printIPList(); t.printOPList();
       // save the ID number recieved by the remote GK
       // notify the service to start using the service
     } else { /* nothing */ }
-    System.out.println("GateKeeper: processResponse2ServiceRequest ended: " + n);
+    masterHabitat.log("GateKeeper: processResponse2ServiceRequest ended: ");
   }

 	class SummitHandler implements Notifiable {
@@ -266,7 +277,7 @@ t.printIPList(); t.printOPList();
 		}
   	public void notify(Notification n[]) {}
   	public void notify(Notification n) {
-      System.out.println("SummitHandler: notify " + n);
+      masterHabitat.log("SummitHandler: notify ");
       // need validation in here

       Notification send_notif = new Notification();
@@ -287,25 +298,32 @@ t.printIPList(); t.printOPList();
         }
       }

-      treaty.printIPList(); treaty.printOPList();
+      masterHabitat.log(treaty.printIPList());
+      masterHabitat.log(treaty.printOPList());
       if (! terminateSummit) {
         ServiceInterface sInf = masterHabitat.getService(localService);
         Hashtable newHash = sInf.performService(treaty.serverHabService, retvals);
-
+
         send_notif = new siena.Notification();
-        for (Enumeration e = newHash.keys(); e.hasMoreElements(); ) {
-          String key = e.nextElement().toString();
-          if (treaty.valid_ip_param(key) || treaty.valid_op_param(key)) {
-            send_notif.putAttribute(key, "" + newHash.get(key));
-          } else {
-// System.out.println("SummitHandler: here, terminating, " + key);
-            send_notif.clear();
-            send_notif.putAttribute("Terminate Summit" , "Invalid number of retvals");
-			  	  break;
+        boolean isResultNull = false;
+
+        if (newHash == null) {
+          send_notif.clear();
+          send_notif.putAttribute("Terminate Summit" , "Nothing to be returned");
+        } else {
+          for (Enumeration e = newHash.keys(); e.hasMoreElements(); ) {
+            String key = e.nextElement().toString();
+            if (treaty.valid_ip_param(key) || treaty.valid_op_param(key)) {
+              send_notif.putAttribute(key, "" + newHash.get(key));
+            } else {
+            // masterHabitat.log("SummitHandler: here, terminating, " + key);
+              send_notif.clear();
+              send_notif.putAttribute("Terminate Summit" , "Invalid number of retvals");
+			    	  break;
+            }
           }
         }
       }
-
       send_notif.putAttribute("CurrentSummitID", treaty.getID() + "_" + targetService);
       try {
         // send out to server
diff --git a/Habitat.java b/Habitat.java
index a568ee4..58fd25d 100644
--- a/Habitat.java
+++ b/Habitat.java
@@ -3,10 +3,14 @@ package psl.habitats;
 import java.io.*;
 import java.util.*;

+import psl.habitats.portal.HabitatPortal;
+

 public class Habitat {
   String roleName, category;
   Hashtable serviceObjects;
+  HabitatPortal hp = null;
+
 	public final GateKeeper gk;
   public Habitat(String name, String c, String file, String sienaMaster) {
 		roleName = name;
@@ -42,13 +46,14 @@ public class Habitat {
 				// ad.cf_add("Started sevice " + s.getDescription()+ "\n");
         System.out.println("Started sevice " + s.getDescription()+ "\n");

-        s.startDisplay();
+        // s.startDisplay();

       } catch (Exception ex) {
 				ex.printStackTrace();
 	    }
 		}
-
+
+    hp = new HabitatPortal(name, serviceObjects.elements());
   }
 	public String getName() {
 		return roleName;
@@ -62,6 +67,9 @@ public class Habitat {
   static public boolean localService(String servDes) {
     return false;
   }
+  public void log(String msg) {
+    hp.log(msg);
+  }

   private static void usage() {
     System.out.println("java psl.habitats.Habitat <habName> <habCategory> [-sl <file>] [-sm <uri>]");
diff --git a/README b/README
new file mode 100644
index 0000000..a802772
--- /dev/null
+++ b/README
@@ -0,0 +1,11 @@
+NOTE : ServiceList for any habitat is in the services directory !
+Step 1: Start Siena
+	java -cp siena-1.2.0.jar siena.StartServer -host canal -port 31331
+
+Step 2: Start the Amtrak and Texas services
+	java psl.habitats.Habitat AmTrak NYCTransitHabitat  -sl .AmTrakServiceList -sm senp://canal:31331
+	java psl.habitats.Habitat Texas TexasStateHabitat -sl .TexasServiceList -sm senp://canal:31331
+
+Step 3: Start the NYPD Habitat
+	java psl.habitats.Habitat NYPD NYPD -sl .NYPDServiceList -sm senp://canal:31331
+
diff --git a/ServiceInterface.java b/ServiceInterface.java
index 53e799a..7580139 100644
--- a/ServiceInterface.java
+++ b/ServiceInterface.java
@@ -1,14 +1,13 @@
 package psl.habitats;

-import siena.*;
-
-import java.util.Vector;
+import javax.swing.JPanel;
 import java.util.Hashtable;

 public interface ServiceInterface {
   public void initialize(Habitat _h);
   public String getDescription();
-	public void startDisplay();
+	public JPanel startDisplay();
+  public String getDetailDescription();
   public Hashtable performService(String _senderService, Hashtable ipList);
-	// public void startDisplay(Graphics g){}
+	// public void startDisplay(Graphics g){}
 }
diff --git a/Treaty.java b/Treaty.java
index 8f01d90..51c3de0 100644
--- a/Treaty.java
+++ b/Treaty.java
@@ -61,12 +61,13 @@ class Treaty {
 	}
 
  //////////////////////////////////////////////////////
 	// 				functions for printing
-	//////////////////////////////////////////////////////
  public void printIPList() {
-    System.out.println(" Printing IP List ==> ");
-    for (Enumeration e = allowed_params.elements(); e.hasMoreElements(); )
-      System.out.println(" .. " + e.nextElement());
  }
-  public void printOPList() {
    System.out.println(" Printing OP List ==> ");
-    for (Enumeration e = allowed_retvals.elements(); e.hasMoreElements(); )
-      System.out.println(" .. " + e.nextElement());
  }
-
+	//////////////////////////////////////////////////////
  public String printIPList() {
    StringBuffer sb = new StringBuffer(" Printing IP List ==> ");
+    if (allowed_retvals.size() > 0) {
      for (Enumeration e = allowed_params.elements(); e.hasMoreElements(); )
+        sb.append(" .. " + e.nextElement());
+    }
+    return sb + "";
  }
+  public String printOPList() {
    StringBuffer sb = new StringBuffer(" Printing OP List ==> ");
+    if (allowed_retvals.size() > 0) {
    for (Enumeration e = allowed_retvals.elements(); e.hasMoreElements(); )
+      sb.append(" .. " + e.nextElement());
+    }
    return sb + "";
  }
 }
diff --git a/portal/HabitatPortal.java b/portal/HabitatPortal.java
new file mode 100644
index 0000000..ebcb987
--- /dev/null
+++ b/portal/HabitatPortal.java
@@ -0,0 +1,109 @@
+package psl.habitats.portal;
+
+import psl.habitats.ServiceInterface;
+
+import java.awt.Dimension;
+import java.awt.CardLayout;
+import java.awt.GridLayout;
+import java.awt.BorderLayout;
+
+import javax.swing.JList;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JTextArea;
+import javax.swing.JScrollPane;
+
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import java.util.Vector;
+import java.util.Hashtable;
+import java.util.Enumeration;
+
+public class HabitatPortal extends JFrame {
+  private static final int WIDTH = 800;
+  private static final int HEIGHT = 600;
+  private static final int CTRL_WIDTH = 200;
+
+  private final Hashtable _portals;
+
+  private final JPanel _mainPanel;
+  private final JPanel _ctrlPanel;
+  private final JList _servicesList;
+  private final JLabel _dataLabel;
+  private final JPanel _portalPanel;
+  private final JTextArea _logArea;
+  private final JScrollPane _logPane;
+
+  private final CardLayout _cardLayout;
+
+  public HabitatPortal(String habitatName, Enumeration services) {
+
+    // Data struRctures ///////////////////////////////////////////////////
+    _portals = new Hashtable();
+
+    // GUI stuff /////////////////////////////////////////////////////////
+    setTitle(habitatName);
+    setSize(HabitatPortal.WIDTH, HabitatPortal.HEIGHT);
+    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+    _mainPanel = new JPanel(new BorderLayout());
+    _ctrlPanel = new JPanel(new GridLayout(2, 1, 5, 5));
+    _dataLabel = new JLabel("");
+    _portalPanel = new JPanel(_cardLayout = new CardLayout());
+    _logPane = new JScrollPane(_logArea = new JTextArea("some text", 8, 10));
+    _logArea.setEditable(false);
+
+    if (services != null) {
+      Vector servicesListing = new Vector();
+      while (services.hasMoreElements()) {
+        ServiceInterface si = (ServiceInterface) services.nextElement();
+        String serviceDesc = si.getDescription();
+        servicesListing.add(serviceDesc);
+        _portalPanel.add(si.startDisplay(), serviceDesc);
+
+        _portals.put(serviceDesc, si);
+      }
+      _servicesList = new JList(servicesListing.toArray());
+    } else _servicesList = new JList(new String[] { "hello", "there" });
+
+    _servicesList.addListSelectionListener(new ListSelectionListener() {
+      public void valueChanged(ListSelectionEvent lse) {
+        String service = "" + _servicesList.getSelectedValue();
+        try {
+          _dataLabel.setText(generateHTML(_portals.get(service)));
+          _cardLayout.show(_portalPanel, service);
+        } catch (Exception e) { }
+      }
+    });
+
+    _mainPanel.add(_ctrlPanel, BorderLayout.WEST);
+    _mainPanel.add(_portalPanel, BorderLayout.CENTER);
+    _mainPanel.add(_logPane, BorderLayout.SOUTH);
+
+    _ctrlPanel.add(_servicesList);
+    _ctrlPanel.add(new JScrollPane(_dataLabel));
+    _ctrlPanel.setMinimumSize(new Dimension(CTRL_WIDTH, HEIGHT));
+
+    getContentPane().add(_mainPanel);
+    show();
+  }
+
+  public void updatePortal(String key) {
+    _cardLayout.show(_portalPanel, key);
+  }
+  public void log(String msg) {
+    _logArea.append(msg + "\n");
+  }
+
+  private String generateHTML(Object o) {
+    if (o instanceof ServiceInterface)
+      return ((ServiceInterface) o).getDetailDescription();
+    else return "INVALID";
+  }
+
+  public static void main(String args[]) {
+    new HabitatPortal("HabitatPortal", null);
+  }
+}
\ No newline at end of file
diff --git a/services/.AmTrakServiceList b/services/.AmTrakServiceList
index df47176..b13831a 100644
--- a/services/.AmTrakServiceList
+++ b/services/.AmTrakServiceList
@@ -1 +1,2 @@
 NYC_Passengers_Query,psl.habitats.services.NYCPassListService
+AlertService,psl.habitats.services.AlertService
diff --git a/services/.NYPDServiceList b/services/.NYPDServiceList
index ec99e44..b3386f7 100644
--- a/services/.NYPDServiceList
+++ b/services/.NYPDServiceList
@@ -1,2 +1,3 @@
 Maps,psl.habitats.services.MapService
 EventListener,psl.habitats.services.EventService
+AlertService,psl.habitats.services.AlertService
diff --git a/services/.TexasServiceList b/services/.TexasServiceList
index 403a054..9dd876e 100644
--- a/services/.TexasServiceList
+++ b/services/.TexasServiceList
@@ -1 +1,2 @@
 TexasResidentInfo,psl.habitats.services.ResidentsListService
+AlertService,psl.habitats.services.AlertService
diff --git a/services/EventService.java b/services/EventService.java
index 239299a..2ef024f 100644
--- a/services/EventService.java
+++ b/services/EventService.java
@@ -1,188 +1,224 @@
-package psl.habitats.services;
-import psl.habitats.*;
-
-import java.util.Vector;
-import java.util.Hashtable;
-import java.util.Enumeration;
-
-public class EventService implements ServiceInterface {
-  String myDescription = "Event_Manager";
-  Habitat masterHabitat = null;
-
-  private final Hashtable informationCatalogue = new Hashtable();
-
-  private static final String key1 = "First_Name";
-  private static final String key2 = "Last_Name";
-  private static final String key3 = "Boarding_City";
-  private static final String key4 = "Boarding_Date";
-  private static final String key5 = "Address";
-  private static final String key6 = "Telephone";
-  private static final String key7 = "SSN";
-  private static final String key8 = "Image";
-  private static final String key9 = "Age";
-
-  public void initialize(Habitat _h){
-    masterHabitat = _h;
-  }
-  public String getDescription(){
-    return myDescription;
-  }
-	public void startDisplay(){
-    // start the GUI here
-    phaseOne();
-  }
-
-  private static final String PHASE_ONE_PEER = "NYC_Passengers_Query";
-  private static final String PHASE_TWO_PEER = "TexasResidentInfo";
-  private static final String PHASE_THREE_PEER = "AlertService";
-
-  int phaseOneProgress = 0, phaseTwoProgress = 0, phaseThreeProgress = 0;
-
-  private String hashtableListing(Hashtable h) {
-    StringBuffer sb = new StringBuffer("");
-    for (Enumeration e = h.keys(); e.hasMoreElements(); ) {
-      String key = "" + e.nextElement();
-      sb.append("key: " + key + ", val: " + h.get(key));
-    }
-    return "" + sb;
-  }
-  public Hashtable performService(String _senderService, Hashtable ipList) {
-    System.out.println(myDescription + ": performService - " + _senderService);
-    Hashtable result = new Hashtable();
-    if(_senderService.equals(PHASE_ONE_PEER)) {
-      System.out.println(": performService :: PHASE_ONE_PEER" + phaseOneProgress);
-      switch (phaseOneProgress) {
-      case 0:
-        result.put(key1, "Alpa");
-        phaseOneProgress++;
-        break;
-
-      case 1:
-        for (Enumeration e=ipList.keys(); e.hasMoreElements(); ) {
-          String key = e.nextElement().toString();
-          informationCatalogue.put(key, ipList.get(key));
-        }
-        result.put("Terminate_Session", "SESSION_ENDED");
-        phaseOneProgress = 0;
-
-        // initiate phase-II
-        phaseTwo();
-        break;
-
-      }
-
-    } else if(_senderService.equals(PHASE_TWO_PEER)) {
-      System.out.println(": performService :: PHASE_TWO_PEER" + phaseTwoProgress);
-      switch (phaseTwoProgress) {
-      case 0:
-        result.put(key1, informationCatalogue.get(key1));
-        result.put(key2, informationCatalogue.get(key2));
-        phaseTwoProgress++;
-        break;
-
-      case 1:
-        for (Enumeration e=ipList.keys(); e.hasMoreElements(); ) {
-          String key = e.nextElement().toString();
-          informationCatalogue.put(key, ipList.get(key));
-        }
-        result.put("Terminate_Session", "SESSION_ENDED");
-        phaseTwoProgress = 0;
-
-        // initiate phase-III
-        phaseThree();
-        break;
-
-      }
-    } else if(_senderService.equals(PHASE_THREE_PEER)) {
-      System.out.println(": performService :: PHASE_THREE_PEER" + phaseThreeProgress);
-      switch (phaseThreeProgress) {
-      case 0:
-        for (Enumeration e=informationCatalogue.keys(); e.hasMoreElements(); ) {
-          String key = e.nextElement().toString();
-          if (key.equals(key3) || key.equals(key4)) continue;
-          result.put(key, informationCatalogue.get(key));
-        }
-        phaseThreeProgress++;
-        break;
-
-      case 1:
-        phaseThreeProgress = 0;
-        result.put("Terminate_Session", "SESSION_ENDED");
-        break;
-
-      }
-    }
-
-    System.out.println(myDescription + ": performService, returning: " + hashtableListing(result));
-    return result;
-  }
-  private void phaseOne() {
-    // invoked by user entering chor's name
-    // some intelligent workflow suggested that service to be contacted
-    System.out.println(myDescription + ": phaseOne");
-    String useService = "NYC_Passengers_Query";
-    if (!Habitat.localService(useService)) {
-      Hashtable ipList = new Hashtable();
-      ipList.put("habitatCategory","NYCTransitHabitat");
-      ipList.put("EventType","ServiceRequest");
-      ipList.put("Request4Service", useService);
-      ipList.put("totalParams","1");
-      ipList.put("params1", key1);
-      ipList.put("totalRetvals", "4");
-      ipList.put("retvals1", key1);
-      ipList.put("retvals2", key2);
-      ipList.put("retvals3", key3);
-      ipList.put("retvals4", key4);
-
-      masterHabitat.gk.broadcast_req(myDescription, useService, ipList);
-    }
-    System.out.println(myDescription + ": phaseOne, returned");
-  }
-
-  private void phaseTwo() {
-    System.out.println(myDescription + ": phaseTwo");
-    String useService = "TexasResidentInfo";
-    if (!Habitat.localService(useService)) {
-      Hashtable ipList = new Hashtable();
-      ipList.put("habitatCategory","TexasStateHabitat");
-      ipList.put("EventType","ServiceRequest");
-      ipList.put("Request4Service", useService);
-      ipList.put("totalParams","2");
-      ipList.put("params1", key1);
-      ipList.put("params2", key2);
-      ipList.put("totalRetvals", "5");
-      ipList.put("retvals1", key5);
-      ipList.put("retvals2", key6);
-      ipList.put("retvals3", key7);
-      ipList.put("retvals4", key8);
-      ipList.put("retvals5", key9);
-
-      masterHabitat.gk.broadcast_req(myDescription, useService, ipList);
-    }
-    System.out.println(myDescription + ": phaseTwo, returned");
-  }
-
-  private void phaseThree() {
-    System.out.println(myDescription + ": phaseThree");
-    String useService = "AlertService";
-    if (!Habitat.localService(useService)) {
-      Hashtable ipList = new Hashtable();
-      ipList.put("habitatCategory","NYCTransitHabitat");
-      ipList.put("EventType","ServiceRequest");
-      ipList.put("Request4Service", useService);
-      ipList.put("totalParams","2");
-      ipList.put("params1", key1);
-      ipList.put("params2", key2);
-      ipList.put("params3", key5);
-      ipList.put("params4", key6);
-      ipList.put("params5", key7);
-      ipList.put("params6", key8);
-      ipList.put("params7", key9);
-      ipList.put("totalRetvals", "0");
-
-      masterHabitat.gk.broadcast_req(myDescription, useService, ipList);
-    }
-    System.out.println(myDescription + ": phaseThree, returned");
+package psl.habitats.services;
+import psl.habitats.*;
+
+import java.awt.*;
+import java.awt.event.*;
import javax.swing.*;
+
+import java.util.Vector;
+import java.util.Hashtable;
+import java.util.Enumeration;
+
+public class EventService implements ServiceInterface {
+  String myDescription = "Event_Manager";
+  Habitat masterHabitat = null;
+
+  private final Hashtable informationCatalogue = new Hashtable();
+
+  private static final String key1 = "First_Name";
+  private static final String key2 = "Last_Name";
+  private static final String key3 = "Boarding_City";
+  private static final String key4 = "Boarding_Date";
+  private static final String key5 = "Address";
+  private static final String key6 = "Telephone";
+  private static final String key7 = "SSN";
+  private static final String key8 = "Age";
+  private static final String key9 = "Image";
+
+  public void initialize(Habitat _h){
+    masterHabitat = _h;
+  }
+  public String getDescription() {
+    return myDescription;
+  }
+  public String getDetailDescription(){
+    StringBuffer _stringBuffer = new StringBuffer();
+    _stringBuffer.setLength(0);
+    _stringBuffer.append("<html><body>");
+    _stringBuffer.append("<h1>" + getDescription() + "</h1>");
+    _stringBuffer.append("<table border=4>");
+    _stringBuffer.append("<tr><td>Purpose</td><td>Receive and Update Events </td></tr>");
+    _stringBuffer.append("<tr><td>Availablity</td><td>Local</td></tr>");
+    _stringBuffer.append("<tr><td>Monitor</td><td>True</td></tr>");
+    _stringBuffer.append("<tr><td>Monitor-Mode</td><td>Text</td></tr>");
+    _stringBuffer.append("</table>");
+    _stringBuffer.append("</body></html>");
+    return _stringBuffer + "";
   }

-}
+  private String phaseOneData;
+	public JPanel startDisplay(){
+    // start the GUI here
+    final JPanel panel = new JPanel(new BorderLayout());
    final JLabel label = new JLabel("Enter name: ");
+    final JTextField text = new JTextField(20);
    JButton button = new JButton("Search");
+    final JPanel panel2 = new JPanel(new BorderLayout());
    panel2.add(label, BorderLayout.WEST);
+    panel2.add(text, BorderLayout.CENTER); 
    panel2.add(button, BorderLayout.EAST);
+
+    panel.add(panel2, BorderLayout.NORTH);
    panel.add(new JLabel("" +
+                         "<html><body>" +
                         "Enter: <input><br>" +
                         "</body></html>"
                         ), BorderLayout.CENTER);
    button.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent ae) {
        phaseOneData = text.getText();
        phaseOne();
+      }
    });
    return panel;
+  }
+
+  private static final String PHASE_ONE_PEER = "NYC_Passengers_Query";
+  private static final String PHASE_TWO_PEER = "TexasResidentInfo";
+  private static final String PHASE_THREE_PEER = "AlertService";
+
+  int phaseOneProgress = 0, phaseTwoProgress = 0, phaseThreeProgress = 0;
+
+  private String hashtableListing(Hashtable h) {
+    StringBuffer sb = new StringBuffer("");
+    for (Enumeration e = h.keys(); e.hasMoreElements(); ) {
+      String key = "" + e.nextElement();
+      sb.append("key: " + key + ", val: " + h.get(key));
+    }
+    return "" + sb;
+  }
+  public Hashtable performService(String _senderService, Hashtable ipList) {
+    Hashtable result = new Hashtable();
+    if(_senderService.equals(PHASE_ONE_PEER)) {
+      masterHabitat.log(myDescription + " :: PHASE_ONE_PEER " + PHASE_ONE_PEER);
+      switch (phaseOneProgress) {
+      case 0:
+        result.put(key1, phaseOneData);
+        phaseOneProgress++;
+        break;
+
+      case 1:
+        for (Enumeration e=ipList.keys(); e.hasMoreElements(); ) {
+          String key = e.nextElement().toString();
+          informationCatalogue.put(key, ipList.get(key));
+        }
+        masterHabitat.log(myDescription + ":: Terminating Session with " + PHASE_TWO_PEER);
+        result.put("Terminate_Session", "SESSION_ENDED");
+        phaseOneProgress = 0;
+
+        // initiate phase-II
+        phaseTwo();
+        break;
+
+      }
+
+    } else if(_senderService.equals(PHASE_TWO_PEER)) {
+      masterHabitat.log(myDescription + ":: PHASE_TWO_PEER " + PHASE_TWO_PEER);
+      switch (phaseTwoProgress) {
+      case 0:
+        result.put(key1, informationCatalogue.get(key1));
+        result.put(key2, informationCatalogue.get(key2));
+        phaseTwoProgress++;
+        break;
+
+      case 1:
+        for (Enumeration e=ipList.keys(); e.hasMoreElements(); ) {
+          String key = e.nextElement().toString();
+          informationCatalogue.put(key, ipList.get(key));
+        }
+        result.put("Terminate_Session", "SESSION_ENDED");
+				masterHabitat.log(myDescription + " Terminating Session with " + PHASE_TWO_PEER);
+        phaseTwoProgress = 0;
+
+        // initiate phase-III
+        phaseThree();
+        break;
+
+      }
+    } else if(_senderService.equals(PHASE_THREE_PEER)) {
+      masterHabitat.log(myDescription + ":: PHASE_THREE_PEER" + PHASE_THREE_PEER);
+      switch (phaseThreeProgress) {
+      case 0:
+        for (Enumeration e=informationCatalogue.keys(); e.hasMoreElements(); ) {
+          String key = e.nextElement().toString();
+          if (key.equals(key3) || key.equals(key4)) continue;
+          result.put(key, informationCatalogue.get(key));
+          // masterHabitat.log("$$$$$$$$Sending this " + key);
+        }
+        phaseThreeProgress++;
+        break;
+
+      case 1:
+        phaseThreeProgress = 0;
+				masterHabitat.log(myDescription + " Terminating Session with " + PHASE_THREE_PEER);
+        result.put("Terminate_Session", "SESSION_ENDED");
+        break;
+      }
+    }
+
+    masterHabitat.log(myDescription + ": performService, returning: " + hashtableListing(result));
+    return result;
+  }
+  private void phaseOne() {
+		masterHabitat.log(myDescription + " Received some new Info - processing it .. ");
+		masterHabitat.log(myDescription + " Number of Steps Suggested -> 3 ");
+    masterHabitat.log(myDescription + " Entering Phase One ");
+		masterHabitat.log(myDescription + " Need to gather information on 'NYC Passengers'" );
+		masterHabitat.log(myDescription + " Contact Habitat -> 'NYCTransitHabitat'");
+		masterHabitat.log(myDescription + " Contact Service -> 'NYC_Passengers_Query'");
+
+    // invoked by user entering chor's name
+    // some intelligent workflow suggested that service to be contacted
+    String useService = "NYC_Passengers_Query";
+    if(!Habitat.localService(useService)) {
+      Hashtable ipList = new Hashtable();
+      ipList.put("habitatCategory","NYCTransitHabitat");
+      ipList.put("EventType","ServiceRequest");
+      ipList.put("Request4Service", useService);
+      ipList.put("totalParams","1");
+      ipList.put("params1", key1);
+      ipList.put("totalRetvals", "4");
+      ipList.put("retvals1", key1);
+      ipList.put("retvals2", key2);
+      ipList.put("retvals3", key3);
+      ipList.put("retvals4", key4);
+
+      masterHabitat.gk.broadcast_req(myDescription, useService, ipList);
+			masterHabitat.log(myDescription + " Requesting Gatekeeper to contact Remote Service");
+    }
+    masterHabitat.log(myDescription + ": phaseOne, returned");
+  }
+
+  private void phaseTwo() {
+    masterHabitat.log(myDescription + ": phaseTwo");
+    String useService = "TexasResidentInfo";
+    if (!Habitat.localService(useService)) {
+      Hashtable ipList = new Hashtable();
+      ipList.put("habitatCategory","TexasStateHabitat");
+      ipList.put("EventType","ServiceRequest");
+      ipList.put("Request4Service", useService);
+      ipList.put("totalParams","2");
+      ipList.put("params1", key1);
+      ipList.put("params2", key2);
+      ipList.put("totalRetvals", "5");
+      ipList.put("retvals1", key5);
+      ipList.put("retvals2", key6);
+      ipList.put("retvals3", key7);
+      ipList.put("retvals4", key8);
+      ipList.put("retvals5", key9);
+
+      masterHabitat.gk.broadcast_req(myDescription, useService, ipList);
+    }
+    masterHabitat.log(myDescription + ": phaseTwo, returned");
+  }
+
+  private void phaseThree() {
+    masterHabitat.log(myDescription + ": phaseThree");
+    String useService = "AlertService";
+    if (!Habitat.localService(useService)) {
+      Hashtable ipList = new Hashtable();
+      ipList.put("habitatCategory","NYCTransitHabitat");
+      ipList.put("EventType","ServiceRequest");
+      ipList.put("Request4Service", useService);
+      ipList.put("totalParams","7");
+      ipList.put("params1", key1);
+      ipList.put("params2", key2);
+      ipList.put("params3", key5);
+      ipList.put("params4", key6);
+      ipList.put("params5", key7);
+      ipList.put("params6", key8);
+      ipList.put("params7", key9);
+      ipList.put("totalRetvals", "0");
+
+      masterHabitat.gk.broadcast_req(myDescription, useService, ipList);
+    }
+    masterHabitat.log(myDescription + ": phaseThree, returned");
+  }
+
+}
diff --git a/services/MapService.java b/services/MapService.java
index f9655f4..f81321e 100644
--- a/services/MapService.java
+++ b/services/MapService.java
@@ -2,6 +2,7 @@ package psl.habitats.services;

 import psl.habitats.*;

+import javax.swing.*;
 import java.util.Hashtable;

 public class MapService implements ServiceInterface {  
  private static String serviceDescription = "MapService";
@@ -10,7 +11,25 @@ public class MapService implements ServiceInterface {  
  private static String
   public String getDescription() {
     return serviceDescription;
   }
-  public void startDisplay() { }
+  public JPanel startDisplay() {
+    return new JPanel();
+  }
+
+  public String getDetailDescription(){
+    StringBuffer _stringBuffer = new StringBuffer();
+    _stringBuffer.setLength(0);
+    _stringBuffer.append("<html><body>");
+    _stringBuffer.append("<h1>" + getDescription() + "</h1>");
+    _stringBuffer.append("<table border=4>");
+    _stringBuffer.append("<tr><td>Purpose</td><td>Maps Database</td></tr>");
+    _stringBuffer.append("<tr><td>Availablity</td><td>Not available</td></tr>");
+    _stringBuffer.append("<tr><td>Monitor</td><td>Probably</td></tr>");
+    _stringBuffer.append("<tr><td>Monitor-Mode</td><td>NA</td></tr>");
+    _stringBuffer.append("</table>");
+    _stringBuffer.append("</body></html>");
+  return _stringBuffer + "";
+  }
+
   public Hashtable performService(String _senderService, Hashtable ipList) {
     return null;
   }
diff --git a/services/NYCPassListService.java b/services/NYCPassListService.java
index a552350..efeab7f 100644
--- a/services/NYCPassListService.java
+++ b/services/NYCPassListService.java
@@ -1,6 +1,8 @@
 package psl.habitats.services;
 import psl.habitats.*;

+import javax.swing.*;
+
 import java.util.Date;
 import java.util.Vector;
 import java.util.Hashtable;
@@ -14,7 +16,24 @@ public class NYCPassListService implements ServiceInterface {
   public String getDescription(){
     return myDescription;
   }
-  public void startDisplay() { }
+  public JPanel startDisplay() {
+    return new JPanel();
+  }
+
+  public String getDetailDescription(){
+    StringBuffer _stringBuffer = new StringBuffer();
+    _stringBuffer.setLength(0);
+    _stringBuffer.append("<html><body>");
+    _stringBuffer.append("<h1>" + getDescription() + "</h1>");
+    _stringBuffer.append("<table border=4>");
+    _stringBuffer.append("<tr><td>Purpose     </td><td>AmTrak Passenger List</td></tr>");
+    _stringBuffer.append("<tr><td>Availablity </td><td>Local/Remote         </td></tr>");
+    _stringBuffer.append("<tr><td>Monitor     </td><td>True                 </td></tr>");
+    _stringBuffer.append("<tr><td>Monitor-Mode</td><td>Text                 </td></tr>");
+    _stringBuffer.append("</table>");
+    _stringBuffer.append("</body></html>");
+    return _stringBuffer + "";
+  }

   private static final String key1 = "First_Name";
   private static final String key2 = "Last_Name";
@@ -22,7 +41,7 @@ public class NYCPassListService implements ServiceInterface {
   private static final String key4 = "Boarding_Date";

   public Hashtable performService(String _senderService, Hashtable ipList) {
-    System.out.println(myDescription + ": performService");
+    masterHabitat.log(myDescription + ": performService for " + _senderService);
     Hashtable result = new Hashtable();
     if(ipList.containsKey(key1) || ipList.containsKey(key2)){
       result.put(key1, lookup(key1, masterHabitat.getName()));
@@ -31,7 +50,7 @@ public class NYCPassListService implements ServiceInterface {
       result.put(key4, lookup(key4, masterHabitat.getName()));
     } else
       result = null;
-    System.out.println(myDescription + ": performService, returning: " + result);
+    masterHabitat.log(myDescription + ": returning requested Data ");
     return result;
   }

@@ -39,9 +58,9 @@ public class NYCPassListService implements ServiceInterface {
   private String lookup(String key, String forHab) {
     if (forHab.equals(HABITAT_NAME)) {
       if (key.equals(key1))
-        return ("Alpa");
+        return ("John");
       else if (key.equals(key2))
-        return ("Shah");
+        return ("Salasin");
       else if(key.equals(key3))
         return ("Texas");
       else if (key.equals(key4))
diff --git a/services/ResidentsListService.java b/services/ResidentsListService.java
index 9968245..3a32b0c 100644
--- a/services/ResidentsListService.java
+++ b/services/ResidentsListService.java
@@ -1,6 +1,8 @@
 package psl.habitats.services;
 import psl.habitats.*;

+import javax.swing.*;
+
 import java.util.Vector;
 import java.util.Hashtable;

@@ -14,8 +16,24 @@ public class ResidentsListService implements ServiceInterface {
   public String getDescription() {
     return myDescription;
   }
-	public void startDisplay(){}
-
+  public JPanel startDisplay() {
+    return new JPanel();
+  }
+  public String getDetailDescription(){
+    StringBuffer _stringBuffer = new StringBuffer();
+    _stringBuffer.setLength(0);
+    _stringBuffer.append("<html><body>");
+    _stringBuffer.append("<h1>" + getDescription() + "</h1>");
+    _stringBuffer.append("<table border=4>");
+    _stringBuffer.append("<tr><td>Purpose</td><td>Texas Residents Credentials </td></tr>");
+    _stringBuffer.append("<tr><td>Availablity</td><td>Local/Remote</td></tr>");
+    _stringBuffer.append("<tr><td>Monitor</td><td>True</td></tr>");
+    _stringBuffer.append("<tr><td>Monitor-Mode</td><td>Text</td></tr>");
+    _stringBuffer.append("</table>");
+    _stringBuffer.append("</body></html>");
+    return _stringBuffer + "";
+  }
+
   private static final String key1 = "First_Name";
   private static final String key2 = "Last_Name";
   private static final String key5 = "Address";
@@ -25,36 +43,45 @@ public class ResidentsListService implements ServiceInterface {
   private static final String key9 = "Age";

   public Hashtable performService(String _senderService, Hashtable ipList) {
-    System.out.println(myDescription + ": performService");
+    masterHabitat.log(myDescription + ": performService for " + _senderService);
     Hashtable result = new Hashtable();
     if (ipList.containsKey(key1) && ipList.containsKey(key2)) {
-      result.put(key5, lookup(key5, masterHabitat.getName()));
-      result.put(key6, lookup(key6, masterHabitat.getName()));
-      result.put(key7, lookup(key7, masterHabitat.getName()));
-      result.put(key8, lookup(key8, masterHabitat.getName()));
-      result.put(key9, lookup(key9, masterHabitat.getName()));
+      result.put(key5, lookup(key1, key5, masterHabitat.getName()));
+      result.put(key6, lookup(key1, key6, masterHabitat.getName()));
+      result.put(key7, lookup(key1, key7, masterHabitat.getName()));
+      result.put(key8, lookup(key1, key8, masterHabitat.getName()));
+      result.put(key9, lookup(key1, key9, masterHabitat.getName()));
     } else
       result = null;
-    System.out.println(myDescription + ": performService, returning: " + result);
+    masterHabitat.log(myDescription + ": returning requested data ");
     return result;
   }

   private static final String HABITAT_NAME = "Texas";
-  private String lookup(String key, String forHab) {
-    if(forHab.equals(HABITAT_NAME)) {
-      if (key.equals(key5))
-        return ("608 CEPSR");
-      else if (key.equals(key6))
-        return "7184";
-      else if (key.equals(key7))
-        return "987-65-4321";
-      else if (key.equals(key8))
-        return "http://www.web.com/picture.jpg";
-      else if (key.equals(key9))
-        return "17";
-      else
-        return null;
-    } else
-      return null;
+  private String lookup(String key1, String key, String forHab) {
+    if (forHab.equals(HABITAT_NAME)) {
+      if (key1.equalsIgnoreCase("john")) return "" + johnHash.get(key);
+      if (key1.equalsIgnoreCase("gail")) return "" + gailHash.get(key);
+    }
+    return null;
+  }
+  private static final Hashtable gailHash = new Hashtable();
+  private static final Hashtable johnHash = new Hashtable();
+  static {
+    gailHash.put(key1, "Gail");
+    gailHash.put(key2, "Kaiser");
+    gailHash.put(key5, "New Jersey");
+    gailHash.put(key6, "(212) 939-7100");
+    gailHash.put(key7, "123-45-6789");
+    gailHash.put(key8, "http://www.psl.cs.columbia.edu/personnel/gail.jpg");
+    gailHash.put(key9, "18");
+
+    johnHash.put(key1, "John");
+    johnHash.put(key2, "Salasin");
+    johnHash.put(key5, "DARPA");
+    johnHash.put(key6, "(800) SAL-ASIN");
+    johnHash.put(key7, "987-65-4321");
+    johnHash.put(key8, "http://www.darpa.mil/ito/images/mr-logo.gif");
+    johnHash.put(key9, "18");
   }
 }