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

simplify ChannelEndPoint
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Oct 2016 21:29:19 -0600
parents 7b94f5b33c64
children 790c01734386
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.io.InterruptedIOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.nio.channels.ClosedChannelException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import java.nio.channels.SelectableChannel;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import java.nio.channels.SelectionKey;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import java.nio.channels.SocketChannel;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import java.util.Locale;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
28 import java.util.concurrent.RejectedExecutionException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.io.AsyncEndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.io.Buffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import org.eclipse.jetty.io.ConnectedEndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import org.eclipse.jetty.io.Connection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import org.eclipse.jetty.io.EofException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import org.eclipse.jetty.io.nio.SelectorManager.SelectSet;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
36 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
37 import org.slf4j.LoggerFactory;
940
b77d631b9e28 remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents: 915
diff changeset
38
802
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 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 * An Endpoint that can be scheduled by {@link SelectorManager}.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 */
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
44 public final class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 {
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
46 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
47
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
48 private final SelectorManager.SelectSet _selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
49 private final SelectorManager _manager;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 private SelectionKey _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51 private final Runnable _handler = new Runnable()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
52 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
53 public void run() { handle(); }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 /** The desired value for {@link SelectionKey#interestOps()} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 private int _interestOps;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 * The connection instance is the handler for any IO activity on the endpoint.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 * There is a different type of connection for HTTP, AJP, WebSocket and
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 * ProxyConnect. The connection may change for an SCEP as it is upgraded
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 * from HTTP to proxy connect or websocket.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 private volatile AsyncConnection _connection;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
67 private static final int STATE_NEEDS_DISPATCH = -1;
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
68 private static final int STATE_UNDISPATCHED = 0;
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
69 private static final int STATE_DISPATCHED = 1;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 private int _state;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 /** true if the last write operation succeed and wrote all offered bytes */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 private volatile boolean _writable = true;
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 /** True if a thread has is blocked in {@link #blockReadable(long)} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 private boolean _readBlocked;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 /** True if a thread has is blocked in {@link #blockWritable(long)} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 private boolean _writeBlocked;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 private boolean _ishut;
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 public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 super(channel, maxIdleTime);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 _manager = selectSet.getManager();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 _selectSet = selectSet;
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
90 _state = STATE_UNDISPATCHED;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 _key = key;
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
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
94 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 public Connection getConnection()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 return _connection;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
100 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 public void setConnection(Connection connection)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 {
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
103 _connection = (AsyncConnection)connection;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 /** Called by selectSet to schedule handling
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 *
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 */
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
110 public synchronized void schedule()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 {
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
112 // If there is no key, then do nothing
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
113 if (_key == null || !_key.isValid())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
115 _readBlocked = false;
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
116 _writeBlocked = false;
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
117 this.notifyAll();
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
118 return;
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
119 }
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
120
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
121 // If there are threads dispatched reading and writing
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
122 if (_readBlocked || _writeBlocked)
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
123 {
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
124 // assert _dispatched;
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
125 if (_readBlocked && _key.isReadable())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 _readBlocked=false;
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
127 if (_writeBlocked && _key.isWritable())
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
128 _writeBlocked = false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
130 // wake them up is as good as a dispatched.
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
131 this.notifyAll();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
133 // we are not interested in further selecting
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
134 _key.interestOps(0);
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
135 if (_state<STATE_DISPATCHED)
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
136 updateKey();
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
137 return;
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
138 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
140 // Remove writeable op
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
141 if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE)
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
142 {
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 // Remove writeable op
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
144 _interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE;
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
145 _key.interestOps(_interestOps);
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
146 _writable = true; // Once writable is in ops, only removed with dispatch.
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
147 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
149 // If dispatched, then deregister interest
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
150 if (_state>=STATE_DISPATCHED)
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
151 _key.interestOps(0);
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
152 else
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
153 {
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
154 // other wise do the dispatch
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
155 dispatch();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
159 @Override
947
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
160 public synchronized void dispatch()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 {
947
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
162 if (_state<=STATE_UNDISPATCHED)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
164 _state = STATE_DISPATCHED;
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
165 try {
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
166 _manager.execute(_handler);
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
167 } catch(RejectedExecutionException e) {
947
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
168 _state = STATE_NEEDS_DISPATCH;
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
169 LOG.warn("Dispatched Failed! "+this+" to "+_manager);
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
170 updateKey();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
175 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 public int fill(Buffer buffer) throws IOException
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 int fill=super.fill(buffer);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 return fill;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 int l = super.flush(header, buffer, trailer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 // If there was something to write and it wasn't written, then we are not writable.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 if (l==0 && ( header!=null && header.hasContent() || buffer!=null && buffer.hasContent() || trailer!=null && trailer.hasContent()))
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 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
192 _writable = false;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 if (_state<STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 updateKey();
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 else if (l>0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
199 _writable = true;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 return l;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
203
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 public int flush(Buffer buffer) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 int l = super.flush(buffer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 // If there was something to write and it wasn't written, then we are not writable.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 if (l==0 && buffer!=null && buffer.hasContent())
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 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
214 _writable = false;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 if (_state<STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 else if (l>0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
221 _writable = true;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 return l;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
226
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 /* ------------------------------------------------------------ */
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 * Allows thread to block waiting for further events.
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 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 public boolean blockReadable(long timeoutMs) throws IOException
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 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 if (isInputShutdown())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 throw new EofException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
238
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
239 long now = _selectSet.getNow();
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
240 long end = now+timeoutMs;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
243 _readBlocked = true;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 while (!isInputShutdown() && _readBlocked)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 this.wait(timeoutMs>0?(end-now):10000);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 catch (final InterruptedException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 if (_readBlocked && timeoutMs>0 && now>=end)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 return false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
266 _readBlocked = false;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
271
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 * Allows thread to block waiting for further events.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 public boolean blockWritable(long timeoutMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 if (isOutputShutdown())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 throw new EofException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
283
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 long now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 long end=now+timeoutMs;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
288 _writeBlocked = true;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 while (_writeBlocked && !isOutputShutdown())
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 this.wait(timeoutMs>0?(end-now):10000);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 catch (final InterruptedException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 finally
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 now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 if (_writeBlocked && timeoutMs>0 && now>=end)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 return false;
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
310 _writeBlocked = false;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
315
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
316 @Override
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 public boolean hasProgressed()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 return false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
321
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 /* ------------------------------------------------------------ */
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 * Updates selection key. Adds operations types to the selection key as needed. No operations
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 * are removed as this is only done during dispatch. This method records the new key and
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 * schedules a call to doUpdateKey to do the keyChange
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 private void updateKey()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 final boolean changed;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 synchronized (this)
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 int current_ops=-1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 if (getChannel().isOpen())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended());
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
338
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 _interestOps =
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0);
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 current_ops = ((_key!=null && _key.isValid())?_key.interestOps():-1);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 catch(Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 {
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
348 _key = null;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 LOG.trace("",e);
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 }
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
352 changed = _interestOps!=current_ops;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 }
802
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 if(changed)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
357 doUpdateKey();
950
a778413aefc0 add SaneSelector
Franklin Schmidt <fschmidt@gmail.com>
parents: 949
diff changeset
358 _selectSet.getSelector().update();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
361
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
362
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 */
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
367 synchronized void doUpdateKey()
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
369 if (getChannel().isOpen())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
371 if (_interestOps>0)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
373 if (_key==null || !_key.isValid())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
375 SelectableChannel sc = (SelectableChannel)getChannel();
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
376 if (sc.isRegistered())
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
378 updateKey();
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
382 try
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
383 {
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
384 _key = _selectSet.getSelector().register(sc,_interestOps,this);
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
385 }
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
386 catch (Exception e)
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
387 {
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
388 LOG.trace("",e);
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
389 if (_key!=null && _key.isValid())
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
390 {
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
391 _key.cancel();
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
392 }
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
393
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
394 _key = null;
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
395 }
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 {
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
400 _key.interestOps(_interestOps);
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 else
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 if (_key!=null && _key.isValid())
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
406 _key.interestOps(0);
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
407 else
953
7db4a488fc82 simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 952
diff changeset
408 _key = null;
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
409 }
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
410 }
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
411 else
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
412 {
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
413 if (_key!=null && _key.isValid())
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
414 _key.cancel();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
415
949
e9088af3787f remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 948
diff changeset
416 _key = null;
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
419
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
420 private void handle()
865
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 {
947
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
424 try
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 {
947
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
426 while(true)
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 {
947
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
428 final AsyncConnection next = (AsyncConnection)_connection.handle();
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
429 if (next==_connection)
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
430 break;
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
431 LOG.debug("{} replaced {}",next,_connection);
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
432 _connection=next;
947
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
433 }
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
434 }
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
435 catch (ClosedChannelException e)
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
436 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
437 LOG.trace("",e);
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
438 }
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
439 catch (EofException e)
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
440 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
441 LOG.debug("EOF", e);
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
442 try{close();}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
443 catch(IOException e2){LOG.trace("",e2);}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
444 }
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
445 catch (IOException e)
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
446 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
447 LOG.warn(e.toString());
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
448 try{close();}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
449 catch(IOException e2){LOG.trace("",e2);}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
450 }
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
451 catch (Throwable e)
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
452 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
453 LOG.warn("handle failed", e);
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
454 try{close();}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
455 catch(IOException e2){LOG.trace("",e2);}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
456 }
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
457 finally
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
458 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
459 if (!_ishut && isInputShutdown() && isOpen())
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
460 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
461 _ishut = true;
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
462 try
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
463 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
464 _connection.onInputShutdown();
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
465 }
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
466 catch(Throwable x)
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
467 {
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
468 LOG.warn("onInputShutdown failed", x);
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
469 try{close();}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
470 catch(IOException e2){LOG.trace("",e2);}
64f3d8dae31d simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 946
diff changeset
471 }
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 }
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 {
960
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
477 _state = STATE_UNDISPATCHED;
3cd4c706a61f simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 959
diff changeset
478 updateKey();
865
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
481
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 * @see org.eclipse.io.nio.ChannelEndPoint#close()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 public void close() throws IOException
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 super.close();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 catch (IOException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
502
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 public String toString()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 // Do NOT use synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 // because it's very easy to deadlock when debugging is enabled.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 // We do a best effort to print the right toString() and that's it.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 SelectionKey key = _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 String keyString = "";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 if (key != null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 if (key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 if (key.isReadable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 keyString += "r";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 if (key.isWritable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 keyString += "w";
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 else
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 keyString += "!";
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 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 keyString += "-";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}",
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 hashCode(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 _socket.getRemoteSocketAddress(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 _socket.getLocalSocketAddress(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 _state,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 isOpen(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 isInputShutdown(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 isOutputShutdown(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 _readBlocked,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 _writeBlocked,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 _writable,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 _interestOps,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 keyString,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 _connection);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
544
865
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 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 * Don't set the SoTimeout
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int)
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 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 public void setMaxIdleTime(int timeMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 {
955
6f49b8dfffe6 simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 953
diff changeset
553 _maxIdleTime = timeMs;
865
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
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
556 }