package __MASA_PACKAGE_agent__(AgentSystem); import __MASA_PACKAGE_agentSystem__(*); import __MASA_PACKAGE_agent__(ASManagementAgent.*); import __MASA_PACKAGE_agent__(AgentApplet); import __MASA_PACKAGE_agent__(Migration); import __MASA_PACKAGE_agent__(MigrationHelper); import __MASA_PACKAGE__(tools.NameWrapper); import __MASA_PACKAGE_CfMAF__(*); import java.awt.*; import java.applet.*; import java.util.*; import java.io.*; import java.awt.event.*; import com.sun.java.swing.*; import com.sun.java.swing.text.*; import com.sun.java.swing.table.*; import com.sun.java.swing.event.*; import com.sun.java.swing.JOptionPane; import org.omg.CosEventComm.*; import org.omg.CosEventChannelAdmin.*; import org.omg.CosNaming.*; /** * The applet of the agent system. This applet is loaded, * when the webserver agent is contacted via http the first * time. * * <br>(See Mobile Agent Facility (MAF) * of Open Management Group (OMG)) * * @author Stefan Gerber * @see de.unimuenchen.informatik.mnm.masa.agent.webserver.WebserverStationaryAgent */ public class AgentSystemApplet extends AgentApplet { /* * CORBA reference to the agent system */ private AgentSystemService _ass; private ASManagementAgent _asm; private JButton _bt_create_agent; private JButton _bt_transferAgent; private JButton _bt_resume_agent; private JButton _bt_suspend_agent; private JButton _bt_terminate_agent; private JButton _bt_get_agent_system_info; private JButton _bt_terminate_agent_system; private JButton _bt_readAgentFromFile; private JButton _bt_writeAgentToFile; private JButton _bt_showwebpage; private JButton _bt_update_list; private JButton _bt_update_impl_agents; private JTextArea _ta_output_agent; private JTextArea _ta_output_agent_system; private JTextArea _ta_output_create_agent; private JTextField _tf_file; private JComboBox _ch_create_exclusive; private JComboBox _ch_impl_agents; private JComboBox _ch_constructors = null; private JLabel _label_exclusive; private JLabel _label_identity; private JLabel _label_file; private JLabel _label_agentTable; private AppletTableModel myModel; private JTable agentTable; private JScrollPane tableScrollPane; private ListSelectionModel listSelectionModel; private String agent_identity = null; private java.awt.Component parentComponent; private String impl_agent_list[]; //list of implemented agents generated by get_impl_agents private String impl_package_list[]; //other data concerning implemented agents list private String impl_type_list[]; // "" "" "" private ActionListener actionlistener_ch_impl_agents; private JLabel constructors; private String[] constructor_list; private ParameterTableModel paramTableModel; private JTable paramTable; private JScrollPane paramScrollPane; private String agent_system_name; private Vector[] param_matrix; private PushConsumerImpl pushConsumer = null; /** * Initialize this applet and connect to agent system. * <br>Sets and displays all JFC components and calls various methods to get initial information * about the agent system and itīs agents (e.g. list of running agents, list of implemented agents * and their parameters) * <br>Connects to the agent system and to the ASManagementAgent * * @see AgentSystemService * @see ASManagementAgent */ public void init() { // Connect to appropriate agent system try { org.omg.CORBA.Object obj = initCORBA("AgentSystemService"); _ass = AgentSystemServiceHelper.narrow(obj); } catch(java.net.MalformedURLException e) {//error _ta_output_agent_system.append(e.toString()+"\n"); } catch(java.io.IOException ioe) {//error _ta_output_agent_system.append(ioe.toString()+"\n"); } // Connect to ASManagement Agent try { org.omg.CORBA.Object objekt = initCORBA("ASManagementAgent"); _asm = ASManagementAgentHelper.narrow(objekt); } catch(java.net.MalformedURLException e) { System.err.println(e.toString()+"\n"); e.printStackTrace(); } catch(java.io.IOException ioe) {//error System.err.println(ioe.toString()+"\n"); ioe.printStackTrace(); } // test if ASManagementAgent has been found // if not, then display warning message if (_asm == null) { JOptionPane.showMessageDialog(null, "ASManagementAgent could not be found.\nPlease load it and restart the applet."); } else { //Create tabbed Panel JTabbedPane tabbedPane = new JTabbedPane(); // Set layout to GridBag GridBagLayout gridBag = new GridBagLayout(); getContentPane().setLayout(gridBag); GridBagConstraints c_root = new GridBagConstraints(); /********************************************************** ******* Panel for "Manage Agents" ********************* ***********************************************************/ //Create Layout Manager for "Manage Agents" Part GridBagLayout manage_agents_gridBag = new GridBagLayout(); GridBagConstraints c1 = new GridBagConstraints(); // Create Panel for "Manage agents" part JPanel manage_agents_panel = new JPanel(manage_agents_gridBag); //Create JFC components and arrange them //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ c1.fill = GridBagConstraints.HORIZONTAL; c1.gridwidth = GridBagConstraints.RELATIVE; c1.gridx = 0; c1.weightx = 1; c1.weighty = 2.5; //c1.insets = new Insets(8,0,0,0); //c1.insets.top = 8; c1.insets = new Insets(8,0,0,0); c1.gridwidth = GridBagConstraints.REMAINDER; _label_agentTable = new JLabel("Agents on this Agent System"); manage_agents_gridBag.setConstraints(_label_agentTable, c1); manage_agents_panel.add(_label_agentTable); c1.insets.top = 0; c1.weighty = 2.5; myModel = new AppletTableModel(); agentTable = new JTable(myModel); myModel.addTableModelListener(agentTable); agentTable.setPreferredScrollableViewportSize(new Dimension(250,60)); tableScrollPane = new JScrollPane(agentTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); tableScrollPane.setBorder(BorderFactory.createTitledBorder("Agents on this Agent System")); tableScrollPane.setMinimumSize(new Dimension(tabbedPane.getWidth(), 130)); tableScrollPane.setPreferredSize(new Dimension(tabbedPane.getWidth(), 130)); // Set selection model for agentTable listSelectionModel = agentTable.getSelectionModel(); listSelectionModel.addListSelectionListener(new ListSelectionHandler()); listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //get list of running agents and their status and display in agentTable list_agent_names(); manage_agents_gridBag.setConstraints(tableScrollPane, c1); manage_agents_panel.add(tableScrollPane); //create various buttons for managing the agents c1.insets = new Insets(8,25,0,25); c1.gridx = 0; c1.weighty = 0; c1.gridwidth = GridBagConstraints.RELATIVE; _bt_suspend_agent = new JButton("suspend agent"); _bt_suspend_agent.setMnemonic('s'); _bt_suspend_agent.setToolTipText("suspend the selected agent"); _bt_suspend_agent.setActionCommand("button"); _bt_suspend_agent.setBackground(new Color(12632256)); manage_agents_gridBag.setConstraints(_bt_suspend_agent, c1); manage_agents_panel.add(_bt_suspend_agent); c1.gridx = GridBagConstraints.RELATIVE; c1.gridwidth = GridBagConstraints.REMAINDER; _bt_resume_agent = new JButton("resume agent"); _bt_resume_agent.setMnemonic('u'); _bt_resume_agent.setToolTipText("resume the selected agent"); _bt_resume_agent.setActionCommand("button"); _bt_resume_agent.setBackground(new Color(12632256)); manage_agents_gridBag.setConstraints(_bt_resume_agent, c1); manage_agents_panel.add(_bt_resume_agent); c1.gridx = 0; c1.gridwidth = GridBagConstraints.RELATIVE; c1.insets.top = 0; _bt_terminate_agent = new JButton("terminate agent"); _bt_terminate_agent.setMnemonic('t'); _bt_terminate_agent.setToolTipText("terminate the selected agent"); _bt_terminate_agent.setActionCommand("button"); _bt_terminate_agent.setBackground(new Color(12632256)); manage_agents_gridBag.setConstraints(_bt_terminate_agent, c1); manage_agents_panel.add(_bt_terminate_agent); c1.gridx = GridBagConstraints.RELATIVE; c1.gridwidth = GridBagConstraints.REMAINDER; _bt_showwebpage = new JButton("show agent's webpage"); _bt_showwebpage.setActionCommand("button"); _bt_showwebpage.setMnemonic('w'); _bt_showwebpage.setToolTipText("show the webpage of the selected agent"); _bt_showwebpage.setBackground(new Color(12632256)); manage_agents_gridBag.setConstraints(_bt_showwebpage, c1); manage_agents_panel.add(_bt_showwebpage); c1.gridx = 0; c1.gridwidth = GridBagConstraints.RELATIVE; _bt_transferAgent = new JButton("transfer Agent"); _bt_transferAgent.setMnemonic('f'); _bt_transferAgent.setToolTipText("migrate the selected agent to a different agent system"); _bt_transferAgent.setActionCommand("button"); _bt_transferAgent.setBackground(new Color(12632256)); manage_agents_gridBag.setConstraints(_bt_transferAgent, c1); manage_agents_panel.add(_bt_transferAgent); c1.gridx = GridBagConstraints.RELATIVE; c1.gridwidth = GridBagConstraints.REMAINDER; //Create "update button" _bt_update_list = new JButton("update manually"); _bt_update_list.setMnemonic('u'); _bt_update_list.setToolTipText("update the table of loaded agents manually"); _bt_update_list.setActionCommand("button"); _bt_update_list.setBackground(new Color(12632256)); _bt_update_list.setMargin(new Insets(2,2,2,2)); manage_agents_gridBag.setConstraints(_bt_update_list, c1); manage_agents_panel.add(_bt_update_list); //insert a separator c1.insets = new Insets(26,0,0,0); JSeparator sep2 = new JSeparator(); manage_agents_gridBag.setConstraints(sep2, c1); manage_agents_panel.add(sep2); //create the textfield //the user specifies the input/output file with it c1.insets.top = 26; _label_file = new JLabel("File"); manage_agents_gridBag.setConstraints(_label_file, c1); manage_agents_panel.add(_label_file); c1.insets.top = 0; _tf_file = new JTextField(); manage_agents_gridBag.setConstraints(_tf_file, c1); manage_agents_panel.add(_tf_file); //create buttons for reading/writing agents to files c1.insets = new Insets(8,25,0,25); c1.gridx = 0; c1.gridwidth = GridBagConstraints.RELATIVE; _bt_readAgentFromFile = new JButton("read agent from file"); _bt_readAgentFromFile.setMnemonic('a'); _bt_readAgentFromFile.setToolTipText("read an agent from the specified file"); _bt_readAgentFromFile.setActionCommand("button"); _bt_readAgentFromFile.setBackground(new Color(12632256)); manage_agents_gridBag.setConstraints(_bt_readAgentFromFile, c1); manage_agents_panel.add(_bt_readAgentFromFile); c1.gridwidth = GridBagConstraints.REMAINDER; c1.gridx = GridBagConstraints.RELATIVE; _bt_writeAgentToFile = new JButton("write agent to file"); _bt_writeAgentToFile.setMnemonic('i'); _bt_writeAgentToFile.setToolTipText("write selected agent to the specified file"); _bt_writeAgentToFile.setActionCommand("button"); _bt_writeAgentToFile.setBackground(new Color(12632256)); manage_agents_gridBag.setConstraints(_bt_writeAgentToFile, c1); manage_agents_panel.add(_bt_writeAgentToFile); //create textarea for outputs of various methods in this panel c1.gridx = 0; c1.insets = new Insets(16,0,0,0); c1.gridheight = GridBagConstraints.REMAINDER; c1.weighty = c1.weightx = 2.0; c1.fill = GridBagConstraints.BOTH; _ta_output_agent = new com.sun.java.swing.JTextArea(); _ta_output_agent.setBounds(72,600,624,168); _ta_output_agent.setEditable(false); _ta_output_agent.setMargin(new Insets(5,5,5,5)); Color color = new Color(188,210,238); _ta_output_agent.setBackground(color); JScrollPane scrollPane_agent = new JScrollPane(_ta_output_agent, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane_agent.setBorder(BorderFactory.createTitledBorder("Output:")); scrollPane_agent.setMinimumSize(new Dimension(tabbedPane.getWidth(), 110)); scrollPane_agent.setPreferredSize(new Dimension(tabbedPane.getWidth(), 110)); manage_agents_gridBag.setConstraints(scrollPane_agent, c1); manage_agents_panel.add(scrollPane_agent); //add manage_agents_panel to the tabbed panel tabbedPane.addTab("Manage agents", null, manage_agents_panel, "manage the agents of this agent system"); tabbedPane.setSelectedIndex(0); /*********************************************************** ******* Panel for "Create Agent" ********************* ***********************************************************/ //Create Layout Manager for "Create Agent" Part GridBagLayout create_agent_gridBag = new GridBagLayout(); GridBagConstraints c2 = new GridBagConstraints(); // Create Panel for "Create agent" part JPanel create_agent_panel = new JPanel(create_agent_gridBag); //Create JFC components and arrange them //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ c2.fill = GridBagConstraints.HORIZONTAL; c2.gridwidth = GridBagConstraints.REMAINDER; c2.gridx = 0; c2.weightx = 1; c2.insets = new Insets(8,0,0,0); _label_identity = new JLabel("Choose agent"); _label_identity.setBackground(new Color(8454016)); create_agent_gridBag.setConstraints(_label_identity, c2); create_agent_panel.add(_label_identity); c2.insets.top = 0; // get list of implemented agents from webserver and put it in impl_agent_list get_impl_agents(); //create combobox which displays the implemented agents _ch_impl_agents = new JComboBox(impl_agent_list); _ch_impl_agents.setSelectedIndex(0); _ch_impl_agents.setEditable(false); create_agent_gridBag.setConstraints(_ch_impl_agents, c2); create_agent_panel.add(_ch_impl_agents); //define an actionlistener for _ch_impl_agents actionlistener_ch_impl_agents = new ActionListener() { public void actionPerformed(ActionEvent e) { get_agent_parameters(); } }; //if the user selects an agent from the list itīs parameters are obtained immediately _ch_impl_agents.addActionListener(actionlistener_ch_impl_agents); //create combobox which determines if the new agent will be exclusive c2.insets.top = 16; c2.gridwidth = GridBagConstraints.REMAINDER; c2.gridx = GridBagConstraints.RELATIVE;; _label_exclusive = new JLabel("Exclusive "); _label_exclusive.setBackground(new Color(8454016)); create_agent_gridBag.setConstraints(_label_exclusive, c2); create_agent_panel.add(_label_exclusive); c2.insets = new Insets(0,0,0,300); _ch_create_exclusive = new JComboBox(); _ch_create_exclusive.addItem("false"); _ch_create_exclusive.addItem("true"); _ch_create_exclusive.setSelectedIndex(0); create_agent_gridBag.setConstraints(_ch_create_exclusive, c2); create_agent_panel.add(_ch_create_exclusive); //create combobox which selects between the different constructors for the new agent c2.insets = new Insets(16,0,0,0); c2.gridx = 0; constructors = new JLabel("Create Agent with..."); constructors.setBackground(new Color(8454016)); create_agent_gridBag.setConstraints(constructors, c2); create_agent_panel.add(constructors); c2.insets = new Insets(0,0,0,300); //get list of constructors and put it into constructor_list get_agent_parameters(); _ch_constructors = new JComboBox(constructor_list); _ch_constructors.setSelectedIndex(0); _ch_constructors.setEditable(false); create_agent_gridBag.setConstraints(_ch_constructors, c2); create_agent_panel.add(_ch_constructors); //if a constructor is chosen then the table shows the different types of parameters _ch_constructors.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { show_agent_parameters(_ch_constructors.getSelectedIndex()); } } ); //create table showing the different parameters of a constructor //the user also types in the values for these parameters using this table c2.insets = new Insets(16,0,0,0); paramTableModel = new ParameterTableModel(); paramTable = new JTable(paramTableModel); paramTableModel.addTableModelListener(paramTable); paramTable.setPreferredScrollableViewportSize(new Dimension(250,60)); paramScrollPane = new JScrollPane(paramTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); paramScrollPane.setBorder(BorderFactory.createTitledBorder("Parameters for this constructor")); paramScrollPane.setMinimumSize(new Dimension(tabbedPane.getWidth(), 100)); paramScrollPane.setPreferredSize(new Dimension(tabbedPane.getWidth(), 100)); create_agent_gridBag.setConstraints(paramScrollPane, c2); create_agent_panel.add(paramScrollPane); //show list of parameters for currently selected implemented agent show_agent_parameters(0); //create buttons c2.gridx = 0; c2.gridwidth = GridBagConstraints.RELATIVE; c2.insets = new Insets(20,25,0,25); _bt_create_agent = new JButton("create agent"); _bt_create_agent.setMnemonic('c'); _bt_create_agent.setToolTipText("load the selected Agent with the specified options"); _bt_create_agent.setActionCommand("button"); _bt_create_agent.setBackground(new Color(12632256)); create_agent_gridBag.setConstraints(_bt_create_agent, c2); create_agent_panel.add(_bt_create_agent); c2.gridwidth = GridBagConstraints.REMAINDER; c2.gridx = GridBagConstraints.RELATIVE; _bt_update_impl_agents = new JButton("update list"); _bt_update_impl_agents.setMnemonic('u'); _bt_update_impl_agents.setToolTipText("update the list of loadable agents"); _bt_update_impl_agents.setActionCommand("button"); _bt_update_impl_agents.setBackground(new Color(12632256)); create_agent_gridBag.setConstraints(_bt_update_impl_agents, c2); create_agent_panel.add(_bt_update_impl_agents); //create textarea for output of the methods of this panel c2.gridx = 0; c2.gridheight = 6; c2.weighty = c2.weightx = 2.5; c2.fill = GridBagConstraints.BOTH; c2.insets = new Insets(20,0,0,0); _ta_output_create_agent = new com.sun.java.swing.JTextArea(); _ta_output_create_agent.setEditable(false); _ta_output_create_agent.setMargin(new Insets(5,5,5,5)); _ta_output_create_agent.setBackground(color); JScrollPane scrollPane_create_agent = new JScrollPane(_ta_output_create_agent, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane_create_agent.setBorder(BorderFactory.createTitledBorder("Output:")); create_agent_gridBag.setConstraints(scrollPane_create_agent, c2); create_agent_panel.add(scrollPane_create_agent); //add panel to tabbed pane tabbedPane.addTab("Create agent", null, create_agent_panel, "load a new agent into this agent system"); /*********************************************************** ******* Panel for "Manage agent system" ***************** ***********************************************************/ //Create Layout Manager for "Manage agent system" Part GridBagLayout agent_system_gridBag = new GridBagLayout(); //Create Panel for "Manage agent system" Part JPanel agent_system_panel = new JPanel(agent_system_gridBag); GridBagConstraints c3 = new GridBagConstraints(); //create buttons c3.gridx = 0; c3.gridwidth = GridBagConstraints.REMAINDER; c3.fill = GridBagConstraints.HORIZONTAL; c3.weightx = 1; c3.insets = new Insets(20,150,0,150); _bt_get_agent_system_info = new JButton("get agent system info"); _bt_get_agent_system_info.setMnemonic('i'); _bt_get_agent_system_info.setToolTipText("show information about this agent system"); _bt_get_agent_system_info.setActionCommand("button"); _bt_get_agent_system_info.setBackground(new Color(12632256)); agent_system_gridBag.setConstraints(_bt_get_agent_system_info, c3); agent_system_panel.add(_bt_get_agent_system_info); c3.insets.top = 0; _bt_terminate_agent_system = new JButton("terminate agent system"); _bt_terminate_agent_system.setMnemonic('t'); _bt_terminate_agent_system.setToolTipText("shut down this agent system"); _bt_terminate_agent_system.setActionCommand("button"); _bt_terminate_agent_system.setBackground(new Color(12632256)); agent_system_gridBag.setConstraints(_bt_terminate_agent_system, c3); agent_system_panel.add(_bt_terminate_agent_system); //create textarea for output of the methods of this panel c3.gridx = 0; c3.gridwidth = GridBagConstraints.REMAINDER; c3.insets = new Insets(20,0,0,0); c3.gridheight = 4; c3.weighty = 2; c3.fill = GridBagConstraints.BOTH; _ta_output_agent_system = new com.sun.java.swing.JTextArea(); _ta_output_agent_system.setBounds(72,600,624,168); _ta_output_agent_system.setEditable(false); _ta_output_agent_system.setMargin(new Insets(5,5,5,5)); _ta_output_agent_system.setBackground(color); JScrollPane scrollPane_agent_system = new JScrollPane(_ta_output_agent_system, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane_agent_system.setBorder(BorderFactory.createTitledBorder("Output:")); agent_system_gridBag.setConstraints(scrollPane_agent_system, c3); agent_system_panel.add(scrollPane_agent_system); //add panel to tabbed pane tabbedPane.addTab("Agent System", null, agent_system_panel, "manage the agent system"); //add tabbed Pane to Applet panel c_root.fill = GridBagConstraints.BOTH; c_root.gridx = 0; c_root.gridwidth = GridBagConstraints.REMAINDER; c_root.gridheight = GridBagConstraints.REMAINDER; c_root.weightx = c_root.weighty = 1.0; gridBag.setConstraints(tabbedPane, c_root); getContentPane().add(tabbedPane); //set parentComponent variable to point to this applet //needed to display transfer-agent-dialogue from within ASManagementAgent parentComponent = this; //get the name of the agent system this applet belongs to String as_url = _ass.getURL(); agent_system_name = as_url.substring(as_url.lastIndexOf("/")+1, as_url.lastIndexOf(":")); //create pushConsumer and connect it to the ASManagementAgent //needed to react to events from CORBA event service create_pushConsumer(); //define the action listeners for the various buttons created above this.initEventHandler(); } } /** * Implement all actions that take place when a certain button is pushed. * <br>This method defines the action listeners for the various buttons of this applet and * the mouse listener for the table of loaded agents */ public void initEventHandler() { /* * action listener for create_agent button */ //clear any selection in the table of loaded agents for safety reasons agentTable.clearSelection(); _bt_create_agent.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { // test if the agent is already running in this agent system // if "yes" then show a warning message if ( myModel.isElement((String) _ch_impl_agents.getSelectedItem()) ) { int answer = JOptionPane.showConfirmDialog(null, "An agent with this name is already\nrunning on this agent system!\nDo you really want to start another instance?", "Warning!", JOptionPane.YES_NO_OPTION); //if user cancels then return without any further action, else proceed if (answer == JOptionPane.NO_OPTION) { return; } } // create the parameters for the create_agent() call java.io.ByteArrayOutputStream agentBytes = new java.io.ByteArrayOutputStream(); java.io.ObjectOutputStream outputAgent = new java.io.ObjectOutputStream(agentBytes); //get the index of the item currently selected in the combobox with impl. agents int selected_index = _ch_impl_agents.getSelectedIndex(); //prepare outputAgent with data about the agent to be loaded outputAgent.writeObject(impl_package_list[selected_index]); outputAgent.writeObject(impl_type_list[selected_index]); #ifdef VISIBROKER30 outputAgent.writeObject("_tie_"); outputAgent.writeObject("Operations"); #endif #ifdef ORBACUS311 outputAgent.writeObject("_"); outputAgent.writeObject("ImplBase_tie"); #endif outputAgent.writeObject(new Boolean((String) _ch_create_exclusive.getSelectedItem())); outputAgent.writeObject(""); java.io.ByteArrayOutputStream constructorArgs = new java.io.ByteArrayOutputStream(); java.io.ObjectOutputStream constructorObject = new java.io.ObjectOutputStream(constructorArgs); //get number of rows of parameter table i.e. the number of constructor parameters int nor = paramTableModel.getRowCount(); //fetch the parameter data types and their values provided by the user via paramTable String paramtype = null; for (int i=0; i<nor; i++) { //get parameter type paramtype = (String) paramTableModel.getValueAt(i, 0); //create appropriate object and copy it into the ByteArray if (paramtype.equals("java.lang.String")) { constructorObject.writeObject((String) paramTableModel.getValueAt(i, 1)); } else if (paramtype.equals("java.lang.Integer")) { constructorObject.writeObject(java.lang.Integer.valueOf((String) paramTableModel.getValueAt(i, 1))); } else if (paramtype.equals("java.lang.Float")) { constructorObject.writeObject(java.lang.Float.valueOf((String) paramTableModel.getValueAt(i, 1))); } else if (paramtype.equals("java.lang.Double")) { constructorObject.writeObject(java.lang.Double.valueOf((String) paramTableModel.getValueAt(i, 1))); } //(roelle): IMHO this was missing else if (paramtype.equals("java.lang.Boolean")) { constructorObject.writeObject(java.lang.Boolean.valueOf((String) paramTableModel.getValueAt(i, 1))); } } // agent name is equal class name, so no information about classes needed ClassName[] className = new ClassName[0]; //fetch the name of the agent to be created NameWrapper nw = new NameWrapper((String) _ch_impl_agents.getSelectedItem()); //create the profile of the agent and itīs properties AgentProfile ap = new AgentProfile(); org.omg.CORBA.Any props[] = new org.omg.CORBA.Any[1]; org.omg.CORBA.Any any = getORB().create_any(); #ifdef VISIBROKER30 any.insert_wstring("Property"); #endif #ifdef ORBACUS311 any.insert_string("Property"); #endif props[0]=any; ap.language_id=1; ap.serialization=1; ap.properties= props; ap.agent_system_description= "Agent System of MNM-Team"; // create the agent with the information collected and prepared above Name res = _ass.create_agent(nw._name, ap, agentBytes.toByteArray(), new String("default"), constructorArgs.toByteArray(), className, "", (MAFAgentSystem)_ass); //print a status message to the output window _ta_output_create_agent.append("create_agent(): agent "+_ch_impl_agents.getSelectedItem()+ " created.\n"); } catch(Exception e0){ //error e0.printStackTrace(); _ta_output_create_agent.append("create_agent(): create agent "+_ch_impl_agents.getSelectedItem()+ " failed: "+ e0.toString()+"\n"+ (e0.getMessage() == null ? "" : e0.getMessage()+"\n")); } } } ); /* * action listener for transferAgent button */ _bt_transferAgent.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { // get list of all active agent systems from the ASManagementAgent String agentsystems[] = _asm.identify_agentsystems(); //create a Vector containing the names of the active agent systems java.util.Vector as_names = new java.util.Vector(0,1); int n_o_t = agentsystems.length; for (int i=0; i<n_o_t; i++) { as_names.addElement(agentsystems[i]); } //Show dialogue to get target agent system String target = CommonAppletHelpers.show_migrate_menu(parentComponent, agent_identity, as_names); if (target == null) { //if user pressed the cancel-button //clear selection in agentTable and disable buttons for safety reasons clear_selection(); return; } // connect to agent to transfer NameWrapper nw = new NameWrapper(agent_identity); org.omg.CORBA.Object obj = _ass.connectToAgent(nw._name); Migration agent = MigrationHelper.narrow(obj); // transfer agent to destination agent system agent.migrateToAgentSystem("AgentSystemService/4/mnm/"+target); _ta_output_agent.append("transferAgent: agent "+ agent_identity + " transferred to "+ target + "\n"); } catch(Exception e1){ if (e1 instanceof org.omg.CORBA.BAD_PARAM) { } else { e1.printStackTrace(); _ta_output_agent.append("transferAgent failed: "+e1.toString()+"\n"+e1.getMessage()+"\n"); } } //clear selection in agentTable and disable buttons for safety reasons clear_selection(); } } ); //disable button initially _bt_transferAgent.setEnabled(false); /* * action listener for resume_agent button */ _bt_resume_agent.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { //resume agent NameWrapper nw = new NameWrapper(agent_identity); _ass.resume_agent(nw._name); //update the status of the agent in the agentTable myModel.changeStatus(agentTable.getSelectedRow(), "Running"); //display status message in output window _ta_output_agent.append("resume_agent(): "+agent_identity+" resumed.\n\n"); } catch(Exception e2){ _ta_output_agent.append("resume_agent for "+agent_identity+" failed!\n" +e2.toString()+"\n\n"); } //clear selection in agentTable and disable buttons for safety reasons clear_selection(); } } ); //disable button initially _bt_resume_agent.setEnabled(false); /* * action listener for suspend_agent button */ _bt_suspend_agent.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { //warn the user if the webserver agent is to be suspended if (agent_identity.equals("Webserver") || agent_identity.equals("ASManagementAgent")) { int answer = JOptionPane.showConfirmDialog(null, "Do you really want to suspend this agent?\nThis applet would no longer work correctly!", "Warning!", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.NO_OPTION) { clear_selection(); return; } } //suspend agent NameWrapper nw= new NameWrapper(agent_identity); _ass.suspend_agent(nw._name); //update the status of the agent in the agentTable myModel.changeStatus(agentTable.getSelectedRow(), "Suspended"); //display status message in output window _ta_output_agent.append("suspend_agent(): "+agent_identity+" suspended.\n\n"); } catch(Exception e3){ e3.printStackTrace(); _ta_output_agent.append("suspend_agent for "+agent_identity+" failed!\n" +e3.toString()+"\n\n"); } //clear selection in agentTable and disable buttons for safety reasons clear_selection(); } } ); //disable button initially _bt_suspend_agent.setEnabled(false); /* * action listener for terminate_agent button */ _bt_terminate_agent.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { //warn the user if the webserver is to be terminated if (agent_identity.equals("Webserver") || agent_identity.equals("ASManagementAgent")) { int answer = JOptionPane.showConfirmDialog(null, "Do you really want to terminate this agent?\nThis applet would no longer work correctly!", "Warning!", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.NO_OPTION) { clear_selection(); return; } } //terminate agent NameWrapper nw= new NameWrapper(agent_identity); _ass.terminate_agent(nw._name); //display status message in output window _ta_output_agent.append("terminate_agent(): "+agent_identity+" terminated.\n\n"); } catch(Exception e4){ _ta_output_agent.append("terminate_agent for "+agent_identity+" failed!\n" +e4.toString()+"\n\n"); } //clear selection in agentTable and disable buttons for safety reasons clear_selection(); } } ); //disable button initially _bt_terminate_agent.setEnabled(false); /* * action listener for get_agent_system_info button */ _bt_get_agent_system_info.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { //get information about the agent system this applet belongs to via _ass AgentSystemInfo asi = _ass.get_agent_system_info(); //display the information in the output window _ta_output_agent_system.append("get_agent_system_info():\n"+ "Name:\n"+ " Agent System Type: "+String.valueOf((int)asi.agent_system_name.agent_system_type)+"\n"+ " Authority: "+new String(asi.agent_system_name.authority)+"\n"+ " Identity: "+new String(asi.agent_system_name.identity)+"\n"+ "Description: "+ asi.agent_system_description+"\n\n"); } catch(Exception e6){ e6.printStackTrace(); _ta_output_agent_system.append("get_agent_system_info failed: "+e6.toString()+"\n"+e6.getMessage()+"\n"); } } } ); /* * action listener for terminate_agent_system button */ _bt_terminate_agent_system.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { //give the user a last chance to cancel int answer = JOptionPane.showConfirmDialog(null, "Do you really want to terminate this agent system?", "Warning!", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.NO_OPTION) { return; } //terminate agent system via _ass _ass.terminate_agent_system(); } catch(TerminateFailed e7){ e7.printStackTrace(); _ta_output_agent_system.append("terminate_agent_system(): failed!\n" +e7.toString()+"\n"+e7.getMessage()+"\n" +"This applet no longer works!\n"); } catch(Throwable cf){ // thrown when agent system is disconnected from boa _ta_output_agent_system.append("terminate_agent_system(): all agents and this agent system is terminated\n"+ "This applet no longer works!\n"); } } } ); /* * action listener for readAgentFromFile button */ _bt_readAgentFromFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { //get name and path of the file to be used String file = _tf_file.getText(); try { //read and create the agent from the data provided by the file Name name= _ass.readAgentFromFile(file); _ta_output_agent.append("Read agent "+new String(name.identity)+" from file "+file+"\n"); } catch(Exception e11){ e11.printStackTrace(); _ta_output_agent.append("Read agent failed: "+e11.toString()+"\n"+e11.getMessage()+"\n"); } //clear selection in agentTable and disable buttons for safety reasons clear_selection(); list_agent_names(); // Update the agent list } } ); /* * action listener for writeAgentToFile button */ _bt_writeAgentToFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { //get name and path of the file to be used String file = _tf_file.getText(); try { //write the agent to the file NameWrapper nw = new NameWrapper(agent_identity); _ass.writeAgentToFile(nw._name,file); _ta_output_agent.append("Agent "+agent_identity+" to file "+file+" written.\n"); } catch(Exception e12){ e12.printStackTrace(); _ta_output_agent.append("Write agent failed: "+e12.toString()+"\n"+e12.getMessage()+"\n"); } //clear selection in agentTable and disable buttons for safety reasons clear_selection(); list_agent_names(); // Update the agent list } } ); //disable button initially _bt_writeAgentToFile.setEnabled(false); /* * action listener for showwebpage button */ _bt_showwebpage.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { //create a URL object for the selected agent java.net.URL agent_url = CommonAppletHelpers.getAgentURL(agent_identity, _ass.getURL()); //open another browser window and show agent's webpage getAppletContext().showDocument(agent_url, agent_identity); } catch (Exception ei) { ei.printStackTrace(); } //clear selection in agentTable and disable buttons for safety reasons clear_selection(); } } ); //disable button initially _bt_showwebpage.setEnabled(false); /* * action listener for update_list button */ _bt_update_list.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { list_agent_names(); clear_selection(); } } ); /* * action listener for update_impl_agents button */ _bt_update_impl_agents.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { //prevent from updating too early _ch_impl_agents.removeActionListener(actionlistener_ch_impl_agents); //reload ImplementedAgents.txt get_impl_agents(); //update JCombobox _ch_impl_agents.removeAllItems(); for (int i=0; i<impl_agent_list.length; i++) { _ch_impl_agents.addItem(impl_agent_list[i]); } //reenable ActionListener _ch_impl_agents.addActionListener(actionlistener_ch_impl_agents); //preselect the first choice _ch_impl_agents.setSelectedIndex(0); _ch_impl_agents.setEditable(false); } } ); /* * mouse listener for agentTable */ MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { //if double click try { //get URL of selected agent java.net.URL agent_url = CommonAppletHelpers.getAgentURL(agent_identity, _ass.getURL()); //open another browser window and show agent's webpage getAppletContext().showDocument(agent_url, agent_identity); } catch (Exception ei) { ei.printStackTrace(); } } } }; agentTable.addMouseListener(ml); } /** * Retrieves a list of agents on this agent system. * <br>The name of each loaded agent and itīs status (running/suspended) are * copied to the TableModel of agentTable. */ public void list_agent_names() { String[][] names_n_status = new String[0][0]; try { //contact agent system and retrieve a list of the names of all loaded agents Name name[] = _ass.list_all_agents(); //create a 2D array that will contain the names and the status the the loaded agents names_n_status = new String[name.length][2]; NameWrapper status_name; AgentStatus state; //create new data vector for the AppletTableModel myModel.AppletTableModel(); //provide the name and the status of each loaded agent to the AppletTableModel myModel for (int i = 0; i < name.length; i++) { names_n_status[i][0] = new String(name[i].identity); status_name = new NameWrapper(names_n_status[i][0]); state = _ass.get_agent_status(status_name._name); switch(state.value()){ case AgentStatus._CfMAFRunning: names_n_status[i][1]="Running"; break; case AgentStatus._CfMAFSuspended: names_n_status[i][1]="Suspended"; break; case AgentStatus._CfMAFTerminated: names_n_status[i][1]="Terminated"; break; default: names_n_status[i][1] = "none"; break; } myModel.addValue(names_n_status[i]); } //update the displayed agentTable getContentPane().validate(); tableScrollPane.repaint(); //agentTable_panel.repaint(); } catch(Exception e){ e.printStackTrace(); } } /** * Defines whatīs to be done when applet is terminated. * <br>Disconnects pushConsumer that has been registered with the ASManagementAgent */ public void destroy() { try { _asm.disconnect_push_consumer(pushConsumer.id); } catch (Exception e) { System.err.println("\n\nAgentSystemApplet: Could not disconnect pushConsumer"); e.printStackTrace(); } } /** * Create a PushConsumer and register it with the ASManagementAgent. * <br>The pushConsumer is then provided with CORBA events and reacts appropriately */ public void create_pushConsumer() { try { // create PushConsumer pushConsumer = new PushConsumerImpl(); org.omg.CORBA.ORB orb = CommonAppletHelpers.initialize_orb_for_push_consumer(); //use the Portable Object Adapter (POA) to register the object with the ORB orb.connect(pushConsumer); //register pushConsumer with the ASManagementAgent and retrieve the ID //It is later used to disconnect the pushConsumer from the asm again pushConsumer.id = _asm.connect_push_consumer(pushConsumer); } catch (Exception el) { el.printStackTrace(); } } /** * Retrieve a list of implemented agents and prepare for later use. * <br>The file "ImplementedAgents.txt" contains a list of agents that are ready to load. It * provides the name, the package and the type (mobile/stationary) of the agents. It is * obtained using CommonAppletHelpers.retrieve_implemented_agents_file(...). * * @see CommonAppletHelpers */ public void get_impl_agents() { //retrieve the file ImplementedAgents.txt and store it into string_file String string_file = CommonAppletHelpers.retrieve_implemented_agents_file(_ass.getURL()); //copy the data into the appropriate arrays //they will be used when loading agents into the agent system with create_agent java.util.StringTokenizer agent_tokenizer = new java.util.StringTokenizer(string_file); int noe = (agent_tokenizer.countTokens())/3; impl_agent_list = new String[noe]; impl_package_list = new String[noe]; impl_type_list = new String[noe]; for (int i=0; i<noe; i++) { impl_agent_list[i] = agent_tokenizer.nextToken(); impl_package_list[i] = agent_tokenizer.nextToken(); impl_type_list[i] = agent_tokenizer.nextToken(); } } /** * Clears the selection in the agentTable and disables the buttons. * <br>To prevent accidential execution of agent-manipulating methods the selection in the agentTable * and the buttons that need a preselected agent are disabled after each action. The String variable * agent_identity is also cleared. */ public void clear_selection() { agentTable.clearSelection(); agent_identity = null; _bt_transferAgent.setEnabled(false); _bt_resume_agent.setEnabled(false); _bt_suspend_agent.setEnabled(false); _bt_terminate_agent.setEnabled(false); _bt_writeAgentToFile.setEnabled(false); _bt_showwebpage.setEnabled(false); } /** * Retrieves the parameters for all constructors defined for the selected agent. * <br>An agent can have more than one constructor, each with a different set of parameters. These * parameters are collected into an array of Vectors (param_matrix), each Vector representing * the parameter set of one constructor.<br> * The applet presents to the user a combobox (_ch_constructors) containing a list of constructor * choices defined by the number of parameters the constructor expects. * The parameters are retrieved using the ASManagementAgent. * * @see ASManagementAgent */ public void get_agent_parameters() { //get name, package and type (mobile/stationary) of the selected agent that is to be loaded String agent_name = (String) _ch_impl_agents.getSelectedItem(); int agent_index = _ch_impl_agents.getSelectedIndex(); String agent_package = impl_package_list[agent_index]; String agent_type = impl_type_list[agent_index]; //get parameters of all possible constructors for this agent //the parameter sets of the different constructors are located in the array elements //of the returned String array String parametersets[] = _asm.get_agent_parameters(agent_name, agent_package, agent_type); //check if ASManagementAgent could find the agent's class //if not then display a warning message if (parametersets[0].equals("failed")) { JOptionPane.showMessageDialog(null, "The class of the agent \""+agent_name+"\" could not be found!\nPlease check if the agent is properly installed."); } //parameter_set_tokenizer is used to retrieve the different sets of parameters //java.util.StringTokenizer parameter_set_tokenizer = new java.util.StringTokenizer(parameters, "#"); //parameter_tokenizer is used to retrieve the parameters within one set java.util.StringTokenizer parameter_tokenizer = null; //get number of parameter sets (= number of different constructors) int nop = parametersets.length;//parameter_set_tokenizer.countTokens(); if (nop == 0) { //no constructor defined param_matrix = new Vector[1]; param_matrix[0] = new Vector(0,1); constructor_list = new String[1]; constructor_list[0] = "0 arguments"; } else { param_matrix = new Vector[nop]; //each element of the array represents one parameter set constructor_list = new String[nop]; //list which will be shown in _ch_constructors ComboBox } //create the "matrix" of parameters and set up the combobox with constructor choices for (int i=0; i<nop; i++) { //parameter_tokenizer = new java.util.StringTokenizer(parameter_set_tokenizer.nextToken()); //get parameters of one constructor parameter_tokenizer = new java.util.StringTokenizer(parametersets[i]); //get parameters of one constructor int nop2 = parameter_tokenizer.countTokens(); param_matrix[i] = new Vector(0,1); constructor_list[i] = nop2 + " arguments"; for (int j=0; j<nop2; j++) { //copy parameters of one constructor into appropriate vector param_matrix[i].addElement(parameter_tokenizer.nextToken()); } } //update the displayed combobox with constructor choices repaint_ch_constructors(); } /** * Redefines the ComboBox showing the choice between possible constructors of the selected agent. * <br>Called when a new agent is selected from the implemented-agents-combobox (_ch_impl_agents). */ public void repaint_ch_constructors() { if (_ch_constructors != null) { //if it has already been called... //update the contents of _ch_constructors _ch_constructors.removeAllItems(); for (int i=0; i<constructor_list.length; i++) { _ch_constructors.addItem(constructor_list[i]); } //preselect the first choice _ch_constructors.setSelectedIndex(0); _ch_constructors.setEditable(false); //repaint JComboBox getContentPane().validate(); _ch_constructors.repaint(); //list parameters for the first constructor show_agent_parameters(0); } } /** * Shows the parameter set of the selected constructor in the table. * <br>The value of each parameter is predefined with the String constant "none" * * @param param_index index of the selected constructor */ public void show_agent_parameters(int param_index) { if (param_index != (-1)) { //(-1) after _ch_constructors.removeAllElements() paramTableModel.ParameterTableModel(); //create new data vector int nop = param_matrix[param_index].size(); for (int i=0; i<nop; i++) { String tmp[] = new String[2]; tmp[0] = (String) param_matrix[param_index].elementAt(i); //get parameter #i //check if parameter type is a valid one if (!(tmp[0].equals("java.lang.String")) && !(tmp[0].equals("java.lang.Integer")) && !(tmp[0].equals("java.lang.Float")) && !(tmp[0].equals("java.lang.Double")) && //(roelle): IMHO this was missing !(tmp[0].equals("java.lang.Boolean")) && !(tmp[0].equals("failed")) ) { JOptionPane.showMessageDialog(null, "\""+tmp[0]+"\" is not a valid parameter data type!"); } tmp[1] = "none"; paramTableModel.addValue(tmp); } //repaint table getContentPane().validate(); paramScrollPane.repaint(); } } /** * TableModel managing a list of arguments for an agentīs constructor. * <br>This TableModel manages a parameter set of one constructor. Each time a different constructor * is selected the Vector "data" is completely new defined. Two columns are defined. The first one * contains the data type of a parameter, the second one itīs value which must be provided * by the user. * * @see AbstractTableModel * @author Stefan Gerber */ class ParameterTableModel extends AbstractTableModel { String[] columnNames = {"Expected Parameters", "Values"}; Vector data; public void ParameterTableModel() { data = new Vector(0,1); } public int getColumnCount() { return columnNames.length; } public int getRowCount() { return data.size(); } public String getColumnName (int col) { return columnNames[col]; } public Object getValueAt(int row, int col) { return ((String[]) data.elementAt(row))[col]; } public void setValueAt(Object value, int row, int col) { //first get old value String newvalue[] = {(String) ((String[]) data.elementAt(row))[0], (String) ((String[]) data.elementAt(row))[1]}; newvalue[col] = (String) value; data.setElementAt(newvalue, row); fireTableCellUpdated(row, col); } public void addValue(String[] value) { data.addElement(value); fireTableRowsInserted(data.size()-1, data.size()-1); } public void rmValue(int row) { data.removeElementAt(row); fireTableRowsDeleted(row, row); } public boolean isElement(String an) { for (int i=0; i<data.size(); i++) { if (an.equals((String) (((String[]) data.elementAt(i))[0]))) return true; } return false; } public boolean isCellEditable(int row, int col) { //Note that the data/cell address is constant, //no matter where the cell appears onscreen. if (col < 1) { return false; } else { return true; } } } /** * TableModel managing the list of loaded agents in the agent system and their current status. * <br>Two columns are defined. The first one contains the names of the currently loaded agents, * the second one represents their status (running/suspended). * * @see AbstractTableModel * @author Stefan Gerber */ class AppletTableModel extends AbstractTableModel { String[] columnNames = {"Agent", "Status"}; Vector data; public void AppletTableModel() { data = new Vector(0,1); } public int getColumnCount() { return columnNames.length; } public int getRowCount() { return data.size(); } public String getColumnName (int col) { return columnNames[col]; } public Object getValueAt(int row, int col) { return ((String[]) data.elementAt(row))[col]; } public void setValueAt(Object value, int row, int col) { ((String[]) data.elementAt(row))[col] = (String) value; fireTableCellUpdated(row, col); } public void addValue(String[] value) { data.addElement(value); fireTableRowsInserted(data.size()-1, data.size()-1); } public void rmValue(int row) { data.removeElementAt(row); fireTableRowsDeleted(row, row); } public boolean isElement(String an) { for (int i=0; i<data.size(); i++) { if (an.equals((String) (((String[]) data.elementAt(i))[0]))) return true; } return false; } public void changeStatus(int row, String statusValue) { setValueAt(statusValue, row, 1); } public int whereis(String an) { for (int i=0; i<data.size(); i++) { if (an.equals((String) (((String[]) data.elementAt(i))[0]))) return i; } return (-1); } } /** * SelectionHandler for list of loaded agents (agentTable). * <br>Each time the user selects an agent from the table of loaded agents, the String variable * agent_identity is set and the buttons for the agent management are enabled. * * @see ListSelectionListener * @author Stefan Gerber */ class ListSelectionHandler implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { ListSelectionModel ls_model = (ListSelectionModel) e.getSource(); int index = ls_model.getMinSelectionIndex(); if (index < 0) { _bt_transferAgent.setEnabled(false); _bt_resume_agent.setEnabled(false); _bt_suspend_agent.setEnabled(false); _bt_terminate_agent.setEnabled(false); _bt_writeAgentToFile.setEnabled(false); _bt_showwebpage.setEnabled(false); agent_identity = null; } else { /* check if selected agent is mobile before enabling the transfer_agent-button */ int file_index = -1; String selected_agent = (String) agentTable.getValueAt(index, 0); //determine index where selected agent is in list of implemented agents //this index is stored in file_index for (int i=0; i<impl_agent_list.length; i++) { if (selected_agent.equals(impl_agent_list[i])) { file_index = i; break; } } //use file_index to determine if agent is mobile //enable button if agent is mobile or if no information about the agent was available //i.e. the agent was not in ImplementedAgents.txt if (file_index == (-1)) { _bt_transferAgent.setEnabled(true); } else if (impl_type_list[file_index].equals("MobileAgent")) { _bt_transferAgent.setEnabled(true); } else { _bt_transferAgent.setEnabled(false); } //check if selected agent is running or resumed if (((String) agentTable.getValueAt(index, 1)).equals("Running")) { _bt_resume_agent.setEnabled(false); _bt_suspend_agent.setEnabled(true); } else { _bt_resume_agent.setEnabled(true); _bt_suspend_agent.setEnabled(false); } _bt_terminate_agent.setEnabled(true); _bt_writeAgentToFile.setEnabled(true); _bt_showwebpage.setEnabled(true); agent_identity = (String) agentTable.getValueAt(index, 0); } } } /** * Implements the PushConsumer that is connected to the ASManagementAgent. * <br>The applet connects an instance of this class to the ASManagementAgent on startup. The agent calls * the PushConsumerīs push() method when a CORBA event is registered and supplies the event data. The * push() method defined in this class finds out which CORBA event occurred and reacts appropriately. * * @see ASManagementAgent * @author Stefan Gerber */ class PushConsumerImpl extends _PushConsumerImplBase { String[] event_data; public int id = 0; //id of this pushConsumer, needed for disconnection from ASManagementAgent public PushConsumerImpl() { System.err.println("\n\nAgentSystemApplet: PushConsumer created"); } public void push(org.omg.CORBA.Any any) { System.out.println("\n\nAgentSystemApplet: running push"); //extract CORBA event data out of any event_data = new String[5]; CosNotification.StructuredEvent se = CosNotification.StructuredEventHelper.extract(any); event_data[0] = se.header.fixed_header.event_type.domain_name; event_data[1] = se.header.fixed_header.event_type.type_name; //AgentUp/AgentDown/agentSystemUp/agentSystemDown event_data[2] = se.filterable_data[0].value.extract_string(); //agent_type event_data[3] = se.filterable_data[1].value.extract_string(); //agent_name/agent_system_ame event_data[4] = se.filterable_data[2].value.extract_string(); //event_channel_name if (agent_system_name.equals(event_data[0])) { // is this AS concerned? if (event_data[1].equals("AgentUp")) { //agent was started on this agent system String status = null; try { //find out status of the new agent AgentStatus state = _ass.get_agent_status((new NameWrapper(event_data[3]))._name); switch(state.value()){ case AgentStatus._CfMAFRunning: status = "Running"; break; case AgentStatus._CfMAFSuspended: status = "Suspended"; break; case AgentStatus._CfMAFTerminated: status = "Terminated"; break; default: status = "none"; break; } } catch (Exception e) { e.printStackTrace(); } //add name and status to agentTable String[] value = {event_data[3], status}; myModel.addValue(value); //repaint agentTable getContentPane().validate(); tableScrollPane.repaint(); //agentTable_panel.repaint(); //clear selection in agentTable and disable buttons for safety reasons clear_selection(); } else if (event_data[1].equals("AgentDown")) { //agent was terminated on this agent system //remove entry of the agent from agentTable myModel.rmValue(myModel.whereis(event_data[3])); //repaint agentTable getContentPane().validate(); tableScrollPane.repaint(); //agentTable_panel.repaint(); //clear selection in agentTable and disable buttons for safety reasons clear_selection(); } } } public void disconnect_push_consumer() { try { // Initialize the ORB. //org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(); // Initialize the BOA. //org.omg.CORBA.BOA boa = orb.BOA_init(); System.err.println("\n\nDisconnecting push_consumer...\n"); //boa.exit_impl_ready(); } catch (Exception ex) { ex.printStackTrace(); } } } }