• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Action类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: actionToXML

import eis.iilang.Action; //导入依赖的package包/类
@Override
public Document actionToXML(Action action) {

    // translate parameters to String
    List<String> parameters = new Vector<>();
    action.getParameters().forEach(param -> {
        if (param instanceof Identifier){
            parameters.add(((Identifier) param).getValue());
        }
        else if(param instanceof Numeral){
            parameters.add(((Numeral) param).getValue().toString());
        }
        else{
            log("Cannot translate parameter " + param);
            parameters.add(""); // add empty parameter so the order is not invalidated
        }
    });

    // create massim protocol action
    massim.protocol.messagecontent.Action massimAction =
            new massim.protocol.messagecontent.Action(action.getName(), parameters.toArray(new String[parameters.size()]));
    massimAction.setID(currentActionId);

    return new Message(null, massimAction).toXML();
}
 
开发者ID:agentcontest,项目名称:massim,代码行数:26,代码来源:CityEntity.java


示例2: performAction

import eis.iilang.Action; //导入依赖的package包/类
/**
 * Performs an action by transforming it to XML and sending it to the massim server.
 * @param action the action to perform
 * @throws ActException if the action could not be sent
 */
void performAction(Action action) throws ActException{

    if (!connected) throw new ActException(ActException.FAILURE, "no valid connection");

    // wait for a valid action id
    long startTime = System.currentTimeMillis();
    if (scheduling) {
        while (currentActionId <= lastUsedActionId || currentActionId == -1) {
            try { Thread.sleep(10); } catch (InterruptedException ignored) {}
            if (System.currentTimeMillis() - startTime >= timeout) {
                throw new ActException(ActException.FAILURE, "timeout. no valid action-id available in time");
            }
        }
    }

    Document doc = actionToXML(action);
    try {
        assert currentActionId != lastUsedActionId;
        sendDocument(doc);
        lastUsedActionId = currentActionId;
    } catch (TransformerException | IOException e) {
        releaseConnection();
        throw new ActException(ActException.FAILURE, "sending action failed", e);
    }
}
 
开发者ID:agentcontest,项目名称:massim,代码行数:31,代码来源:EISEntity.java


