/** * Gets the SendTo attribute of the MessageNode object * * @return The SendTo value */ public String getSendTo() { if (theMessage.getAllReceiver().hasNext()) { AID sender = (AID) theMessage.getAllReceiver().next(); return sender.getName(); } return "<unknown>"; }
private void handleInformKilled(VerticalCommand cmd) throws IMTPException, NotFoundException, ServiceException { Object[] params = cmd.getParams(); AID target = (AID) params[0]; // log("Source Sink consuming command INFORM_KILLED. Name is "+target.getName(), 3); if (myLogger.isLoggable(Logger.CONFIG)) myLogger.log( Logger.CONFIG, "Source Sink consuming command INFORM_KILLED. Name is " + target.getName()); // Remove CodeLocator entry. // #J2ME_EXCLUDE_BEGIN codeLocator.removeAgent(target); // #J2ME_EXCLUDE_END // Remove the dead agent from the LADT of the container removeLocalAgent(target); // Notify the main container through its slice AgentManagementSlice mainSlice = (AgentManagementSlice) getSlice(MAIN_SLICE); try { mainSlice.deadAgent(target, cmd); } catch (IMTPException imtpe) { // Try to get a newer slice and repeat... mainSlice = (AgentManagementSlice) getFreshSlice(MAIN_SLICE); mainSlice.deadAgent(target, cmd); } }
public String receivedFrom() { if (theMessage.getSender() != null) { AID sender = theMessage.getSender(); return sender.getName(); } return "<unknown>"; }
private void handleRequestKill(VerticalCommand cmd) throws IMTPException, JADESecurityException, NotFoundException, ServiceException { Object[] params = cmd.getParams(); AID agentID = (AID) params[0]; // log("Source Sink consuming command REQUEST_KILL. Name is "+agentID.getName(), 3); if (myLogger.isLoggable(Logger.CONFIG)) myLogger.log( Logger.CONFIG, "Source Sink consuming command REQUEST_KILL. Name is " + agentID.getName()); MainContainer impl = myContainer.getMain(); if (impl != null) { ContainerID cid = impl.getContainerID(agentID); // Note that since getContainerID() succeeded, targetSlice can't be null AgentManagementSlice targetSlice = (AgentManagementSlice) getSlice(cid.getName()); try { targetSlice.killAgent(agentID, cmd); } catch (IMTPException imtpe) { // Try to get a newer slice and repeat... targetSlice = (AgentManagementSlice) getFreshSlice(cid.getName()); targetSlice.killAgent(agentID, cmd); } } else { // Do nothing for now, but could also route the command to the main slice, thus enabling // e.g. AMS replication } }
/** * create a new ACLMessage that is a reply to this message. In particular, it sets the following * parameters of the new message: receiver, language, ontology, protocol, conversation-id, * in-reply-to, reply-with. The programmer needs to set the communicative-act and the content. Of * course, if he wishes to do that, he can reset any of the fields. * * @return the ACLMessage to send as a reply */ public ACLMessage createReply() { ACLMessage m = new ACLMessage(getPerformative()); Iterator it = getAllReplyTo(); while (it.hasNext()) m.addReceiver((AID) it.next()); if ((reply_to == null) || reply_to.isEmpty()) m.addReceiver(getSender()); m.setLanguage(getLanguage()); m.setOntology(getOntology()); m.setProtocol(getProtocol()); m.setInReplyTo(getReplyWith()); if (source != null) m.setReplyWith(source.getName() + java.lang.System.currentTimeMillis()); else m.setReplyWith("X" + java.lang.System.currentTimeMillis()); m.setConversationId(getConversationId()); // Copy only well defined user-def-params String trace = getUserDefinedParameter(TRACE); if (trace != null) { m.addUserDefinedParameter(TRACE, trace); } // #CUSTOM_EXCLUDE_BEGIN // Set the Aclrepresentation of the reply message to the aclrepresentation of the sent message if (messageEnvelope != null) { m.setDefaultEnvelope(); String aclCodec = messageEnvelope.getAclRepresentation(); if (aclCodec != null) m.getEnvelope().setAclRepresentation(aclCodec); } else m.setEnvelope(null); // #CUSTOM_EXCLUDE_END return m; }
private void handleInformKilled(VerticalCommand cmd) throws NotFoundException, ServiceException { Object[] params = cmd.getParams(); AID agentID = (AID) params[0]; // log("Target sink consuming command INFORM_KILLED: Name is "+agentID.getName(), 2); if (myLogger.isLoggable(Logger.FINE)) myLogger.log( Logger.FINE, "Target sink consuming command INFORM_KILLED: Name is " + agentID.getName()); deadAgent(agentID); }
private void handleRequestKill(VerticalCommand cmd) throws IMTPException, JADESecurityException, NotFoundException, ServiceException { Object[] params = cmd.getParams(); AID agentID = (AID) params[0]; // log("Target sink consuming command REQUEST_KILL: Name is "+agentID.getName(), 2); if (myLogger.isLoggable(Logger.FINE)) myLogger.log( Logger.FINE, "Target sink consuming command REQUEST_KILL: Name is " + agentID.getName()); killAgent(agentID); }
private void handleInformCreated(VerticalCommand cmd) throws NotFoundException, NameClashException, ServiceException { Object[] params = cmd.getParams(); AID agentID = (AID) params[0]; ContainerID cid = (ContainerID) params[1]; if (myLogger.isLoggable(Logger.FINE)) { myLogger.log( Logger.FINE, "Target sink consuming command INFORM_CREATED: Name is " + agentID.getName()); } bornAgent(agentID, cid, cmd.getPrincipal(), cmd.getCredentials()); }
/** * Get a controller (i.e. a proxy) to a local agent given its local-name or GUID. * * @param name The local name or the GUID of the desired agent. * @param isGuid A flag indicating whether <code>name</code> represents the local-name (<code> * AID.ISLOCALNAME</code>) or the GUID (<code>AID.ISGUID</code>) of the desired agent. * @throws ControllerException If any problems occur obtaining this proxy or if no such agent * exists in the local container. */ public AgentController getAgent(String name, boolean isGuid) throws ControllerException { if (myImpl == null || myProxy == null) { throw new StaleProxyException(); } if (!isGuid) { name = AID.createGUID(name, myImpl.getPlatformID()); } AID agentID = new AID(name, AID.ISGUID); // Check that the agent exists jade.core.Agent instance = myImpl.acquireLocalAgent(agentID); if (instance == null) { throw new ControllerException("Agent " + agentID.getName() + " not found."); } myImpl.releaseLocalAgent(agentID); return new AgentControllerImpl(agentID, myProxy, myImpl); }
private void handleInformCreated(VerticalCommand cmd) throws IMTPException, NotFoundException, NameClashException, JADESecurityException, ServiceException { Object[] params = cmd.getParams(); AID target = (AID) params[0]; Agent instance = (Agent) params[1]; JADEPrincipal owner = (JADEPrincipal) params[2]; if (myLogger.isLoggable(Logger.CONFIG)) { String ownerInfo = owner != null ? ", Owner = " + owner : ""; myLogger.log( Logger.CONFIG, "Source Sink consuming command INFORM_CREATED. Name is " + target.getName() + ownerInfo); } initAgent(target, instance, cmd); }
private ACLMessage createMessage() { ACLMessage message; if (id == -1) message = new ACLMessage(ACLMessage.FAILURE); else { message = new ACLMessage(ACLMessage.INFORM); BDDAnswerMessage answer = new BDDAnswerMessage(); answer.setDemande(demande); answer.setUser(user); answer.setId(id); ObjectMapper omap = new ObjectMapper(); String messageCorps; try { messageCorps = omap.writeValueAsString(answer); message.setContent(messageCorps); message.addReceiver(receiver); System.out.println(receiver.getName()); message.setConversationId(conversationId); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return message; }
private void handleRequestCreate(VerticalCommand cmd) throws IMTPException, JADESecurityException, NotFoundException, NameClashException, ServiceException { Object[] params = cmd.getParams(); AID agentID = (AID) params[0]; String className = (String) params[1]; Object[] arguments = (Object[]) params[2]; JADEPrincipal owner = (JADEPrincipal) params[3]; Credentials initialCredentials = (Credentials) params[4]; boolean startIt = ((Boolean) params[5]).booleanValue(); // log("Target sink consuming command REQUEST_CREATE: Name is "+agentID.getName(), 2); if (myLogger.isLoggable(Logger.FINE)) { String ownerInfo = owner != null ? ", Owner = " + owner : ""; myLogger.log( Logger.FINE, "Target sink consuming command REQUEST_CREATE: Name is " + agentID.getName() + ownerInfo); } createAgent(agentID, className, arguments, owner, initialCredentials, startIt); }
public VerticalCommand serve(HorizontalCommand cmd) { VerticalCommand result = null; try { String cmdName = cmd.getName(); Object[] params = cmd.getParams(); if (cmdName.equals(AgentManagementSlice.H_CREATEAGENT)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.REQUEST_CREATE, AgentManagementSlice.NAME, null); AID agentID = (AID) params[0]; String className = (String) params[1]; Object[] arguments = (Object[]) params[2]; JADEPrincipal owner = (JADEPrincipal) params[3]; Credentials initialCredentials = (Credentials) params[4]; Boolean startIt = (Boolean) params[5]; gCmd.addParam(agentID); gCmd.addParam(className); gCmd.addParam(arguments); gCmd.addParam(owner); gCmd.addParam(initialCredentials); gCmd.addParam(startIt); result = gCmd; } else if (cmdName.equals(AgentManagementSlice.H_KILLAGENT)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.REQUEST_KILL, AgentManagementSlice.NAME, null); AID agentID = (AID) params[0]; gCmd.addParam(agentID); result = gCmd; } else if (cmdName.equals(AgentManagementSlice.H_CHANGEAGENTSTATE)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.REQUEST_STATE_CHANGE, AgentManagementSlice.NAME, null); AID agentID = (AID) params[0]; Integer newState = (Integer) params[1]; gCmd.addParam(agentID); gCmd.addParam(newState); result = gCmd; } else if (cmdName.equals(AgentManagementSlice.H_BORNAGENT)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.INFORM_CREATED, AgentManagementSlice.NAME, null); AID agentID = (AID) params[0]; ContainerID cid = (ContainerID) params[1]; gCmd.addParam(agentID); gCmd.addParam(cid); JADEPrincipal owner = cmd.getPrincipal(); if (myLogger.isLoggable(Logger.FINE)) { String ownerInfo = owner != null ? ", Owner = " + owner : ""; myLogger.log( Logger.CONFIG, "Local slice processing H-command BORN_AGENT. Name is " + agentID.getName() + ownerInfo); } result = gCmd; } else if (cmdName.equals(AgentManagementSlice.H_DEADAGENT)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.INFORM_KILLED, AgentManagementSlice.NAME, null); AID agentID = (AID) params[0]; gCmd.addParam(agentID); result = gCmd; } else if (cmdName.equals(AgentManagementSlice.H_SUSPENDEDAGENT)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.INFORM_STATE_CHANGED, AgentManagementSlice.NAME, null); AID agentID = (AID) params[0]; gCmd.addParam(agentID); gCmd.addParam(jade.domain.FIPAAgentManagement.AMSAgentDescription.SUSPENDED); gCmd.addParam("*"); result = gCmd; } else if (cmdName.equals(AgentManagementSlice.H_RESUMEDAGENT)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.INFORM_STATE_CHANGED, AgentManagementSlice.NAME, null); AID agentID = (AID) params[0]; gCmd.addParam(agentID); gCmd.addParam(jade.domain.FIPAAgentManagement.AMSAgentDescription.ACTIVE); gCmd.addParam(jade.domain.FIPAAgentManagement.AMSAgentDescription.SUSPENDED); result = gCmd; } else if (cmdName.equals(AgentManagementSlice.H_EXITCONTAINER)) { GenericCommand gCmd = new GenericCommand( AgentManagementSlice.KILL_CONTAINER, AgentManagementSlice.NAME, null); result = gCmd; } } catch (Throwable t) { cmd.setReturnValue(t); } return result; }
private WSIGService createWSIGService(AID aid, ServiceDescription sd) throws Exception { // Get service prefix & name String servicePrefix = getServicePrefix(sd); String serviceName = servicePrefix + sd.getName(); // Verify if is a wsig service if (!isWSIGService(sd)) { log.info("Service " + serviceName + " discarded (no wsig service)"); return null; } // Verify if the service is already registered if (wsigStore.isServicePresent(serviceName)) { log.info("Service " + serviceName + " of agent " + aid.getName() + " is already registered"); return null; } // Get ontology // FIX-ME elaborate only first ontology String ontoName = null; Iterator ontoIt = sd.getAllOntologies(); if (ontoIt.hasNext()) { ontoName = (String) ontoIt.next(); } if (ontoName == null) { log.info( "Service " + serviceName + " of agent " + aid.getName() + " have not ontology registered"); return null; } // Create ontology instance String ontoClassname = WSIGConfiguration.getInstance().getOntoClassname(ontoName); if (ontoClassname == null) { log.warn("Ontology " + ontoName + " not present in WSIG configuration file"); return null; } Ontology serviceOnto; try { Class ontoClass = Class.forName(ontoClassname); Method getInstanceMethod = ontoClass.getMethod("getInstance"); serviceOnto = (Ontology) getInstanceMethod.invoke(null); } catch (Exception e) { log.warn("Ontology class " + ontoClassname + " not present in WSIG classpath", e); return null; } // Register new onto in anget getContentManager().registerOntology(serviceOnto); // Get mapper class Class mapperClass = getMapperClass(sd); // Create new WSIGService WSIGService wsigService = new WSIGService(); wsigService.setServiceName(serviceName); wsigService.setServicePrefix(servicePrefix); wsigService.setAid(aid); wsigService.setWsdl( new URL(WSIGConfiguration.getInstance().getWsdlUri() + "/" + serviceName + ".wsdl")); wsigService.setOnto(serviceOnto); wsigService.setMapperClass(mapperClass); // Create wsdl SDToWSDL.createWSDLFromSD(this, sd, wsigService); return wsigService; }