annotate src/org/eclipse/jetty/io/nio/SelectorManager.java @ 960:3cd4c706a61f

simplify ChannelEndPoint
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Oct 2016 21:29:19 -0600
parents 7b94f5b33c64
children 94498d6daf5b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.ConnectedEndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import org.eclipse.jetty.io.Connection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.io.EndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import org.eclipse.jetty.util.TypeUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 import org.eclipse.jetty.util.component.AbstractLifeCycle;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 import org.eclipse.jetty.util.component.AggregateLifeCycle;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 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
47 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
48 import org.slf4j.LoggerFactory;
802
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 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 * The Selector Manager manages and number of SelectSets to allow
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 * NIO scheduling to scale to large numbers of connections.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 {
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 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
60
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 private int _maxIdleTime;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 private long _lowResourcesConnections;
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
63 private SelectSet _selectSet;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 * @param maxIdleTime The maximum period in milli seconds that a connection may be idle before it is closed.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 * @see #setLowResourcesMaxIdleTime(long)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 */
951
e542a9cc75ef simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 950
diff changeset
70 public void setMaxIdleTime(int maxIdleTime)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 {
951
e542a9cc75ef simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 950
diff changeset
72 _maxIdleTime = maxIdleTime;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 /** Register a channel
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 * @param channel
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 public void register(SocketChannel channel)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
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
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 set.addChange(channel);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 * @return the lowResourcesConnections
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 public long getLowResourcesConnections()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
94 return _lowResourcesConnections;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 * Set the number of connections, which if exceeded places this manager in low resources state.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 * This is not an exact measure as the connection count is averaged over the select sets.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 * @param lowResourcesConnections the number of connections
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 * @see #setLowResourcesMaxIdleTime(long)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 public void setLowResourcesConnections(long lowResourcesConnections)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
106 _lowResourcesConnections = lowResourcesConnections;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 public abstract void execute(Runnable task);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 /* (non-Javadoc)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 * @see org.eclipse.component.AbstractLifeCycle#doStart()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 protected void doStart() throws Exception
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
119 _selectSet = new SelectSet();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 super.doStart();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 // start a thread to Select
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
124 execute(new Runnable()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
126 public void run()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
128 String name=Thread.currentThread().getName();
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
129 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
131 SelectSet set = _selectSet;
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
132 if (set==null)
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
133 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
135 Thread.currentThread().setName(name+" Selector");
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
136 LOG.debug("Starting {} on {}",Thread.currentThread(),this);
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
137 while (isRunning())
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 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
141 set.doSelect();
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
142 }
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
143 catch(IOException e)
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
144 {
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
145 LOG.trace("",e);
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
146 }
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
147 catch(Exception e)
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
148 {
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
149 LOG.warn("",e);
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 }
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
153 finally
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
154 {
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
155 LOG.debug("Stopped {} on {}",Thread.currentThread(),this);
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
156 Thread.currentThread().setName(name);
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
157 }
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
158 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
160 });
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 protected void doStop() throws Exception
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
167 SelectSet set = _selectSet;
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
168 _selectSet = null;
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
169 if (set!=null)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
171 set.stop();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 super.doStop();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175
958
fc521d2f098e simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 957
diff changeset
176 public abstract AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
178 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 public String dump()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 return AggregateLifeCycle.dump(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
184 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 public void dump(Appendable out, String indent) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 AggregateLifeCycle.dumpObject(out,this);
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
188 AggregateLifeCycle.dump(out,indent,Collections.singletonList(_selectSet));
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
192 public final class SelectSet implements Dumpable
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 {
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
194 private volatile long _now = System.currentTimeMillis();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
196 private final SaneSelector _selector;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197
958
fc521d2f098e simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 957
diff changeset
198 private SelectSet() throws IOException
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 {
950
a778413aefc0 add SaneSelector
Franklin Schmidt <fschmidt@gmail.com>
parents: 949
diff changeset
200 _selector = new SaneSelector();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
203 private void addChange(SocketChannel channel)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
205 try {
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
206 //System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqq a");
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
207 // SelectionKey key = _selector.register(channel,SelectionKey.OP_READ,null);
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
208 SelectionKey key = _selector.register(channel,0,null);
958
fc521d2f098e simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 957
diff changeset
209
fc521d2f098e simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 957
diff changeset
210 SelectChannelEndPoint endpoint = new SelectChannelEndPoint(channel,this,key, _maxIdleTime);
fc521d2f098e simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 957
diff changeset
211 endpoint.setConnection(newConnection(channel,endpoint));
fc521d2f098e simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 957
diff changeset
212
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
213 key.attach(endpoint);
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
214 key.interestOps(SelectionKey.OP_READ);
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
215 _selector.update();
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
216 //System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqq b");
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
217 endpoint.schedule();
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
218 } catch(IOException e) {
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
219 LOG.warn("",e);
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
220 try {
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
221 channel.close();
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
222 } catch(IOException e2) {
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
223 LOG.warn("",e2);
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
224 }
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
225 }
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 }
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
227
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
228 private void doSelect() throws IOException
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
232 _selector.select();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
233
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 // Look for things to do
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
235 for (SelectionKey key: _selector.selectedKeys())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 if (!key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 key.cancel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 if (endpoint != null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 endpoint.doUpdateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 continue;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
247
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
248 if (key.isReadable()||key.isWritable()) {
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
249 SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment();
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
250 endpoint.schedule();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 catch (CancelledKeyException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 catch (Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 if (isRunning())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
265
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 // Everything always handled
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
267 _selector.selectedKeys().clear();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
269 _now = System.currentTimeMillis();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 catch (ClosedSelectorException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 if (isRunning())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 catch (CancelledKeyException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
283
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 public SelectorManager getManager()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 return SelectorManager.this;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 public long getNow()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 {
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
291 return _now;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 }
951
e542a9cc75ef simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 950
diff changeset
293
950
a778413aefc0 add SaneSelector
Franklin Schmidt <fschmidt@gmail.com>
parents: 949
diff changeset
294 SaneSelector getSelector()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 return _selector;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
298
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
299 private synchronized void stop() throws Exception
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 {
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
301 // close endpoints and selector
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
302 for (SelectionKey key : _selector.keys())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
304 EndPoint endpoint = (EndPoint)key.attachment();
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
305 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
307 endpoint.close();
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
308 }
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
309 catch(IOException e)
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
310 {
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
311 LOG.trace("",e);
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 }
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
314
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
315 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 {
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
317 _selector.close();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 }
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
319 catch (IOException e)
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
320 {
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
321 LOG.trace("",e);
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
322 }
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
324
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
325 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 public String dump()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 return AggregateLifeCycle.dump(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
330
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
331 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 public void dump(Appendable out, String indent) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
334 out.append(String.valueOf(this)).append("\n");
944
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
335 AggregateLifeCycle.dump(out,indent,Collections.emptyList());
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
337
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
338 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 public String toString()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 {
950
a778413aefc0 add SaneSelector
Franklin Schmidt <fschmidt@gmail.com>
parents: 949
diff changeset
341 SaneSelector selector=_selector;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 return String.format("%s keys=%d selected=%d",
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 super.toString(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 selector != null && selector.isOpen() ? selector.keys().size() : -1,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 selector != null && selector.isOpen() ? selector.selectedKeys().size() : -1);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
348
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
349 }