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