@Override public void setArrivalTerminalExit() { ClientCom con = new ClientCom(genRepInfo.getHostName(), genRepInfo.getPortNumber()); Message inMessage, outMessage; while (!con.open()) { try { Thread.sleep((long) (10)); } catch (InterruptedException e) { } } outMessage = new Message( Message.INT_INT_STR, Message.SET_ARRIVAL_TERMINAL_EXIT, arrTermExitInfo.getPortNumber(), arrTermExitInfo.getHostName()); con.writeObject(outMessage); inMessage = (Message) con.readObject(); con.close(); if (inMessage.getType() != Message.ACK) { System.out.println("Invalid message type!"); System.exit(1); } }
/** @param busQueue */ @Override public void updateDriverQueue(int[] busQueue) { ClientCom con = new ClientCom(genRepInfo.getHostName(), genRepInfo.getPortNumber()); Message inMessage, outMessage; while (!con.open()) { try { Thread.sleep((long) (10)); } catch (InterruptedException e) { } } outMessage = new Message(Message.INT_INTARR, Message.UPDATE_DRIVER_QUEUE, busQueue); con.writeObject(outMessage); inMessage = (Message) con.readObject(); con.close(); if (inMessage.getType() != Message.ACK) { System.out.println("Invalid message type!"); System.exit(1); } }
@Override public void action() { // We have to use a timeout to allow the WakerBehaviour to take place final ACLMessage msg = this.myAgent.blockingReceive(100); if (msg == null) { return; } final AID sender = msg.getSender(); Message message = null; try { message = (Message) msg.getContentObject(); } catch (final UnreadableException e) { System.err.println("[" + this.myAgent.getAID() + "] Error receiving message from " + sender); e.printStackTrace(System.err); return; } System.err.println( "INFO: [" + this.myAgent.getAID() + "] ReceiveMessage (" + message.getType() + ")"); switch (message.getType()) { case FIRST_ASSIGNATION_REQUEST: // TODO: This should maybe be an INFORM message, with reply this.teacher.sendMessage( sender, new FirstAssignationMessage(this.firstAssignation(sender))); this.alumnCount += 1; assert this.alumnCount <= TeacherBehaviour.EXPECTED_ALUMN_COUNT; if (TeacherBehaviour.EXPECTED_ALUMN_COUNT == this.alumnCount) { this.teacher.sendMessageToType("alumn", new InitMessage()); } return; case TEACHER_GROUP_CHANGE_REQUEST: final TeacherGroupChangeRequestMessage requestMessage = (TeacherGroupChangeRequestMessage) message; assert requestMessage.fromAlumn.equals(sender); // Ensure those alumns haven't been changed previously if (this.groups.get(requestMessage.fromAlumn) == requestMessage.fromGroup && this.groups.get(requestMessage.toAlumn) == requestMessage.toGroup) { this.groups.put(requestMessage.fromAlumn, requestMessage.toGroup); this.groups.put(requestMessage.toAlumn, requestMessage.fromGroup); this.teacher.sendMessageToType( "alumn", new TeacherGroupChangeMessage( requestMessage.fromAlumn, requestMessage.toAlumn, requestMessage.fromGroup, requestMessage.toGroup)); } else { this.teacher.sendMessage( requestMessage.fromAlumn, new TeacherGroupChangeRequestDenegationMessage()); } return; default: System.err.println( "ERROR: Unexpected message of type " + message.getType() + " received in TeacherBehaviour. Sender: " + sender + "; Receiver: " + this.teacher.getAID()); return; } }