本文整理汇总了Java中eis.exceptions.ActException类的典型用法代码示例。如果您正苦于以下问题:Java ActException类的具体用法?Java ActException怎么用?Java ActException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActException类属于eis.exceptions包,在下文中一共展示了ActException类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: performAction
import eis.exceptions.ActException; //导入依赖的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
示例2: goTo
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void goTo(double x, double y) throws ActException {
try {
Parameter[] xParam = Translator.getInstance().translate2Parameter(x);
Parameter[] yParam = Translator.getInstance().translate2Parameter(y);
Parameter[] parameters = new Parameter[2];
parameters[0] = xParam[0];
parameters[1] = yParam[0];
bw4tenv.performEntityAction(entityId, new Action("goTo", parameters));
} catch (RemoteException | TranslationException e) {
ActException ex = new ActException("goTo", e);
ex.setType(ActException.FAILURE);
throw ex;
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:19,代码来源:BW4TAgent.java
示例3: getAssociatedEntities
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Gets the associated entities and performs a series of checks regarding prerequisites.
*
* @param remoteEnvironment
* the remote environment which should be acted upon
* @param action
* the action being requested
* @param agent
* the agent requesting the action
* @return the associated entities
* which belong to the agent
* @throws ActException the act exception
* which is thrown if something is wrong with the prerequisites
* @throws AgentException the agent exception
* which is thrown if the environment is suddenly disconnected.
*/
private static Set<String> getAssociatedEntities(RemoteEnvironment remoteEnvironment, Action action, String agent)
throws ActException, AgentException {
/** Check to see if the agent is actually registered. */
if (!remoteEnvironment.getAgents().contains(agent)) {
throw new ActException(ActException.NOTREGISTERED);
}
/** Check if the action is supported by the environment. */
if (!remoteEnvironment.isSupportedByEnvironment(action)) {
throw new ActException(ActException.NOTSUPPORTEDBYENVIRONMENT);
}
/** Get a list of associated entities and target entities. */
Set<String> associatedEntities = remoteEnvironment.getAssociatedEntities(agent);
if ((associatedEntities == null) || associatedEntities.isEmpty()) {
throw new ActException(ActException.NOENTITIES);
}
return associatedEntities;
}
开发者ID:eishub,项目名称:BW4T,代码行数:34,代码来源:ActionHandler.java
示例4: checkSupportedEntities
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Check if the entity types and the entities are supported.
*
* @param entities
* - The entities which need to be checked.
* @param remoteEnvironment
* - The {@link RemoteEnvironment} which is currently used.
* @param action
* - The {@link Action} which is requested to be performed.
* @throws ActException
* Thrown if the action is not support by the type of entity, or by the entity.
*/
private static void checkSupportedEntities(String[] entities, RemoteEnvironment remoteEnvironment, Action action)
throws ActException {
for (String entity : entities) {
try {
String type = remoteEnvironment.getType(entity);
if (!remoteEnvironment.isSupportedByType(action, type)) {
throw new ActException(ActException.NOTSUPPORTEDBYTYPE);
}
if (!remoteEnvironment.isSupportedByEntity(action, type)) {
throw new ActException(ActException.NOTSUPPORTEDBYENTITY);
}
} catch (EntityException e) {
throw new ActException("Can't get entity type", e);
}
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:29,代码来源:ActionHandler.java
示例5: getActionPercept
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Perform the action on the server and get the resulting {@link Percept}{@code s}.
*
* @param targetEntities
* - The entities which should perform the action.
* @param remoteEnvironment
* - The {@link RemoteEnvironment} which is acted upon.
* @param action
* - The {@link Action} to be performed.
* @return The map of resulting percepts.
* @throws ActException
* Thrown if the server could not perform the action.
*/
private static Map<String, Percept> getActionPercept(Set<String> targetEntities,
RemoteEnvironment remoteEnvironment, Action action) throws ActException {
Map<String, Percept> actionPercepts = new HashMap<>();
for (String entity : targetEntities) {
try {
Percept percept = remoteEnvironment.performEntityAction(entity, action);
if (percept != null) {
actionPercepts.put(entity, percept);
}
} catch (RemoteException e) {
throw new ActException(ActException.FAILURE, "performAction failed:", e);
}
}
return actionPercepts;
}
开发者ID:eishub,项目名称:BW4T,代码行数:29,代码来源:ActionHandler.java
示例6: testPerformActionDelegated
import eis.exceptions.ActException; //导入依赖的package包/类
@Test
public void testPerformActionDelegated() throws ActException, AgentException {
List<String> agentsList = new LinkedList<>();
agentsList.add("testAgent");
Set<String> entitySet = new HashSet<>(1);
entitySet.add("testEntity");
String agent = "testAgent";
when(remoteEnvironment.getAgents()).thenReturn(agentsList);
when(remoteEnvironment.isSupportedByEnvironment(any(Action.class))).thenReturn(true);
when(remoteEnvironment.getAssociatedEntities(agent)).thenReturn(entitySet);
when(remoteEnvironment.isSupportedByType(any(Action.class), any(String.class))).thenReturn(true);
when(remoteEnvironment.isSupportedByEntity(any(Action.class), any(String.class))).thenReturn(true);
String entities = "testEntity";
ActionHandler.performActionDelegated(agent, new Action("test"), remoteEnvironment, entities);
}
开发者ID:eishub,项目名称:BW4T,代码行数:18,代码来源:ActionHandlerTest.java
示例7: movementTest
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Here we test if movement and collision is working properly.
*
* @throws TranslationException If the test fails.
* @throws ActException If the test fails.
* @throws InterruptedException May be thrown while sleeping.
*/
@Test
public void movementTest() throws TranslationException, ActException, InterruptedException {
// We verify that we are indeed at the starting area, then move to RoomC1
TestFunctions.retrievePercepts(bot1);
assertTrue(TestFunctions.hasPercept("at(FrontDropZone)"));
Parameter[] param = Translator.getInstance().translate2Parameter("RoomC1");
client.performAction(bot1, new Action("goTo", param));
Thread.sleep(4000L);
// We verify if we have arrived correctly
TestFunctions.retrievePercepts(bot1);
assertTrue(TestFunctions.hasPercept("in(RoomC1)"));
// Next we test collision by having a second bot attempt to enter the same room
TestFunctions.retrievePercepts(bot2);
assertTrue(TestFunctions.hasPercept("at(FrontDropZone)"));
param = Translator.getInstance().translate2Parameter("RoomC1");
client.performAction(bot2, new Action("goTo", param));
Thread.sleep(4000L);
// We verify if we've collided with the door as intended
TestFunctions.retrievePercepts(bot2);
assertTrue(TestFunctions.hasPercept("state(collided)"));
assertTrue(TestFunctions.hasPercept("at(FrontRoomC1)"));
}
开发者ID:eishub,项目名称:BW4T,代码行数:33,代码来源:MovementTest.java
示例8: sendMessage
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Instructs the robot to send a message
*
* @param message
* , the message that should be sent
* @param receiver
* , the receiver of the message (can be all or the id of another
* robot
* @throws ActException
* if the action fails
*/
@AsAction(name = "sendMessage")
public void sendMessage(String receiver, String message) throws ActException {
ourRobot.getAgentRecord().addSentMessage();
// Translate the message into parameters
Parameter[] parameters = new Parameter[2];
try {
parameters[0] = Translator.getInstance().translate2Parameter(ourRobot.getName())[0];
parameters[1] = Translator.getInstance().translate2Parameter(message)[0];
} catch (TranslationException e) {
throw new ActException("translating of message failed:" + message, e);
}
// Send to all other entities (except self)
if ("all".equals(receiver)) {
for (String entity : BW4TEnvironment.getInstance().getEntities()) {
BW4TEnvironment.getInstance().performClientAction(entity, new Action("receiveMessage", parameters));
}
// Send to a single entity
} else {
BW4TEnvironment.getInstance().performClientAction(receiver, new Action("receiveMessage", parameters));
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:35,代码来源:RobotEntity.java
示例9: sendMessage
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Instructs the robot to send a message
*
* @param message
* , the message that should be sent
* @param receiver
* , the receiver of the message (can be all or the id of another robot
* @throws ActException
* if the action fails
*/
@AsAction(name = "sendMessage")
public void sendMessage(String receiver, String message) throws ActException {
// Translate the message into parameters
Parameter[] parameters = new Parameter[2];
try {
parameters[0] = Translator.getInstance().translate2Parameter(ourEPartner.getName())[0];
parameters[1] = Translator.getInstance().translate2Parameter(message)[0];
} catch (TranslationException e) {
throw new ActException("translating of message failed:" + message, e);
}
// Send to all other entities (except self)
if ("all".equals(receiver)) {
for (String entity : BW4TEnvironment.getInstance().getEntities()) {
BW4TEnvironment.getInstance().performClientAction(entity, new Action("receiveMessage", parameters));
}
// Send to a single entity
} else {
BW4TEnvironment.getInstance().performClientAction(receiver, new Action("receiveMessage", parameters));
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:32,代码来源:EPartnerEntity.java
示例10: performAction
import eis.exceptions.ActException; //导入依赖的package包/类
@Override
public final Percept performAction(Action action) throws ActException {
String actionName = EIS2JavaUtil.getNameOfAction(action);
Method actionMethod = actionMethods.get(actionName);
if (actionMethod == null) {
throw new ActException(ActException.FAILURE,
"Entity does not support action: " + action);
}
// workaround/fix for an EIS issue. #1986.
try {
return performAction(entity, actionMethod, action);
} catch (Exception e) {
if (e instanceof ActException) {
throw (ActException) e;
}
throw new ActException(ActException.FAILURE, "execution of action "
+ action + "failed", e);
}
}
开发者ID:eishub,项目名称:eis,代码行数:21,代码来源:DefaultActionHandler.java
示例11: performEntityAction
import eis.exceptions.ActException; //导入依赖的package包/类
@Override
protected Percept performEntityAction(String agent, Action action) throws ActException {
try {
boolean ok = jasonEnv.executeAction(agent, Translator.actoinToStructure(action) );
if (!ok)
throw new ActException("error executing action "+action.toProlog());
} catch (JasonException e) {
e.printStackTrace();
throw new ActException(e.getMessage());
}
return null;
}
开发者ID:jason-lang,项目名称:apps,代码行数:13,代码来源:JasonAdapter.java
示例12: performEntityAction
import eis.exceptions.ActException; //导入依赖的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
示例13: pickUpEPartner
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Pick up a certain epartner in the world
*
* @throws ActException
*/
public void pickUpEPartner() throws ActException {
try {
getEnvironment().performEntityAction(entityId, new Action("pickUpEPartner"));
} catch (Exception e) {
ActException ex = new ActException("pickUpEPartner failed", e);
ex.setType(ActException.FAILURE);
throw ex;
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:15,代码来源:HumanAgent.java
示例14: putDownEPartner
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Put down a block in the world
*
* @throws ActException
*/
public void putDownEPartner() throws ActException {
try {
getEnvironment().performEntityAction(entityId, new Action("putDownEPartner"));
} catch (RemoteException e) {
ActException ex = new ActException("putDownEPartner failed", e);
ex.setType(ActException.FAILURE);
throw ex;
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:15,代码来源:HumanAgent.java
示例15: run
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Retrieve and process percepts in the environment.
*/
@Override
public void run() {
try {
while (!environmentKilled) {
percepts();
action();
Thread.sleep(200);
}
} catch (InterruptedException | ActException e) {
LOGGER.error("The Agent could not succesfully complete its run.", e);
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:16,代码来源:TestAgent.java
示例16: action
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* Perform the next action - only if we're not already busy.
*
* @throws ActException the act exception
*/
private void action() throws ActException {
if (!"traveling".equals(state) && !places.isEmpty()) {
goTo(places.get(nextDestination));
nextDestination++;
if (nextDestination == places.size()) {
nextDestination = 0;
}
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:15,代码来源:TestAgent.java
示例17: goToBlock
import eis.exceptions.ActException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void goToBlock(long id) throws ActException {
try {
Parameter[] idParam = Translator.getInstance().translate2Parameter(id);
bw4tenv.performEntityAction(entityId, new Action("goToBlock", idParam));
} catch (TranslationException | RemoteException e) {
ActException ex = new ActException("goToBlock failed", e);
ex.setType(ActException.FAILURE);
throw ex;
}
}
开发者ID:eishub,项目名称:BW4T,代码行数:15,代码来源:BW4TAgent.java
注:本文中的eis.exceptions.ActException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论