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
|
74
|
25 public Editor() {
|
|
26 }
|
|
27
|
56
|
28 private void setHostAndPort(SocketChannel channel) {
|
|
29 String socketString = channel.socket().getRemoteSocketAddress().toString();
|
|
30 String[] split = socketString.split("/");
|
|
31 int length = split.length;
|
|
32 String hostAndPort = split[length-1];
|
|
33 split = hostAndPort.split(":");
|
|
34 host = split[0];
|
|
35 port = split[1];
|
1
|
36 }
|
|
37
|
|
38 public SocketChannel getChannel() {
|
56
|
39 return myChannel;
|
1
|
40 }
|
21
|
41
|
|
42 public void setHost(String host){
|
|
43 this.host = host;
|
|
44 }
|
|
45 public void setPort(String port){
|
|
46 this.port = port;
|
|
47 }
|
|
48
|
|
49 public String getHost(){
|
|
50 return host;
|
|
51 }
|
|
52 public String getPort(){
|
|
53 return port;
|
|
54 }
|
|
55
|
23
|
56 public int getEID() {
|
|
57 return eid;
|
|
58 }
|
|
59
|
|
60 public void setEID(int eid) {
|
|
61 this.eid = eid;
|
|
62 }
|
24
|
63 public String toString(){
|
74
|
64 return (host + ":" + port + ":" + file);
|
|
65 //return ("eid:" + eid + ":" + myChannel.socket().getLocalSocketAddress().toString());
|
24
|
66 }
|
23
|
67
|
38
|
68 public String getName() {
|
39
|
69 return file;
|
|
70 }
|
|
71
|
|
72 public void setName(String string) {
|
|
73 file = string;
|
38
|
74 }
|
|
75
|
56
|
76 public void send(REPCommand repCmd) {
|
|
77 REPPacketSend send = new REPPacketSend(myChannel);
|
|
78 send.send(repCmd);
|
|
79 }
|
|
80
|
1
|
81 }
|