]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/DEBUG_JMSCreateTable.java
fixed some synchronisation problems in jms.
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / DEBUG_JMSCreateTable.java
1 package at.ac.tuwien.sbc.valesriegler;
2
3 import javax.jms.Connection;
4 import javax.jms.DeliveryMode;
5 import javax.jms.MessageProducer;
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.types.PizzaType;
13 import at.ac.tuwien.sbc.valesriegler.types.Table;
14
15 /**
16  * a helper to generate Tables.
17  * 
18  * @author jan
19  * 
20  */
21 public class DEBUG_JMSCreateTable {
22         private static final Logger log = LoggerFactory.getLogger(DEBUG_JMSCreateTable.class);
23         private static int nextID = 0;
24         final private int id;
25
26         public static void main(String[] args) throws Exception {
27                 new DEBUG_JMSCreateTable(++nextID);
28         }
29
30         public DEBUG_JMSCreateTable(int id) {
31                 this.id = id;
32                 log.info("I AM A DEBUG_CreateTable WITH ID {}", this.id);
33                 produce(PizzaType.CARDINALE);
34         }
35
36         public void produce(PizzaType pizzatype) {
37                 try {
38                         // Connecting to the Broker and to the output queue
39                         ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
40                         Connection connection = connectionFactory.createConnection();
41                         connection.start();
42                         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
43
44                         MessageProducer tableprod = session.createProducer(session.createQueue("TablesFree"));
45                         tableprod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
46
47                         // Create Tables
48                         for (int i = 0; i < 2; i++) {
49                                 tableprod.send(session.createObjectMessage(new Table(i)));
50                         }
51
52                         // // Create Groups
53                         // for (int i = 0; i < 1; i++) {
54                         // Group g = new Group();
55                         // g.setId(i);
56                         // g.setSize(4);
57                         // ArrayList<PizzaType> p = new ArrayList<PizzaType>();
58                         // p.add(PizzaType.CARDINALE);
59                         // p.add(PizzaType.MARGHERITA);
60                         // p.add(PizzaType.SALAMI);
61                         // p.add(PizzaType.MARGHERITA);
62                         // Order o = new Order(p);
63                         // g.setOrder(o);
64                         // g.goGrabSomeFood(); // start the workflow.
65                         // }
66
67                         // Clean up
68                         session.close();
69                         connection.close();
70                 } catch (Exception e) {
71                         log.error("Caught: ", e);
72                         e.printStackTrace();
73                 }
74         }
75 }