Janak's fixes to the gui :)

jjp32 [2001-12-07 22:26:10]
Janak's fixes to the gui :)
Filename
GateKeeper.java
portal/HabitatPortal.java
services/AlertService.java
services/EventService.java
diff --git a/GateKeeper.java b/GateKeeper.java
index 352713e..0e27ad1 100644
--- a/GateKeeper.java
+++ b/GateKeeper.java
@@ -1,372 +1 @@
-package psl.habitats;
-import java.io.*;
-import java.util.Iterator;
-import java.util.Enumeration;
-import java.util.Vector;
-import java.util.Hashtable;
-import siena.*;
-import org.omg.CosNaming.*;
-import org.omg.CosNaming.NamingContextPackage.*;
-import org.omg.CORBA.*;
-
-// Alpa : need to replace the siena Notification with a generalised service descritpion
-// Alpa: need to add someway of removing treaty when recieved BYE
-
-public class GateKeeper implements Notifiable {
-	static private Habitat masterHabitat;
-	static private Hashtable summits_list;
-	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
-    myDescription += "_" + masterHabitat.getName();
-		hd = new HierarchicalDispatcher();
-    try {
-      if (sm != null) sienaMaster = sm;
-      hd.setMaster(sienaMaster);
-      // masterHabitat.log(": master is " + sienaMaster);
-    } catch (siena.InvalidSenderException ihe) {
-      ihe.printStackTrace();
-    } catch (IOException ioe) {
-      ioe.printStackTrace();
-    }
-    Filter filter = null;
-
-    filter = new Filter();
-    filter.addConstraint("habitatCategory", masterHabitat.getCategory());
-    new FilterThread(hd, filter, this).start();
-
-    filter = new Filter();
-    filter.addConstraint("habitatName", masterHabitat.getName());
-    new FilterThread(hd, filter, this).start();
-  }
-
-  public void notify(Notification[] e) {}
-  public void notify(Notification n) {
-    masterHabitat.log("GateKeeper: recevied ");
-    AttributeValue rav = n.getAttribute("EventType");
-    if (rav == null) {
-			masterHabitat.log("Received a null attribute for: EventType");
-			return;
-		}
-
-		String av = rav.stringValue();
-
-    if(av.equals("ServiceRequest")) {
-			processServiceRequest(n);
-    } else if(av.equals("Response2ServiceRequest")) {
-			processResponse2ServiceRequest(n);
-    }
-	}
-
-  private static final String SERVER_S = "ServerService";
-  private static final String CLIENT_S = "ClientService";
-  private static final String TOTALPARAMS = "totalParams";
-  private static final String TOTALRETVALS = "totalRetvals";
-
-	public void broadcast_req(String clientService, String serverService, Hashtable h) {
-    masterHabitat.log("GateKeeper: broadcast_req for " + serverService);
-    // maintain local reference to hashTable: h
-    currServiceReqList.put(clientService, h);
-
-    Notification n = new siena.Notification();
-    for (Enumeration e=h.keys(); e.hasMoreElements(); ) {
-      String key = e.nextElement().toString();
-      n.putAttribute(key, "" + h.get(key));
-    }
-		n.putAttribute("source", masterHabitat.getName());
-		n.putAttribute(SERVER_S, serverService);
-		n.putAttribute(CLIENT_S, clientService);
-
-		try {
-      masterHabitat.log("GateKeeper: broadcasting: ");
-      // send out event
-			hd.publish(n);
-		} catch (siena.SienaException se) {
-			se.printStackTrace();
-		}
-	}
-
-  private boolean allowed(String _sName, String _sDesc) {
-    return true;
-  }
-
-	private int getNextID() {
-		return (int) (Math.random() * 1000);
-	}
-
-  public void processServiceRequest(Notification 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
-		// if security cleared create a proxy of the service object
-
-		String clientHabitat = null, clientService = null, serverService = null;
-		int totalParams = 0, totalRetvals = 0;
-		Notification res_notif = new Notification();
-
-		AttributeValue av = n.getAttribute("source");
-		if (av != null) clientHabitat = av.stringValue();
-
-    av = n.getAttribute(CLIENT_S);
-		if (av != null) clientService = av.stringValue();
-
-    av = n.getAttribute(SERVER_S);
-		if (av != null) serverService = av.stringValue();
-
-    av = n.getAttribute(TOTALPARAMS);
-		if (av != null) totalParams = av.intValue();		// total parameters
-
-    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);
-			res_notif.putAttribute("EventType", "Response2ServiceRequest");
-			res_notif.putAttribute("Access", "Allowed");			// could have used ID only but just in case
-			res_notif.putAttribute("Treaty", "AcceptedAll");
-			/* AcceptAll = all the ip_params and op_params sent in the
-			*  request were allowed. OR
-			*  New Treaty = the new treaty description follows thsi event
-			*  that gives a new description of the ip_params and the op_params
-			*  currently only AcceptAll implemented
-			*/
-			res_notif.putAttribute(CLIENT_S, clientService);
-			res_notif.putAttribute(SERVER_S, serverService);
-			res_notif.putAttribute("ID", ID);
-
-			Vector params = new Vector();
-			Vector retvals = new Vector();
-
-      for (int i=1; i<=totalParams; i++) {
-				av = n.getAttribute("params" + i);
-				if (av != null) params.add(av.stringValue());
-			}
-
-			for (int i=1; i<=totalRetvals; i++) {
-				av = n.getAttribute("retvals" + i);
-				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,
-                                  clientHabitat, masterHabitat.getName(),
-                                  params, retvals));
-
-      Filter f1 = new Filter();
-      f1.addConstraint("CurrentSummitID", ID + "_" + serverService);
-      new FilterThread(hd, f1, new SummitHandler(clientService, serverService, t, this)).start();
-
-		}
-		else {
-			// send a -ve response
-			res_notif.putAttribute("habitatName", clientHabitat);
-			res_notif.putAttribute("EventType", "Response2ServiceRequest");
-			res_notif.putAttribute("Access", "Denied");
-		}
-
-		try {
-      // treaty created, now send reply to requesting habService
-			hd.publish(res_notif);
-		} catch (siena.SienaException se) {
-			se.printStackTrace();
-		}
-	}
-
-	private Vector get_IP_params_from_Notification(Notification n) {
-		return (new Vector());
-	}
-
-  public void processResponse2ServiceRequest(Notification n) {
-    masterHabitat.log( myDescription + " :: Recieved Response2ServiceRequest");
-    AttributeValue av = n.getAttribute("Access");
-    int ID;
-    if (av != null) {
-      if ((av.stringValue()).equals("Allowed")) {
-        av = n.getAttribute("ID");
-        if (av != null) {
-          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") + "";
-
-          int totalParams = Integer.parseInt("" + oldHash.get("totalParams"));
-          int totalRetvals = Integer.parseInt("" + oldHash.get("totalRetvals"));
-
-          // figure out num params/retvals
-          Vector params = new Vector(totalParams), retvals = new Vector(totalRetvals);
-          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();
-          // 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 masterHabitat.log("Invalid IP");
-          }
-          n.putAttribute("CurrentSummitID", ID + "_" + serverHabService);
-
-          Filter f1 = new Filter();
-          f1.addConstraint("CurrentSummitID", ID + "_" + clientHabService);
-          new FilterThread(hd, f1, new SummitHandler(serverHabService, clientHabService, t, this)).start();
-
-          try {
-            masterHabitat.log("GateKeeper: publishing: ");
-            // send out to server
-            hd.publish(n);
-          } catch (SienaException se) {
-            se.printStackTrace();
-          }
-
-        } else { /* nothing */ }
-      } else {
-        masterHabitat.log("Access Denied");
-        // masterHabitat.notifyService(); .. wake up the service waiting for this failure notification
-      }
-      // response to the service request
-      // create a treaty with the params
-      // save the ID number recieved by the remote GK
-      // notify the service to start using the service
-    } else { /* nothing */ }
-    masterHabitat.log("GateKeeper: processResponse2ServiceRequest ended: ");
-  }
-
-	class SummitHandler implements Notifiable {
-    final Treaty treaty;
-		final GateKeeper masterGK;
-    final String targetService;
-    final String localService;
-		public SummitHandler(String ts, String ls, Treaty _t, GateKeeper _gk) {
-      treaty = _t;
-			masterGK = _gk;
-      targetService = ts;
-      localService = ls;
-		}
-  	public void notify(Notification n[]) {}
-  	public void notify(Notification n) {
-      masterHabitat.log("SummitHandler: notify ");
-      // need validation in here
-
-      Notification send_notif = new Notification();
-      Hashtable retvals = new Hashtable();
-
-      boolean terminateSummit = false;
-      for (Iterator i = n.attributeNamesIterator(); i.hasNext(); ) {
-        String key = "" + i.next();
-        if (!key.equals("CurrentSummitID") && !key.equals("habitatCategory")) {
-          if (treaty.valid_ip_param(key) || treaty.valid_op_param(key)) {
-            retvals.put(key, n.getAttribute(key).stringValue());
-          } else {
-            send_notif.clear();
-            send_notif.putAttribute("Terminate Summit" , "Invalid number of params");
-            terminateSummit = true;
-		  		  break;
-          }
-        }
-      }
-
-      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();
-        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
-        hd.publish(send_notif);
-      } catch (SienaException se) {
-        se.printStackTrace();
-      }
-
-
-      /* Notification send_notif = new Notification();
-			send_notif.putAttribute("currentSummitID", ID);
-			Treaty currTreaty = (Treaty) masterGK.summits_list.get(new Integer(ID));
-			// check for termination by peer
-			if (send_notif.size() != currTreaty.get_IP_size()) {
-				send_notif.putAttribute("Terminate Summit" , "Invalid number of params");
-				return;
-			} else {
-				Vector ip = (Vector) currTreaty.getIPList();
-			  Hashtable forService = new Hashtable();
-			  for(int i =0; i < ip.size(); i++) {
-			  	String ip_par = (String) ip.elementAt(i);
-			  	AttributeValue av = send_notif.getAttribute(ip_par);
-			  	if (av!= null) {
-			  		forService.put(ip_par, av.stringValue()); // need to pass the list to the params
-			  	}
-			  }
-
-				// might be replaced by a lookup on a corba object
-				ServiceInterface _service = masterHabitat.getService(currTreaty.servUsed);
-				Vector result2Bsent = _service.performService(forService);
-
-				for (int _v = 0; _v < result2Bsent.size(); _v++) {
-					MyAttributeValuePair _avp = (MyAttributeValuePair) result2Bsent.elementAt(_v);
-					if (currTreaty.valid_op_param(_avp.getValue())) {
-						send_notif.putAttribute(_avp.getAttribute(), _avp.getValue());
-					}
-					else {
-						send_notif.clear();
-						send_notif.putAttribute("Terminate Summit" , "Invalid number of params");
-						// break;
-					}
-				}
-			}*/
-		}
-	}
-}
+package psl.habitats;


