annotate src/org/eclipse/jetty/io/nio/SelectorManager.java @ 970:d82eb99e8df6

remove ConnectorSelectorManager
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 14 Oct 2016 05:24:18 -0600
parents 0650077fcd6c
children f997df37cec1
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.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;
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
46 import org.eclipse.jetty.server.nio.SelectChannelConnector;
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 */
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
57 public final class SelectorManager extends AbstractLifeCycle implements Dumpable
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
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
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
61 private final SelectChannelConnector scc;
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
62 private volatile long _now = System.currentTimeMillis();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
63 private SaneSelector _selector;
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 */
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
70 public SelectorManager(SelectChannelConnector scc)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 {
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
72 this.scc = scc;
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 */
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
79 public final void register(SocketChannel channel)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
81 /*
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
82 SelectSet set = _selectSet;
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
83 if (set!=null)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 set.addChange(channel);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 }
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
87 */
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
88 try {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
89 SelectionKey key = _selector.register(channel,0,null);
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
90 SelectChannelEndPoint endpoint = new SelectChannelEndPoint(channel,this,key, scc.getMaxIdleTime());
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
91 key.attach(endpoint);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
92 _selector.update();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
93 //System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqq b");
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
94 endpoint.schedule();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
95 } catch(IOException e) {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
96 LOG.warn("",e);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
97 try {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
98 channel.close();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
99 } catch(IOException e2) {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
100 LOG.warn("",e2);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
101 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
102 }
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
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
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
106 public void execute(Runnable task) {
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
107 scc.server.threadPool.execute(task);
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
108 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
110
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 protected void doStart() throws Exception
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
114 _selector = new SaneSelector();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 super.doStart();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 // start a thread to Select
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
119 execute(new Runnable()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
121 public void run()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 {
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
123 String name=Thread.currentThread().getName();
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
124 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
126 if (_selector==null)
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
127 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
129 Thread.currentThread().setName(name+" Selector");
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
130 LOG.debug("Starting {} on {}",Thread.currentThread(),this);
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
131 while (isRunning())
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
132 {
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
133 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
135 doSelect();
954
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 catch(IOException 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 LOG.trace("",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 catch(Exception e)
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 LOG.warn("",e);
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 }
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
147 finally
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
148 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
149 _selector = null;
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
150 LOG.debug("Stopped {} on {}",Thread.currentThread(),this);
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
151 Thread.currentThread().setName(name);
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
152 }
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
153 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154
954
a021c4c9c244 use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
155 });
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 @Override
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
160 protected synchronized void doStop() throws Exception
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
162 if (_selector!=null)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
164 // close endpoints and selector
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
165 for (SelectionKey key : _selector.keys())
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
166 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
167 EndPoint endpoint = (EndPoint)key.attachment();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
168 try
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
169 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
170 endpoint.close();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
171 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
172 catch(IOException e)
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
173 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
174 LOG.trace("",e);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
175 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
176 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
177
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
178 try
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
179 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
180 _selector.close();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
181 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
182 catch (IOException e)
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
183 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
184 LOG.trace("",e);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
185 }
865
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 super.doStop();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189
970
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
190 public AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint) {
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
191 return scc.newConnection(channel,endpoint);
d82eb99e8df6 remove ConnectorSelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 969
diff changeset
192 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
194 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 public String dump()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 return AggregateLifeCycle.dump(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
200 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 public void dump(Appendable out, String indent) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 AggregateLifeCycle.dumpObject(out,this);
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
204 // AggregateLifeCycle.dump(out,indent,Collections.emptyList());
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
208 // from SelectSet
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
210 private void doSelect() throws IOException
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
211 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
212 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
214 _selector.select();
958
fc521d2f098e simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 957
diff changeset
215
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
216 // Look for things to do
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
217 for (SelectionKey key: _selector.selectedKeys())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
219 try
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
220 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
221 if (!key.isValid())
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
222 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
223 key.cancel();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
224 continue;
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
225 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
226
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
227 if (key.isReadable()||key.isWritable()) {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
228 SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment();
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
229 endpoint.schedule();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 }
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
232 catch (CancelledKeyException e)
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
233 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
234 // LOG.trace("",e);
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 LOG.warn("",e);
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
236 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
237 catch (Exception e)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
239 LOG.warn("",e);
865
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 }
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
242
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
243 // Everything always handled
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
244 _selector.selectedKeys().clear();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
245
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
246 _now = System.currentTimeMillis();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 }
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
248 catch (ClosedSelectorException e)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 {
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
250 if (isRunning())
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
251 LOG.warn("",e);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
252 else
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
253 LOG.trace("",e);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
254 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
255 catch (CancelledKeyException e)
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
256 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
257 LOG.trace("",e);
865
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
260
964
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
261 public final long getNow()
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
262 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
263 return _now;
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
264 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
265
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
266 final SaneSelector getSelector()
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
267 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
268 return _selector;
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
269 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
270
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
271 @Override
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
272 public final String toString()
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
273 {
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
274 SaneSelector selector=_selector;
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
275 return String.format("%s keys=%d selected=%d",
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
276 super.toString(),
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
277 selector != null && selector.isOpen() ? selector.keys().size() : -1,
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
278 selector != null && selector.isOpen() ? selector.selectedKeys().size() : -1);
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
279 }
768414c16e10 remove SelectSet
Franklin Schmidt <fschmidt@gmail.com>
parents: 962
diff changeset
280
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
281 }