annotate rep/Editor.java @ 56:6ead43b2475e

*** empty log message ***
author pin
date Fri, 16 Nov 2007 13:58:25 +0900
parents c873ee0318f8
children 391d44c94799
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
1 package rep;
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
2
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
3 import java.nio.channels.SocketChannel;
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
4 import java.util.StringTokenizer;
1
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
5
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
6 public class Editor {
23
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
7 private int eid;
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
8 private SocketChannel myChannel;
2
02fa9a68d9a2 *** empty log message ***
pin
parents: 1
diff changeset
9 private SocketChannel nextChannel;
21
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
10 private String host;
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
11 private String port;
23
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
12 //public int getEID;
39
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
13 private String file;
1
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
14
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
15 public Editor(int editorNo, SocketChannel channel){
23
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
16 this.eid = editorNo;
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
17 this.myChannel = channel;
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
18 }
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
19
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
20 public Editor(SocketChannel channel) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
21 this.myChannel = channel;
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
22 setHostAndPort(myChannel);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
23 }
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
24
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
25 private void setHostAndPort(SocketChannel channel) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
26 String socketString = channel.socket().getRemoteSocketAddress().toString();
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
27 String[] split = socketString.split("/");
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
28 int length = split.length;
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
29 String hostAndPort = split[length-1];
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
30 split = hostAndPort.split(":");
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
31 host = split[0];
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
32 port = split[1];
1
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
33 }
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
34
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
35 public SocketChannel getChannel() {
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
36 return myChannel;
1
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
37 }
21
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
38
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
39 public void setHost(String host){
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
40 this.host = host;
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
41 }
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
42 public void setPort(String port){
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
43 this.port = port;
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
44 }
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
45
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
46 public String getHost(){
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
47 return host;
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
48 }
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
49 public String getPort(){
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
50 return port;
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
51 }
2d4bab638a71 *** empty log message ***
pin
parents: 2
diff changeset
52
23
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
53 public int getEID() {
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
54 return eid;
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
55 }
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
56
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
57 public void setEID(int eid) {
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
58 this.eid = eid;
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
59 }
24
7012a944e58f *** empty log message ***
pin
parents: 23
diff changeset
60 public String toString(){
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
61 return ("eid:" + eid + ":" + myChannel.socket().getLocalSocketAddress().toString());
24
7012a944e58f *** empty log message ***
pin
parents: 23
diff changeset
62 }
23
01657c033761 *** empty log message ***
pin
parents: 21
diff changeset
63
38
de8638eb0edd *** empty log message ***
pin
parents: 24
diff changeset
64 public String getName() {
39
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
65 return file;
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
66 }
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
67
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
68 public void setName(String string) {
c873ee0318f8 *** empty log message ***
pin
parents: 38
diff changeset
69 file = string;
38
de8638eb0edd *** empty log message ***
pin
parents: 24
diff changeset
70 }
de8638eb0edd *** empty log message ***
pin
parents: 24
diff changeset
71
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
72 public void send(REPCommand repCmd) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
73 REPPacketSend send = new REPPacketSend(myChannel);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
74 send.send(repCmd);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
75 }
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
76
1
3f5bf0255f5e *** empty log message ***
pin
parents:
diff changeset
77 }