import java.io.*;


import java.util.Iterator;


import java.util.Enumeration;


import java.util.Vector;


import java.util.Hashtable;


import siena.*;


import org.omg.CosNaming.*;


import org.omg.CosNaming.NamingContextPackage.*;


import org.omg.CORBA.*;





// Alpa : need to replace the siena Notification with a generalised service descritpion


// Alpa: need to add someway of removing treaty when recieved BYE





public class GateKeeper implements Notifiable {


	static private Habitat masterHabitat;


	static private Hashtable summits_list; 


	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


    myDescription += "_" + masterHabitat.getName();


		hd = new HierarchicalDispatcher();


    try {


      if (sm != null) sienaMaster = sm;


      hd.setMaster(sienaMaster);


      // masterHabitat.log(": master is " + sienaMaster);


    } catch (siena.InvalidSenderException ihe) {


      ihe.printStackTrace();


    } catch (IOException ioe) {


      ioe.printStackTrace();


    }

    Runtime.getRuntime().addShutdownHook(new Thread() {
	public void run() {
	  System.err.println("Shutting down");
	  hd.shutdown();
	}
      });




    Filter filter = null;





    filter = new Filter();


    filter.addConstraint("habitatCategory", masterHabitat.getCategory());


    new FilterThread(hd, filter, this).start();


    


