Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/nio/ChannelEndPoint.java @ 960:3cd4c706a61f
simplify ChannelEndPoint
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 13 Oct 2016 21:29:19 -0600 |
parents | fc521d2f098e |
children | 866f2e801618 |
comparison
equal
deleted
inserted
replaced
959:7b94f5b33c64 | 960:3cd4c706a61f |
---|---|
50 protected final InetSocketAddress _remote; | 50 protected final InetSocketAddress _remote; |
51 protected volatile int _maxIdleTime; | 51 protected volatile int _maxIdleTime; |
52 private volatile boolean _ishut; | 52 private volatile boolean _ishut; |
53 private volatile boolean _oshut; | 53 private volatile boolean _oshut; |
54 | 54 |
55 public ChannelEndPoint(ByteChannel channel) throws IOException | 55 protected ChannelEndPoint(ByteChannel channel, int maxIdleTime) throws IOException |
56 { | 56 { |
57 super(); | |
58 this._channel = channel; | 57 this._channel = channel; |
59 _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; | 58 _maxIdleTime = maxIdleTime; |
59 _socket = (channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; | |
60 if (_socket!=null) | 60 if (_socket!=null) |
61 { | 61 { |
62 _local=(InetSocketAddress)_socket.getLocalSocketAddress(); | 62 _local = (InetSocketAddress)_socket.getLocalSocketAddress(); |
63 _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); | 63 _remote = (InetSocketAddress)_socket.getRemoteSocketAddress(); |
64 _maxIdleTime=_socket.getSoTimeout(); | 64 _socket.setSoTimeout(_maxIdleTime); |
65 } | 65 } |
66 else | 66 else |
67 { | 67 { |
68 _local=_remote=null; | 68 _local = _remote = null; |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 protected ChannelEndPoint(ByteChannel channel, int maxIdleTime) throws IOException | 72 @Override |
73 { | 73 public final boolean isBlocking() |
74 this._channel = channel; | |
75 _maxIdleTime=maxIdleTime; | |
76 _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; | |
77 if (_socket!=null) | |
78 { | |
79 _local=(InetSocketAddress)_socket.getLocalSocketAddress(); | |
80 _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); | |
81 _socket.setSoTimeout(_maxIdleTime); | |
82 } | |
83 else | |
84 { | |
85 _local=_remote=null; | |
86 } | |
87 } | |
88 | |
89 public boolean isBlocking() | |
90 { | 74 { |
91 return !(_channel instanceof SelectableChannel) || ((SelectableChannel)_channel).isBlocking(); | 75 return !(_channel instanceof SelectableChannel) || ((SelectableChannel)_channel).isBlocking(); |
92 } | 76 } |
93 | 77 |
78 @Override | |
94 public boolean blockReadable(long millisecs) throws IOException | 79 public boolean blockReadable(long millisecs) throws IOException |
95 { | 80 { |
96 return true; | 81 return true; |
97 } | 82 } |
98 | 83 |
84 @Override | |
99 public boolean blockWritable(long millisecs) throws IOException | 85 public boolean blockWritable(long millisecs) throws IOException |
100 { | 86 { |
101 return true; | 87 return true; |
102 } | 88 } |
103 | 89 |
104 /* | 90 @Override |
105 * @see org.eclipse.io.EndPoint#isOpen() | 91 public final boolean isOpen() |
106 */ | |
107 public boolean isOpen() | |
108 { | 92 { |
109 return _channel.isOpen(); | 93 return _channel.isOpen(); |
110 } | 94 } |
111 | 95 |
112 /** Shutdown the channel Input. | 96 @Override |
113 * Cannot be overridden. To override, see {@link #shutdownInput()} | 97 public final void shutdownInput() throws IOException |
114 * @throws IOException | |
115 */ | |
116 protected final void shutdownChannelInput() throws IOException | |
117 { | 98 { |
118 LOG.debug("ishut {}", this); | 99 LOG.debug("ishut {}", this); |
119 _ishut = true; | 100 _ishut = true; |
120 if (_channel.isOpen()) | 101 if (_channel.isOpen()) |
121 { | 102 { |
142 } | 123 } |
143 } | 124 } |
144 } | 125 } |
145 } | 126 } |
146 | 127 |
147 /* (non-Javadoc) | 128 @Override |
148 * @see org.eclipse.io.EndPoint#close() | 129 public final void shutdownOutput() throws IOException |
149 */ | |
150 public void shutdownInput() throws IOException | |
151 { | |
152 shutdownChannelInput(); | |
153 } | |
154 | |
155 protected final void shutdownChannelOutput() throws IOException | |
156 { | 130 { |
157 LOG.debug("oshut {}",this); | 131 LOG.debug("oshut {}",this); |
158 _oshut = true; | 132 _oshut = true; |
159 if (_channel.isOpen()) | 133 if (_channel.isOpen()) |
160 { | 134 { |
181 } | 155 } |
182 } | 156 } |
183 } | 157 } |
184 } | 158 } |
185 | 159 |
186 /* (non-Javadoc) | 160 @Override |
187 * @see org.eclipse.io.EndPoint#close() | 161 public final boolean isOutputShutdown() |
188 */ | |
189 public void shutdownOutput() throws IOException | |
190 { | |
191 shutdownChannelOutput(); | |
192 } | |
193 | |
194 public boolean isOutputShutdown() | |
195 { | 162 { |
196 return _oshut || !_channel.isOpen() || _socket != null && _socket.isOutputShutdown(); | 163 return _oshut || !_channel.isOpen() || _socket != null && _socket.isOutputShutdown(); |
197 } | 164 } |
198 | 165 |
199 public boolean isInputShutdown() | 166 @Override |
167 public final boolean isInputShutdown() | |
200 { | 168 { |
201 return _ishut || !_channel.isOpen() || _socket != null && _socket.isInputShutdown(); | 169 return _ishut || !_channel.isOpen() || _socket != null && _socket.isInputShutdown(); |
202 } | 170 } |
203 | 171 |
204 /* (non-Javadoc) | 172 @Override |
205 * @see org.eclipse.io.EndPoint#close() | |
206 */ | |
207 public void close() throws IOException | 173 public void close() throws IOException |
208 { | 174 { |
209 LOG.debug("close {}",this); | 175 LOG.debug("close {}",this); |
210 _channel.close(); | 176 _channel.close(); |
211 } | 177 } |