Last change
on this file since 273 was 273, checked in by Tim Baarslag, 5 years ago |
Buyer and Seller agents
|
File size:
1.1 KB
|
Rev | Line | |
---|
[269] | 1 | package onetomany.bargainingchipsgame.players;
|
---|
| 2 |
|
---|
| 3 | import java.util.concurrent.BlockingQueue;
|
---|
| 4 |
|
---|
| 5 | import onetomany.bargainingchipsgame.Bundle;
|
---|
| 6 | import onetomany.bargainingchipsgame.interactions.Offer;
|
---|
[270] | 7 | import onetomany.bargainingchipsgame.interactions.SampleOffer;
|
---|
[269] | 8 |
|
---|
[273] | 9 | public abstract class BilateralAgent implements Runnable
|
---|
[269] | 10 | {
|
---|
[273] | 11 | String name;
|
---|
[269] | 12 | BlockingQueue<Offer> in;
|
---|
| 13 | BlockingQueue<Offer> out;
|
---|
| 14 |
|
---|
[273] | 15 | public BilateralAgent(String name, BlockingQueue<Offer> in, BlockingQueue<Offer> out)
|
---|
[269] | 16 | {
|
---|
| 17 | super();
|
---|
[273] | 18 | this.name = name;
|
---|
[269] | 19 | this.in = in;
|
---|
[273] | 20 | this.out = out;
|
---|
[269] | 21 | }
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | @Override
|
---|
| 25 | public void run()
|
---|
| 26 | {
|
---|
| 27 | while (true)
|
---|
| 28 | {
|
---|
| 29 | Offer o;
|
---|
| 30 | try {
|
---|
| 31 | o = in.take();
|
---|
| 32 | Bundle bundle = o.getBundle();
|
---|
| 33 | System.out.println("Received " + bundle);
|
---|
[273] | 34 | receiveOffer(bundle);
|
---|
[270] | 35 | out.put(new SampleOffer(10));
|
---|
| 36 | System.out.println("Sent " + out);
|
---|
[269] | 37 | } catch (InterruptedException e) {
|
---|
| 38 | // TODO Auto-generated catch block
|
---|
| 39 | e.printStackTrace();
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[273] | 44 | protected abstract void receiveOffer(Bundle bundle);
|
---|
| 45 |
|
---|
| 46 | protected abstract Offer sendOffer();
|
---|
| 47 |
|
---|
[269] | 48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.