1 package at.ac.tuwien.sbc.valesriegler.group;
3 import java.util.ArrayList;
6 import javax.swing.SwingUtilities;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
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;
18 * The Main class of the Group component.
20 * Start the communication and the group GUI:
22 * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
26 public class GroupAgent {
28 private static final Logger log = LoggerFactory.getLogger(GroupAgent.class);
29 private GroupOverviewModel groupModel;
30 private AbstractGroupConnector groupconn;
31 private GroupAgentXVSM xvsm;
33 public static GroupAgent groupAgent;
35 public static void main(String[] args) {
36 // TODO: use jms and xvsm manager here.
37 groupAgent = new GroupAgent(new JMSGroupConnector());
39 SwingUtilities.invokeLater(new GroupGUI());
42 public GroupAgent(JMSGroupConnector groupconn) {
43 groupModel = new GroupOverviewModel();
45 this.groupconn = groupconn;
49 xvsm = new GroupAgentXVSM();
51 xvsm.listenForTableAssigned();
52 xvsm.listenForOrdersTaken();
53 // xvsm.listenForGroupDataChanges();
54 xvsm.listenForDeliveredOrders();
55 xvsm.listenForPaymentRequest();
56 xvsm.listenForPaymentDone();
60 public static GroupAgent getInstance() {
64 public AbstractGroupConnector getGroupcomm() {
68 public GroupOverviewModel getGroupModel() {
72 public void onGroupsCreated(List<Group> newGroups) {
74 List<GroupData> groupData = new ArrayList<>();
76 for (Group group : newGroups) {
77 groupData.add(group.getGroupData());
79 xvsm.sendNewGroupsToSpace(groupData);
81 log.info("New Groups were sent to the space");
83 // start the space group in a new thread
84 for (GroupData group : groupData) {
85 new Thread(new SpaceGroup(group.getId())).start();