]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java
XVSMConnector refactoring
[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
15 import at.ac.tuwien.sbc.valesriegler.common.Util;
16 import at.ac.tuwien.sbc.valesriegler.group.gui.GroupOverviewModel;
17 import at.ac.tuwien.sbc.valesriegler.group.jms.JMSGroupConnector;
18 import at.ac.tuwien.sbc.valesriegler.types.GroupData;
19 import at.ac.tuwien.sbc.valesriegler.xvsm.XVSMConnector;
20
21 /**
22  * The Main class of the Group component.
23  * <p />
24  * Start the communication and the group GUI:
25  * 
26  * @author Gregor Riegler <gregor DOT riegler AT gmail DOT com>
27  * @author jan
28  * 
29  */
30 public class GroupAgent {
31         
32         
33         public static GroupAgent groupAgent;
34         private GroupOverviewModel groupModel;
35         private AbstractGroupConnector groupconn;
36         private XVSMConnector xvsm;
37
38         public static void main(String[] args) {
39                 // TODO: use jms and xvsm manager here.
40                 groupAgent = new GroupAgent(new JMSGroupConnector());
41                 
42                 SwingUtilities.invokeLater(new GroupGUI());
43         }
44
45         public GroupAgent(JMSGroupConnector groupconn) {
46                 groupModel = new GroupOverviewModel();
47                 if(Util.useJMS) {
48                         this.groupconn = groupconn;
49                         groupconn.init();
50                 }
51                 else {
52                         xvsm = new XVSMConnector();
53                         xvsm.initSpaceCommunication();
54                         xvsm.useGroupsContainer();
55
56                 }
57         }
58
59         public static GroupAgent getInstance() {
60                 return groupAgent;
61         }
62
63         public AbstractGroupConnector getGroupcomm() {
64                 return groupconn;
65         }
66
67         public GroupOverviewModel getGroupModel() {
68                 return groupModel;
69         }
70
71         public void onGroupsCreated(List<Group> newGroups) {
72                 if(!Util.useJMS) {
73                         List<GroupData> groupData = new ArrayList<>();
74                         
75                         for (Group group : newGroups) {
76                                 groupData.add(group.getGroupData());
77                         }
78                         xvsm.sendGroupsToSpace(groupData);
79                 }
80
81         }
82 }