]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/cook/JMSCook.java
JMS: pizzeriaGui now displays everything correctly.
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / cook / JMSCook.java
1 package at.ac.tuwien.sbc.valesriegler.cook;
2
3 import javax.jms.Connection;
4 import javax.jms.JMSException;
5 import javax.jms.MessageConsumer;
6 import javax.jms.Session;
7
8 import org.apache.activemq.ActiveMQConnectionFactory;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12 import at.ac.tuwien.sbc.valesriegler.common.HasId;
13 import at.ac.tuwien.sbc.valesriegler.cook.jms.messageListeners.OrdersToCook;
14
15 /**
16  * (JMS)Cook is far too primitive to require any abstraction. It would take more
17  * time to it, than to code it twice.
18  * 
19  * @author jan
20  * 
21  */
22 public class JMSCook implements HasId {
23         private static final Logger log = LoggerFactory.getLogger(JMSCook.class);
24         private static int nextID = 0;
25         final private int id;
26
27         public static void main(String[] args) throws Exception {
28                 new JMSCook(++nextID);
29         }
30
31         public JMSCook(int id) {
32                 this.id = id;
33                 log.info("I AM A JMSCook WITH ID {}", this.id);
34
35                 try {
36                         // Connecting to the Broker and to the output queue
37                         ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
38                         Connection connection = connectionFactory.createConnection();
39                         connection.start();
40
41                         Session sessWantToSit = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
42                         MessageConsumer consWantToSit = sessWantToSit.createConsumer(sessWantToSit.createQueue("OrdersToCook"));
43                         consWantToSit.setMessageListener(new OrdersToCook(this));
44                 } catch (JMSException e) {
45                         log.error("EXCEPTION!", e);
46                 }
47         }
48
49         @Override
50         public int getId() {
51                 return id;
52         }
53 }