distributed_automated/multi_agent_system/src/com/mas/main/PalletAgent.java
<reponame>haiderali27/master_assignmentspackage com.mas.main;

import java.util.Random;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.TickerBehaviour;
import jade.lang.acl.ACLMessage;

public class PalletAgent extends Agent{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int palletPlacedCount;
	protected void setup(){
		addBehaviour(new PalletBehaviour(this, 5000L));
	}
	   private class PalletBehaviour extends TickerBehaviour  {
	        public PalletBehaviour(Agent a, long period) {
			super(a, period);
		}

			/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

			@Override
			public void onTick() {
				Random random = new Random();
			    int randomNumber1 = random.nextInt(14) + 1; 
			    int randomNumber2 = random.nextInt(14) + 1; 
	            System.out.println("Agent is placing Pallet on Conveyor: "+randomNumber1+", with Dest:"+randomNumber2);
	            // Send a message to Agent 2
	            ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
	            msg.setContent("ADD_PALLET:"+Integer.toString(randomNumber2));
	            msg.addReceiver(new AID("ConveyorAgent"+randomNumber1, AID.ISLOCALNAME));
	            send(msg);
	            ACLMessage response = blockingReceive(); // Wait for a response
	            if (response != null) {
	                // Process the response
	                String content = response.getContent();
	                System.out.println("Received response From ConveyorAgent"+randomNumber1+": " + content);
	            } else {
	                System.out.println("Did not receive a response from ConveyorAgent"+randomNumber1);
	            }
	            
	        }

	    }

}
