.


:




:

































 

 

 

 


, , "" - behaviours. , jade.core.behaviours.Behaviour. () addBehaviour() Agen t. , ( setup()).

Behaviour : action() done(). action() , , . done() boolean value, , ().

. , (pre-emptive (as for Java threads)), . , , , action() . .. , . , , , :

Java ( , , , );

, Java;

( ), .. Java;

( ) ( ).

3.3.

 

setup(), . . , , , , . (, ) ( ). takeDown().

 

, , , , .. action() .

public class OverbearingBehaviour extends Behaviour {

public void action() {

while (true) {

// do something}

}

public boolean done() {

return true; } }

 

.

 

1) (one-shot) , action () , . jade.core.behaviours.OneShotBehaviour done(), true, .

public class MyOneShotBehaviour extends OneShotBehaviour {
public void action() {
// perform operation X
}}
.

2) (yclic) , . action() , . jade.core.behaviours.CyclicBehaviour done(), false, .

public class MyCyclicBehaviour extends CyclicBehaviour {
public void action() {
// perform operation Y
} }

Y , , .

 

3) (generic) , . , , done().

public class MyThreeStepBehaviour extends Behaviour {
private int step = 0;
public void action() {
switch (step) {
case 0:
// perform operation X
step++;
break;
case 1:
// perform operation Y
step++;
break;
case 2:
// perform operation Z
step++;
break;
}

public boolean done() {
return step == 3;
}}

 

X, Y Z , .

JADE , .

JADE ( jade.core.behaviours), , .

1) WakerBehaviour, action() done() , handleElapsedTimeout() ( ). handleElapsedTimeout() .

 

public class MyAgent extends Agent {
protected void setup() {
System.out.println(Adding waker behaviour);
addBehaviour(new WakerBehaviour(this, 10000) {
protected void handleElapsedTimeout() {
// perform operation X
}
});
}

X 10 Adding waker behaviour.

2) TickerBehaviour, action() done() , onTick() , ( ). TickerBehaviour .

public class MyAgent extends Agent {


protected void setup() {
addBehaviour(new TickerBehaviour(this, 10000) {
protected void onTick() {
// perform operation Y
}
});

}

Y 10 .

 

3.6.

, Book-buyer Book-seller .

3.6.1. Book-buyer

Book-buyer , . , TickerBehaviour , , -. setup() BookBuyerAgent .

 

protected void setup() {
// Printout a welcome message
System.out.println(Hello! Buyer-agent +getAID().getName()+ is ready.);
// Get the title of the book to buy as a start-up argument

 

Object[] args = getArguments();

 

if (args!= null && args.length > 0) {//

targetBookTitle = (String) args[0];

System.out.println(Trying to buy +targetBookTitle);

// TickerBehaviour,

addBehaviour(new TickerBehaviour(this, 60000) {

 

protected void onTick() {

myAgent. addBehaviour(new RequestPerformer());

}
});

}
else {
// Make the agent terminate
System.out.println(No target book title specified);
doDelete();
}

myAgent: () , . RequestPerformer, -, й3 - , .

 

3.6.2. Book-seller

Book-seller . :

(OfferRequestsServer).

(PurchaseOrdersServer).

.

.

Book-seller : , .

, Book-seller , , , GUI. BookSellerAgent ( OfferRequestsServer PurchaseOrdersServer й3 ).

 

import jade.core.Agent;
import jade.core.behaviours.*;
import java.util.*;
public class BookSellerAgent extends Agent {
// The catalogue of books for sale (maps the title of a book to its price)

private Hashtable catalogue;
// The GUI by means of which the user can add books in the catalogue

private BookSellerGui myGui;

 

protected void setup()

{
// Create the catalogue
catalogue = new Hashtable();
// Create and show the GUI
myGui = new BookSellerGui(this);
myGui.show();

 

// Add the behaviour serving requests for offer from buyer agents
addBehaviour(new OfferRequestsServer());
// Add the behaviour serving purchase orders from buyer agents
addBehaviour(new PurchaseOrdersServer());
}

 

protected void takeDown() {

myGui.dispose();

System.out.println(Seller-agent +getAID().getName()+ terminating.);
}

 

/**
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() {
public void action() {
catalogue.put(title, new Integer(price));
}

});

}

:

1. (, bookTrading), 3- : BookSellerAgent, BookByerAgent, BookSellerGui JADE\src\examples\bookTrading.

2. , : -gui agents seller:< >.BookSellerAgent; byer:< >.BookBuyerAgent1(Java_programming)

:

, .. , , ( ). , , .

3. -:

, <> , :

: ! !

 

 

4. - . , ,

Arguments:

: , .. , , ( ). , , .

. .

. ( ) .

й3

1. , .

2. .

3. .

 

3. .

: BookTrading - - .



<== | ==>
JADE | .1.
:


: 2018-10-18; !; : 406 |


:

:

- - , .
==> ...

1643 - | 1604 -


© 2015-2024 lektsii.org - -

: 0.029 .