Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/nio/SelectorManager.java @ 968:0d20943cfea2
remove ConnectedEndPoint
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 14 Oct 2016 02:37:53 -0600 |
| parents | 768414c16e10 |
| children | 0650077fcd6c |
| rev | line source |
|---|---|
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.io.nio; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.io.IOException; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.nio.channels.CancelledKeyException; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.nio.channels.Channel; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.nio.channels.ClosedSelectorException; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.nio.channels.SelectableChannel; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.nio.channels.SelectionKey; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import java.nio.channels.ServerSocketChannel; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import java.nio.channels.SocketChannel; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 import java.util.ArrayList; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import java.util.List; |
|
944
1d24b6e422fa
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
943
diff
changeset
|
31 import java.util.Collections; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import java.util.Set; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import java.util.concurrent.ConcurrentHashMap; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import java.util.concurrent.ConcurrentLinkedQueue; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import java.util.concurrent.ConcurrentMap; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import java.util.concurrent.CountDownLatch; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 import java.util.concurrent.TimeUnit; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 import org.eclipse.jetty.io.AsyncEndPoint; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 import org.eclipse.jetty.io.Connection; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 import org.eclipse.jetty.io.EndPoint; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 import org.eclipse.jetty.util.TypeUtil; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 import org.eclipse.jetty.util.component.AbstractLifeCycle; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 import org.eclipse.jetty.util.component.AggregateLifeCycle; |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 import org.eclipse.jetty.util.component.Dumpable; |
|
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
46 import org.slf4j.Logger; |
|
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
47 import org.slf4j.LoggerFactory; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 /* ------------------------------------------------------------ */ |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 /** |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 * The Selector Manager manages and number of SelectSets to allow |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 * NIO scheduling to scale to large numbers of connections. |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 * <p> |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 */ |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 { |
| 964 | 58 public static final Logger LOG = LoggerFactory.getLogger("org.eclipse.jetty.io.nio"); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 |
| 964 | 60 private final int _maxIdleTime; |
| 61 private volatile long _now = System.currentTimeMillis(); | |
| 62 private SaneSelector _selector; | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
63 |
| 865 | 64 /* ------------------------------------------------------------ */ |
| 65 /** | |
| 66 * @param maxIdleTime The maximum period in milli seconds that a connection may be idle before it is closed. | |
| 67 * @see #setLowResourcesMaxIdleTime(long) | |
| 68 */ | |
| 964 | 69 public SelectorManager(int maxIdleTime) |
| 865 | 70 { |
|
951
e542a9cc75ef
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
950
diff
changeset
|
71 _maxIdleTime = maxIdleTime; |
| 865 | 72 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
73 |
| 865 | 74 /* ------------------------------------------------------------ */ |
| 75 /** Register a channel | |
| 76 * @param channel | |
| 77 */ | |
| 964 | 78 public final void register(SocketChannel channel) |
| 865 | 79 { |
| 964 | 80 /* |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
81 SelectSet set = _selectSet; |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
82 if (set!=null) |
| 865 | 83 { |
| 84 set.addChange(channel); | |
| 85 } | |
| 964 | 86 */ |
| 87 try { | |
| 88 SelectionKey key = _selector.register(channel,0,null); | |
| 89 SelectChannelEndPoint endpoint = new SelectChannelEndPoint(channel,this,key, _maxIdleTime); | |
| 90 endpoint.setConnection(newConnection(channel,endpoint)); | |
| 91 key.attach(endpoint); | |
| 92 _selector.update(); | |
| 93 //System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqq b"); | |
| 94 endpoint.schedule(); | |
| 95 } catch(IOException e) { | |
| 96 LOG.warn("",e); | |
| 97 try { | |
| 98 channel.close(); | |
| 99 } catch(IOException e2) { | |
| 100 LOG.warn("",e2); | |
| 101 } | |
| 102 } | |
| 865 | 103 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
104 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
105 |
| 865 | 106 public abstract void execute(Runnable task); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
107 |
| 964 | 108 |
| 865 | 109 @Override |
| 110 protected void doStart() throws Exception | |
| 111 { | |
| 964 | 112 _selector = new SaneSelector(); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
113 |
| 865 | 114 super.doStart(); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
115 |
| 865 | 116 // start a thread to Select |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
117 execute(new Runnable() |
| 865 | 118 { |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
119 public void run() |
| 865 | 120 { |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
121 String name=Thread.currentThread().getName(); |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
122 try |
| 865 | 123 { |
| 964 | 124 if (_selector==null) |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
125 return; |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
126 |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
127 Thread.currentThread().setName(name+" Selector"); |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
128 LOG.debug("Starting {} on {}",Thread.currentThread(),this); |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
129 while (isRunning()) |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
130 { |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
131 try |
| 865 | 132 { |
| 964 | 133 doSelect(); |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
134 } |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
135 catch(IOException e) |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
136 { |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
137 LOG.trace("",e); |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
138 } |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
139 catch(Exception e) |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
140 { |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
141 LOG.warn("",e); |
| 865 | 142 } |
| 143 } | |
| 144 } | |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
145 finally |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
146 { |
| 964 | 147 _selector = null; |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
148 LOG.debug("Stopped {} on {}",Thread.currentThread(),this); |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
149 Thread.currentThread().setName(name); |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
150 } |
|
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
151 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
152 |
|
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
153 }); |
| 865 | 154 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
155 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
156 |
| 865 | 157 @Override |
| 964 | 158 protected synchronized void doStop() throws Exception |
| 865 | 159 { |
| 964 | 160 if (_selector!=null) |
| 865 | 161 { |
| 964 | 162 // close endpoints and selector |
| 163 for (SelectionKey key : _selector.keys()) | |
| 164 { | |
| 165 EndPoint endpoint = (EndPoint)key.attachment(); | |
| 166 try | |
| 167 { | |
| 168 endpoint.close(); | |
| 169 } | |
| 170 catch(IOException e) | |
| 171 { | |
| 172 LOG.trace("",e); | |
| 173 } | |
| 174 } | |
| 175 | |
| 176 try | |
| 177 { | |
| 178 _selector.close(); | |
| 179 } | |
| 180 catch (IOException e) | |
| 181 { | |
| 182 LOG.trace("",e); | |
| 183 } | |
| 865 | 184 } |
| 185 super.doStop(); | |
| 186 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 |
|
958
fc521d2f098e
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
957
diff
changeset
|
188 public abstract AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint); |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
189 |
|
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
959
diff
changeset
|
190 @Override |
| 865 | 191 public String dump() |
| 192 { | |
| 193 return AggregateLifeCycle.dump(this); | |
| 194 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 |
|
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
959
diff
changeset
|
196 @Override |
| 865 | 197 public void dump(Appendable out, String indent) throws IOException |
| 198 { | |
| 199 AggregateLifeCycle.dumpObject(out,this); | |
| 964 | 200 // AggregateLifeCycle.dump(out,indent,Collections.emptyList()); |
| 865 | 201 } |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
202 |
|
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
203 |
| 964 | 204 // from SelectSet |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
205 |
| 964 | 206 private void doSelect() throws IOException |
| 207 { | |
| 208 try | |
| 865 | 209 { |
| 964 | 210 _selector.select(); |
|
958
fc521d2f098e
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
957
diff
changeset
|
211 |
| 964 | 212 // Look for things to do |
| 213 for (SelectionKey key: _selector.selectedKeys()) | |
| 865 | 214 { |
| 964 | 215 try |
| 216 { | |
| 217 if (!key.isValid()) | |
| 218 { | |
| 219 key.cancel(); | |
| 220 continue; | |
| 221 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
222 |
| 964 | 223 if (key.isReadable()||key.isWritable()) { |
| 224 SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment(); | |
| 225 endpoint.schedule(); | |
| 865 | 226 } |
| 227 } | |
| 964 | 228 catch (CancelledKeyException e) |
| 229 { | |
| 230 // LOG.trace("",e); | |
| 865 | 231 LOG.warn("",e); |
| 964 | 232 } |
| 233 catch (Exception e) | |
| 865 | 234 { |
| 964 | 235 LOG.warn("",e); |
| 865 | 236 } |
| 237 } | |
|
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
238 |
| 964 | 239 // Everything always handled |
| 240 _selector.selectedKeys().clear(); | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
241 |
| 964 | 242 _now = System.currentTimeMillis(); |
| 865 | 243 } |
| 964 | 244 catch (ClosedSelectorException e) |
| 865 | 245 { |
| 964 | 246 if (isRunning()) |
| 247 LOG.warn("",e); | |
| 248 else | |
| 249 LOG.trace("",e); | |
| 250 } | |
| 251 catch (CancelledKeyException e) | |
| 252 { | |
| 253 LOG.trace("",e); | |
| 865 | 254 } |
| 255 } | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
256 |
| 964 | 257 public final long getNow() |
| 258 { | |
| 259 return _now; | |
| 260 } | |
| 261 | |
| 262 final SaneSelector getSelector() | |
| 263 { | |
| 264 return _selector; | |
| 265 } | |
| 266 | |
| 267 @Override | |
| 268 public final String toString() | |
| 269 { | |
| 270 SaneSelector selector=_selector; | |
| 271 return String.format("%s keys=%d selected=%d", | |
| 272 super.toString(), | |
| 273 selector != null && selector.isOpen() ? selector.keys().size() : -1, | |
| 274 selector != null && selector.isOpen() ? selector.selectedKeys().size() : -1); | |
| 275 } | |
| 276 | |
|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
277 } |
