]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java
Space waiters pay and overall remaining space workflow refactoring
[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.listenForGroupDataChanges();
52                         xvsm.listenForDeliveredOrders();
53                         xvsm.listenForPaymentRequest();
54                         xvsm.listenForPayment();
55                 }
56         }
57
58         public static GroupAgent getInstance() {
59                 return groupAgent;
60         }
61
62         public AbstractGroupConnector getGroupcomm() {
63                 return groupconn;
64         }
65
66         public GroupOverviewModel getGroupModel() {
67                 return groupModel;
68         }
69
70         public void onGroupsCreated(List<Group> newGroups) {
71                 if(!Util.useJMS) {
72                         List<GroupData> groupData = new ArrayList<>();
73                         
74                         for (Group group : newGroups) {
75                                 groupData.add(group.getGroupData());
76                         }
77                         xvsm.sendNewGroupsToSpace(groupData);
78                         
79                         log.info("New Groups were sent to the space");
80                         
81                      // start the space group in a new thread
82                         for (GroupData group : groupData) {
83                                  new Thread(new SpaceGroup(group.getId())).start();
84                         }
85                 }
86
87         }
88 }