comparison rep/Editor.java @ 56:6ead43b2475e

*** empty log message ***
author pin
date Fri, 16 Nov 2007 13:58:25 +0900
parents c873ee0318f8
children 391d44c94799
comparison
equal deleted inserted replaced
55:57a16534ba5a 56:6ead43b2475e
1 package rep; 1 package rep;
2 2
3 import java.nio.channels.SocketChannel; 3 import java.nio.channels.SocketChannel;
4 import java.util.StringTokenizer;
4 5
5 public class Editor { 6 public class Editor {
6 private int eid; 7 private int eid;
7 private SocketChannel channel; 8 private SocketChannel myChannel;
8 private SocketChannel nextChannel; 9 private SocketChannel nextChannel;
9 private String host; 10 private String host;
10 private String port; 11 private String port;
11 //public int getEID; 12 //public int getEID;
12 private String file; 13 private String file;
13 14
14 public Editor(int editorNo, SocketChannel channel){ 15 public Editor(int editorNo, SocketChannel channel){
15 this.eid = editorNo; 16 this.eid = editorNo;
16 this.channel = channel; 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];
17 } 33 }
18 34
19 public SocketChannel getChannel() { 35 public SocketChannel getChannel() {
20 return channel; 36 return myChannel;
21 } 37 }
22 38
23 public void setHost(String host){ 39 public void setHost(String host){
24 this.host = host; 40 this.host = host;
25 } 41 }
40 56
41 public void setEID(int eid) { 57 public void setEID(int eid) {
42 this.eid = eid; 58 this.eid = eid;
43 } 59 }
44 public String toString(){ 60 public String toString(){
45 return ("eid:" + eid + ":" + channel.socket().getLocalSocketAddress().toString()); 61 return ("eid:" + eid + ":" + myChannel.socket().getLocalSocketAddress().toString());
46 } 62 }
47 63
48 public String getName() { 64 public String getName() {
49 return file; 65 return file;
50 } 66 }
51 67
52 public void setName(String string) { 68 public void setName(String string) {
53 file = string; 69 file = string;
54 } 70 }
55 71
72 public void send(REPCommand repCmd) {
73 REPPacketSend send = new REPPacketSend(myChannel);
74 send.send(repCmd);
75 }
76
56 } 77 }