]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java
Space cooks prepare pizzas and Pizzeria GUI shows that
[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.io.Serializable;
4 import java.rmi.server.Operation;
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import javax.management.Notification;
9 import javax.management.NotificationListener;
10 import javax.swing.SwingUtilities;
11
12 import org.mozartspaces.core.CapiUtil;
13 import org.mozartspaces.core.Entry;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 import at.ac.tuwien.sbc.valesriegler.common.Util;
18 import at.ac.tuwien.sbc.valesriegler.group.gui.GroupOverviewModel;
19 import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector;
20 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
21 import at.ac.tuwien.sbc.valesriegler.xvsm.AbstractXVSMConnector;
22 import at.ac.tuwien.sbc.valesriegler.xvsm.GroupAgentXVSM;
23 import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector;
24
25 /**
26  * The Main class of the Group component.
27  * <p />
28  * Start the communication and the group GUI:
29  * 
30  * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
31  * @author jan
32  * 
33  */
34 public class GroupAgent {
35         
36         private static final Logger log = LoggerFactory.getLogger(GroupAgent.class);
37         private GroupOverviewModel groupModel;
38         private AbstractGroupConnector groupconn;
39         private GroupAgentXVSM xvsm;
40         
41         public static GroupAgent groupAgent;
42
43         public static void main(String[] args) {
44                 // TODO: use jms and xvsm manager here.
45                 groupAgent = new GroupAgent(new JMSGroupConnector());
46                 
47                 SwingUtilities.invokeLater(new GroupGUI());
48         }
49
50         public GroupAgent(JMSGroupConnector groupconn) {
51                 groupModel = new GroupOverviewModel();
52                 if(Util.useJMS) {
53                         this.groupconn = groupconn;
54                         groupconn.init();
55                 }
56                 else {
57                         xvsm = new GroupAgentXVSM();
58
59                         xvsm.listenForGroupDataChanges();
60                 }
61         }
62
63         public static GroupAgent getInstance() {
64                 return groupAgent;
65         }
66
67         public AbstractGroupConnector getGroupcomm() {
68                 return groupconn;
69         }
70
71         public GroupOverviewModel getGroupModel() {
72                 return groupModel;
73         }
74
75         public void onGroupsCreated(List<Group> newGroups) {
76                 if(!Util.useJMS) {
77                         List<GroupData> groupData = new ArrayList<>();
78                         
79                         for (Group group : newGroups) {
80                                 groupData.add(group.getGroupData());
81                         }
82                         xvsm.sendNewGroupsToSpace(groupData);
83                         
84                         log.info("New Groups were sent to the space");
85                 }
86
87         }
88 }