    filter = new Filter();


    filter.addConstraint("habitatName", masterHabitat.getName());


    new FilterThread(hd, filter, this).start();


  }


  


  public void notify(Notification[] e) {}


  public void notify(Notification n) {


    masterHabitat.log("GateKeeper: recevied ");


    AttributeValue rav = n.getAttribute("EventType");


    if (rav == null) {


			masterHabitat.log("Received a null attribute for: EventType");


			return;


		}


    


		String av = rav.stringValue();


    


    if(av.equals("ServiceRequest")) {


			processServiceRequest(n);


    } else if(av.equals("Response2ServiceRequest")) {


			processResponse2ServiceRequest(n);


    }


	}





  private static final String SERVER_S = "ServerService";


  private static final String CLIENT_S = "ClientService";


  private static final String TOTALPARAMS = "totalParams";


  private static final String TOTALRETVALS = "totalRetvals";





	public void broadcast_req(String clientService, String serverService, Hashtable h) {


    masterHabitat.log("GateKeeper: broadcast_req for " + serverService);


    // maintain local reference to hashTable: h


    currServiceReqList.put(clientService, h);


    


    Notification n = new siena.Notification();


    for (Enumeration e=h.keys(); e.hasMoreElements(); ) {


      String key = e.nextElement().toString();


      n.putAttribute(key, "" + h.get(key));


    }


		n.putAttribute("source", masterHabitat.getName());


		n.putAttribute(SERVER_S, serverService);     


		n.putAttribute(CLIENT_S, clientService);     


    


		try {


      masterHabitat.log("GateKeeper: broadcasting: ");


      // send out event


			hd.publish(n);


		} catch (siena.SienaException se) {


			se.printStackTrace();


		}


	}





  private boolean allowed(String _sName, String _sDesc) {


    return true;


  }





	private int getNextID() {


		return (int) (Math.random() * 1000);


	}





  public void processServiceRequest(Notification 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


		// if security cleared create a proxy of the service object





		String clientHabitat = null, clientService = null, serverService = null;


		int totalParams = 0, totalRetvals = 0;


		Notification res_notif = new Notification();


    


		AttributeValue av = n.getAttribute("source");


		if (av != null) clientHabitat = av.stringValue();


		


    av = n.getAttribute(CLIENT_S);


		if (av != null) clientService = av.stringValue();


		


    av = n.getAttribute(SERVER_S);


		if (av != null) serverService = av.stringValue();


		


    av = n.getAttribute(TOTALPARAMS);


		if (av != null) totalParams = av.intValue();		// total parameters


		


    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);


			res_notif.putAttribute("EventType", "Response2ServiceRequest");


			res_notif.putAttribute("Access", "Allowed");			// could have used ID only but just in case


			res_notif.putAttribute("Treaty", "AcceptedAll");	


			/* AcceptAll = all the ip_params and op_params sent in the 


			*  request were allowed. OR


			*  New Treaty = the new treaty description follows thsi event 


			*  that gives a new description of the ip_params and the op_params


			*  currently only AcceptAll implemented


			*/


			res_notif.putAttribute(CLIENT_S, clientService);


			res_notif.putAttribute(SERVER_S, serverService);


			res_notif.putAttribute("ID", ID); 


			


			Vector params = new Vector();


			Vector retvals = new Vector();





      for (int i=1; i<=totalParams; i++) {


				av = n.getAttribute("params" + i);


				if (av != null) params.add(av.stringValue());


			}


      


			for (int i=1; i<=totalRetvals; i++) {


				av = n.getAttribute("retvals" + i);


				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, 


                                  clientHabitat, masterHabitat.getName(), 


                                  params, retvals));





      Filter f1 = new Filter();


      f1.addConstraint("CurrentSummitID", ID + "_" + serverService);


      new FilterThread(hd, f1, new SummitHandler(clientService, serverService, t, this)).start();





		}


		else {


			// send a -ve response


			res_notif.putAttribute("habitatName", clientHabitat);


			res_notif.putAttribute("EventType", "Response2ServiceRequest");


			res_notif.putAttribute("Access", "Denied");


		}


    


		try {


      // treaty created, now send reply to requesting habService


			hd.publish(res_notif);


		} catch (siena.SienaException se) {


			se.printStackTrace();


		}


	}


  


	private Vector get_IP_params_from_Notification(Notification n) {


		return (new Vector());


	}


  


  public void processResponse2ServiceRequest(Notification n) {


    masterHabitat.log( myDescription + " :: Recieved Response2ServiceRequest");


    AttributeValue av = n.getAttribute("Access");


    int ID;


    if (av != null) {


      if ((av.stringValue()).equals("Allowed")) {


        av = n.getAttribute("ID");


        if (av != null) {


          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") + "";





          int totalParams = Integer.parseInt("" + oldHash.get("totalParams"));


          int totalRetvals = Integer.parseInt("" + oldHash.get("totalRetvals"));





          // figure out num params/retvals


          Vector params = new Vector(totalParams), retvals = new Vector(totalRetvals);


          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();


          // 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 masterHabitat.log("Invalid IP");


          }


          n.putAttribute("CurrentSummitID", ID + "_" + serverHabService);


          


          Filter f1 = new Filter();


          f1.addConstraint("CurrentSummitID", ID + "_" + clientHabService);


          new FilterThread(hd, f1, new SummitHandler(serverHabService, clientHabService, t, this)).start();





          try {


            masterHabitat.log("GateKeeper: publishing: ");


            // send out to server 


            hd.publish(n);


          } catch (SienaException se) {


            se.printStackTrace();


          }


          


        } else { /* nothing */ }


      } else {


        masterHabitat.log("Access Denied");


        // masterHabitat.notifyService(); .. wake up the service waiting for this failure notification


      }


      // response to the service request


      // create a treaty with the params 


      // save the ID number recieved by the remote GK


      // notify the service to start using the service


    } else { /* nothing */ }


    masterHabitat.log("GateKeeper: processResponse2ServiceRequest ended: ");


  }


	


	class SummitHandler implements Notifiable {


    final Treaty treaty;


		final GateKeeper masterGK;


    final String targetService;


    final String localService;


		public SummitHandler(String ts, String ls, Treaty _t, GateKeeper _gk) {


      treaty = _t;


			masterGK = _gk;


      targetService = ts;


      localService = ls;


		}


  	public void notify(Notification n[]) {}


  	public void notify(Notification n) {


      masterHabitat.log("SummitHandler: notify ");


      // need validation in here


      


      Notification send_notif = new Notification();


      Hashtable retvals = new Hashtable();





      boolean terminateSummit = false;


      for (Iterator i = n.attributeNamesIterator(); i.hasNext(); ) {


        String key = "" + i.next();


        if (!key.equals("CurrentSummitID") && !key.equals("habitatCategory")) {


          if (treaty.valid_ip_param(key) || treaty.valid_op_param(key)) {


            retvals.put(key, n.getAttribute(key).stringValue());            


          } else {


            send_notif.clear();


            send_notif.putAttribute("Terminate Summit" , "Invalid number of params");


            terminateSummit = true;


		  		  break;


          }


        }


      }





      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();


        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


        hd.publish(send_notif);


      } catch (SienaException se) {


        se.printStackTrace();


      }


      


      


      /* Notification send_notif = new Notification();


			send_notif.putAttribute("currentSummitID", ID);


			Treaty currTreaty = (Treaty) masterGK.summits_list.get(new Integer(ID)); 


			// check for termination by peer 


			if (send_notif.size() != currTreaty.get_IP_size()) {


				send_notif.putAttribute("Terminate Summit" , "Invalid number of params");


				return;


			} else { 


				Vector ip = (Vector) currTreaty.getIPList();


			  Hashtable forService = new Hashtable();


			  for(int i =0; i < ip.size(); i++) {


			  	String ip_par = (String) ip.elementAt(i);


			  	AttributeValue av = send_notif.getAttribute(ip_par);


			  	if (av!= null) {


			  		forService.put(ip_par, av.stringValue()); // need to pass the list to the params


			  	}


			  }





				// might be replaced by a lookup on a corba object


				ServiceInterface _service = masterHabitat.getService(currTreaty.servUsed);


				Vector result2Bsent = _service.performService(forService);





				for (int _v = 0; _v < result2Bsent.size(); _v++) {


					MyAttributeValuePair _avp = (MyAttributeValuePair) result2Bsent.elementAt(_v);


					if (currTreaty.valid_op_param(_avp.getValue())) {


						send_notif.putAttribute(_avp.getAttribute(), _avp.getValue());


					}


					else {


						send_notif.clear();


						send_notif.putAttribute("Terminate Summit" , "Invalid number of params");


						// break;


					}


				}


			}*/


		}


	}


}
\ No newline at end of file
diff --git a/portal/HabitatPortal.java b/portal/HabitatPortal.java
index ebcb987..a8de0da 100644
--- a/portal/HabitatPortal.java
+++ b/portal/HabitatPortal.java
@@ -1,109 +1 @@
-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
+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.JSplitPane;


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 static final int CTRL_HEIGHT = 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());

    _logArea = new JTextArea();
    _logPane = new JScrollPane(_logArea);


    _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);
	  validate();
        } catch (Exception e) { }
      }
    });

    _mainPanel.add(_ctrlPanel, BorderLayout.WEST);
    _mainPanel.add(_portalPanel, BorderLayout.CENTER);
    //    _mainPanel.add(_logPane, BorderLayout.SOUTH);

    _ctrlPanel.add(new JScrollPane(_servicesList));
    _ctrlPanel.add(new JScrollPane(_dataLabel));
    //    _ctrlPanel.setMinimumSize(new Dimension(CTRL_WIDTH, CTRL_HEIGHT));

    JSplitPane _mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, 
					   _mainPanel, 
					   _logPane);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(_mainSplit, "Center");
    show();
  }


  


  public void updatePortal(String key) {


    _cardLayout.show(_portalPanel, key);


  }


  public void log(String msg) {


    _logArea.append(msg + "\n");
    
    _logArea.setCaretPosition(_logArea.getDocument().getLength());

  }


  


  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/AlertService.java b/services/AlertService.java
