<commit_before>package org.pikater.core.agents.system.manager;

import jade.content.Concept;
import jade.content.lang.Codec.CodecException;
import jade.content.onto.OntologyException;
import jade.content.onto.UngroundedException;
import jade.content.onto.basic.Action;
import jade.domain.FIPAAgentManagement.NotUnderstoodException;
import jade.domain.FIPAAgentManagement.RefuseException;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.proto.AchieveREResponder;

import org.pikater.core.agents.system.Agent_Manager;
import org.pikater.core.agents.system.computationDescriptionParser.Parser;
import org.pikater.core.agents.system.computationDescriptionParser.dependencyGraph.ComputationGraph;
import org.pikater.core.agents.system.computationDescriptionParser.dependencyGraph.events.LoggerObserver;
import org.pikater.core.agents.system.data.DataManagerService;
import org.pikater.core.ontology.subtrees.batch.Batch;
import org.pikater.core.ontology.subtrees.batch.ExecuteBatchDebug;
import org.pikater.core.ontology.subtrees.batch.NewBatch;
import org.pikater.core.ontology.subtrees.batchDescription.ComputationDescription;
import org.pikater.shared.database.jpa.status.JPABatchStatus;

public class ParserBehaviour extends AchieveREResponder {
	
	private static final long serialVersionUID = 4754473043512463873L;
	
	private Agent_Manager agent;

    public ParserBehaviour(Agent_Manager agent_Manager) {
    	super(agent_Manager, MessageTemplate.MatchPerformative(ACLMessage.REQUEST));
    	
		this.agent = agent_Manager;

    }
    
    @Override
    protected ACLMessage handleRequest(final ACLMessage request) throws NotUnderstoodException, RefuseException {
   
    	Concept concept = null;
 
    	try {
            concept = ((Action)(agent.getContentManager().extractContent(request))).getAction();
        } catch (UngroundedException e) {
			agent.logError(e.getMessage(), e);
		} catch (CodecException e) {
			agent.logError(e.getMessage(), e);
		} catch (OntologyException e) {
			agent.logError(e.getMessage(), e);
		}
           
    	
    	/*
    	 * ExecuteBatchDebug is deprecated
    	 */
    	if (concept instanceof ExecuteBatchDebug) {
    		
    		ExecuteBatchDebug executeBatch =
    				(ExecuteBatchDebug) concept;
    		ComputationDescription comDescription =
					executeBatch.getDescription();
    		int batchID = executeBatch.getBatchID();
    		int userID = executeBatch.getUserID();
    		
    		return respondToNewBatch(comDescription, batchID, userID, request);
        }
    	
    	/*
    	 * NewBatch inform
    	 */
    	if (concept instanceof NewBatch) {
    		
    		NewBatch newBatch = (NewBatch) concept;
    		int userID = newBatch.getUserId();
    		
    		Batch batch = DataManagerService.loadBatch(agent, newBatch.getBatchId());
    		
    		ComputationDescription comDescription = batch.getDescription();
    		int batchID = batch.getId();
    		
    		return respondToNewBatch(comDescription, batchID, userID, request);
    		
    	}
   
		ACLMessage failure = request.createReply();
		failure.setPerformative(ACLMessage.FAILURE);
		agent.logError("Failure responding to request: " + request.getContent());
		
		return failure;
    }
    
    private ACLMessage respondToNewBatch(ComputationDescription comDescription,
    		int batchID, int userID, ACLMessage request) {

        Parser parser = new Parser(agent);
        parser.parseRoots(comDescription, batchID, userID);

        ComputationGraph computationGraph = parser.getComputationGraph();
        computationGraph.setBatchID(batchID);
        computationGraph.addObserver(new LoggerObserver(agent));
        ComputationCollectionItem item = new ComputationCollectionItem(
        		computationGraph, request, batchID);
        agent.addComputation(item);
        
        // change status to computing and log to database
        DataManagerService.updateBatchStatus(agent, batchID, JPABatchStatus.COMPUTING.name());
        
		computationGraph.startBatchComputation();
		
		
    	ACLMessage reply = request.createReply();
        reply.setPerformative(ACLMessage.INFORM);
        reply.setContent("OK");
        
        return reply;
    }
    
}<commit_msg>Agent_Manager - Bug fix - Faster reaction<commit_after>package org.pikater.core.agents.system.manager;

