annotate rep/Session.java @ 82:4bb583553a42

*** empty log message ***
author pin
date Tue, 11 Dec 2007 14:26:13 +0900
parents 248d774be113
children f0bc200d963d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e41994ce73c7 *** empty log message ***
pin
parents:
diff changeset
1 package rep;
e41994ce73c7 *** empty log message ***
pin
parents:
diff changeset
2
1
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
3 import java.nio.channels.SocketChannel;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
4 import java.util.LinkedList;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
5 import java.util.List;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
6
0
e41994ce73c7 *** empty log message ***
pin
parents:
diff changeset
7 public class Session {
38
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
8 private Editor masterEditor;
1
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
9 private int sessionID;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
10 private String sessionName;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
11 private LinkedList<Editor> editorList = new LinkedList<Editor>();
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
12 private String masterHost;
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
13 private String masterPort;
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
14 private LinkedList<REPNode> routingTable = new LinkedList<REPNode>();
66
99196780bbf5 *** empty log message ***
pin
parents: 56
diff changeset
15 private int incrementEID;
67
13e4c3f2c6f9 *** empty log message ***
pin
parents: 66
diff changeset
16 private boolean isOwner = false;
9
2d4c2c19d2d0 *** empty log message ***
pin
parents: 3
diff changeset
17
1
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
18 public Session(int sessionID, String string, SocketChannel channel) {
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
19 masterEditor = new Editor(sessionID, channel);
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
20 this.sessionID = sessionID;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
21 this.sessionName = string;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
22 }
39
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
23 public Session(Editor editor) {
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
24 masterEditor = editor;
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
25 masterHost = editor.getHost();
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
26 masterPort = editor.getPort();
39
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
27 this.sessionID = 0;
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
28 this.sessionName = editor.getName();
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
29 }
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
30
1
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
31 public void addEditor(int editorID, SocketChannel channel) {
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
32 editorList.add(new Editor(editorID, channel));
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
33 }
39
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
34 public LinkedList<Editor> getEditorList() {
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
35 if(editorList == null) System.out.println("null!");
1
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
36 return editorList;
3f5bf0255f5e *** empty log message ***
pin
parents: 0
diff changeset
37 }
3
f31fcac5a949 *** empty log message ***
pin
parents: 2
diff changeset
38 public String toString(){
f31fcac5a949 *** empty log message ***
pin
parents: 2
diff changeset
39 return sessionName;
f31fcac5a949 *** empty log message ***
pin
parents: 2
diff changeset
40 }
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
41 public int getSID() {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
42 return sessionID;
38
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
43 }
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
44 public Editor getMaster() {
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
45 return masterEditor;
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
46 }
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
47 public String getName() {
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
48 return sessionName;
de8638eb0edd *** empty log message ***
pin
parents: 9
diff changeset
49 }
66
99196780bbf5 *** empty log message ***
pin
parents: 56
diff changeset
50 public int addEditor(Editor editor) {
99196780bbf5 *** empty log message ***
pin
parents: 56
diff changeset
51 incrementEID++;
39
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
52 editorList.add(editor);
66
99196780bbf5 *** empty log message ***
pin
parents: 56
diff changeset
53 return incrementEID;
39
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
54 }
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
55 public void setSID(int sessionID2) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
56 sessionID = sessionID2;
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
57 }
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
58 public void addToRoutingTable(Editor editor) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
59 routingTable.add(new REPNode(editor));
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
60 }
66
99196780bbf5 *** empty log message ***
pin
parents: 56
diff changeset
61 public boolean isOwner() {
67
13e4c3f2c6f9 *** empty log message ***
pin
parents: 66
diff changeset
62 return isOwner;
13e4c3f2c6f9 *** empty log message ***
pin
parents: 66
diff changeset
63 }
13e4c3f2c6f9 *** empty log message ***
pin
parents: 66
diff changeset
64 public void setOwner(boolean b) {
13e4c3f2c6f9 *** empty log message ***
pin
parents: 66
diff changeset
65 isOwner = true;
66
99196780bbf5 *** empty log message ***
pin
parents: 56
diff changeset
66 }
70
248d774be113 *** empty log message ***
pin
parents: 67
diff changeset
67 public void sendToEditor(REPCommand repCmd) {
248d774be113 *** empty log message ***
pin
parents: 67
diff changeset
68 for(Editor editor : editorList){
248d774be113 *** empty log message ***
pin
parents: 67
diff changeset
69 REPPacketSend send = new REPPacketSend(editor.getChannel());
248d774be113 *** empty log message ***
pin
parents: 67
diff changeset
70 send.send(repCmd);
248d774be113 *** empty log message ***
pin
parents: 67
diff changeset
71 }
248d774be113 *** empty log message ***
pin
parents: 67
diff changeset
72 }
0
e41994ce73c7 *** empty log message ***
pin
parents:
diff changeset
73 }