9
|
1 package rep;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.nio.channels.ClosedChannelException;
|
|
5 import java.nio.channels.SelectableChannel;
|
|
6 import java.nio.channels.SelectionKey;
|
|
7 import java.nio.channels.Selector;
|
|
8 import java.nio.channels.SocketChannel;
|
|
9 import java.nio.channels.spi.SelectorProvider;
|
|
10
|
|
11 public class SelectableEditorChannel extends SelectableChannel{
|
|
12
|
|
13 private SocketChannel channel;
|
|
14 private REPPacketSend repsend;
|
|
15 private REPPacketReceive reprec;
|
|
16
|
|
17 public SelectableEditorChannel(SocketChannel channel){
|
|
18 this.channel = channel;
|
|
19 repsend = new REPPacketSend(channel);
|
|
20 reprec = new REPPacketReceive(channel);
|
|
21
|
|
22 }
|
|
23
|
|
24 @Override
|
|
25 public Object blockingLock() {
|
|
26 return channel.blockingLock();
|
|
27 //return null;
|
|
28 }
|
|
29
|
|
30 @Override
|
|
31 public SelectableChannel configureBlocking(boolean block) throws IOException {
|
|
32 return channel.configureBlocking(block);
|
|
33 //return null;
|
|
34 }
|
|
35
|
|
36 @Override
|
|
37 public boolean isBlocking() {
|
|
38
|
|
39 return channel.isBlocking();
|
|
40 }
|
|
41
|
|
42 @Override
|
|
43 public boolean isRegistered() {
|
|
44 return channel.isRegistered();
|
|
45 }
|
|
46
|
|
47 @Override
|
|
48 public SelectionKey keyFor(Selector sel) {
|
|
49 return channel.keyFor(sel);
|
|
50 }
|
|
51
|
|
52 @Override
|
|
53 public SelectorProvider provider() {
|
|
54 return channel.provider();
|
|
55 }
|
|
56
|
|
57 @Override
|
|
58 public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException {
|
|
59 return channel.register(sel, ops, att);
|
|
60 }
|
|
61
|
|
62 @Override
|
|
63 public int validOps() {
|
|
64 return channel.validOps();
|
|
65 }
|
|
66
|
|
67 @Override
|
|
68 protected void implCloseChannel() throws IOException {
|
|
69
|
|
70 }
|
|
71
|
|
72 public void putPacket(REPCommand comm){
|
|
73 repsend.send(comm);
|
|
74 }
|
|
75 public REPCommand getPacket(){
|
|
76 REPCommand command = reprec.unpack();
|
|
77 return command;
|
|
78 }
|
|
79
|
|
80 //public void setIO(SocketChannel channel) {
|
|
81 // repsend = new REPPacketSend(channel);
|
|
82 // reprec = new REPPacketReceive(channel);
|
|
83 //}
|
|
84
|
|
85 }
|