goal.getParameter((String) paramEntry.getKey()).setValue(paramEntry.getValue()); goal.addGoalListener(new IGoalListener()
public void goalFinished(AgentEvent ae) if(goal.isSucceeded()) IParameter[] params = goal.getParameters(); for(int i=0; i<params.length; i++) IParameterSet[] paramsets = goal.getParameterSets(); for(int i=0; i<paramsets.length; i++) ret.setException(goal.getException()!=null? goal.getException(): new RuntimeException());
/** * The body method is called on the * instantiated plan instance from the scheduler. */ public void body() { String[] goalnames = (String[]) getParameter("goals").getValue(); IGoal[] goals = new IGoal[goalnames.length]; for (int i = 0; i < goalnames.length; ++i) { goals[i] = createGoal(goalnames[i]); dispatchSubgoal(goals[i]); } for (int i = 0; i < goals.length; ++i) { waitForGoal(goals[i]); if (!goals[i].isSucceeded()) { for (int j = 0; j < goals.length; ++j) { goals[j].drop(); } fail(goals[i].getException()); } } } }
public void goalFinished(AgentEvent ae) { IGoal goal = (IGoal)ae.getSource(); if(goal.isSucceeded()) { goalcnt++; if(goalcnt==agoalnames.length) lis.resultAvailable(null); } else { lis.exceptionOccurred(goal.getException()); } }
/** * Decide about the next iteration. * @param cfp_info The cfp info. * @param history The history. * @return The new cfp and cfp_info as an object array. */ protected Object[] decideIteration(Object cfp_info, Object[] history) { Object[] ret = null; IGoal di = createGoal("ea_decide_iteration"); di.getParameter("cfp_info").setValue(cfp_info); di.getParameterSet("history").addValues(history); try { dispatchSubgoalAndWait(di); ret = new Object[2]; ret[0] = di.getParameter("cfp").getValue(); ret[1] = di.getParameter("cfp_info").getValue(); } //catch(Throwable e) catch(BDIFailureException e) { getLogger().fine("No further iteration: "+e); //e.printStackTrace(); } return ret; }
/** * Decide about the request. * @param request The request. * @param initiator The requesting agent. * @return True, if should send agree. False for sending refuse. Exception/null for sending nothing. */ public Boolean decideRequest(Object request, IComponentIdentifier initiator) { IGoal decide_request = createGoal("rp_decide_request"); decide_request.getParameter("action").setValue(request); decide_request.getParameter("initiator").setValue(initiator); dispatchSubgoalAndWait(decide_request); return (Boolean)decide_request.getParameter("accept").getValue(); }
List<IParameter> params = SUtil.arrayToList(goal.getParameters()); List<IParameterSet> paramsets = SUtil.arrayToList(goal.getParameterSets()); goal.addGoalListener(new IGoalListener()
goal.addGoalListener(listener); dispatchSubgoal(goal); if(!goal.isSucceeded()) mviolated = goal;
public void goalFinished(AgentEvent ae) { goalFuture.setResult(goal.getParameters()); }
IMessageEvent inimsg = (IMessageEvent)interaction_goal.getParameter("message").getValue(); IMessageEvent canceldummy = createMessageEvent("cm_cancel"); // Hack??? Need some conversation message to wait for canceldummy.getParameter(SFipa.CONVERSATION_ID).setValue(inimsg.getParameter(SFipa.CONVERSATION_ID).getValue()); approve_cancel.getParameter(SFipa.CONVERSATION_ID).setValue(cancel_msg.getParameter(SFipa.CONVERSATION_ID).getValue()); approve_cancel.getParameter(SFipa.PROTOCOL).setValue(inimsg.getParameter(SFipa.PROTOCOL).getValue()); approve_cancel.getParameter("initiator").setValue(cancel_msg.getParameter(SFipa.SENDER).getValue()); dispatchSubgoalAndWait(approve_cancel); getLogger().info("Receiver approved cancel: "+getComponentName()); if(!((Boolean)approve_cancel.getParameter("result").getValue()).booleanValue()) failure_reason = approve_cancel.getParameter("failure_reason").getValue(); if(failure_reason==null) InteractionState state = (InteractionState)interaction_goal.getParameter("interaction_state").getValue(); if(InteractionState.INTERACTION_RUNNING.equals(state.getInteractionState())) interaction_goal.drop(); try
public void run() { Object rgoal = ((ElementFlyweight)goal).getHandle(); // Directly add rgoal to waitqueue if already finished. if(goal.isFinished()) { getState().addAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_waitqueueelements, rgoal); } else { SFlyweightFunctionality.addGoal(getOrCreateWaitAbstraction(), (ElementFlyweight)goal, getState(), getScope()); } } };
/** * Decide about the next iteration. * @param cfp_info The cfp info. * @param history The history. * @return The new cfp and cfp_info as an object array. */ protected Object[] decideIteration(Object cfp_info, Object[] history) { Object[] ret = null; IGoal di = createGoal("da_decide_iteration"); di.getParameter("cfp_info").setValue(cfp_info); di.getParameterSet("history").addValues(history); try { dispatchSubgoalAndWait(di); ret = new Object[2]; ret[0] = di.getParameter("cfp").getValue(); ret[1] = di.getParameter("cfp_info").getValue(); getLogger().info(getComponentName() + "calculated new cfp: "+ret[0]); } catch(BDIFailureException e) { getLogger().fine("No further iteration: "+e); //e.printStackTrace(); } return ret; }
/** * Make a proposal based on the task description. * @param cfp The cfp including the task to execute. * @return The proposal for executing the task. */ public Object[] makeProposal(Object cfp, IComponentIdentifier initiator) { IGoal make_proposal = createGoal(getShortProtocolName()+"_make_proposal"); make_proposal.getParameter("cfp").setValue(cfp); make_proposal.getParameter("initiator").setValue(initiator); dispatchSubgoalAndWait(make_proposal); return new Object[]{make_proposal.getParameter("proposal").getValue(), make_proposal.getParameter("proposal_info").getValue()}; }
/** * The body method is called on the * instantiated plan instance from the scheduler. */ public void body() { String[] goalnames = (String[]) getParameter("goals").getValue(); IGoal[] goals = new IGoal[goalnames.length]; for (int i = 0; i < goalnames.length; ++i) { goals[i] = createGoal(goalnames[i]); dispatchSubgoalAndWait(goals[i]); if (!goals[i].isSucceeded()) { fail(goals[i].getException()); } } } }
/** * Wait for a goal. * @param goal The goal. * @param timeout The timeout. */ public void waitForGoal(final IGoal goal, long timeout) { if(goal.isFinished()) { // Todo: check thread access. if(OAVBDIRuntimeModel.GOALPROCESSINGSTATE_FAILED.equals( getState().getAttributeValue(((ElementFlyweight)goal).getHandle(), OAVBDIRuntimeModel.goal_has_processingstate))) { throw new GoalFailureException("Goal failed: "+goal); } } else { // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addGoal(wa, (ElementFlyweight)goal, getState(), getRCapability()); PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); } }
/** * The body method is called on the * instatiated plan instance from the scheduler. */ public void body() { CMSSearchComponents sa = (CMSSearchComponents)getParameter("action").getValue(); IGoal sag = createGoal("cms_search_components"); sag.getParameter("description").setValue(sa.getComponentDescription()); sag.getParameter("constraints").setValue(sa.getSearchConstraints()); sag.getParameter("remote").setValue(sa.isRemote()? Boolean.TRUE: Boolean.FALSE); dispatchSubgoalAndWait(sag); sa.setComponentDescriptions((IComponentDescription[])sag.getParameterSet("result").getValues()); getParameter("result").setValue(new Done(sa)); } }
/** * Execute the request. * @param request The request. * @param initiator The requesting agent. * @return The result. */ public Object executeRequest(Object request, IComponentIdentifier initiator) { IGoal execute_request = createGoal("rp_execute_request"); execute_request.getParameter("action").setValue(request); execute_request.getParameter("initiator").setValue(initiator); dispatchSubgoalAndWait(execute_request); return execute_request.getParameter("result").getValue(); } }
sel.getParameter("cfp").setValue(nr.getCFP()); sel.getParameter("cfp_info").setValue(nr.getCFPInfo()); sel.getParameterSet("participants").addValues(nr.getParticipants()); sel.getParameterSet("proposals").addValues(nr.getProposals()); sel.getParameterSet("history").addValues(getParameterSet("history").getValues()); try if(((Boolean)sel.getParameter("iterate").getValue()).booleanValue()) Object cfp = sel.getParameter("cfp").getValue(); Object cfp_info = sel.getParameter("cfp_info").getValue(); IComponentIdentifier[] participants = (IComponentIdentifier[])sel.getParameterSet("participants").getValues(); ret = new NegotiationRecord(cfp, cfp_info, participants, getTime()); getParameterSet("history").addValue(ret);
/** * Execute the task. * @param proposal The proposal. * @param proposal_info The proposal info. * @return The result of the task. */ public Object executeTask(Object proposal, Object proposal_info, IComponentIdentifier initiator) { IGoal execute_task = createGoal(getShortProtocolName()+"_execute_task"); execute_task.getParameter("proposal").setValue(proposal); execute_task.getParameter("proposal_info").setValue(proposal_info); execute_task.getParameter("initiator").setValue(initiator); dispatchSubgoalAndWait(execute_task); return execute_task.getParameter("result").getValue(); } }