1 package at.ac.tuwien.sbc.valesriegler.group;
3 import at.ac.tuwien.sbc.valesriegler.common.Util;
4 import at.ac.tuwien.sbc.valesriegler.group.gui.DeliveryOverviewModel;
5 import at.ac.tuwien.sbc.valesriegler.group.gui.GroupOverviewModel;
6 import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector;
7 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
8 import at.ac.tuwien.sbc.valesriegler.xvsm.GroupAgentXVSM;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
13 import java.util.ArrayList;
14 import java.util.List;
17 * The Main class of the Group component.
19 * Start the communication and the group GUI:
21 * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
24 public class GroupAgent {
25 private static final String USAGE = "This application needs exactly 1 parameter: <\"XVSM\"|\"JMS\">";
27 private static final Logger log = LoggerFactory.getLogger(GroupAgent.class);
28 private GroupOverviewModel groupModel;
29 private AbstractGroupConnector groupconn;
30 private DeliveryOverviewModel deliveryOverviewModel;
31 private GroupAgentXVSM xvsm;
33 public static GroupAgent groupAgent;
35 public static void main(String[] args) {
36 if (args.length != 1) {
37 throw new IllegalArgumentException(USAGE);
41 log.info("Middleware: " + mw);
43 if ("JMS".equalsIgnoreCase(mw)) {
44 groupAgent = new GroupAgent(new JMSGroupConnector());
46 } else if ("XVSM".equalsIgnoreCase(mw)) {
47 // TODO: XVSM Connector?
49 groupAgent = new GroupAgent(null);
51 throw new IllegalArgumentException(USAGE);
54 SwingUtilities.invokeLater(new GroupGUI());
57 public GroupAgent(AbstractGroupConnector groupconn) {
58 groupModel = new GroupOverviewModel();
60 this.groupconn = groupconn;
63 xvsm = new GroupAgentXVSM();
65 xvsm.listenForTableAssigned();
66 xvsm.listenForOrdersTaken();
67 xvsm.listenForDeliveredOrders();
68 xvsm.listenForPaymentRequest();
69 xvsm.listenForPaymentDone();
73 public static GroupAgent getInstance() {
77 public AbstractGroupConnector getGroupcomm() {
81 public GroupOverviewModel getGroupModel() {
85 public DeliveryOverviewModel getDeliveryModel() {
86 return deliveryOverviewModel;
89 public void onGroupsCreated(List<Group> newGroups) {
91 List<GroupData> groupData = new ArrayList<>();
93 for (Group group : newGroups) {
94 groupData.add(group.getGroupData());
96 xvsm.sendNewGroupsToSpace(groupData);
98 log.info("New Groups were sent to the space");
100 // start the space group in a new thread
101 for (GroupData group : groupData) {
102 new Thread(new SpaceGroup(group.getId())).start();