Magentix2
2.1.1
|
Public Member Functions | |
SF (AgentID aid) throws Exception | |
SF () throws Exception | |
void | setSFServiceDescriptionLocation (String SFUrl) |
String | getSFServiceDescriptionLocation () |
Protected Member Functions | |
void | finalize (CProcessor firstProcessor, ACLMessage finalizeMessage) |
void | execution (CProcessor firstProcessor, ACLMessage welcomeMessage) |
Package Attributes | |
Configuration | configuration = Configuration.getConfiguration() |
ServiceTools | st = new ServiceTools() |
SFInterface | sfInterface = new SFInterface() |
Static Package Attributes | |
static Logger | logger = Logger.getLogger(SF.class) |
SF agent is responsible for managing all the request messages from other entities. It follows a FIPA-Request protocol
es.upv.dsic.gti_ia.organization.SF.SF | ( | AgentID | aid | ) | throws Exception |
Returns an instance of the agents SF
agent |
aid | AgentID which will be used to create the agent |
Exception |
Definition at line 74 of file SF.java.
{ super(aid); sfServicesURLs.put("RegisterService", 1); sfServicesURLs.put("DeregisterService",2); sfServicesURLs.put("GetService", 3); sfServicesURLs.put("SearchService", 4); sfServicesURLs.put("RemoveProvider", 5); }
es.upv.dsic.gti_ia.organization.SF.SF | ( | ) | throws Exception |
Constructor which creates and initializes the OMS agent. In this case the agent ID is SF.
Exception |
Definition at line 89 of file SF.java.
{ super(new AgentID("SF")); sfServicesURLs.put("RegisterService", 1); sfServicesURLs.put("DeregisterService",2); sfServicesURLs.put("GetService", 3); sfServicesURLs.put("SearchService", 4); sfServicesURLs.put("RemoveProvider", 5); }
void es.upv.dsic.gti_ia.organization.SF.execution | ( | CProcessor | firstProcessor, |
ACLMessage | welcomeMessage | ||
) | [protected, virtual] |
This is the main method of the agent
firstProcessor | The CProcessor managing the welcome conversation |
welcomeMessage | The message sent by the platform to the agent |
Implements es.upv.dsic.gti_ia.cAgents.CAgent.
Definition at line 122 of file SF.java.
{ class myFIPA_REQUEST extends FIPA_REQUEST_Participant { @Override protected String doAction(CProcessor myProcessor) { String next = ""; try { HashMap<String, String> inputs = new HashMap<String, String>(); // Extract the service name and inputs of the request String serviceName = st.extractServiceContent(myProcessor.getLastReceivedMessage().getContent(), inputs); String resultContent = ""; switch(sfServicesURLs.get(serviceName)) { case 1: //Register service resultContent = sfInterface.registerService(inputs.get("ServiceURL")); break; case 2: //De-register service resultContent = sfInterface.deregisterService(inputs.get("ServiceProfile")); break; case 3: //Get service resultContent = sfInterface.getService(inputs.get("ServiceProfile")); break; case 4: //Search service ArrayList<String> inputsService=new ArrayList<String>(); ArrayList<String> outputsService=new ArrayList<String>(); ArrayList<String> keywordsService=new ArrayList<String>(); StringTokenizer tokInputs=new StringTokenizer(inputs.get("Inputs"), "|"); while(tokInputs.hasMoreTokens()){ String in=tokInputs.nextToken().trim(); inputsService.add(in); logger.info("\t\t"+in); } logger.info("\tOutputs:"); StringTokenizer tokOutputs=new StringTokenizer(inputs.get("Outputs"), "|"); while(tokOutputs.hasMoreTokens()){ String out=tokOutputs.nextToken().trim(); outputsService.add(out); logger.info("\t\t"+out); } logger.info("\tKeywords:"); StringTokenizer tokKeywords=new StringTokenizer(inputs.get("Keywords"), "|"); while(tokKeywords.hasMoreTokens()){ String key=tokKeywords.nextToken().trim(); keywordsService.add(key); logger.info("\t\t"+key); } resultContent = sfInterface.searchService(inputsService, outputsService,keywordsService); break; case 5: //Remove provider String serviceProfile=inputs.get("ServiceProfile").trim(); String providerID=inputs.get("ProviderID").trim(); resultContent = sfInterface.removeProvider(serviceProfile, providerID); break; } // get the SF service WSDL URL // String serviceWSDLURL = sfServicesURLs.get(serviceName); // execute the SF service Requested // HashMap<String, Object> result = st.executeWebService(serviceWSDLURL, inputs); logger.info("[SF] Values obtained... "); logger.info("[SF] Creating inform message to send..."); next = "INFORM"; // get the result and put it in the response //String resultContent = (String) result.get("Result"); myProcessor.getLastReceivedMessage().setContent(resultContent); } catch (Exception e) { next = "FAILURE"; logger.error("[SF] Error at doAction."); } return next; } @Override protected void doInform(CProcessor myProcessor, ACLMessage response) { ACLMessage lastReceivedMessage = myProcessor.getLastReceivedMessage(); response.setContent(lastReceivedMessage.getContent()); } @Override protected String doReceiveRequest(CProcessor myProcessor, ACLMessage request) { String next = ""; ACLMessage msg = request; if (msg != null) { try { // extract the data of the request to check if the // requested service is one of the SF services HashMap<String, String> inputs = new HashMap<String, String>(); String serviceName = st.extractServiceContent(msg.getContent(), inputs); logger.info("[SF] Service Name: " + serviceName); if (sfServicesURLs.containsKey(serviceName)) { logger.info("AGREE"); next = "AGREE"; } else { logger.info("REFUSE"); next = "REFUSE"; } } catch (Exception e) { logger.info("EXCEPTION"); System.out.println(e); e.printStackTrace(); throw new RuntimeException(e.getMessage()); } } else { logger.info("NOTUNDERSTOOD"); next = "NOT_UNDERSTOOD"; } logger.info("[SF] Sending First message:" + next); return next; } } CFactory talk = new myFIPA_REQUEST().newFactory("TALK", null, 1, firstProcessor.getMyAgent()); // Finally the factory is setup to answer to incoming messages that // can start the participation of the agent in a new conversation this.addFactoryAsParticipant(talk); }
void es.upv.dsic.gti_ia.organization.SF.finalize | ( | CProcessor | firstProcessor, |
ACLMessage | finalizeMessage | ||
) | [protected, virtual] |
This method is executed just before the agent ends its execution
firstProcessor | The CProcessor managing the welcome conversation |
finalizeMessage | The final message produced by this conversation |
Implements es.upv.dsic.gti_ia.cAgents.CAgent.
Definition at line 118 of file SF.java.
{ }
void es.upv.dsic.gti_ia.organization.SF.setSFServiceDescriptionLocation | ( | String | SFUrl | ) |
Logger es.upv.dsic.gti_ia.organization.SF.logger = Logger.getLogger(SF.class) [static, package] |
The logger variable considers to print any event that occurs by the agent
Reimplemented from es.upv.dsic.gti_ia.core.BaseAgent.
SFInterface es.upv.dsic.gti_ia.organization.SF.sfInterface = new SFInterface() [package] |
ServiceTools es.upv.dsic.gti_ia.organization.SF.st = new ServiceTools() [package] |
Reimplemented from es.upv.dsic.gti_ia.core.BaseAgent.