annotate src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 913:17f4fe8271de

simplify connectors
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 08 Oct 2016 23:57:11 -0600
parents 6b210bb66c63
children 54308d65265a
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;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import org.eclipse.jetty.util.thread.Timeout.Task;
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 boolean WORK_AROUND_JVM_BUG_6346658 = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
49 private final SelectorManager.SelectSet _selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 private final SelectorManager _manager;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51 private SelectionKey _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
52 private final Runnable _handler = new Runnable()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
53 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 public void run() { handle(); }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 /** The desired value for {@link SelectionKey#interestOps()} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 private int _interestOps;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 * 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
62 * There is a different type of connection for HTTP, AJP, WebSocket and
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 * ProxyConnect. The connection may change for an SCEP as it is upgraded
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 * from HTTP to proxy connect or websocket.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 private volatile AsyncConnection _connection;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 private static final int STATE_NEEDS_DISPATCH=-1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 private static final int STATE_UNDISPATCHED=0;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 private static final int STATE_DISPATCHED=1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 private static final int STATE_ASYNC=2;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 private int _state;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 private boolean _onIdle;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 /** true if the last write operation succeed and wrote all offered bytes */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 private volatile boolean _writable = true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 /** True if a thread has is blocked in {@link #blockReadable(long)} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 private boolean _readBlocked;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 /** True if a thread has is blocked in {@link #blockWritable(long)} */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 private boolean _writeBlocked;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 /** true if {@link SelectSet#destroyEndPoint(SelectChannelEndPoint)} has not been called */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 private boolean _open;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 private volatile long _idleTimestamp;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 private volatile boolean _checkIdle;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 private boolean _interruptable;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 private boolean _ishut;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95
865
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 public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 super(channel, maxIdleTime);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 _manager = selectSet.getManager();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 _selectSet = selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 _state=STATE_UNDISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 _onIdle=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 _open=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 _key = key;
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 setCheckForIdle(true);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 public SelectionKey getSelectionKey()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 return _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 public SelectorManager getSelectManager()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 return _manager;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 public Connection getConnection()
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 return _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 public void setConnection(Connection connection)
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 Connection old=_connection;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 _connection=(AsyncConnection)connection;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 if (old!=null && old!=_connection)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 _manager.endPointUpgraded(this,old);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 public long getIdleTimestamp()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 return _idleTimestamp;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 /** Called by selectSet to schedule handling
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 *
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 public void schedule()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 // If there is no key, then do nothing
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 if (_key == null || !_key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 _readBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 _writeBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 this.notifyAll();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 return;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 // If there are threads dispatched reading and writing
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 if (_readBlocked || _writeBlocked)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 // assert _dispatched;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 if (_readBlocked && _key.isReadable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 _readBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 if (_writeBlocked && _key.isWritable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 _writeBlocked=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 // wake them up is as good as a dispatched.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 this.notifyAll();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 // we are not interested in further selecting
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 _key.interestOps(0);
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 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 return;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 // Remove writeable op
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 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
186 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 // Remove writeable op
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 _interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 _key.interestOps(_interestOps);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 _writable = true; // Once writable is in ops, only removed with dispatch.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 // If dispatched, then deregister interest
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 if (_state>=STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 _key.interestOps(0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 // other wise do the dispatch
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 dispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 if (_state>=STATE_DISPATCHED && !_selectSet.getManager().isDeferringInterestedOps0())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 _key.interestOps(0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207
865
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 public void asyncDispatch()
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 synchronized(this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 switch(_state)
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 case STATE_NEEDS_DISPATCH:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 case STATE_UNDISPATCHED:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 dispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 break;
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 case STATE_DISPATCHED:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 case STATE_ASYNC:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 _state=STATE_ASYNC;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 break;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 public void dispatch()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 synchronized(this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 if (_state<=STATE_UNDISPATCHED)
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 if (_onIdle)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 _state = STATE_NEEDS_DISPATCH;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 else
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 _state = STATE_DISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 try {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 _manager.execute(_handler);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 } catch(RejectedExecutionException e) {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 _state = STATE_NEEDS_DISPATCH;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 LOG.warn("Dispatched Failed! "+this+" to "+_manager);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
251
865
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 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 * Called when a dispatched thread is no longer handling the endpoint.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 * The selection key operations are updated.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 * @return If false is returned, the endpoint has been redispatched and
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 * thread must keep handling the endpoint.
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 protected boolean undispatch()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 synchronized (this)
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 switch(_state)
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 case STATE_ASYNC:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 _state=STATE_DISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 return false;
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 default:
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 _state=STATE_UNDISPATCHED;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
276
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 public void cancelTimeout(Task task)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 getSelectSet().cancelTimeout(task);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 public void scheduleTimeout(Task task, long timeoutMs)
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 getSelectSet().scheduleTimeout(task,timeoutMs);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 public void setCheckForIdle(boolean check)
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 if (check)
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 _idleTimestamp=System.currentTimeMillis();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 _checkIdle=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 _checkIdle=false;
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 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 public boolean isCheckForIdle()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 return _checkIdle;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
306
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 protected void notIdle()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 _idleTimestamp=System.currentTimeMillis();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
312
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 public void checkIdleTimestamp(long now)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 if (isCheckForIdle() && _maxIdleTime>0)
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 final long idleForMs=now-_idleTimestamp;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
319
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 if (idleForMs>_maxIdleTime)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 // Don't idle out again until onIdleExpired task completes.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 setCheckForIdle(false);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 _manager.execute(new Runnable()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 public void run()
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 onIdleExpired(idleForMs);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 setCheckForIdle(true);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 });
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
341
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 public void onIdleExpired(long idleForMs)
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 synchronized (this)
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 _onIdle=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
351
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 _connection.onIdleExpired(idleForMs);
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 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 _onIdle=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 if (_state==STATE_NEEDS_DISPATCH)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 dispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
364
865
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 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 public int fill(Buffer buffer) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 int fill=super.fill(buffer);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 if (fill>0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 notIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 return fill;
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 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
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 int l = super.flush(header, buffer, trailer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
380
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 // 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
382 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
383 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 _writable=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 if (_state<STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 else if (l>0)
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 _writable=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 notIdle();
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 return l;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
398
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 public int flush(Buffer buffer) throws IOException
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 int l = super.flush(buffer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
406
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 // 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
408 if (l==0 && buffer!=null && buffer.hasContent())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 _writable=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 if (_state<STATE_DISPATCHED)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 updateKey();
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 else if (l>0)
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 _writable=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 notIdle();
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 return l;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
425
865
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 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 * Allows thread to block waiting for further events.
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 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 public boolean blockReadable(long timeoutMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 if (isInputShutdown())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 throw new EofException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
437
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 long now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 long end=now+timeoutMs;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 boolean check=isCheckForIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 setCheckForIdle(true);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 try
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 _readBlocked=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 while (!isInputShutdown() && _readBlocked)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 try
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 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 this.wait(timeoutMs>0?(end-now):10000);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 catch (final InterruptedException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 if (_interruptable)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 throw new InterruptedIOException(){{this.initCause(e);}};
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 finally
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 now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
462
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 if (_readBlocked && timeoutMs>0 && now>=end)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 return false;
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 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 _readBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 setCheckForIdle(check);
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
475
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 * Allows thread to block waiting for further events.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 public boolean blockWritable(long timeoutMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 if (isOutputShutdown())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 throw new EofException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
487
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 long now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 long end=now+timeoutMs;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 boolean check=isCheckForIdle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 setCheckForIdle(true);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 _writeBlocked=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 while (_writeBlocked && !isOutputShutdown())
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 this.wait(timeoutMs>0?(end-now):10000);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 catch (final InterruptedException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 LOG.warn("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 if (_interruptable)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 throw new InterruptedIOException(){{this.initCause(e);}};
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 now=_selectSet.getNow();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 if (_writeBlocked && timeoutMs>0 && now>=end)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 return false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 _writeBlocked=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 setCheckForIdle(check);
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 return true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
524
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 /** Set the interruptable mode of the endpoint.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 * If set to false (default), then interrupts are assumed to be spurious
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 * and blocking operations continue unless the endpoint has been closed.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 * If true, then interrupts of blocking operations result in InterruptedIOExceptions
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 * being thrown.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 * @param interupable
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 public void setInterruptable(boolean interupable)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 synchronized (this)
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 _interruptable=interupable;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
540
865
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 public boolean isInterruptable()
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 return _interruptable;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 * @see org.eclipse.jetty.io.AsyncEndPoint#scheduleWrite()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 public void scheduleWrite()
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 if (_writable)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 LOG.debug("Required scheduleWrite {}",this);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
555
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 _writable=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
559
865
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 public boolean isWritable()
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 return _writable;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
565
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 public boolean hasProgressed()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 return false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
571
865
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 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 * 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
575 * 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
576 * schedules a call to doUpdateKey to do the keyChange
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 private void updateKey()
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 final boolean changed;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 synchronized (this)
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 int current_ops=-1;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 if (getChannel().isOpen())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended());
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
588
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 _interestOps =
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 current_ops = ((_key!=null && _key.isValid())?_key.interestOps():-1);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 catch(Exception e)
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 _key=null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 LOG.trace("",e);
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 changed=_interestOps!=current_ops;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
604
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 if(changed)
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 _selectSet.addChange(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608 _selectSet.wakeup();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
611
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
612
865
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 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 * 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
616 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 void doUpdateKey()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 if (getChannel().isOpen())
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 if (_interestOps>0)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 if (_key==null || !_key.isValid())
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 SelectableChannel sc = (SelectableChannel)getChannel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 if (sc.isRegistered())
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 updateKey();
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 else
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 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 _key=((SelectableChannel)getChannel()).register(_selectSet.getSelector(),_interestOps,this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 catch (Exception e)
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 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 if (_key!=null && _key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 _key.cancel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
645
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 if (_open)
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 _selectSet.destroyEndPoint(this);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 _open=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 _key = null;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 }
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 _key.interestOps(_interestOps);
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 if (_key!=null && _key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 _key.interestOps(0);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 _key=null;
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 if (_key!=null && _key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 _key.cancel();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
672
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 if (_open)
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 _open=false;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 _selectSet.destroyEndPoint(this);
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 _key = null;
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
682
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 /*
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 protected void handle()
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 boolean dispatched=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 try
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 while(dispatched)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 while(true)
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 final AsyncConnection next = (AsyncConnection)_connection.handle();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 if (next!=_connection)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 LOG.debug("{} replaced {}",next,_connection);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 Connection old=_connection;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 _connection=next;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 _manager.endPointUpgraded(this,old);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 continue;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 break;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 }
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 catch (ClosedChannelException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 catch (EofException e)
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 LOG.debug("EOF", e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 catch(IOException e2){LOG.trace("",e2);}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 catch (IOException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 LOG.warn(e.toString());
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 catch(IOException e2){LOG.trace("",e2);}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 catch (Throwable e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 LOG.warn("handle failed", e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 catch(IOException e2){LOG.trace("",e2);}
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 finally
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 if (!_ishut && isInputShutdown() && isOpen())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 _ishut=true;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 try
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 _connection.onInputShutdown();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 catch(Throwable x)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 LOG.warn("onInputShutdown failed", x);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 try{close();}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 catch(IOException e2){LOG.trace("",e2);}
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
751 dispatched=!undispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 }
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 finally
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 if (dispatched)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 dispatched=!undispatch();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 while (dispatched)
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 LOG.warn("SCEP.run() finally DISPATCHED");
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 dispatched=!undispatch();
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 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
767 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
768
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 /*
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 * @see org.eclipse.io.nio.ChannelEndPoint#close()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 public void close() throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
776 // On unix systems there is a JVM issue that if you cancel before closing, it can
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 // cause the selector to block waiting for a channel to close and that channel can
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 // block waiting for the remote end. But on windows, if you don't cancel before a
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 // close, then the selector can block anyway!
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
780 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=357318
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 if (WORK_AROUND_JVM_BUG_6346658)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
782 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
785 SelectionKey key = _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
786 if (key!=null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
787 key.cancel();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 catch (Throwable e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
790 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
791 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
794
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 try
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
797 super.close();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
798 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 catch (IOException e)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 LOG.trace("",e);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
803 finally
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
804 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 updateKey();
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
806 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
807 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
808
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
809 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
810 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
811 public String toString()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
812 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
813 // Do NOT use synchronized (this)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 // because it's very easy to deadlock when debugging is enabled.
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 // 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
816 SelectionKey key = _key;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
817 String keyString = "";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
818 if (key != null)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
819 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
820 if (key.isValid())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
821 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
822 if (key.isReadable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 keyString += "r";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 if (key.isWritable())
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
825 keyString += "w";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
826 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
827 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
828 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 keyString += "!";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
830 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
831 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
832 else
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
833 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
834 keyString += "-";
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
835 }
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
836 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
837 hashCode(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
838 _socket.getRemoteSocketAddress(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 _socket.getLocalSocketAddress(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
840 _state,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 isOpen(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 isInputShutdown(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
843 isOutputShutdown(),
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
844 _readBlocked,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845 _writeBlocked,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
846 _writable,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
847 _interestOps,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
848 keyString,
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
849 _connection);
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
851
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
852 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
853 public SelectSet getSelectSet()
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
854 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
855 return _selectSet;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
857
865
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
858 /* ------------------------------------------------------------ */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
859 /**
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 * Don't set the SoTimeout
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
861 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int)
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
862 */
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
863 @Override
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 public void setMaxIdleTime(int timeMs) throws IOException
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
865 {
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
866 _maxIdleTime=timeMs;
6b210bb66c63 remove ThreadPool
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
867 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
868
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
869 }