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 {
27 private static final String USAGE = "This application needs exactly 1 parameter: <\"XVSM\"|\"JMS\">";
29 private static final Logger log = LoggerFactory.getLogger(GroupAgent.class);
30 private GroupOverviewModel groupModel;
31 private AbstractGroupConnector groupconn;
32 private GroupAgentXVSM xvsm;
34 public static GroupAgent groupAgent;
36 public static void main(String[] args) {
37 if (args.length != 1) {
38 throw new IllegalArgumentException(USAGE);
42 log.info("Middleware: " + mw);
44 if ("JMS".equalsIgnoreCase(mw)) {
45 groupAgent = new GroupAgent(new JMSGroupConnector());
46 } else if ("XVSM".equalsIgnoreCase(mw)) {
47 // TODO: XVSM Connector?
48 groupAgent = new GroupAgent(new JMSGroupConnector());
50 throw new IllegalArgumentException(USAGE);
53 SwingUtilities.invokeLater(new GroupGUI());
56 public GroupAgent(AbstractGroupConnector groupconn) {
57 groupModel = new GroupOverviewModel();
59 this.groupconn = groupconn;
62 xvsm = new GroupAgentXVSM();
64 xvsm.listenForTableAssigned();
65 xvsm.listenForOrdersTaken();
66 xvsm.listenForDeliveredOrders();
67 xvsm.listenForPaymentRequest();
68 xvsm.listenForPaymentDone();
72 public static GroupAgent getInstance() {
76 public AbstractGroupConnector getGroupcomm() {
80 public GroupOverviewModel getGroupModel() {
84 public void onGroupsCreated(List<Group> newGroups) {
86 List<GroupData> groupData = new ArrayList<>();
88 for (Group group : newGroups) {
89 groupData.add(group.getGroupData());
91 xvsm.sendNewGroupsToSpace(groupData);
93 log.info("New Groups were sent to the space");
95 // start the space group in a new thread
96 for (GroupData group : groupData) {
97 new Thread(new SpaceGroup(group.getId())).start();