package __MASA_PACKAGE_agentSystem;
import __MASA_PACKAGE_agent__(AgentApplet);
import __MASA_PACKAGE__(tools.NameWrapper);
import __MASA_PACKAGE_CfMAF__(AgentStatus);
import java.awt.*;
import java.applet.*;
import java.util.*;
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.*;
/**
* This class contains some methods which are used by both AgentSystemApplet and ASManagementAgentApplet.
* <br>All methods are declared public static, so they can be called from every other class without even
* creating an instance of CommonAppletHelpers.
*
* @author Stefan Gerber
* @author extended by Harald Roelle
* @see AgentSystemApplet
* @see de.unimuenchen.informatik.mnm.masa.agent.asmanagementagent.ASManagementAgentApplet
*/
public class CommonAppletHelpers {
/**
* Returns the URL of an agent specified by "identity" on the agent system "host".
* <br>The URL is resolved using the Webserveragent by sending a request for "identity.url" to it.
*
* @param identity name of agent
* @param host URL of agent system
* @return URL of the agent
*/
public static java.net.URL getAgentURL(String identity, String host)
throws java.net.MalformedURLException, java.io.IOException {
System.err.println("\n\nCommonAppletHelpers.getAgentURL: host = "+host);
// create URL of the webserver-agent and url request:
// e.g.: http://sunhegering2:4300/FOO.url
// if identity is FOO.
String urlname= new String(host+"/"+identity+".url");
// send the request
java.net.URL urlIOR= new java.net.URL(urlname);
java.net.URLConnection con= urlIOR.openConnection();
// getting the answer
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));
String inputLine;
String urlstring=new String();
while ((inputLine = in.readLine()) != null)
urlstring=urlstring.concat(inputLine);
in.close();
System.err.println("CommonAppletHelpers.getAgentURL: urlstring = "+urlstring);
return (new java.net.URL(urlstring));
}
/**
* Shows a ComboBox from which the user can select the target agent system for an agent transfer.
* <br>The possible alternatives are defined by the Vector as_names. "parentComponent" is needed
* for JOptionPane.showInputDialog().
*
* @param parentComponent parent applet
* @param agent_identity name of agent to be transferred
* @param as_names vector containing the names of possible target agent systems
* @return String containing the name of the target agent system
*/
public static String show_migrate_menu(Component parentComponent, String agent_identity, java.util.Vector as_names) {
//specify the size str_as_names will have
//Both "global" and "voyager" are no agent systems a MASA agent can be transferred to.
int size = 0;
if (as_names.contains("voyager")) {
size = as_names.size() - 2; //-2 because of "global" and "voyager"
}
else {
size = as_names.size() - 1; //-1 because of "global"
}
String[] str_as_names = new String[size];
//copy names of all agent systems except "global" and "voyager"
int j =0;
String n;
for (int i = 0; i < as_names.size(); i++) {
n = (String) as_names.elementAt(i);
if (!((n.equals("global")) || (n.equals("voyager")))) {
str_as_names[j++] = n;
}
}
String target = (String) JOptionPane.showInputDialog(parentComponent,
"Migrating agent \""+ agent_identity +
"\"\n" + "Select the target agent system",
"Migrate agent dialog",
JOptionPane.QUESTION_MESSAGE,
null,
str_as_names,
str_as_names[0]);
return(target);
}
/**
* Retrieve a list of implemented agents from the Webserver agent
* <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īs location
* is defined by the MASA properties of the agent system, therefore it is read by
* the webserver agent and provided via HTTP request.
*
* @see de.unimuenchen.informatik.mnm.masa.agent.webserver.WebserverStationaryAgent
*/
public static String retrieve_implemented_agents_file(String host) {
//prepare the request for the list of implemented agents
String urlname = new String(host+"/"+"ImplementedAgents");
java.net.URL urlIOR = null;
java.net.URLConnection con = null;
String string_file = new String(); //will contain the answer of the webserver
try {
// send the request
urlIOR= new java.net.URL(urlname);
con= urlIOR.openConnection();
// getting the answer
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));
String inputLine;
//put the answer into string_file
while ((inputLine = in.readLine()) != null)
string_file = string_file.concat(inputLine)+ " ";
in.close();
} catch (Exception e1) {
System.err.println( "get_impl_agents urlname="+urlname);
e1.printStackTrace();
}
return string_file;
}
public static org.omg.CORBA.ORB initialize_orb_for_push_consumer()
{
#ifdef VISIBROKER30
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
#endif
#ifdef ORBACUS311
java.util.Properties props = new java.util.Properties();
props.put( "ooc.orb.conc_model", "threaded");
props.put( "ooc.boa.conc_model", "thread_per_request");
props.put( "org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB");
props.put( "org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton");
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init( new String[0], props);
// with Orbacus we still need the BOA for the event channel, sorry
org.omg.CORBA.BOA boa = ((com.ooc.CORBA.ORB)orb).BOA_init( new String[0], props);
((com.ooc.CORBA.BOA)boa).init_servers();
#endif
return orb;
}
}