1
|
1 package rep;
|
|
2
|
|
3 import java.nio.channels.SocketChannel;
|
56
|
4 import java.util.StringTokenizer;
|
1
|
5
|
|
6 public class Editor {
|
23
|
7 private int eid;
|
56
|
8 private SocketChannel myChannel;
|
2
|
9 private SocketChannel nextChannel;
|
21
|
10 private String host;
|
|
11 private String port;
|
23
|
12 //public int getEID;
|
39
|
13 private String file;
|
1
|
14
|
|
15 public Editor(int editorNo, SocketChannel channel){
|
23
|
16 this.eid = editorNo;
|
56
|
17 this.myChannel = channel;
|
|
18 }
|
|
19
|
|
20 public Editor(SocketChannel channel) {
|
|
21 this.myChannel = channel;
|
|
22 setHostAndPort(myChannel);
|
|
23 }
|
|
24
|
|
25 private void setHostAndPort(SocketChannel channel) {
|
|
26 String socketString = channel.socket().getRemoteSocketAddress().toString();
|
|
27 String[] split = socketString.split("/");
|
|
28 int length = split.length;
|
|
29 String hostAndPort = split[length-1];
|
|
30 split = hostAndPort.split(":");
|
|
31 host = split[0];
|
|
32 port = split[1];
|
1
|
33 }
|
|
34
|
|
35 public SocketChannel getChannel() {
|
56
|
36 return myChannel;
|
1
|
37 }
|
21
|
38
|
|
39 public void setHost(String host){
|
|
40 this.host = host;
|
|
41 }
|
|
42 public void setPort(String port){
|
|
43 this.port = port;
|
|
44 }
|
|
45
|
|
46 public String getHost(){
|
|
47 return host;
|
|
48 }
|
|
49 public String getPort(){
|
|
50 return port;
|
|
51 }
|
|
52
|
23
|
53 public int getEID() {
|
|
54 return eid;
|
|
55 }
|
|
56
|
|
57 public void setEID(int eid) {
|
|
58 this.eid = eid;
|
|
59 }
|
24
|
60 public String toString(){
|
56
|
61 return ("eid:" + eid + ":" + myChannel.socket().getLocalSocketAddress().toString());
|
24
|
62 }
|
23
|
63
|
38
|
64 public String getName() {
|
39
|
65 return file;
|
|
66 }
|
|
67
|
|
68 public void setName(String string) {
|
|
69 file = string;
|
38
|
70 }
|
|
71
|
56
|
72 public void send(REPCommand repCmd) {
|
|
73 REPPacketSend send = new REPPacketSend(myChannel);
|
|
74 send.send(repCmd);
|
|
75 }
|
|
76
|
1
|
77 }
|