Magentix2  2.1.1
es.upv.dsic.gti_ia.organization.SF Class Reference
Inheritance diagram for es.upv.dsic.gti_ia.organization.SF:
Collaboration diagram for es.upv.dsic.gti_ia.organization.SF:

List of all members.

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)

Detailed Description

SF agent is responsible for managing all the request messages from other entities. It follows a FIPA-Request protocol

Author:
Jose Alemany Bordera - jalemany1@dsic.upv.es

Definition at line 22 of file SF.java.


Constructor & Destructor Documentation

Returns an instance of the agents SF

Parameters:
agent
Returns:
sf Returns an instance of the agents SF
sf Constructor which creates and initializes the SF agent.
Parameters:
aidAgentID which will be used to create the agent
Exceptions:
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);
        }

Constructor which creates and initializes the OMS agent. In this case the agent ID is SF.

Exceptions:
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);
        }

Member Function Documentation

void es.upv.dsic.gti_ia.organization.SF.execution ( CProcessor  firstProcessor,
ACLMessage  welcomeMessage 
) [protected, virtual]

This is the main method of the agent

Parameters:
firstProcessorThe CProcessor managing the welcome conversation
welcomeMessageThe 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

Parameters:
firstProcessorThe CProcessor managing the welcome conversation
finalizeMessageThe final message produced by this conversation

Implements es.upv.dsic.gti_ia.cAgents.CAgent.

Definition at line 118 of file SF.java.

                                                                                       {
        }

get the URL where the OWL-S document is located.

Parameters:
SFUrl

Definition at line 113 of file SF.java.

                                                        {
                return this.SFServiceDescriptionLocation;
        }

Change the URL where the OWL-S document is located.

Parameters:
SFUrl

Definition at line 104 of file SF.java.

                                                                  {
                this.SFServiceDescriptionLocation = SFUrl;
        }

Member Data Documentation

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.

Definition at line 30 of file SF.java.

Definition at line 33 of file SF.java.

Reimplemented from es.upv.dsic.gti_ia.core.BaseAgent.

Definition at line 32 of file SF.java.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables