annotate src/org/eclipse/jetty/io/nio/SelectorManager.java @ 948:f5aefdc4a81a

simplify SelectChannelConnector
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 11 Oct 2016 22:16:29 -0600
parents 1d24b6e422fa
children e9088af3787f
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.Selector;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import java.nio.channels.ServerSocketChannel;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import java.nio.channels.SocketChannel;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import java.util.ArrayList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import java.util.List;
944
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
32 import java.util.Collections;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import java.util.Set;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import java.util.concurrent.ConcurrentHashMap;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import java.util.concurrent.ConcurrentLinkedQueue;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import java.util.concurrent.ConcurrentMap;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import java.util.concurrent.CountDownLatch;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import java.util.concurrent.TimeUnit;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 import org.eclipse.jetty.io.AsyncEndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import org.eclipse.jetty.io.ConnectedEndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.io.Connection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import org.eclipse.jetty.io.EndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 import org.eclipse.jetty.util.TypeUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 import org.eclipse.jetty.util.component.AbstractLifeCycle;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 import org.eclipse.jetty.util.component.AggregateLifeCycle;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 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
48 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 import org.slf4j.LoggerFactory;
802
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 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 * The Selector Manager manages and number of SelectSets to allow
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 * NIO scheduling to scale to large numbers of connections.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 {
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 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
61
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 private static final int __MONITOR_PERIOD=Integer.getInteger("org.eclipse.jetty.io.nio.MONITOR_PERIOD",1000).intValue();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 private static final int __MAX_SELECTS=Integer.getInteger("org.eclipse.jetty.io.nio.MAX_SELECTS",100000).intValue();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 private static final int __BUSY_PAUSE=Integer.getInteger("org.eclipse.jetty.io.nio.BUSY_PAUSE",50).intValue();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 private static final int __IDLE_TICK=Integer.getInteger("org.eclipse.jetty.io.nio.IDLE_TICK",400).intValue();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 private int _maxIdleTime;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 private long _lowResourcesConnections;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 private SelectSet[] _selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 private int _selectSets=1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 private volatile int _set=0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 * @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
76 * @see #setLowResourcesMaxIdleTime(long)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 public void setMaxIdleTime(long maxIdleTime)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 _maxIdleTime=(int)maxIdleTime;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82
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 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 * @param selectSets number of select sets to create
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 public void setSelectSets(int selectSets)
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 long lrc = _lowResourcesConnections * _selectSets;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 _selectSets=selectSets;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 _lowResourcesConnections=lrc/_selectSets;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 /** Register a channel
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 * @param channel
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 public void register(SocketChannel channel)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 // The ++ increment here is not atomic, but it does not matter.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 // so long as the value changes sometimes, then connections will
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 // be distributed over the available sets.
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103
948
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
104 int s = _set++;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 if (s<0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 s=-s;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 s=s%_selectSets;
948
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
108 SelectSet[] sets = _selectSet;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 if (sets!=null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 SelectSet set=sets[s];
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 set.addChange(channel);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 set.wakeup();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 /** Register a {@link ServerSocketChannel}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 * @param acceptChannel
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 public void register(ServerSocketChannel acceptChannel)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 int s=_set++;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 if (s<0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 s=-s;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 s=s%_selectSets;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 SelectSet set=_selectSet[s];
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 set.addChange(acceptChannel);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 set.wakeup();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 * @return the lowResourcesConnections
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 public long getLowResourcesConnections()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 return _lowResourcesConnections*_selectSets;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 * 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
145 * 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
146 * @param lowResourcesConnections the number of connections
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 * @see #setLowResourcesMaxIdleTime(long)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 public void setLowResourcesConnections(long lowResourcesConnections)
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 _lowResourcesConnections=(lowResourcesConnections+_selectSets-1)/_selectSets;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 public abstract void execute(Runnable task);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 /* (non-Javadoc)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 * @see org.eclipse.component.AbstractLifeCycle#doStart()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 protected void doStart() throws Exception
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 _selectSet = new SelectSet[_selectSets];
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 for (int i=0;i<_selectSet.length;i++)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 _selectSet[i]= new SelectSet(i);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 super.doStart();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 // start a thread to Select
948
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
171 for (int i=0;i<_selectSets;i++)
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 final int id=i;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 execute(new Runnable()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 public void run()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 String name=Thread.currentThread().getName();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 try
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 SelectSet[] sets=_selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 if (sets==null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 return;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 SelectSet set=sets[id];
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 Thread.currentThread().setName(name+" Selector"+id);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 LOG.debug("Starting {} on {}",Thread.currentThread(),this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 while (isRunning())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 set.doSelect();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 catch(IOException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 catch(Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 }
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 LOG.debug("Stopped {} on {}",Thread.currentThread(),this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 Thread.currentThread().setName(name);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 });
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
214
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
215
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 /* ------------------------------------------------------------------------------- */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 protected void doStop() throws Exception
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 SelectSet[] sets= _selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 _selectSet=null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 if (sets!=null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 for (SelectSet set : sets)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 if (set!=null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 set.stop();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 }
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 super.doStop();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 /* ------------------------------------------------------------------------------- */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 public abstract AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
235
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 public String dump()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 return AggregateLifeCycle.dump(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
240
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 public void dump(Appendable out, String indent) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 AggregateLifeCycle.dumpObject(out,this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 AggregateLifeCycle.dump(out,indent,TypeUtil.asList(_selectSet));
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
247
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 public class SelectSet implements Dumpable
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 private final int _setID;
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
251 private volatile long _now = System.currentTimeMillis();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
252
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 private final ConcurrentLinkedQueue<Object> _changes = new ConcurrentLinkedQueue<Object>();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
254
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 private volatile Selector _selector;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 private volatile Thread _selecting;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 private int _busySelects;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 private long _monitorNext;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 private boolean _pausing;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 private boolean _paused;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 private volatile long _idleTick;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 private ConcurrentMap<SelectChannelEndPoint,Object> _endPoints = new ConcurrentHashMap<SelectChannelEndPoint, Object>();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
264
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 SelectSet(int acceptorID) throws Exception
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 _setID=acceptorID;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 _idleTick = System.currentTimeMillis();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
270
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 // create a selector;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 _selector = Selector.open();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 _monitorNext=System.currentTimeMillis()+__MONITOR_PERIOD;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
275
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 public void addChange(Object change)
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 _changes.add(change);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
280
865
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 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 * Select and dispatch tasks found from changes and the selector.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 *
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 * @throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 public void doSelect() throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 _selecting=Thread.currentThread();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 final Selector selector=_selector;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 // Stopped concurrently ?
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 if (selector == null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
296
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 // Make any key changes required
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 Object change;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 int changes=_changes.size();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 while (changes-->0 && (change=_changes.poll())!=null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 Channel ch=null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 SelectionKey key=null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
304
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 if (change instanceof EndPoint)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 // Update the operations for a key.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 SelectChannelEndPoint endpoint = (SelectChannelEndPoint)change;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 ch=endpoint.getChannel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 endpoint.doUpdateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 else if (change instanceof SocketChannel)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 // Newly registered channel
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 final SocketChannel channel=(SocketChannel)change;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 ch=channel;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 key = channel.register(selector,SelectionKey.OP_READ,null);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 SelectChannelEndPoint endpoint = createEndPoint(channel,key);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 key.attach(endpoint);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 endpoint.schedule();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 else if (change instanceof Runnable)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 execute((Runnable)change);
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 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 throw new IllegalArgumentException(change.toString());
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 catch (CancelledKeyException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 catch (Throwable e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 if (isRunning())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 LOG.debug("",e);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
341
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 if (ch!=null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 ch.close();
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 catch(IOException e2)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 LOG.debug("",e2);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
353
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
354
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 // Do and instant select to see if any connections can be handled.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 int selected=selector.selectNow();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
357
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
358 _now = System.currentTimeMillis();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
359
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 // if no immediate things to do
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 if (selected==0 && selector.selectedKeys().isEmpty())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 // If we are in pausing mode
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 if (_pausing)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 Thread.sleep(__BUSY_PAUSE); // pause to reduce impact of busy loop
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 catch(InterruptedException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 }
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
374 _now = System.currentTimeMillis();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
376
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 // workout how long to wait in select
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 long wait = _changes.size()==0?__IDLE_TICK:0L;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
379
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 // If we should wait with a select
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 if (wait>0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 {
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
383 long before = _now;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 selector.select(wait);
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
385 _now = System.currentTimeMillis();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
386
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 // If we are monitoring for busy selector
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 // and this select did not wait more than 1ms
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
389 if (__MONITOR_PERIOD>0 && _now-before <=1)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 // count this as a busy select and if there have been too many this monitor cycle
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 if (++_busySelects>__MAX_SELECTS)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 // Start injecting pauses
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 _pausing=true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
396
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 // if this is the first pause
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 if (!_paused)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 // Log and dump some status
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 _paused=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 LOG.warn("Selector {} is too busy, pausing!",this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
408
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 // have we been destroyed while sleeping
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 if (_selector==null || !selector.isOpen())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
412
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 // Look for things to do
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 for (SelectionKey key: selector.selectedKeys())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 SocketChannel channel=null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
417
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 if (!key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 key.cancel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 if (endpoint != null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 endpoint.doUpdateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 continue;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
428
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 Object att = key.attachment();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 if (att instanceof SelectChannelEndPoint)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 if (key.isReadable()||key.isWritable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 ((SelectChannelEndPoint)att).schedule();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 else if (key.isConnectable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 // Complete a connection of a registered channel
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 channel = (SocketChannel)key.channel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 boolean connected=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 connected=channel.finishConnect();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 catch(Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 {
948
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
446 LOG.warn(e+","+channel+","+att);
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
447 LOG.debug("",e);
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 if (connected)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 key.interestOps(SelectionKey.OP_READ);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 SelectChannelEndPoint endpoint = createEndPoint(channel,key);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 key.attach(endpoint);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 endpoint.schedule();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 key.cancel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 channel.close();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 // Wrap readable registered channel in an endpoint
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 channel = (SocketChannel)key.channel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 SelectChannelEndPoint endpoint = createEndPoint(channel,key);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 key.attach(endpoint);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 if (key.isReadable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 endpoint.schedule();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 key = null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 catch (CancelledKeyException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 catch (Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 if (isRunning())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 LOG.trace("",e);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
486
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 if (channel!=null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 channel.close();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 catch(IOException e2)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 LOG.debug("",e2);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
496
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 if (key != null && !(key.channel() instanceof ServerSocketChannel) && key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 key.cancel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
501
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 // Everything always handled
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 selector.selectedKeys().clear();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
504
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
505 _now = System.currentTimeMillis();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
506
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 // Idle tick
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
508 if (_now-_idleTick>__IDLE_TICK)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 {
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
510 _idleTick = _now;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
511
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 final long idle_now=((_lowResourcesConnections>0 && selector.keys().size()>_lowResourcesConnections))
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
513 ?(_now+_maxIdleTime)
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
514 :_now;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
515
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 execute(new Runnable()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 public void run()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 for (SelectChannelEndPoint endp:_endPoints.keySet())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 endp.checkIdleTimestamp(idle_now);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 public String toString() {return "Idle-"+super.toString();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 });
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
527
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
529
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 // Reset busy select monitor counts
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
531 if (__MONITOR_PERIOD>0 && _now>_monitorNext)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 _busySelects=0;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 _pausing=false;
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
535 _monitorNext=_now+__MONITOR_PERIOD;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
536
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 catch (ClosedSelectorException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 if (isRunning())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 catch (CancelledKeyException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 _selecting=null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
555
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 public SelectorManager getManager()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 return SelectorManager.this;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
560
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 public long getNow()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 {
943
96f60ce98949 remove Timeout
Franklin Schmidt <fschmidt@gmail.com>
parents: 942
diff changeset
563 return _now;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
565
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 public void wakeup()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 {
944
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
568 Selector selector = _selector;
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
569 if (selector!=null)
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
570 selector.wakeup();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
572
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 private SelectChannelEndPoint createEndPoint(SocketChannel channel, SelectionKey sKey) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 {
948
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
575 SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,this,sKey, _maxIdleTime);
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
576 endp.setConnection(getManager().newConnection(channel,endp, sKey.attachment()));
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 LOG.debug("created {}",endp);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 _endPoints.put(endp,this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 return endp;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
581
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 public void destroyEndPoint(SelectChannelEndPoint endp)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 LOG.debug("destroyEndPoint {}",endp);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 _endPoints.remove(endp);
948
f5aefdc4a81a simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents: 944
diff changeset
586 endp.getConnection().onClose();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
588
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 Selector getSelector()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 return _selector;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
593
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 void stop() throws Exception
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 // Spin for a while waiting for selector to complete
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 // to avoid unneccessary closed channel exceptions
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 for (int i=0;i<100 && _selecting!=null;i++)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 wakeup();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 Thread.sleep(10);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 catch(Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 {
944
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
608 LOG.warn("",e);
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
610
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 // close endpoints and selector
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 Selector selector=_selector;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 for (SelectionKey key:selector.keys())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 if (key==null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 continue;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 Object att=key.attachment();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 if (att instanceof EndPoint)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 EndPoint endpoint = (EndPoint)att;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 endpoint.close();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 catch(IOException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
633
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 selector=_selector;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 if (selector != null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 selector.close();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 catch (IOException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 }
944
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
644 _selector = null;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
647
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 public String dump()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 return AggregateLifeCycle.dump(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
652
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 public void dump(Appendable out, String indent) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 out.append(String.valueOf(this)).append(" id=").append(String.valueOf(_setID)).append("\n");
944
1d24b6e422fa simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 943
diff changeset
656 AggregateLifeCycle.dump(out,indent,Collections.emptyList());
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
658
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 public String toString()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 Selector selector=_selector;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 return String.format("%s keys=%d selected=%d",
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 super.toString(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 selector != null && selector.isOpen() ? selector.keys().size() : -1,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 selector != null && selector.isOpen() ? selector.selectedKeys().size() : -1);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
668
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
669 }