index 18ac624..e110628 100644
--- a/services/AlertService.java
+++ b/services/AlertService.java
@@ -1,71 +1 @@
-package psl.habitats.services;
-import psl.habitats.*;
-
-import javax.swing.*;
-
-import java.util.Date;
-import java.util.Vector;
-import java.util.Hashtable;
-import java.util.Enumeration;
-
-public class AlertService implements ServiceInterface {
-  private static final String myDescription = "AlertService";
-  Habitat masterHabitat = null;
-  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>Hit Panic Button</td></tr>");
-    _stringBuffer.append("<tr><td>Availablity</td><td>Selected</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 JPanel panel;
-  public JPanel startDisplay() {
-    return (panel = new JPanel());
-  }
-
-  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 Hashtable performService(String _senderService, Hashtable ipList) {
-    StringBuffer _stringBuffer = new StringBuffer();
-    _stringBuffer.setLength(0);
-    _stringBuffer.append("<html><body>\n");
-    _stringBuffer.append("<h1>" + getDescription() + "</h1>\n");
-    _stringBuffer.append("<table border=4>\n");
-    for (Enumeration e=ipList.keys(); e.hasMoreElements(); ) {
-      String key = e.nextElement().toString();
-      if (key.equals(key9)) continue;
-      _stringBuffer.append("<tr><td>"+key+"</td><td>"+ipList.get(key)+"</td></tr>\n");
-    }
-    _stringBuffer.append("<tr><td colspan=2><img src="+ipList.get(key9)+"></td></tr>\n");
-    _stringBuffer.append("</table>\n");
-    _stringBuffer.append("</body></html>\n");
-
-    JLabel label = new JLabel("" + _stringBuffer);
-    JOptionPane.showMessageDialog(panel, label, "Alert Service", JOptionPane.WARNING_MESSAGE);
-    masterHabitat.log("" + _stringBuffer);
-    System.out.println("JUST LOGGED: " + _stringBuffer);
-
-    return null;
-  }
-}
+package psl.habitats.services;


import psl.habitats.*;





import java.awt.*;
import java.awt.event.*;
import javax.swing.*;





import java.util.Date;


import java.util.Vector;


import java.util.Hashtable;


import java.util.Enumeration;





public class AlertService implements ServiceInterface {


  private static final String myDescription = "AlertService";


  Habitat masterHabitat = null;


  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>Hit Panic Button</td></tr>");


    _stringBuffer.append("<tr><td>Availablity</td><td>Selected</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 JPanel panel;


  public JPanel startDisplay() {


    return (panel = new JPanel());


  }





  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 Hashtable performService(String _senderService, Hashtable ipList) {


    StringBuffer _stringBuffer = new StringBuffer();


    _stringBuffer.setLength(0);


    _stringBuffer.append("<html><body>\n");


    _stringBuffer.append("<h1>" + getDescription() + "</h1>\n");


    _stringBuffer.append("<table border=4>\n");


    for (Enumeration e=ipList.keys(); e.hasMoreElements(); ) {


      String key = e.nextElement().toString();


      if (key.equals(key9)) continue; 


      _stringBuffer.append("<tr><td>"+key+"</td><td>"+ipList.get(key)+"</td></tr>\n");


    }


    _stringBuffer.append("<tr><td colspan=2><img src="+ipList.get(key9)+"></td></tr>\n");


    _stringBuffer.append("</table>\n");


    _stringBuffer.append("</body></html>\n");





    final JLabel label = new JLabel("" + _stringBuffer);


    JOptionPane.showMessageDialog(null, label, "Alert Service", JOptionPane.WARNING_MESSAGE);

    /** Janak's lame attempt at getting flashing to work: either flash
     * while the JOptionPane is up (Thread must start before
     * showMessageDialog), or by using a JDialog with a custom border
     */

//     new Thread() {
//       public void run() {
// 	try {
// 	  for(int i=0; i < 10; i++) {
// 	    label.setBackground(Color.red);
// 	    Thread.currentThread().sleep(500);
// 	    label.setBackground(Color.black);
// 	    Thread.currentThread().sleep(500);
// 	  }
// 	} catch(InterruptedException ie) { ; }
//       }
//     }.start();


//     final JDialog d = new JDialog();

//     d.setLayout(new BorderLayout());

//     JLabel alertLabel = new JLabel("ALERT!", SwingConstants.CENTER);
//     d.add(alertLabel, "North");
//     d.add(label, "Center");
//     JButton okButton = new JButton("OK");
//     okButton.addActionListener(new ActionListener() {
// 	public void actionPerformed(ActionEvent e) {
// 	  d.dispose();
// 	}
//       });
//     d.add(okButton, "South");
    
//     d.pack();
//     d.setVisible(true);

    masterHabitat.log("" + _stringBuffer);


    System.out.println("JUST LOGGED: " + _stringBuffer);





    return null;


  }


}
\ No newline at end of file
diff --git a/services/EventService.java b/services/EventService.java
index c7d7b69..aec5f2a 100644
--- a/services/EventService.java
+++ b/services/EventService.java
@@ -2,7 +2,7 @@ package psl.habitats.services;
 import psl.habitats.*;

 import java.awt.*;
-import java.awt.event.*;
import javax.swing.*;
+import java.awt.event.*;import javax.swing.*;

 import java.util.Vector;
 import java.util.Hashtable;
@@ -29,36 +29,85 @@ public class EventService implements ServiceInterface {
   }
   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 + "";
-  }
-
+  }
+  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(){
+  public JPanel startDisplay(){
     // start the GUI here
-    final JPanel panel = new JPanel(new GridLayout(20, 1));
+    JPanel panel = new JPanel();
+    panel.setLayout(new BorderLayout(0, 10));
+    panel.add(new JLabel("FOR USE BY AUTHORIZED PERSONNEL!",
+			 SwingConstants.CENTER), "North");
+
+    // Set up the entry fields
+    JPanel gridPanel = new JPanel();
+    gridPanel.setLayout(new GridLayout(4,2));
+
+    gridPanel.add(new JLabel("Type of Event: "));
+    gridPanel.add(new JTextField(10));
+
+    gridPanel.add(new JLabel("Available Data: "));
+    gridPanel.add(new JTextField(10));
+
+    gridPanel.add(new JLabel("Description: "));
+    gridPanel.add(new JTextField(10));
+
     final JLabel label = new JLabel("Enter name: ");
-    final JTextField text = new JTextField(20);
    JButton button = new JButton("Action!");

    panel.add(new JLabel("FOR USE BY AUTHORISED PERSONNEL!"));
-    {JPanel p = new JPanel(new GridLayout(1, 2));p.add(new JLabel("Type of Event: "));p.add(new JTextField(10));panel.add(p);}
    {JPanel p = new JPanel(new GridLayout(1, 2));p.add(new JLabel("Available Data: "));p.add(new JTextField(10));panel.add(p);}
-    {JPanel p = new JPanel(new GridLayout(1, 2));p.add(new JLabel("Description: "));p.add(new JTextField(10));panel.add(p);}
-    {JPanel p = new JPanel(new GridLayout(1, 2));p.add(label);p.add(text);panel.add(p);}
-    panel.add(button);
-
-    button.addActionListener(new ActionListener() {
-      public void actionPerformed(ActionEvent ae) {
        phaseOneData = text.getText();
        phaseOne();
-      }
    });
    return panel;
+    final JTextField text = new JTextField(20);
+    gridPanel.add(label);
+    gridPanel.add(text);
+
+    // Stick the fields and buttons together so that they remain adjacent
+    // in the main panel
+    JPanel fieldsAndButtonsPanel = new JPanel();
+    fieldsAndButtonsPanel.setLayout(new BorderLayout());
+
+    // Now add gridpanel to our parent, but wrap it in a BorderLayout
+    // to "squeeze" it at the top
+    {
+      JPanel fieldPanel = new JPanel();
+      fieldPanel.setLayout(new BorderLayout());
+      fieldPanel.add(gridPanel, "North");
+      fieldsAndButtonsPanel.add(fieldPanel, "North");
+    }
+
+    {
+      // Set up our buttons
+      JPanel buttonPanel = new JPanel();
+      buttonPanel.setLayout(new FlowLayout());
+      JButton button = new JButton("Action!");
+      buttonPanel.add(button);
+      fieldsAndButtonsPanel.add(buttonPanel, "Center");
+
+      button.addActionListener(new ActionListener() {
+	  public void actionPerformed(ActionEvent ae) {
+	    phaseOneData = text.getText();
+	    phaseOne();
+	  }
+	});
+
+      panel.add(fieldsAndButtonsPanel, "Center");
+
+    }
+
+
+    // Put the whole thing into a BorderLayout so that it squeezes up nicely
+    panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
+    return panel;
   }

   private static final String PHASE_ONE_PEER = "NYC_Passengers_Query";