<commit_before>/*****************************************************************
JADE - Java Agent DEvelopment Framework is a framework to develop
multi-agent systems in compliance with the FIPA specifications.
Copyright (C) 2000 CSELT S.p.A.

GNU Lesser General Public License

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, 
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.
*****************************************************************/

package jade.proto;

import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.*;
import jade.domain.FIPAAgentManagement.NotUnderstoodException;
import jade.domain.FIPAAgentManagement.RefuseException;
import jade.domain.FIPAAgentManagement.FailureException;
import jade.proto.states.MsgReceiver;

/**
 *
 * This is a single homogeneous and effective implementation of
 * all the FIPA-Request-like interaction protocols defined by FIPA,
 * that is all those protocols where the initiator sends a single message
 * (i.e. it performs a single communicative act) within the scope
 * of an interaction protocol in order to verify if the RE (Rational
 * Effect) of the communicative act has been achieved or not.
 * @see AchieveREInitiator
 * @author <NAME> - TILab
 * @author <NAME> - TILab
 * @author <NAME> - TILab
 * @version $Date$ $Revision$
 **/
public class AchieveREResponder extends FSMBehaviour implements FIPAProtocolNames {
	
    /** 
     * key to retrieve from the DataStore of the behaviour the ACLMessage 
     *	object sent by the initiator.
     **/
    public final String REQUEST_KEY = "__request" + hashCode();
    /** 
     * key to retrieve from the DataStore of the behaviour the ACLMessage 
     *	object sent as a response to the initiator.
     **/
    public final String RESPONSE_KEY = "__response" + hashCode();
    /** 
     * key to retrieve from the DataStore of the behaviour the ACLMessage 
     *	object sent as a result notification to the initiator.
     **/
    public final String RESULT_NOTIFICATION_KEY = "__result-notification" + hashCode();

    // FSM states names
    private static final String RECEIVE_REQUEST = "Receive-request";
    private static final String PREPARE_RESPONSE = "Prepare-response";
    private static final String SEND_RESPONSE = "Send-response";
    private static final String PREPARE_RESULT_NOTIFICATION = "Prepare-result-notification";
    private static final String SEND_RESULT_NOTIFICATION = "Send-result-notification";
	

    // The MsgReceiver behaviour used to receive request messages
    MsgReceiver rec = null;
	
    /**
       This static method can be used 
       to set the proper message Template (based on the interaction protocol 
       and the performative)
       into the constructor of this behaviour.
       @see FIPAProtocolNames.FIPA_REQUEST_PROTOCOL
       @see FIPAProtocolNames.FIPA_QUERY_PROTOCOL
    **/
    public static MessageTemplate createMessageTemplate(String iprotocol){
	
	if(CaseInsensitiveString.equalsIgnoreCase(FIPA_REQUEST,iprotocol))
	    return MessageTemplate.and(MessageTemplate.MatchProtocol(FIPA_REQUEST),MessageTemplate.MatchPerformative(ACLMessage.REQUEST));
	else
	    if(CaseInsensitiveString.equalsIgnoreCase(FIPA_QUERY,iprotocol))
		return MessageTemplate.and(MessageTemplate.MatchProtocol(FIPA_QUERY),MessageTemplate.or(MessageTemplate.MatchPerformative(ACLMessage.QUERY_IF),MessageTemplate.MatchPerformative(ACLMessage.QUERY_REF)));
	    else
		return MessageTemplate.MatchProtocol(iprotocol);
    }

    /**
     * Constructor of the behaviour that creates a new empty DataStore
     * @see AchieveREResponder(Agent a, MessageTemplate mt, DataStore store) 
     **/
    public AchieveREResponder(Agent a, MessageTemplate mt){
	this(a,mt, new DataStore());
    }

