All Downloads are FREE. Search and download functionalities are using the official Maven repository.

es.upm.dit.gsi.beast.platform.jadex.JadexMessenger Maven / Gradle / Ivy

Go to download

BEhavioural Agents Simple Testing Tool - BEAST Tool The aim of this project is the development of a system which allows Behavior Driven Development (BDD) in Multi-Agent Systems (MAS), to make testing practices more accessible and intuitive to everybody. In one hand, in order to let tests be writable by newcomers and experts alike, system must allow the redaction of tests in plain text, because client does not need to have knowledge of our code. This plain text will be traduced to software later. The definition of test will be realized with the terminology Given-When-Then, which allows trace an easy guide of the behavior of a given scenario when something happened. In the other hand, due to the complexity of MAS, making unit testing of an agent that needs the interaction with others is almost impossible until the whole system is finished. This implies to leave testing issues to the end of the project, generating big troubles in case of malfunction. Consequently, its necessary to carry out a tool to allow the creation of mock agents and to perform tests during the whole development process. Therefore another objective of our systems is to include a mocking tool which permits testing continuously. Definitively, our tool allows the testing of any MAS in the development process, increasing its modularity and decreasing its elaboration and testing cost. These tests will be written in plain text so that anyone would be able to understand them. For further reading, a paper published in ITMAS2012 workshop can be found in: http://scholar.google.es/citations?view_op=view_citation&hl=es&user=mT3KgXUAAAAJ&citation_for_view=mT3KgXUAAAAJ:Tyk-4Ss8FVUC

The newest version!
package es.upm.dit.gsi.beast.platform.jadex;

import jadex.base.fipa.SFipa;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IMessageService;
import jadex.commons.Tuple;

import java.util.ArrayList;
import java.util.HashMap;

import es.upm.dit.gsi.beast.platform.Connector;
import es.upm.dit.gsi.beast.platform.Messenger;

/**
 * Project: beast
 * File: es.upm.dit.gsi.beast.platform.jadex.JadexMessenger.java
 * 
 * To send messages to our jadex agents.
 * 
 * Grupo de Sistemas Inteligentes
 * Departamento de Ingeniería de Sistemas Telemáticos
 * Universidad Politécnica de Madrid (UPM)
 * 
 * @author Jorge Solitario
 * 
 * @author alvarocarrera
 * @email [email protected]
 * @twitter @alvarocarrera
 * @version 0.1
 * 
 */
public class JadexMessenger implements Messenger {

    private static JadexMessenger INSTANCE = new JadexMessenger();

    private JadexMessenger() {
    }

    public static JadexMessenger getInstance() {
        return INSTANCE;
    }

    /**
     * This method sends the same message to many agents.
     * 
     * @param agent_name
     *            The id of the agents that receive the message
     * @param msgtype
     * @param message_content
     *            The content of the message
     * @param connector
     *            The connector to get the external access
     */
    public void sendMessageToAgents(String[] agent_name, String msgtype,
            Object message_content, Connector connector) {
        HashMap hm = new HashMap();
        hm.put("performative", msgtype);
        hm.put(SFipa.CONTENT, message_content);
        IComponentIdentifier[] ici = new IComponentIdentifier[agent_name.length];
        for (int i = 0; i < agent_name.length; i++) {
            ici[i] = (IComponentIdentifier) connector.getAgentID(agent_name[i]);
        }
        ((IMessageService) connector.getMessageService()).deliverMessage(hm,
                "fipa", ici);
    }

    /**
     * This method works as the one above, adding some properties to the message
     * 
     * @param agent_name
     *            The id of the agents that receive the message
     * @param msgtype
     * @param message_content
     *            The content of the message
     * @param properties
     *            to be added to the message
     * @param connector
     *            The connector to get the external access
     */
    public void sendMessageToAgentsWithExtraProperties(String[] agent_name,
            String msgtype, Object message_content,
            ArrayList properties, Connector connector) {
        HashMap hm = new HashMap();
        hm.put("performative", msgtype);
        hm.put(SFipa.CONTENT, message_content);

        for (Object property : properties) {
            // Logger logger = Logger.getLogger("JadexMessenger");
            // logger.info("Sending message with extra property: "+property.get(0)+", with value "+property.get(1));
            hm.put((String) ((Tuple) property).get(0), ((Tuple) property).get(1));
        }

        IComponentIdentifier[] ici = new IComponentIdentifier[agent_name.length];
        for (int i = 0; i < agent_name.length; i++) {
            ici[i] = (IComponentIdentifier) connector.getAgentID(agent_name[i]);
        }
        ((IMessageService) connector.getMessageService()).deliverMessage(hm,
                "fipa", ici);
    }

}