欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

实操指南:Java Settings类的运用示例

最编程 2024-02-21 15:55:49
...

实例1: tryToIncludeMindInspectorForAg

import jason.runtime.Settings; //导入依赖的package包/类
private boolean tryToIncludeMindInspectorForAg(String path) {
    try {
        Agent ag = registeredAgents.get(getAgNameFromPath(path));
        if (ag != null) {
            AgArch arch = ag.getTS().getUserAgArch();
            if (arch != null) {
                // should add a new conf for mindinspector, otherwise will start a new gui for the agent
                arch.getTS().getSettings().addOption(Settings.MIND_INSPECTOR,"web(cycle,html,no_history)");
                MindInspectorAgArch miArch = new MindInspectorAgArch();
                arch.insertAgArch(miArch);
                miArch.init();
                miArch.addAgState();
                return true;
            }
        }
    } catch (Exception e) { 
        e.printStackTrace();
    }
    return false;
}
 

实例2: changeToDebugMode

import jason.runtime.Settings; //导入依赖的package包/类
/** change the current running MAS to debug mode */
void changeToDebugMode() {
    try {
        if (control == null) {
            control = new CentralisedExecutionControl(new ClassParameters(ExecutionControlGUI.class.getName()), this);
            for (CentralisedAgArch ag : ags.values()) {
                ag.setControlInfraTier(control);
                Settings stts = ag.getTS().getSettings();
                stts.setVerbose(2);
                stts.setSync(true);
                ag.getLogger().setLevel(Level.FINE);
                ag.getTS().getLogger().setLevel(Level.FINE);
                ag.getTS().getAg().getLogger().setLevel(Level.FINE);
            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error entering in debug mode", e);
    }
}
 

实例3: createArchs

import jason.runtime.Settings; //导入依赖的package包/类
/**
 * Creates the user agent architecture, default architecture is
 * jason.architecture.AgArch. The arch will create the agent that creates
 * the TS.
 */
public void createArchs(List<String> agArchClasses, String agClass, ClassParameters bbPars, String asSrc, Settings stts, RunCentralisedMAS masRunner) throws JasonException {
    try {
        this.masRunner = masRunner;
        Agent.create(this, agClass, bbPars, asSrc, stts);
        insertAgArch(this);
        
        createCustomArchs(agArchClasses);

        // mind inspector arch
        if (stts.getUserParameter(Settings.MIND_INSPECTOR) != null) {
            insertAgArch( (AgArch)Class.forName( Config.get().getMindInspectorArchClassName()).newInstance() );
            getFirstAgArch().init();
        }
        
        setLogger();
    } catch (Exception e) {
        running = false;
        throw new JasonException("as2j: error creating the agent class! - "+e.getMessage(), e);
    }
}
 

实例4: addInitialGoalsFromProjectInBB

import jason.runtime.Settings; //导入依赖的package包/类
protected void addInitialGoalsFromProjectInBB() {
    String sGoals = getTS().getSettings().getUserParameter(Settings.INIT_GOALS);
    if (sGoals != null) {
        try {
            for (Term t: ASSyntax.parseList("["+sGoals+"]")) {
                Literal g = ((Literal)t).forceFullLiteralImpl();
                g.makeVarsAnnon();
                if (! g.hasSource())
                    g.addAnnot(BeliefBase.TSelf);
                getTS().getC().addAchvGoal(g,Intention.EmptyInt);            
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "Initial goals from project '["+sGoals+"]' is not a list of literals.");
        }
    }
}
 

实例5: initAg

import jason.runtime.Settings; //导入依赖的package包/类
@Override
   public void initAg(String agClass, ClassParameters bbPars, String asSrc, Settings stts) throws JasonException {
	super.initAg(agClass, bbPars, asSrc, stts);
	logger = Logger.getLogger(ACArchitecture.class.getName()+"."+getAgName());

	String username = stts.getUserParameter("username");
       if (username.startsWith("\"")) username = username.substring(1,username.length()-1);
       String password = stts.getUserParameter("password");
       if (password.startsWith("\"")) password = password.substring(1,password.length()-1);
       
	proxy = new ACProxy( 	this, 
							stts.getUserParameter("host"), 
							Integer.parseInt(stts.getUserParameter("port")),
							username,
							password);
	proxy.start();
}