Java Examples for jade.core.behaviours.OneShotBehaviour

The following java examples will help you to understand the usage of jade.core.behaviours.OneShotBehaviour. These source code samples are taken from different open source projects.

Example 1
Project: eugene-master  File: VwapBehaviour.java View source code
@Override
public void onStart() {
    final VwapStatus vwapStatus = new VwapStatus(deadline, vwapExecution);
    final OrderReferenceListenerProxy proxy = proxy(vwapStatus);
    LOG.info("Start trading: {}", vwapStatus);
    LOG.info("LIMIT_AGE_THRESHOLD={}", LIMIT_AGE_THRESHOLD);
    final State cancelLimitState = new CancelLimitState();
    final State sendMarketState = new SendMarketState();
    registerFirstState(new CyclicFinishableBehaviour(new Task() {

        @Override
        public void action(final FinishableBehaviour b, final Agent agent) {
            decisionState(b, vwapStatus);
        }
    }), DECISION_STATE);
    registerState(new OneShotFinishableBehaviour(new Task<OneShotFinishableBehaviour>() {

        @Override
        public void action(final OneShotFinishableBehaviour b, final Agent agent) {
            sendMarketState.enter(session, topOfBook, b, vwapStatus, proxy);
        }
    }), SEND_MARKET_STATE);
    registerState(new OneShotFinishableBehaviour(new Task<OneShotFinishableBehaviour>() {

        @Override
        public void action(final OneShotFinishableBehaviour b, final Agent agent) {
            sendLimitState.enter(session, topOfBook, b, vwapStatus, proxy);
        }
    }), SEND_LIMIT_STATE);
    registerState(new OneShotFinishableBehaviour(new Task<OneShotFinishableBehaviour>() {

        @Override
        public void action(final OneShotFinishableBehaviour b, final Agent agent) {
            cancelLimitState.enter(session, topOfBook, b, vwapStatus, proxy);
        }
    }), CANCEL_LIMIT_STATE);
    registerLastState(new OneShotBehaviour() {

        @Override
        public void action() {
            LOG.info("Finished: {}", vwapStatus);
        }
    }, END_STATE);
    registerTransition(DECISION_STATE, SEND_LIMIT_STATE, GOTO_SEND_LIMIT_STATE, STATES);
    registerTransition(DECISION_STATE, SEND_MARKET_STATE, GOTO_SEND_MARKET_STATE, STATES);
    registerTransition(DECISION_STATE, CANCEL_LIMIT_STATE, GOTO_CANCEL_LIMIT_STATE, STATES);
    registerTransition(DECISION_STATE, END_STATE, GOTO_END_STATE, STATES);
    registerDefaultTransition(SEND_LIMIT_STATE, DECISION_STATE);
    registerDefaultTransition(SEND_MARKET_STATE, DECISION_STATE);
    registerDefaultTransition(CANCEL_LIMIT_STATE, DECISION_STATE);
}
Example 2
Project: sos-ws2010-mas-master  File: SimpleAgent.java View source code
public void action() {
    switch(step) {
        case 1:
            // Perform operation 1: print out a message
            System.out.println("Operation 1");
            break;
        case 2:
            // Perform operation 2: Add a OneShotBehaviour
            System.out.println("Operation 2. Adding one-shot behaviour");
            myAgent.addBehaviour(new OneShotBehaviour(myAgent) {

                public void action() {
                    System.out.println("One-shot");
                }
            });
            break;
        case 3:
            // Perform operation 3: print out a message
            System.out.println("Operation 3");
            break;
        case 4:
            // Perform operation 3: print out a message
            System.out.println("Operation 4");
            break;
    }
    step++;
}
Example 3
Project: jade-booktrading-master  File: BookSellerAgent.java View source code
/**
     This is invoked by the GUI when the user adds a new book for sale
	 */
public void updateCatalogue(final String title, final int price) {
    addBehaviour(new OneShotBehaviour() {

        /**
			 * 
			 */
        private static final long serialVersionUID = 1L;

        public void action() {
            catalogue.put(title, new Integer(price));
            System.out.println(title + " inserted into catalogue. Price = " + price);
        }
    });
}
Example 4
Project: jade_agents-master  File: MonitorAgent.java View source code
private void assignProductionPlan(String what, int count) {
    class AssignProductionPlan extends OneShotBehaviour {

        String what;

        int count;

        AID where;

        public AssignProductionPlan(Agent a, String what, AID where, int count) {
            super(a);
            this.what = what;
            this.where = where;
            this.count = count;
        }

        @Override
        public void action() {
            try {
                System.out.println("MonitorAgent is assigning productionplan: " + what + " to " + where.getName());
                ProductionPlan p = new ProductionPlan(what, constructionPlans.get(what), count);
                ACLMessage msg = new ACLMessage(ACLMessage.QUERY_IF);
                msg.addReceiver(where);
                msg.setLanguage(codec.getName());
                msg.setOntology(ontology.getName());
                getContentManager().fillContent(msg, p);
                send(msg);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    System.out.println("ASSIGN PRODUCTION");
    AID workplace = null;
    try {
        SearchConstraints onlyOne = new SearchConstraints();
        onlyOne.setMaxResults(new Long(1));
        DFAgentDescription tmpl = new DFAgentDescription();
        ServiceDescription sd = new ServiceDescription();
        sd.setType("Workplace");
        sd.addProperties(new Property("Product", what));
        tmpl.addServices(sd);
        DFAgentDescription[] result = DFService.search(this, tmpl, onlyOne);
        System.out.println("search resulted in: " + result);
        for (DFAgentDescription da : result) {
            System.out.println("found: for " + what + ":" + da.getName());
        }
        if (result.length == 1) {
            // we found a workplace that can produce the item
            workplace = result[0].getName();
        } else {
            // no workplace can produce this item - buy it!
            workplace = new AID("WorkplacePurchase", false);
        }
        // send a new productionplan to a workplace
        addBehaviour(new AssignProductionPlan(this, what, workplace, count));
    } catch (FIPAException ex) {
        ex.printStackTrace();
        Logger.getLogger(StorageAgent.class.getName()).log(Level.SEVERE, null, ex);
    }
}