01: package example;
02:
03: import java.io.*;
04: import java.util.*;
05: import java.util.logging.*;
06: import java.util.concurrent.BlockingQueue;
07:
08: import javax.jms.*;
09: import javax.webbeans.*;
10:
11: public class AdProducer implements MessageListener {
12:
13: private static final Logger log = Logger.getLogger(AdProducer.class
14: .getName());
15:
16: private Random _random = new Random();
17:
18: @Named("AdQueue")
19: private BlockingQueue _producer;
20:
21: private static final String[] _ads = { "Buy widgets",
22: "Watch this movie", "Eat at Joe's", "Learn a new trade",
23: "Find your mate" };
24:
25: public void ejbCreate() {
26: try {
27: String ad = _ads[_random.nextInt(_ads.length)];
28:
29: _producer.put(ad);
30: } catch (Exception e) {
31: log.fine(e.toString());
32: }
33: }
34:
35: public void onMessage(Message incomingMessage) {
36: try {
37: String ad = _ads[_random.nextInt(_ads.length)];
38:
39: _producer.put(ad);
40: } catch (Exception e) {
41: throw new RuntimeException(e);
42: }
43: }
44: }
|