]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/driver/jms/JMSDriver.java
[JMS] new WF works now (hopefully)
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / driver / jms / JMSDriver.java
1 package at.ac.tuwien.sbc.valesriegler.driver.jms;
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.driver.jms.messageListeners.CookedDeliveryOrders;
14
15 /**
16  * JMSDriver registers all the Listeners.
17  * 
18  * @author jan
19  * 
20  */
21 public class JMSDriver implements HasId {
22         private static final Logger log = LoggerFactory.getLogger(JMSDriver.class);
23         private final String CONNECTSTRING;
24         public String getCONNECTSTRING() {
25                 return CONNECTSTRING;
26         }
27
28         final private int id;
29
30         public JMSDriver(String jmsURL, int id) {
31                 CONNECTSTRING = jmsURL;
32                 this.id = id;
33                 log.info("I AM A JMSDriver WITH ID {}", this.id);
34
35                 try {
36                         // Connecting to the Broker and to the output queue
37                         ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(CONNECTSTRING);
38                         Connection connection = connectionFactory.createConnection();
39                         connection.start();
40
41                         Session sessCookedDeliveryOrders = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
42                         MessageConsumer consCookedDeliveryOrders = sessCookedDeliveryOrders.createConsumer(sessCookedDeliveryOrders
43                                         .createQueue("OrdersToCook"));
44                         consCookedDeliveryOrders.setMessageListener(new CookedDeliveryOrders(this));
45                 } catch (JMSException e) {
46                         log.error("EXCEPTION!", e);
47                 }
48         }
49
50         @Override
51         public int getId() {
52                 return id;
53         }
54 }