/** * This method configures and send a ACLMessage to start a new remote-Container. * * @param remConf the RemoteContainerConfig * @param preventUsageOfAlreadyUsedComputers the boolean prevent usage of already used computers * @return the name of the container */ private String sendMsgRemoteContainerRequest(RemoteContainerConfig inConf) { // --- Get the local Address of JADE ------------------------ String myPlatformAddress = myContainer.getPlatformID(); // --- If the remote-configuration is null configure it now - RemoteContainerConfig remConf = this.getRemoteContainerConfigAuto(); if (inConf != null) { if (inConf.getJadeContainerName() != null) { String name = inConf.getJadeContainerName(); int suf = getSuffixNo(inConf.getJadeContainerName()); name = name + suf; remConf.setJadeContainerName(name); } if (inConf.getJadeHost() != null) { remConf.setJadeHost(inConf.getJadeHost()); } if (inConf.getJadePort() != null) { remConf.setJadePort(inConf.getJadePort()); } if (inConf.getJadeServices() != null) { remConf.setJadeServices(inConf.getJadeServices()); } } // --- Define the AgentAction ------------------------------- ClientRemoteContainerRequest req = new ClientRemoteContainerRequest(); req.setRemoteConfig(remConf); Action act = new Action(); act.setActor(myContainer.getAMS()); act.setAction(req); // --- Define receiver of the Message ----------------------- AID agentGUIAgent = new AID("server.client" + "@" + myPlatformAddress, AID.ISGUID); // --- Build Message ---------------------------------------- ACLMessage msg = new ACLMessage(ACLMessage.INFORM); msg.setSender(myContainer.getAMS()); msg.addReceiver(agentGUIAgent); msg.setLanguage(new SLCodec().getName()); msg.setOntology(DistributionOntology.getInstance().getName()); try { msg.setContentObject(act); } catch (IOException errCont) { logger.error(errCont); } // --- Send message ----------------------------------------- myContainer.postMessageToLocalAgent(msg, agentGUIAgent); // --- Remind, that we're waiting for this container -------- loadInfo.setNewContainer2Wait4(remConf.getJadeContainerName()); // --- Return ----------------------------------------------- return remConf.getJadeContainerName(); }
/** * 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); }
/** * Add an Agent to this container. Typically Agent would be some class extending Agent which was * instantiated and configured. * * @param nickname A platform-unique nickname for the newly created agent. The agent will be given * a FIPA compliant agent identifier using the nickname and the ID of the platform it is * running on. * @param anAgent The agent to be added to this agent container. * @return An AgentController, allowing to call state-transition forcing methods on the real agent * instance. */ public AgentController acceptNewAgent(String nickname, jade.core.Agent anAgent) throws StaleProxyException { if (myImpl == null || myProxy == null) { throw new StaleProxyException(); } AID agentID = new AID(AID.createGUID(nickname, myImpl.getPlatformID()), AID.ISGUID); // FIXME: This call skips the security checks on the local container try { jade.core.NodeDescriptor nd = myImpl.getNodeDescriptor(); // The owner of the new agent is the owner of the local container. // The new agent has NO initial credentials myImpl.initAgent(agentID, anAgent, nd.getOwnerPrincipal(), null); } catch (Exception e) { throw new StaleProxyException(e); } return new AgentControllerImpl(agentID, myProxy, myImpl); }
/** * This method returns a default configuration for a new remote container. * * @param preventUsageOfAlreadyUsedComputers the prevent usage of already used computers * @return the default RemoteContainerConfig */ private RemoteContainerConfig getRemoteContainerConfigAuto() { // --- Variable for the new container name ------------------ String newContainerPrefix = "remote"; String newContainerName; // --- Get the local IP-Address ----------------------------- String myIP = myContainer.getNodeDescriptor().getContainer().getAddress(); // --- Get the local port of JADE --------------------------- String myPort = myContainer.getNodeDescriptor().getContainer().getPort(); // --- Get the List of services started here ---------------- String myServices = ""; List<?> services = myContainer.getServiceManager().getLocalServices(); Iterator<?> it = services.iterator(); while (it.hasNext()) { ServiceDescriptor serviceDesc = (ServiceDescriptor) it.next(); String service = serviceDesc.getService().getClass().getName() + ";"; myServices += service; } newContainerName = newContainerPrefix + getSuffixNo(newContainerPrefix); logger.info("-- Infos to start the remote container ------------"); logger.info("=> Services2Start: " + myServices); logger.info("=> NewContainerName: " + newContainerName); logger.info("=> ThisAddresses: " + myIP + " - Port: " + myPort); // --- Define the 'RemoteContainerConfig' - Object ---------- RemoteContainerConfig remConf = new RemoteContainerConfig(); remConf.setJadeServices(myServices); remConf.setJadeIsRemoteContainer(true); remConf.setJadeHost(myIP); remConf.setJadePort(myPort); remConf.setJadeContainerName(newContainerName); remConf.setJadeShowGUI(true); // --- Apply defaults, if set ------------------------------- if (this.defaults4RemoteContainerConfig != null) { remConf.setJadeShowGUI(this.defaults4RemoteContainerConfig.getJadeShowGUI()); remConf.setJvmMemAllocInitial(this.defaults4RemoteContainerConfig.getJvmMemAllocInitial()); remConf.setJvmMemAllocMaximum(this.defaults4RemoteContainerConfig.getJvmMemAllocMaximum()); } return remConf; }
/* (non-Javadoc) * @see jade.core.BaseService#init(jade.core.AgentContainer, jade.core.Profile) */ @Override public void init(AgentContainer ac, Profile p) throws ProfileException { super.init(ac, p); myContainer = ac; myMainContainer = ac.getMain(); // --- Create filters ----------------------------- outFilter = new CommandOutgoingFilter(); incFilter = new CommandIncomingFilter(); // --- Create local slice ------------------------- localSlice = new ServiceComponent(); if (myContainer != null) { logger.info("Starting LoadService: My-Container: " + myContainer.toString()); } if (myMainContainer != null) { logger.info("Main-Container: " + myMainContainer.toString()); } // --- Start the Load-Measurements on this Node --- new LoadMeasureThread().start(); }
protected void initPlatformController() throws ControllerException { if (myPlatformController == null) { if (myImpl == null) { throw new ControllerException("Stale proxy."); } MainContainer main = myImpl.getMain(); if (main == null) { throw new ControllerException("Not a Main Container."); } if (main instanceof AgentManager) { myPlatformController = new PlatformControllerImpl(this, (AgentManager) main); } else { throw new ControllerException("Platform not accessible."); } } }
/** * Creates a new JADE agent, running within this container, * * @param nickname A platform-unique nickname for the newly created agent. The agent will be given * a FIPA compliant agent identifier using the nickname and the ID of the platform it is * running on. * @param className The fully qualified name of the class that implements the agent. * @param args An object array, containing initialization parameters to pass to the new agent. * @return A proxy object, allowing to call state-transition forcing methods on the real agent * instance. */ public AgentController createNewAgent(String nickname, String className, Object[] args) throws StaleProxyException { if (myImpl == null || myProxy == null) { throw new StaleProxyException(); } AID agentID = new AID(AID.createGUID(nickname, myImpl.getPlatformID()), AID.ISGUID); try { myProxy.createAgent(agentID, className, args); return new AgentControllerImpl(agentID, myProxy, myImpl); } catch (Throwable t) { t.printStackTrace(); throw new StaleProxyException(t); } }
/** * This method defines the local field 'myCRCReply' which is an instance of * 'ClientRemoteContainerReply' and holds the information about Performance, BenchmarkResult, * Network-Addresses of this container-node. * * @param loadFile indicates if the local file should be used or not */ private void setLocalCRCReply(boolean loadFile) { ClientRemoteContainerReply crcReply = null; // if (loadFile == true) { // // --- Load the Descriptions from the local file ---------------------------- // crcReply = loadCRCReply(); // } if (crcReply == null) { // --- Build the Descriptions from the running system ----------------------- // --- Get infos about the network connection ----- InetAddress currAddress = null; InetAddress addressLocal; InetAddress addressLocalAlt; String hostIP, hostName, port; try { currAddress = InetAddress.getByName(myContainer.getID().getAddress()); addressLocal = InetAddress.getLocalHost(); addressLocalAlt = InetAddress.getByName("127.0.0.1"); if (currAddress.equals(addressLocalAlt)) { currAddress = addressLocal; } } catch (UnknownHostException e) { logger.error(e); } hostIP = currAddress.getHostAddress(); hostName = currAddress.getHostName(); port = myContainer.getID().getPort(); // --- Define Platform-Info ----------------------- PlatformAddress myPlatform = new PlatformAddress(); myPlatform.setIp(hostIP); myPlatform.setUrl(hostName); myPlatform.setPort(Integer.parseInt(port)); myPlatform.setHttp4mtp(myContainerMTPurl); // --- Set OS-Informations ------------------------ OSInfo myOS = new OSInfo(); myOS.setOs_name(System.getProperty("os.name")); myOS.setOs_version(System.getProperty("os.version")); myOS.setOs_arch(System.getProperty("os.arch")); // --- Set the Performance of machine ------------- LoadMeasureSigar sys = LoadMeasureThread.getLoadCurrent(); PlatformPerformance myPerformance = new PlatformPerformance(); myPerformance.setCpu_vendor(sys.getVendor()); myPerformance.setCpu_model(sys.getModel()); myPerformance.setCpu_numberOf(sys.getTotalCpu()); myPerformance.setCpu_speedMhz((int) sys.getMhz()); myPerformance.setMemory_totalMB( (int) LoadUnits.bytes2(sys.getTotalMemory(), LoadUnits.CONVERT2_MEGA_BYTE)); // --- Set the performance (Mflops) of the system - BenchmarkResult bench = new BenchmarkResult(); bench.setBenchmarkValue(LoadMeasureThread.getCompositeBenchmarkValue()); // --- Get the PID of this JVM -------------------- String jvmPID = LoadMeasureThread.getLoadCurrentJVM().getJvmPID(); // --- Finally define this local description ------ crcReply = new ClientRemoteContainerReply(); crcReply.setRemoteContainerName(myContainer.getID().getName()); crcReply.setRemotePID(jvmPID); crcReply.setRemoteAddress(myPlatform); crcReply.setRemoteOS(myOS); crcReply.setRemotePerformance(myPerformance); crcReply.setRemoteBenchmarkResult(bench); } // --- Set the local value of the ClientRemoteContainerReply -------------------- myCRCReply = crcReply; // --- Broadcast the ClientRemoteContainerReply-Object to all other container --- Service.Slice[] slices; try { slices = getAllSlices(); broadcastPutContainerDescription(slices, myCRCReply); } catch (ServiceException e) { logger.error(e); } }
public boolean isJoined() { return myImpl != null && myImpl.isJoined(); }
/** * Retrieve the name of the wrapped container. * * @return the name of this platform container. */ public String getContainerName() throws ControllerException { if (myImpl == null) { throw new ControllerException("Stale proxy."); } return myImpl.here().getName(); }