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;
16 * The Main class of the Group component.
18 * Start the communication and the group GUI:
20 * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
23 public class GroupAgent {
24 private static final String USAGE = "This application needs exactly 1 parameter: <\"XVSM\"|\"JMS\">";
26 private static final Logger log = LoggerFactory.getLogger(GroupAgent.class);
27 private GroupOverviewModel groupModel;
28 private AbstractGroupConnector groupconn;
29 private DeliveryOverviewModel deliveryOverviewModel;
30 private GroupAgentXVSM xvsm;
32 /* Contains the identifiers of the pizzerias. Whenever a new Pizzeria emerges or dies the group agent has to be
33 notified about this somehow and the list has to be adapted as it is the model of the dropdown in the GUI for
34 selecting for which pizzeria the customer groups are created
35 In case of XVSM the identifier string is a port number*/
36 private Set<String> pizzeriaIdentifiers = Collections.synchronizedSet(new HashSet<String>());
38 public static GroupAgent groupAgent;
40 public static void main(String[] args) {
41 if (args.length != 1) {
42 throw new IllegalArgumentException(USAGE);
46 log.info("Middleware: " + mw);
48 if ("JMS".equalsIgnoreCase(mw)) {
50 } else if ("XVSM".equalsIgnoreCase(mw)) {
53 throw new IllegalArgumentException(USAGE);
56 groupAgent = new GroupAgent();
58 SwingUtilities.invokeLater(new GroupGUI());
62 groupModel = new GroupOverviewModel();
64 this.groupconn = new JMSGroupConnector();
67 xvsm = new GroupAgentXVSM();
69 xvsm.listenForNewPizzerias();
70 xvsm.listenForTableAssigned();
71 xvsm.listenForOrdersTaken();
72 xvsm.listenForDeliveredOrders();
73 xvsm.listenForPaymentRequest();
74 xvsm.listenForPaymentDone();
78 public static GroupAgent getInstance() {
82 public AbstractGroupConnector getGroupcomm() {
86 public Set<String> getPizzeriaIdentifiers() {
87 return pizzeriaIdentifiers;
90 public GroupOverviewModel getGroupModel() {
94 public DeliveryOverviewModel getDeliveryModel() {
95 return deliveryOverviewModel;
98 public void onGroupsCreated(List<Group> newGroups) {
100 List<GroupData> groupData = new ArrayList<>();
102 for (Group group : newGroups) {
103 groupData.add(group.getGroupData());
105 final String pizzeriaId = groupData.get(0).getPizzeriaId();
107 int pizzeriaSpacePort = 0;
109 pizzeriaSpacePort = Integer.parseInt(pizzeriaId);
110 } catch (NumberFormatException e) {
111 log.error("Pizzeria Identifier should be an integer in the XVSM version!");
113 xvsm.sendNewGroupsToSpace(groupData, pizzeriaSpacePort);
115 log.info("New Groups were sent to the space");
117 // start the space group in a new thread
118 for (GroupData group : groupData) {
119 new Thread(new SpaceGroup(group.getId(), pizzeriaSpacePort)).start();
126 public void onDeliveryGroupsCreated(List<DeliveryGroup> newDeliveryGroups) {
127 //To change body of created methods use File | Settings | File Templates.