示例3: isSupportedByEntity

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected boolean isSupportedByEntity(Action action, String entity) {

	Vector<String> actions = new Vector<String>();
	actions.add("attack");
	actions.add("buy");
	actions.add("goto");
	actions.add("inspect");
	actions.add("parry");
	actions.add("probe");
	actions.add("recharge");
	actions.add("repair");
	actions.add("skip");
	actions.add("survey");
	
	if ( actions.contains(action.getName()) ) {
		return true;
	}
	
	return false;
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:22,代码来源:EnvironmentInterface.java


示例4: actionToXML

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected Document actionToXML(Action action) {

	String actionType = null;
	actionType = action.getName();
	
	String actionParameter = null;
	if ( action.getParameters().size() != 0)
		actionParameter = action.getParameters().element().toProlog();
	
	String actionId = null;
	actionId = "" + getCurrentActionId();
	
		// create document
	Document doc = null;
	try {
		
		doc = documentbuilderfactory.newDocumentBuilder().newDocument();
		Element root = doc.createElement("message");
		root.setAttribute("type","action");
		doc.appendChild(root);
		
		Element auth = doc.createElement("action");
		auth.setAttribute("type",actionType);
		if ( actionParameter != null )
			auth.setAttribute("param",actionParameter);
		auth.setAttribute("id",actionId);
		root.appendChild(auth);
		
	} catch (ParserConfigurationException e) {
		System.err.println("unable to create new document");
		return null;
	}
	
	//System.out.println(action.toProlog());
	//System.out.println(XMLToString(doc));
	
	return doc;

}
 
开发者ID:jason-lang,项目名称:apps,代码行数:41,代码来源:Mars2013Entity.java


示例5: performEntityAction

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected Percept performEntityAction(String entity, Action action)
		throws ActException {
	Entity e = entityNamesToObjects.get(entity);
	if ( e.isConnected() == false ) {
		//throw new ActException(ActException.FAILURE,"no valid connection");
	}
	try {
		e.performAction(action);
	} 
	catch (ActException ee) {
		throw ee;
	} 
	return new Percept("done");
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:16,代码来源:EnvironmentInterface.java


示例6: isSupportedByEnvironment

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected boolean isSupportedByEnvironment(Action action) {
    return action != null && supportedActions.contains( action.getName());
}
 
开发者ID:agentcontest,项目名称:massim,代码行数:5,代码来源:EnvironmentInterface.java


示例7: isSupportedByType

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected boolean isSupportedByType(Action action, String type) {
    return action != null && supportedActions.contains(action.getName());
}
 
开发者ID:agentcontest,项目名称:massim,代码行数:5,代码来源:EnvironmentInterface.java


示例8: isSupportedByEntity

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected boolean isSupportedByEntity(Action action, String entity) {
    return action != null && supportedActions.contains(action.getName());
}
 
开发者ID:agentcontest,项目名称:massim,代码行数:5,代码来源:EnvironmentInterface.java


示例9: performEntityAction

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected Percept performEntityAction(String name, Action action) throws ActException {
    EISEntity entity = entities.get(name);
    entity.performAction(action);
    return new Percept("done");
}
 
开发者ID:agentcontest,项目名称:massim,代码行数:7,代码来源:EnvironmentInterface.java


示例10: isSupportedByEntity

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected boolean isSupportedByEntity(Action arg0, String arg1) {
    return true;
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:5,代码来源:EISHouseEnv.java


示例11: isSupportedByType

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected boolean isSupportedByType(Action action, String type) {
	return true;
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:5,代码来源:EnvironmentInterface.java


示例12: performAction

import eis.iilang.Action; //导入依赖的package包/类
/**
 * Performs an action. The action is fistly transformed to an XML-message.
 * Secondly it is sent off.
 * @param action
 * @throws ActException 
 */
public void performAction(Action action) throws ActException {
			
	if ( connected == false ) {
		establishConnection();
		if ( connected == false ) {
			releaseConnection();
			throw new ActException(ActException.FAILURE,"no valid connection");
		}
	}
	
	// waiting for a valid action id
	long startTime = System.currentTimeMillis();
	if ( scheduling == true ) {
		while ( currentActionId <= lastUsedActionId || currentActionId == -1 ) {
			//System.out.println("waiting for valid id. last=" + lastUsedActionId + " current=" + currentActionId);
			try { Thread.sleep(10); } catch (InterruptedException e) {}
			long diff = System.currentTimeMillis() - startTime;
			if ( diff >= timeout ) {
				//releaseConnection();
				throw new ActException(ActException.FAILURE,"timeout. no valid action-id available in time");
			}
		}
	}
	
	
	//
	Document doc = null;
	doc = actionToXML(action);

	// send
	try {
		assert currentActionId != lastUsedActionId;
		//println("using action id " + currentActionId);
		sendDocument(doc);
		lastUsedActionId = currentActionId;
	} catch (IOException e) {
		//e.printStackTrace();
		// TODO some text
		//System.out.println("connection lost");
		//connected = false;
		releaseConnection();
		throw new ActException(ActException.FAILURE,"sending failed action",e);
	}

	//println("sent");
	if(statsActivated)
		stats.submitAction(name, currentActionId, action.getName(), startTime);
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:55,代码来源:Entity.java


示例13: literalToAction

import eis.iilang.Action; //导入依赖的package包/类
public static Action literalToAction(Literal action) {
    Parameter[] pars = new Parameter[action.getArity()];
    for (int i=0; i<action.getArity(); i++)
        pars[i] = termToParameter(action.getTerm(i));            
    return new Action(action.getFunctor(), pars);
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:7,代码来源:Translator.java


示例14: actoinToStructure

import eis.iilang.Action; //导入依赖的package包/类
public static Structure actoinToStructure(Action action) throws JasonException {
    Structure s = ASSyntax.createStructure(action.getName());
    for (Parameter par: action.getParameters())
        s.addTerm(parameterToTerm(par));
    return s;
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:7,代码来源:Translator.java


示例15: isSupportedByEnvironment

import eis.iilang.Action; //导入依赖的package包/类
@Override
protected boolean isSupportedByEnvironment(Action action) {
	return true;
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:5,代码来源:EnvironmentInterface.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PermissionHandler类代码示例发布时间:2022-05-22
下一篇:
Java Requires类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap