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
|
Line | |
---|
1 | package onetomany.bargainingchipsgame.players;
|
---|
2 |
|
---|
3 | import java.util.concurrent.BlockingQueue;
|
---|
4 |
|
---|
5 | import onetomany.bargainingchipsgame.Bundle;
|
---|
6 | import onetomany.bargainingchipsgame.interactions.Offer;
|
---|
7 | import onetomany.bargainingchipsgame.interactions.SampleOffer;
|
---|
8 |
|
---|
9 | public abstract class BilateralAgent implements Runnable
|
---|
10 | {
|
---|
11 | String name;
|
---|
12 | BlockingQueue<Offer> in;
|
---|
13 | BlockingQueue<Offer> out;
|
---|
14 |
|
---|
15 | public BilateralAgent(String name, BlockingQueue<Offer> in, BlockingQueue<Offer> out)
|
---|
16 | {
|
---|
17 | super();
|
---|
18 | this.name = name;
|
---|
19 | this.in = in;
|
---|
20 | this.out = out;
|
---|
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);
|
---|
34 | receiveOffer(bundle);
|
---|
35 | out.put(new SampleOffer(10));
|
---|
36 | System.out.println("Sent " + out);
|
---|
37 | } catch (InterruptedException e) {
|
---|
38 | // TODO Auto-generated catch block
|
---|
39 | e.printStackTrace();
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected abstract void receiveOffer(Bundle bundle);
|
---|
45 |
|
---|
46 | protected abstract Offer sendOffer();
|
---|
47 |
|
---|
48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.