    /**
     * Constructor.
     * @param a is the reference to the Agent object
     * @param mt is the MessageTemplate that must be used to match
     * the initiator message. Take care that 
     * if mt is null every message is consumed by this protocol.
     * @param store the DataStore for this protocol
     **/
    public AchieveREResponder(Agent a, MessageTemplate mt, DataStore store) {
	super(a);
		
	setDataStore(store);
		
	// Register the FSM transitions
	registerDefaultTransition(RECEIVE_REQUEST, PREPARE_RESPONSE);
	registerDefaultTransition(PREPARE_RESPONSE, SEND_RESPONSE);
	registerTransition(SEND_RESPONSE, PREPARE_RESULT_NOTIFICATION, ACLMessage.AGREE);
	registerDefaultTransition(SEND_RESPONSE, RECEIVE_REQUEST);
	registerDefaultTransition(PREPARE_RESULT_NOTIFICATION, SEND_RESULT_NOTIFICATION);		
	registerDefaultTransition(SEND_RESULT_NOTIFICATION, RECEIVE_REQUEST);
	
	// Create and register the states that make up the FSM
	Behaviour b = null;
	// RECEIVE_REQUEST
	<commit_msg>fixed error in javac doc references<commit_after>/*****************************************************************
JADE - Java Agent DEvelopment Framework is a framework to develop
multi-agent systems in compliance with the FIPA specifications.
Copyright (C) 2000 CSELT S.p.A.

GNU Lesser General Public License

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, 
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.
*****************************************************************/

package jade.proto;

import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.*;
import jade.domain.FIPAAgentManagement.NotUnderstoodException;
import jade.domain.FIPAAgentManagement.RefuseException;
import jade.domain.FIPAAgentManagement.FailureException;
import jade.proto.states.MsgReceiver;

/**
 *
 * This is a single homogeneous and effective implementation of
 * all the FIPA-Request-like interaction protocols defined by FIPA,
 * that is all those protocols where the initiator sends a single message
 * (i.e. it performs a single communicative act) within the scope
 * of an interaction protocol in order to verify if the RE (Rational
 * Effect) of the communicative act has been achieved or not.
 * @see AchieveREInitiator
 * @author <NAME> - TILab
 * @author <NAME> - TILab
 * @author <NAME> - TILab
 * @version $Date$ $Revision$
 **/
public class AchieveREResponder extends FSMBehaviour implements FIPAProtocolNames {
	
    /** 
     * key to retrieve from the DataStore of the behaviour the ACLMessage 
     *	object sent by the initiator.
     **/
    public final String REQUEST_KEY = "__request" + hashCode();
    /** 
     * key to retrieve from the DataStore of the behaviour the ACLMessage 
     *	object sent as a response to the initiator.
     **/
    public final String RESPONSE_KEY = "__response" + hashCode();
    /** 
     * key to retrieve from the DataStore of the behaviour the ACLMessage 
     *	object sent as a result notification to the initiator.
     **/
    public final String RESULT_NOTIFICATION_KEY = "__result-notification" + hashCode();

    // FSM states names
    private static final String RECEIVE_REQUEST = "Receive-request";
    private static final String PREPARE_RESPONSE = "Prepare-response";
    private static final String SEND_RESPONSE = "Send-response";
    private static final String PREPARE_RESULT_NOTIFICATION = "Prepare-result-notification";
    private static final String SEND_RESULT_NOTIFICATION = "Send-result-notification";
	

    // The MsgReceiver behaviour used to receive request messages
    MsgReceiver rec = null;
	
    /**
       This static method can be used 
       to set the proper message Template (based on the interaction protocol 
       and the performative)
       into the constructor of this behaviour.
       @see FIPAProtocolNames
    **/
    public static MessageTemplate createMessageTemplate(String iprotocol){
	
	if(CaseInsensitiveString.equalsIgnoreCase(FIPA_REQUEST,iprotocol))
	    return MessageTemplate.and(MessageTemplate.MatchProtocol(FIPA_REQUEST),MessageTemplate.MatchPerformative(ACLMessage.REQUEST));
	else
	    if(CaseInsensitiveString.equalsIgnoreCase(FIPA_QUERY,iprotocol))
		return MessageTemplate.and(MessageTemplate.MatchProtocol(FIPA_QUERY),MessageTemplate.or(MessageTemplate.MatchPerformative(ACLMessage.QUERY_IF),MessageTemplate.MatchPerformative(ACLMessage.QUERY_REF)));
	    else
		return MessageTemplate.MatchProtocol(iprotocol);
    }

    /**
     * Constructor of the behaviour that creates a new empty DataStore
     * @see #AchieveREResponder(Agent a, MessageTemplate mt, DataStore store) 
     **/
    public AchieveREResponder(Agent a, MessageTemplate mt){
	this(a,mt, new DataStore());
    }

    /**
     * Constructor.
     * @param a is the reference to the Agent object
     * @param mt is the MessageTemplate that must be used to match
     * the initiator message. Take care that 
     * if mt is null every message is consumed by this protocol.
     * @param store the DataStore for this protocol
     **/
    public AchieveREResponder(Agent a, MessageTemplate mt, DataStore store) {
	super(a);
		
	setDataStore(store);
		
	// Register the FSM transitions
	registerDefaultTransition(RECEIVE_REQUEST, PREPARE_RESPONSE);
	registerDefaultTransition(PREPARE_RESPONSE, SEND_RESPONSE);
	registerTransition(SEND_RESPONSE, PREPARE_RESULT_NOTIFICATION, ACLMessage.AGREE);
	registerDefaultTransition(SEND_RESPONSE, RECEIVE_REQUEST);
	registerDefaultTransition(PREPARE_RESULT_NOTIFICATION, SEND_RESULT_NOTIFICATION);		
	registerDefaultTransition(SEND_RESULT_NOTIFICATION, RECEIVE_REQUEST);
	
	// Create and register the states that make up the FSM
	Behaviour b = null;
	// RECEIVE_REQUEST
	
{'fraction_non_alphanumeric': 0.09002364066193853, 'fraction_numerical': 0.0037825059101654845, 'mean_word_length': 4.317244846656611, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116066', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2839, 'n_words': 1017}