]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java
Some space refactoring. Doing away with unnecessary containers. Auto-Reloading of...
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / group / GroupAgent.java
1 package at.ac.tuwien.sbc.valesriegler.group;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.swing.SwingUtilities;
7
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import at.ac.tuwien.sbc.valesriegler.common.Util;
12 import at.ac.tuwien.sbc.valesriegler.group.gui.GroupOverviewModel;
13 import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector;
14 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
15 import at.ac.tuwien.sbc.valesriegler.xvsm.GroupAgentXVSM;
16
17 /**
18  * The Main class of the Group component.
19  * <p />
20  * Start the communication and the group GUI:
21  * 
22  * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
23  * @author jan
24  * 
25  */
26 public class GroupAgent {
27         
28         private static final Logger log = LoggerFactory.getLogger(GroupAgent.class);
29         private GroupOverviewModel groupModel;
30         private AbstractGroupConnector groupconn;
31         private GroupAgentXVSM xvsm;
32         
33         public static GroupAgent groupAgent;
34
35         public static void main(String[] args) {
36                 // TODO: use jms and xvsm manager here.
37                 groupAgent = new GroupAgent(new JMSGroupConnector());
38                 
39                 SwingUtilities.invokeLater(new GroupGUI());
40         }
41
42         public GroupAgent(JMSGroupConnector groupconn) {
43                 groupModel = new GroupOverviewModel();
44                 if(Util.useJMS) {
45                         this.groupconn = groupconn;
46                         groupconn.init();
47                 }
48                 else {
49                         xvsm = new GroupAgentXVSM();
50
51                         xvsm.listenForTableAssigned();
52                         xvsm.listenForOrdersTaken();
53 //                      xvsm.listenForGroupDataChanges();
54                         xvsm.listenForDeliveredOrders();
55                         xvsm.listenForPaymentRequest();
56                         xvsm.listenForPaymentDone();
57                 }
58         }
59
60         public static GroupAgent getInstance() {
61                 return groupAgent;
62         }
63
64         public AbstractGroupConnector getGroupcomm() {
65                 return groupconn;
66         }
67
68         public GroupOverviewModel getGroupModel() {
69                 return groupModel;
70         }
71
72         public void onGroupsCreated(List<Group> newGroups) {
73                 if(!Util.useJMS) {
74                         List<GroupData> groupData = new ArrayList<>();
75                         
76                         for (Group group : newGroups) {
77                                 groupData.add(group.getGroupData());
78                         }
79                         xvsm.sendNewGroupsToSpace(groupData);
80                         
81                         log.info("New Groups were sent to the space");
82                         
83                      // start the space group in a new thread
84                         for (GroupData group : groupData) {
85                                  new Thread(new SpaceGroup(group.getId())).start();
86                         }
87                 }
88
89         }
90 }