import jade.content.Concept;
import jade.content.lang.Codec.CodecException;
import jade.content.onto.OntologyException;
import jade.content.onto.UngroundedException;
import jade.content.onto.basic.Action;
import jade.domain.FIPAAgentManagement.NotUnderstoodException;
import jade.domain.FIPAAgentManagement.RefuseException;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.proto.AchieveREResponder;

import org.pikater.core.agents.system.Agent_Manager;
import org.pikater.core.agents.system.computationDescriptionParser.Parser;
import org.pikater.core.agents.system.computationDescriptionParser.dependencyGraph.ComputationGraph;
import org.pikater.core.agents.system.computationDescriptionParser.dependencyGraph.events.LoggerObserver;
import org.pikater.core.agents.system.data.DataManagerService;
import org.pikater.core.ontology.subtrees.batch.Batch;
import org.pikater.core.ontology.subtrees.batch.ExecuteBatchDebug;
import org.pikater.core.ontology.subtrees.batch.NewBatch;
import org.pikater.core.ontology.subtrees.batchDescription.ComputationDescription;
import org.pikater.shared.database.jpa.status.JPABatchStatus;

public class ParserBehaviour extends AchieveREResponder {
	
	private static final long serialVersionUID = 4754473043512463873L;
	
	private Agent_Manager agent;

    public ParserBehaviour(Agent_Manager agent_Manager) {
    	super(agent_Manager, MessageTemplate.MatchPerformative(ACLMessage.REQUEST));
    	
		this.agent = agent_Manager;

    }
    
    @Override
    protected ACLMessage handleRequest(final ACLMessage request) throws NotUnderstoodException, RefuseException {
   
    	Concept concept = null;
 
    	try {
            concept = ((Action)(agent.getContentManager().extractContent(request))).getAction();
        } catch (UngroundedException e) {
			agent.logError(e.getMessage(), e);
		} catch (CodecException e) {
			agent.logError(e.getMessage(), e);
		} catch (OntologyException e) {
			agent.logError(e.getMessage(), e);
		}
           
    	
    	/*
    	 * ExecuteBatchDebug is deprecated
    	 */
    	if (concept instanceof ExecuteBatchDebug) {
    		
    		ExecuteBatchDebug executeBatch =
    				(ExecuteBatchDebug) concept;
    		ComputationDescription comDescription =
					executeBatch.getDescription();
    		int batchID = executeBatch.getBatchID();
    		int userID = executeBatch.getUserID();
    		
    		return respondToNewBatch(comDescription, batchID, userID, request);
        }
    	
    	/*
    	 * NewBatch inform
    	 */
    	if (concept instanceof NewBatch) {
    		
    		NewBatch newBatch = (NewBatch) concept;
    		int userID = newBatch.getUserId();
    		
    		Batch batch = DataManagerService.loadBatch(agent, newBatch.getBatchId());
    		
    		ComputationDescription comDescription = batch.getDescription();
    		int batchID = batch.getId();
    		
    		return respondToNewBatch(comDescription, batchID, userID, request);
    		
    	}
   
		ACLMessage failure = request.createReply();
		failure.setPerformative(ACLMessage.FAILURE);
		agent.logError("Failure responding to request: " + request.getContent());
		
		return failure;
    }
    
    private ACLMessage respondToNewBatch(ComputationDescription comDescription,
    		int batchID, int userID, ACLMessage request) {

    	ACLMessage reply = request.createReply();
        reply.setPerformative(ACLMessage.INFORM);
        reply.setContent("OK");
        this.agent.send(reply);
        
        Parser parser = new Parser(agent);
        parser.parseRoots(comDescription, batchID, userID);

        ComputationGraph computationGraph = parser.getComputationGraph();
        computationGraph.setBatchID(batchID);
        computationGraph.addObserver(new LoggerObserver(agent));
        ComputationCollectionItem item = new ComputationCollectionItem(
        		computationGraph, request, batchID);
        agent.addComputation(item);
        
        // change status to computing and log to database
        DataManagerService.updateBatchStatus(agent, batchID, JPABatchStatus.COMPUTING.name());
        
		computationGraph.startBatchComputation();
		
        return null;
    }
    
}
{'fraction_non_alphanumeric': 0.09018912529550828, 'fraction_numerical': 0.004491725768321513, 'mean_word_length': 3.708402893711742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5324764', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2463, 'n_words': 419}