@Override protected void setup() { try { Thread.sleep((int) (Math.random() * 500)); } catch (InterruptedException e) { } // spread console output // curator interest setup int numberOfInterests = 2 + ((int) (Math.random() * 8)); // 2-9 int i = 0; int randomGenre; while (i < numberOfInterests) { randomGenre = (int) (Math.random() * Auctioneer.genres.length); if (!interests.contains(Auctioneer.genres[randomGenre])) { // already taken? interests.add(Auctioneer.genres[randomGenre]); priorityInterests.add(1 + ((int) (Math.random() * 5))); i++; } } System.out.print(getName() + ": My interests & priority: "); for (int j = 0; j < interests.size(); j++) System.out.print( interests.get(j) + "(" + priorityInterests.get(j) + ")" + ((j != interests.size() - 1) ? ", " : "")); System.out.print("\n"); publishServices(); MessageTemplate mt = AchieveREResponder.createMessageTemplate(FIPANames.InteractionProtocol.FIPA_REQUEST); addBehaviour(new ArtifactLookup(this, mt)); addBehaviour(new AuctionFSM(this)); // participate in auction addBehaviour(new Income(this, 3000)); // give curators new money every 3th auction }
/* * Method that register the room agent to the df and defines requests managment */ protected void registerRoom() { // Create the agent description. DFAgentDescription dfd = new DFAgentDescription(); dfd.setName(getAID()); // Create the services description. ServiceDescription deviceListSD = new ServiceDescription(); deviceListSD.setType(HomeAutomation.SERVICE_ROOM_DEVICE_LIST); deviceListSD.setName("JADE-room-device-list"); ServiceDescription deviceRegistrationSD = new ServiceDescription(); deviceRegistrationSD.setType("room-device-registration"); deviceRegistrationSD.setType(HomeAutomation.SERVICE_ROOM_DEVICE_REGISTRATION); deviceRegistrationSD.setName("JADE-room-device-registration"); // Add the services description to the agent description. // TODO add here other Sevice Descriptions dfd.addServices(deviceListSD); dfd.addServices(deviceRegistrationSD); try { // Register the service log( "Registering '" + deviceListSD.getType() + "' service named '" + deviceListSD.getName() + "'" + "to the default DF..."); DFService.register(this, dfd); log("Waiting for request..."); } catch (FIPAException fe) { fe.printStackTrace(); } // Add the behaviour serving queries from controller agents. MessageTemplate template = AchieveREResponder.createMessageTemplate(FIPANames.InteractionProtocol.FIPA_REQUEST); addBehaviour( new AchieveREResponder(this, template) { @Override protected ACLMessage handleRequest(ACLMessage request) throws NotUnderstoodException, RefuseException { log("Handle request with content"); return new ACLMessage(ACLMessage.AGREE); } @Override protected ACLMessage prepareResultNotification(ACLMessage request, ACLMessage response) { // log("Prepare result notification with content: " + request.getContent()); response.setPerformative(ACLMessage.INFORM); Message message = null; try { message = (Message) request.getContentObject(); } catch (UnreadableException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (message != null) { if (message.getService().equals(HomeAutomation.SERVICE_ROOM_DEVICE_LIST)) { try { // send device array response.setContentObject(devices); } catch (IOException e) { e.printStackTrace(); } } else if (message .getService() .equals(HomeAutomation.SERVICE_ROOM_DEVICE_REGISTRATION)) { RegistrationMessage regMessage = (RegistrationMessage) message; if (regMessage.getParentId().equals(id)) { AgentMessage agentDesc = new AgentMessage( regMessage.getAid(), regMessage.getParentId(), regMessage.getName(), regMessage.getDescription()); devices.add(agentDesc); log( "Device " + request.getSender() + " successfully added to room's device list."); } else { // send refuse.. log("Wrong room!!"); response.setPerformative(ACLMessage.REFUSE); } } } return response; } }); }