annotate src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 946:901dcfa05c32

remove SelectChannelEndPoint._interruptable
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 11 Oct 2016 21:10:17 -0600
parents 89fe80dfab2c
children 64f3d8dae31d
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 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint
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
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 private static final int STATE_NEEDS_DISPATCH=-1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 private static final int STATE_UNDISPATCHED=0;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 private static final int STATE_DISPATCHED=1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 private static final int STATE_ASYNC=2;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 private int _state;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 private boolean _onIdle;
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 the last write operation succeed and wrote all offered bytes */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 private volatile boolean _writable = true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 /** True if a thread has is blocked in {@link #blockReadable(long)} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 private boolean _readBlocked;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 /** True if a thread has is blocked in {@link #blockWritable(long)} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 private boolean _writeBlocked;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 /** true if {@link SelectSet#destroyEndPoint(SelectChannelEndPoint)} has not been called */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 private boolean _open;
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 private volatile long _idleTimestamp;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 private volatile boolean _checkIdle;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 private boolean _ishut;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 throws IOException
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 super(channel, maxIdleTime);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 _manager = selectSet.getManager();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 _selectSet = selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 _state=STATE_UNDISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 _onIdle=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 _open=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 _key = key;
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 setCheckForIdle(true);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 public SelectionKey getSelectionKey()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 return _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 public SelectorManager getSelectManager()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 return _manager;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 public Connection getConnection()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 return _connection;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 public void setConnection(Connection connection)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 _connection=(AsyncConnection)connection;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 }
802
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 /** Called by selectSet to schedule handling
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 *
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 void schedule()
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 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 // If there is no key, then do nothing
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 if (_key == null || !_key.isValid())
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 _readBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 _writeBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 this.notifyAll();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 return;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 // If there are threads dispatched reading and writing
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 if (_readBlocked || _writeBlocked)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 // assert _dispatched;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 if (_readBlocked && _key.isReadable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 _readBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 if (_writeBlocked && _key.isWritable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 _writeBlocked=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 // wake them up is as good as a dispatched.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 this.notifyAll();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 // we are not interested in further selecting
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 _key.interestOps(0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 if (_state<STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 return;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 // Remove writeable op
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE)
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 // Remove writeable op
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 _interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 _key.interestOps(_interestOps);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 _writable = true; // Once writable is in ops, only removed with dispatch.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 // If dispatched, then deregister interest
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 if (_state>=STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 _key.interestOps(0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 // other wise do the dispatch
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 dispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188
865
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 public void dispatch()
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 synchronized(this)
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 if (_state<=STATE_UNDISPATCHED)
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 if (_onIdle)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 _state = STATE_NEEDS_DISPATCH;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 else
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 _state = STATE_DISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 try {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 _manager.execute(_handler);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 } catch(RejectedExecutionException e) {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 _state = STATE_NEEDS_DISPATCH;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 LOG.warn("Dispatched Failed! "+this+" to "+_manager);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 }
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
212
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 * Called when a dispatched thread is no longer handling the endpoint.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 * The selection key operations are updated.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 * @return If false is returned, the endpoint has been redispatched and
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 * thread must keep handling the endpoint.
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 protected boolean undispatch()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 synchronized (this)
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 switch(_state)
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 case STATE_ASYNC:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 _state=STATE_DISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 default:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 _state=STATE_UNDISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
237
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 public void setCheckForIdle(boolean check)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 if (check)
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 _idleTimestamp=System.currentTimeMillis();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 _checkIdle=true;
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 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 _checkIdle=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
249
865
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 public boolean isCheckForIdle()
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 return _checkIdle;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
255
865
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 protected void notIdle()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 _idleTimestamp=System.currentTimeMillis();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
261
865
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 public void checkIdleTimestamp(long now)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 if (isCheckForIdle() && _maxIdleTime>0)
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 final long idleForMs=now-_idleTimestamp;
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 if (idleForMs>_maxIdleTime)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 // Don't idle out again until onIdleExpired task completes.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 setCheckForIdle(false);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 _manager.execute(new Runnable()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 public void run()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 try
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 onIdleExpired(idleForMs);
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 finally
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 setCheckForIdle(true);
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 }
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 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
290
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 public void onIdleExpired(long idleForMs)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 try
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 synchronized (this)
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 _onIdle=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
300
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 _connection.onIdleExpired(idleForMs);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 synchronized (this)
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 _onIdle=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 if (_state==STATE_NEEDS_DISPATCH)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 dispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
313
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 public int fill(Buffer buffer) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 int fill=super.fill(buffer);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 if (fill>0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 notIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 return fill;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
323
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
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 int l = super.flush(header, buffer, trailer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
329
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 // 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
331 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
332 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 synchronized (this)
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 _writable=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 if (_state<STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 else if (l>0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 _writable=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 notIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 return l;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
347
865
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 /*
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 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 public int flush(Buffer buffer) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 int l = super.flush(buffer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
355
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 // 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
357 if (l==0 && buffer!=null && buffer.hasContent())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 _writable=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 if (_state<STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 updateKey();
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 else if (l>0)
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 _writable=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 notIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
371
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 return l;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
374
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 * Allows thread to block waiting for further events.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 public boolean blockReadable(long timeoutMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 if (isInputShutdown())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 throw new EofException();
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 long now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 long end=now+timeoutMs;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 boolean check=isCheckForIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 setCheckForIdle(true);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 _readBlocked=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 while (!isInputShutdown() && _readBlocked)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 try
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 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 this.wait(timeoutMs>0?(end-now):10000);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 catch (final InterruptedException e)
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 LOG.warn("",e);
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 finally
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 now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
409
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 if (_readBlocked && timeoutMs>0 && now>=end)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 return false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 finally
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 _readBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 setCheckForIdle(check);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 }
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 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
422
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 * Allows thread to block waiting for further events.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 public boolean blockWritable(long timeoutMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 synchronized (this)
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 (isOutputShutdown())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 throw new EofException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
434
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 long now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 long end=now+timeoutMs;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 boolean check=isCheckForIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 setCheckForIdle(true);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 _writeBlocked=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 while (_writeBlocked && !isOutputShutdown())
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 this.wait(timeoutMs>0?(end-now):10000);
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 catch (final InterruptedException e)
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 LOG.warn("",e);
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 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 if (_writeBlocked && timeoutMs>0 && now>=end)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 return false;
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 finally
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 _writeBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 setCheckForIdle(check);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 }
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 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
469
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 * @see org.eclipse.jetty.io.AsyncEndPoint#scheduleWrite()
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 public void scheduleWrite()
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 if (_writable)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 LOG.debug("Required scheduleWrite {}",this);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
478
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 _writable=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
482
865
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 public boolean isWritable()
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 return _writable;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
488
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 public boolean hasProgressed()
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 return false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
494
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 /* ------------------------------------------------------------ */
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 * 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
498 * 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
499 * schedules a call to doUpdateKey to do the keyChange
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 private void updateKey()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 final boolean changed;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 synchronized (this)
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 int current_ops=-1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 if (getChannel().isOpen())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended());
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable);
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 _interestOps =
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 current_ops = ((_key!=null && _key.isValid())?_key.interestOps():-1);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 catch(Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 _key=null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 LOG.trace("",e);
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 changed=_interestOps!=current_ops;
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 if(changed)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 _selectSet.addChange(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 _selectSet.wakeup();
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
534
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
535
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 /* ------------------------------------------------------------ */
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 * 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
539 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 void doUpdateKey()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 if (getChannel().isOpen())
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 if (_interestOps>0)
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 if (_key==null || !_key.isValid())
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 SelectableChannel sc = (SelectableChannel)getChannel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 if (sc.isRegistered())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 _key=((SelectableChannel)getChannel()).register(_selectSet.getSelector(),_interestOps,this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 catch (Exception e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 if (_key!=null && _key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 _key.cancel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
568
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 if (_open)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 _selectSet.destroyEndPoint(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 _open=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 _key = null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 _key.interestOps(_interestOps);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 if (_key!=null && _key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 _key.interestOps(0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 _key=null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 }
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 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 if (_key!=null && _key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 _key.cancel();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
595
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 if (_open)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 _open=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 _selectSet.destroyEndPoint(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 _key = null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
605
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 protected void handle()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 boolean dispatched=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 try
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 while(dispatched)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 while(true)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 final AsyncConnection next = (AsyncConnection)_connection.handle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 if (next!=_connection)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 LOG.debug("{} replaced {}",next,_connection);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 _connection=next;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 continue;
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 break;
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 catch (ClosedChannelException e)
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 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 catch (EofException e)
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 LOG.debug("EOF", e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 catch(IOException e2){LOG.trace("",e2);}
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.warn(e.toString());
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 catch(IOException e2){LOG.trace("",e2);}
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 catch (Throwable e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 LOG.warn("handle failed", e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 catch(IOException e2){LOG.trace("",e2);}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 if (!_ishut && isInputShutdown() && isOpen())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 _ishut=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 _connection.onInputShutdown();
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 catch(Throwable x)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 LOG.warn("onInputShutdown failed", x);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 catch(IOException e2){LOG.trace("",e2);}
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 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 dispatched=!undispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
677 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 if (dispatched)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 dispatched=!undispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 while (dispatched)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 LOG.warn("SCEP.run() finally DISPATCHED");
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 dispatched=!undispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
689
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 * @see org.eclipse.io.nio.ChannelEndPoint#close()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 public void close() throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
696 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 super.close();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 catch (IOException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
710
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 public String toString()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 // Do NOT use synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 // because it's very easy to deadlock when debugging is enabled.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 // 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
718 SelectionKey key = _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 String keyString = "";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 if (key != null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 if (key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 if (key.isReadable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 keyString += "r";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 if (key.isWritable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 keyString += "w";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 keyString += "!";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 keyString += "-";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
737 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 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
739 hashCode(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 _socket.getRemoteSocketAddress(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 _socket.getLocalSocketAddress(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 _state,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 isOpen(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 isInputShutdown(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 isOutputShutdown(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 _readBlocked,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 _writeBlocked,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 _writable,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 _interestOps,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 keyString,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
751 _connection);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
753
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
754 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 public SelectSet getSelectSet()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
756 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
757 return _selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
759
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
762 * Don't set the SoTimeout
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 public void setMaxIdleTime(int timeMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
767 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
768 _maxIdleTime=timeMs;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
770
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
771 }