import heartMonitor.*; import org.omg.CORBA.*; import org.omg.CosNaming.*; import org.omg.PortableServer.*; import org.omg.CosNaming.NamingContextPackage.*; import java.util.*; import javax.swing.*; // This class implements a very simple CORBA based Heart rate monitor for // a nurse's station. It can work with a number of local monitors in // individual patient's rooms. // // This Server requires that a CORBA Name Service be running. // // Written by: Stuart Hansen // Date: February 3, 2009 public class NursesStation extends HeartRateMonitorPOA{ private ORB orb; // the orb for this server private POA rootpoa; // the root POA for this server // A hashtable to store all the values received. private Hashtable> patients; // The constructor sets up the ORB for communication public NursesStation (String [] args) { patients = new Hashtable>(); setUpServerORB(args); } // Register a new patient with the monitor public void register (String name) { patients.put(name, new ArrayList()); } // Unregister a patient public void unregister (String name) { patients.remove(name); } // Add a value for a particular patient public void newRate (String name, int value) { patients.get(name).add(value); } // Sound an alarm for a patient public void soundAlarm (String name, int value) { JOptionPane.showMessageDialog(null, name + " has a heart rate of " + value); } // This method setups the Server ORB public void setUpServerORB(String [] args) { try{ // create and initialize the ORB orb = ORB.init(args, null); // get reference to rootpoa & activate the POAManager rootpoa = POAHelper.narrow( orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // Convert our server to a CORBA object and IOR org.omg.CORBA.Object ref = rootpoa.servant_to_reference(this); HeartRateMonitor monitor = HeartRateMonitorHelper.narrow(ref); // Look up the Name Service org.omg.CORBA.Object nameServiceObj = orb.resolve_initial_references("NameService"); NamingContextExt nameService = NamingContextExtHelper.narrow(nameServiceObj); // Bind (register) the Calculator Server with the Name Service String name = "NursesStation"; NameComponent path[] = nameService.to_name( name ); nameService.rebind(path, monitor); System.out.println("Heart Monitor Ready"); // wait for client requests orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } } // The main program simply creates a new Calculator Server public static void main(String [] args) { new NursesStation (args); } }