当前位置: 首页>>代码示例>>Java>>正文


Java Agent类代码示例

本文整理汇总了Java中jade.core.Agent的典型用法代码示例。如果您正苦于以下问题:Java Agent类的具体用法?Java Agent怎么用?Java Agent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Agent类属于jade.core包,在下文中一共展示了Agent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAgent

import jade.core.Agent; //导入依赖的package包/类
/**
 * Adds an agent to the start list corresponding to the current network component .
 * 
 * @param networkComponent the NetworkComponent
 */
public void addAgent(NetworkComponent networkComponent) {

	if (networkComponent == null) {
		return;
	}
	Class<? extends Agent> agentClass = this.getAgentClass(networkComponent.getAgentClassName());
	if (agentClass != null) {

		int newPosNo = this.getEmptyPosition4Agents2Start();
		// --- Agent class found. Create new list element ---------
		AgentClassElement4SimStart ace4s = new AgentClassElement4SimStart(agentClass, SimulationSetup.AGENT_LIST_EnvironmentConfiguration);
		ace4s.setStartAsName(networkComponent.getId());
		ace4s.setPostionNo(newPosNo);
		// --- Add the new list element to the list ---------------
		this.getAgents2Start().add(newPosNo - 1, ace4s);
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:23,代码来源:GraphEnvironmentController.java

示例2: getAgentClass

import jade.core.Agent; //导入依赖的package包/类
/**
 * Returns the agent class.
 * 
 * @param agentReference the agent reference
 * @return the agent class
 */
@SuppressWarnings("unchecked")
private Class<? extends Agent> getAgentClass(String agentReference) {

	if (agentReference == null || agentReference.equals("")) {
		return null;
	}

	Class<? extends Agent> agentClass = null;
	try {
		agentClass = (Class<? extends Agent>) ClassLoadServiceUtility.forName(agentReference);
	} catch (ClassNotFoundException ex) {
		System.err.println("Could not find agent class '" + agentReference + "'");
	}
	return agentClass;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:22,代码来源:GraphEnvironmentController.java

示例3: startAgent

import jade.core.Agent; //导入依赖的package包/类
/**
 * Method to start a new agent.
 *
 * @param nickName the nick name
 * @param agentClassName the agent class name
 * @param args the start arguments as Object array
 * @param toLocation the location, where the agent should start
 * @return true, if successful
 */
protected boolean startAgent(String nickName, String agentClassName, Object[] args, Location toLocation ) {
	
	if (agentClassName==null | agentClassName.equalsIgnoreCase("") | agentClassName.equalsIgnoreCase(Language.translate("Keine")) ) {
		System.err.println(Language.translate("Agent '" + nickName + "': " + Language.translate("Keine Klasse definiert") + "!"));
	} else {
		// --- Initialize the agent-class -------------
		try {
			Class<? extends Agent> agentClass = ClassLoadServiceUtility.getAgentClass(agentClassName);
			return this.startAgent(nickName, agentClass, args, toLocation);
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	return false;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:26,代码来源:BaseLoadBalancing.java

示例4: SingleAgentMonitor

import jade.core.Agent; //导入依赖的package包/类
/**
 * Instantiates a new agent monitor.
 *
 * @param agent the agent to monitor
 * @param monitoringMeasureType the actual MonitoringMeasureType
 * @param runnable the runnable
 */
public SingleAgentMonitor(Agent agent, MonitoringMeasureType monitoringMeasureType, Runnable runnable) {
	if (agent==null) {
		throw new IllegalArgumentException("No agent was specified for the monitoring task.");
	}
	if (monitoringMeasureType==null) {
		throw new IllegalArgumentException("No measure were specified in case of a thread failure.");
	}
	if (monitoringMeasureType==MonitoringMeasureType.CUSTOM_MEASURE && runnable==null) {
		throw new IllegalArgumentException("No runnable was defined for the custom measure.");
	}
	
	this.agentName = agent.getLocalName();
	this.agentClass = agent.getClass().getName();
	this.agentStartArguments = agent.getArguments();
	this.containerController = agent.getContainerController();
	
	this.monitoringMeasureType = monitoringMeasureType;
	this.measure = runnable;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:27,代码来源:SingleAgentMonitor.java

示例5: getStartAndStaticLoadBalancingClass

import jade.core.Agent; //导入依赖的package包/类
/**
 * This method will initiate the one shot behaviour of the type {@link StaticLoadBalancingBase}
 * in order to start the agency.
 *
 * @return the start and static load balancing instance
 */
private StaticLoadBalancingBase getStartAndStaticLoadBalancingClass(Agent myAgent) {
	
	// --- Get the current distribution setup ---------
	DistributionSetup currDisSetup = Application.getProjectFocused().getDistributionSetup();
	if (currDisSetup.isDoStaticLoadBalancing()==true) {

		try {
			return ClassLoadServiceUtility.getStaticLoadBalancing(currDisSetup.getStaticLoadBalancingClass(), myAgent);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
	} else {
		return new StaticLoadBalancing(this);
	}
	return null;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:24,代码来源:LoadExecutionAgent.java

示例6: GameLoadBehaviour

import jade.core.Agent; //导入依赖的package包/类
public GameLoadBehaviour(Agent agent, String filename) throws FileNotFoundException
{
    super(agent);
    
    // Loads the board
    ((GameAgent) agent).setBoard(loadBoard(filename));
    
    if (Constant.DEBUG)
    {
        System.out.println("Board model initialized...\nInitial board:");
        board.print();
    }
    
    // Fetches the container manager instance
    containerManager = ContainerManager.getInstance();
}
 
开发者ID:wguilen,项目名称:pacman-mas,代码行数:17,代码来源:GameLoadBehaviour.java

示例7: register

import jade.core.Agent; //导入依赖的package包/类
public static void register(Agent a, String service, Codec codec, String protocol, Ontology ontology) throws FIPAException {
    DFAgentDescription dfad = new DFAgentDescription();
    dfad.setName(a.getAID());
    dfad.addLanguages(codec.getName());
    dfad.addProtocols(protocol);

    ServiceDescription sd = new ServiceDescription();
    sd.setName(service + "-" + a.getLocalName());
    sd.setType(service);
    sd.addOntologies(ontology.getName());
    sd.addLanguages(codec.getName());
    sd.addProtocols(protocol);

    dfad.addServices(sd);
    DFService.register(a, dfad);
}
 
开发者ID:0xC70FF3,项目名称:java-gems,代码行数:17,代码来源:DFServiceHelper.java

示例8: findAllByService

import jade.core.Agent; //导入依赖的package包/类
public static ArrayList<AID> findAllByService(Agent a, String serviceName) throws FIPAException {
    DFAgentDescription adTemplate = new DFAgentDescription();
    ServiceDescription sd = new ServiceDescription();
    sd.setType(serviceName);
    adTemplate.addServices(sd);

    DFAgentDescription[] dfAgentDescriptions = DFService.search(a, adTemplate);
    if (dfAgentDescriptions.length <= 0) {
        throw new FIPAException("Could not find proper service");
    }
    ArrayList<AID> aids = new ArrayList<AID>();
    for (DFAgentDescription dfAgentDescription : dfAgentDescriptions) {
        aids.add(dfAgentDescription.getName());
    }
    return aids;
}
 
开发者ID:0xC70FF3,项目名称:java-gems,代码行数:17,代码来源:DFServiceHelper.java

示例9: agentTest

import jade.core.Agent; //导入依赖的package包/类
@Test
public void agentTest() throws Exception
{
	final AgentContainer container = getContainer();
	final String agName = "MyTestAgent";
	final MySemanticAgent agObject = new MySemanticAgent();
	LOG.trace("Adding new agent: " + agName + "...");
	container.acceptNewAgent(agName, agObject);

	while (agObject.getAgentState().getValue() != Agent.AP_DELETED)
	{
		LOG.trace("Waiting for " + agName + " (state: "
				+ agObject.getAgentState() + ") to be killed via GUI...");
		try
		{
			Thread.sleep(1000);
		} catch (final InterruptedException ignore)
		{
			//
		}
	}
	
	container.kill();
}
 
开发者ID:krevelen,项目名称:coala,代码行数:25,代码来源:TestSemanticAgent.java

示例10: registerAgent

import jade.core.Agent; //导入依赖的package包/类
/**
 * Register the agent in the platform
 * 
 * @param agent_name
 *          The name of the agent to be registered
 * @param agent
 *          The agent to register.
 * @throws FIPAException 
 */
public static void registerAgent(Agent agent, String serviceName, String serviceType) throws FIPAException{
    DFAgentDescription dfd = new DFAgentDescription();
    ServiceDescription sd = new ServiceDescription();
    
    sd.setType(serviceType);
    sd.setName(serviceName);
    
    //NOTE El serviceType es un string que define el tipo de servicio publicado en el DF por el Agente X. 
    //     He escogido crear nombres en clave en jade.common.Definitions para este campo. 
    //NOTE El serviceName es el nombre efectivo del servicio. 
    //     Esto es lo que el usuario va a definir en MockConfiguration.DFNameService y no el tipo como estaba puesto. 
    //        sd.setType(agentType);
    //        sd.setName(agent.getLocalName());
    
    //Add services??
    
    // Sets the agent description
    dfd.setName(agent.getAID());
    dfd.addServices(sd);
    
    // Register the agent
    DFService.register(agent, dfd);
}
 
开发者ID:gsi-upm,项目名称:BeastTool,代码行数:33,代码来源:AgentRegistration.java

示例11: sendMessageToAgents

import jade.core.Agent; //导入依赖的package包/类
@Override
public void sendMessageToAgents(String[] agent_name, String msgtype,
        Object message_content, Connector connector) {
    Agent messenger = (Agent) connector.getMessageService();
    JadeAgentIntrospector introspector = (JadeAgentIntrospector) PlatformSelector.getAgentIntrospector("jade");

    ACLMessage msg = null;
    if(message_content instanceof ACLMessage) {
        msg = (ACLMessage) message_content;
    } else if (message_content instanceof String) {
        msg = new ACLMessage(ACLMessage.getInteger(msgtype)); 
        msg.setContent( (String) message_content);            
    } else {
        connector.getLogger().warning("Incorrect message_content value. It should be a ACLMessage or a String.");
    }

    for (String name : agent_name) {
        Agent agent = introspector.getAgent(name);
        AID aid = agent.getAID();
        msg.addReceiver(aid);
        connector.getLogger().finer("Receiver added to the message...");
    }
    messenger.send(msg);
    connector.getLogger().finer("Message sent...");
}
 
开发者ID:gsi-upm,项目名称:BeastTool,代码行数:26,代码来源:JadeMessenger.java

示例12: setup

import jade.core.Agent; //导入依赖的package包/类
public void setup() {
	this.myIntrospector = JadeAgentIntrospector.getMyInstance((Agent) this);
	LogActivator.logToFile(logger, this.getName(), Level.ALL);
	// Register the service
	try {
		DFAgentDescription dfd = new DFAgentDescription();
		ServiceDescription sd = new ServiceDescription();
        
        sd.setType("server");
        sd.setName("report-service");
        // Sets the agent description
        dfd.setName(this.getAID());
        dfd.addServices(sd);
        
        // Register the agent
        DFService.register(this, dfd);
		
	} catch (Exception e) {
		logger.severe("Exception registering agent in DF. Agent: " + this.getName());
	}

	MessageTemplate t = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
	addBehaviour(new ReportServer(this,t));
}
 
开发者ID:gsi-upm,项目名称:BeastTool,代码行数:25,代码来源:ReporterAgent.java

示例13: setup

import jade.core.Agent; //导入依赖的package包/类
public void setup() {
	this.myIntrospector = JadeAgentIntrospector.getMyInstance((Agent) this);
	LogActivator.logToFile(logger, this.getName(), Level.ALL);
	// Register the service
	try {
		DFAgentDescription dfd = new DFAgentDescription();
		ServiceDescription sd = new ServiceDescription();
        
        sd.setType("server");
        sd.setName("helpdesk-service");
        // Sets the agent description
        dfd.setName(this.getAID());
        dfd.addServices(sd);
        
        // Register the agent
        DFService.register(this, dfd);
		
	} catch (Exception e) {
		logger.severe("Exception registering agent in DF. Agent: " + this.getName());
	}

	MessageTemplate t = MessageTemplate.MatchPerformative(ACLMessage.REQUEST);
	addBehaviour(new HelpDeskServer(this,t));
	
}
 
开发者ID:gsi-upm,项目名称:BeastTool,代码行数:26,代码来源:HelpDeskAgent.java

示例14: getMyEnvironmentType

import jade.core.Agent; //导入依赖的package包/类
/**
 * Returns my personal EnvironmentType.
 * @return the my environment type
 */
private EnvironmentType getMyEnvironmentType() {
	
	String key = "Squared";
	String displayName = "Discrete squares environment";
	String displayNameLanguage = Language.EN;
	Class<? extends EnvironmentController> controllerClass = SquaredEnvironmentController.class;
	Class<? extends Agent> agentClass = DisplayAgent.class;
	
	EnvironmentType myEnvType = new EnvironmentType(key, displayName, displayNameLanguage, controllerClass, agentClass);
	return myEnvType;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:16,代码来源:GameOfLifePlugIn.java

示例15: getAgentClassesCellEditor

import jade.core.Agent; //导入依赖的package包/类
/**
 * Returns the ClassSelectionDialog cell editor for Agent classes.
 * @return cell editor for the class selection
 */
private TableCellEditor4ClassSelector getAgentClassesCellEditor(){
	if(agentClassesCellEditor == null){
		agentClassesCellEditor = new TableCellEditor4ClassSelector(Application.getMainWindow(), Agent.class, "", "", Language.translate("Agenten"), true);
	}
	return agentClassesCellEditor;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:11,代码来源:ComponentTypeDialog.java


注:本文中的jade.core.Agent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。