Package it.unito.di.test

Source Code of it.unito.di.test.TestCNPProtocolCommits

package it.unito.di.test;

import java.util.ArrayList;

import it.unito.di.artifact.examples.cnpCommits.InitiatorAgent;
import it.unito.di.artifact.examples.cnpCommits.ParticipantAgent;
import it.unito.di.logic.exception.MissingOperandException;
import it.unito.di.logic.exception.WrongOperandsNumberException;
import it.unito.di.logic.expression.CompositeExpression;
import it.unito.di.logic.expression.Fact;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
import cartago.CartagoException;
import cartago.CartagoService;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class TestCNPProtocolCommits {
 
  private static Logger logger = LogManager.getLogger(TestCNPProtocolCommits.class);
 
  public static void main(String[] args)  {
    try {
      CartagoService.startNode();
      testAgents();
     
//      testExpressionTree();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
       
  }
 
  private static void testAgents() throws Exception {
   
    final Runtime rt = Runtime.instance();
    Profile p = new ProfileImpl();
    p.setParameter("gui", "true");
    ContainerController cc = rt.createMainContainer(p);
   
    java.lang.Runtime.getRuntime().addShutdownHook(new Thread()
    {
        @Override
        public void run()
        {
            rt.shutDown();
        }
    });
   
    AgentController initiator = cc.createNewAgent("Initiator",
        InitiatorAgent.class.getCanonicalName(), null);
   
    ArrayList<AgentController> participants = new ArrayList<AgentController>();
    for (int i=0;i<2;i++) {
      participants.add(cc.createNewAgent("Participant-"+i,
        ParticipantAgent.class.getCanonicalName(), null));
    }
   
    for (AgentController part : participants) {
      part.start();
    }
   
   
    initiator.start();
  }
 
  private static void testExpressionTree() throws MissingOperandException, WrongOperandsNumberException, CartagoException {
   
    CompositeExpression le1 =
        CompositeExpression.and(new Fact("pippo", new Fact("pippoInside")),
            CompositeExpression.or(new Fact("ripippo"),
              CompositeExpression.not(new Fact("ripippo")))
            );
   
    logger.info(le1.toString());   
    logger.error("pippo");
       
  }
 
 
}
TOP

Related Classes of it.unito.di.test.TestCNPProtocolCommits

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.