0
|
1 package rep;
|
|
2
|
1
|
3 import java.nio.channels.SocketChannel;
|
|
4 import java.util.LinkedList;
|
|
5 import java.util.List;
|
|
6
|
0
|
7 public class Session {
|
38
|
8 private Editor masterEditor;
|
1
|
9 private int sessionID;
|
|
10 private String sessionName;
|
|
11 private LinkedList<Editor> editorList = new LinkedList<Editor>();
|
56
|
12 private String masterHost;
|
|
13 private String masterPort;
|
|
14 private LinkedList<REPNode> routingTable = new LinkedList<REPNode>();
|
66
|
15 private int incrementEID;
|
67
|
16 private boolean isOwner = false;
|
9
|
17
|
1
|
18 public Session(int sessionID, String string, SocketChannel channel) {
|
|
19 masterEditor = new Editor(sessionID, channel);
|
|
20 this.sessionID = sessionID;
|
|
21 this.sessionName = string;
|
|
22 }
|
39
|
23 public Session(Editor editor) {
|
|
24 masterEditor = editor;
|
56
|
25 masterHost = editor.getHost();
|
|
26 masterPort = editor.getPort();
|
39
|
27 this.sessionID = 0;
|
|
28 this.sessionName = editor.getName();
|
|
29 }
|
|
30
|
1
|
31 public void addEditor(int editorID, SocketChannel channel) {
|
|
32 editorList.add(new Editor(editorID, channel));
|
|
33 }
|
39
|
34 public LinkedList<Editor> getEditorList() {
|
|
35 if(editorList == null) System.out.println("null!");
|
1
|
36 return editorList;
|
|
37 }
|
3
|
38 public String toString(){
|
|
39 return sessionName;
|
|
40 }
|
56
|
41 public int getSID() {
|
|
42 return sessionID;
|
38
|
43 }
|
|
44 public Editor getMaster() {
|
|
45 return masterEditor;
|
|
46 }
|
|
47 public String getName() {
|
|
48 return sessionName;
|
|
49 }
|
66
|
50 public int addEditor(Editor editor) {
|
|
51 incrementEID++;
|
39
|
52 editorList.add(editor);
|
66
|
53 return incrementEID;
|
39
|
54 }
|
56
|
55 public void setSID(int sessionID2) {
|
|
56 sessionID = sessionID2;
|
|
57 }
|
|
58 public void addToRoutingTable(Editor editor) {
|
|
59 routingTable.add(new REPNode(editor));
|
|
60 }
|
66
|
61 public boolean isOwner() {
|
67
|
62 return isOwner;
|
|
63 }
|
|
64 public void setOwner(boolean b) {
|
|
65 isOwner = true;
|
66
|
66 }
|
70
|
67 public void sendToEditor(REPCommand repCmd) {
|
|
68 for(Editor editor : editorList){
|
|
69 REPPacketSend send = new REPPacketSend(editor.getChannel());
|
|
70 send.send(repCmd);
|
|
71 }
|
|
72 }
|
0
|
73 }
|