Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/Connector.java @ 1039:a7319f14ba1e
remove Buffer.isImmutable()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 22:55:28 -0600 |
parents | 8c13b9224cff |
children | a8c92b0a08ed |
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.server; |
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; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
22 import java.net.InetAddress; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
23 import java.net.Socket; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
24 import java.net.UnknownHostException; |
909 | 25 import java.nio.channels.ServerSocketChannel; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
26 import java.util.concurrent.ThreadPoolExecutor; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
27 import java.util.concurrent.atomic.AtomicLong; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
29 import javax.servlet.ServletRequest; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
31 import org.eclipse.jetty.io.Buffer; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
32 import org.eclipse.jetty.io.Buffers; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
33 import org.eclipse.jetty.io.EndPoint; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
34 import org.eclipse.jetty.io.EofException; |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
35 import org.eclipse.jetty.io.nio.DirectNIOBuffer; |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
36 import org.eclipse.jetty.io.nio.IndirectNIOBuffer; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
37 import org.eclipse.jetty.util.component.AggregateLifeCycle; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
38 import org.eclipse.jetty.util.component.Dumpable; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
39 import org.slf4j.Logger; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
40 import org.slf4j.LoggerFactory; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
41 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 /** |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
43 * Abstract Connector implementation. This abstract implementation of the Connector interface provides: |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
44 * <ul> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
45 * <li>AbstractLifeCycle implementation</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
46 * <li>Implementations for connector getters and setters</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
47 * <li>Buffer management</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
48 * <li>Socket configuration</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
49 * <li>Base acceptor thread</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
50 * <li>Optional reverse proxy headers checking</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
51 * </ul> |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 */ |
1005 | 53 public abstract class Connector extends AggregateLifeCycle implements Dumpable, Runnable |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
54 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
55 private static final Logger LOG = LoggerFactory.getLogger(Connector.class); |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
56 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
57 private String _name; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
885
diff
changeset
|
59 public final Server server; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
60 private String _host; |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
885
diff
changeset
|
61 public final int port; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
62 |
948
f5aefdc4a81a
simplify SelectChannelConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
914
diff
changeset
|
63 protected final int _maxIdleTime = 200000; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
64 protected int _soLingerTime = -1; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
65 |
909 | 66 // from child classes |
67 protected transient ServerSocketChannel _acceptChannel; | |
68 | |
996 | 69 protected Connector(Server server,int port) { |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
885
diff
changeset
|
70 this.server = server; |
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
885
diff
changeset
|
71 this.port = port; |
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
885
diff
changeset
|
72 server.connectors.add(this); |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
73 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
74 |
996 | 75 public final void setHost(String host) |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
76 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
77 _host = host; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
78 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
79 |
996 | 80 public final String getHost() |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
81 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
82 return _host; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
83 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
84 |
996 | 85 public final int getMaxIdleTime() |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
86 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
87 return _maxIdleTime; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
88 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
89 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
90 /* ------------------------------------------------------------ */ |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
91 /** |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
92 * Set the maximum Idle time for a connection, which roughly translates to the {@link Socket#setSoTimeout(int)} call, although with NIO implementations |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
93 * other mechanisms may be used to implement the timeout. The max idle time is applied: |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
94 * <ul> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
95 * <li>When waiting for a new request to be received on a connection</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
96 * <li>When reading the headers and content of a request</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
97 * <li>When writing the headers and content of a response</li> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
98 * </ul> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
99 * Jetty interprets this value as the maximum time between some progress being made on the connection. So if a single byte is read or written, then the |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
100 * timeout (if implemented by jetty) is reset. However, in many instances, the reading/writing is delegated to the JVM, and the semantic is more strictly |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
101 * enforced as the maximum time a single read/write operation can take. Note, that as Jetty supports writes of memory mapped file buffers, then a write may |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
102 * take many 10s of seconds for large content written to a slow device. |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
103 * <p> |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
104 * Previously, Jetty supported separate idle timeouts and IO operation timeouts, however the expense of changing the value of soTimeout was significant, so |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
105 * these timeouts were merged. With the advent of NIO, it may be possible to again differentiate these values (if there is demand). |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
106 * |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
107 * @param maxIdleTime |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
108 * The maxIdleTime to set. |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
109 */ |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
110 |
996 | 111 public final int getSoLingerTime() |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
112 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
113 return _soLingerTime; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
114 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
115 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
116 /* ------------------------------------------------------------ */ |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
117 /** |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
118 * @param soLingerTime |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
119 * The soLingerTime to set or -1 to disable. |
818
ad292e148964
remove util/statistic
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
120 */ |
996 | 121 public final void setSoLingerTime(int soLingerTime) |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
122 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
123 _soLingerTime = soLingerTime; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
124 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
125 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
126 @Override |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
127 protected void doStart() throws Exception |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
128 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
129 super.doStart(); |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
130 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
131 // Start selector thread |
905
e7175965e6cf
remove Connector._acceptorThreads
Franklin Schmidt <fschmidt@gmail.com>
parents:
904
diff
changeset
|
132 ThreadPoolExecutor _threadPool = server.threadPool; |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
133 _threadPool.execute(this); |
905
e7175965e6cf
remove Connector._acceptorThreads
Franklin Schmidt <fschmidt@gmail.com>
parents:
904
diff
changeset
|
134 if (server.isLowOnThreads()) |
e7175965e6cf
remove Connector._acceptorThreads
Franklin Schmidt <fschmidt@gmail.com>
parents:
904
diff
changeset
|
135 LOG.warn("insufficient threads configured for {}",this); |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
136 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
137 LOG.info("Started {}",this); |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
138 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
139 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
140 @Override |
913 | 141 protected synchronized void doStop() throws Exception |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
142 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
143 try |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
144 { |
913 | 145 if (_acceptChannel != null) |
146 _acceptChannel.close(); | |
147 _acceptChannel=null; | |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
148 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
149 catch (IOException e) |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
150 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
151 LOG.warn("",e); |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
152 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
153 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
154 super.doStop(); |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
155 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
156 |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
157 |
914
54308d65265a
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
913
diff
changeset
|
158 protected final void configure(Socket socket) throws IOException |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
159 { |
914
54308d65265a
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
913
diff
changeset
|
160 socket.setTcpNoDelay(true); |
54308d65265a
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
913
diff
changeset
|
161 if (_soLingerTime >= 0) |
54308d65265a
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
913
diff
changeset
|
162 socket.setSoLinger(true,_soLingerTime / 1000); |
54308d65265a
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
913
diff
changeset
|
163 else |
54308d65265a
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
913
diff
changeset
|
164 socket.setSoLinger(false,0); |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
165 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
166 |
1001 | 167 public abstract void customize(AbstractHttpConnection con) throws IOException; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
168 |
972
5ee36654b383
simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents:
956
diff
changeset
|
169 public boolean isConfidential() |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
170 { |
889 | 171 return false; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
172 } |
818
ad292e148964
remove util/statistic
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
173 |
906 | 174 protected abstract void accept() throws IOException, InterruptedException; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
175 |
996 | 176 @Override |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
177 public String toString() |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
178 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
179 return String.format("%s@%s:%d", |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
180 getClass().getSimpleName(), |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
181 getHost()==null?"0.0.0.0":getHost(), |
909 | 182 port); |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
183 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
184 |
909 | 185 |
996 | 186 @Override |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
187 public void run() |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
188 { |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
189 Thread current = Thread.currentThread(); |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
190 String name = current.getName(); |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
191 current.setName(name + " Acceptor" + " " + Connector.this); |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
192 |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
193 try |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
194 { |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
195 while (isRunning() && _acceptChannel != null) |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
196 { |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
197 try |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
198 { |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
199 accept(); |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
200 } |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
201 catch (EofException e) |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
202 { |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
203 LOG.trace("",e); |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
204 } |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
205 catch (IOException e) |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
206 { |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
207 LOG.trace("",e); |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
208 } |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
209 catch (InterruptedException x) |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
210 { |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
211 // Connector has been stopped |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
212 LOG.trace("",x); |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
213 } |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
214 catch (Throwable e) |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
215 { |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
216 LOG.warn("",e); |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
217 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
218 } |
954
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
219 } |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
220 finally |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
221 { |
a021c4c9c244
use just one SelectSet per SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
222 current.setName(name); |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
223 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
224 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
225 |
996 | 226 public final String getName() |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
227 { |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
228 if (_name == null) |
909 | 229 _name = (getHost() == null?"0.0.0.0":getHost()) + ":" + port; |
885
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
230 return _name; |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
231 } |
150092cebf3e
remove AbstractConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
232 |
907
bc4e299de953
remove AbstractNIOConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
906
diff
changeset
|
233 |
1007
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
234 |
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
235 // from HttpBuffersImpl |
907
bc4e299de953
remove AbstractNIOConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
906
diff
changeset
|
236 |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
237 protected int _requestHeaderSize = 6*1024; |
1007
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
238 protected int _requestBufferSize = 16*1024; |
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
239 private final int _responseHeaderSize = 6*1024; |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
240 private final int _responseBufferSize = 32*1024; |
1007
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
241 |
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
242 public final Buffers getRequestBuffers() |
907
bc4e299de953
remove AbstractNIOConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
906
diff
changeset
|
243 { |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
244 return new MyBuffers(_requestHeaderSize,_requestBufferSize); |
1007
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
245 } |
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
246 |
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
247 public final Buffers getResponseBuffers() |
945568ee77ac
remove HttpBuffersImpl
Franklin Schmidt <fschmidt@gmail.com>
parents:
1006
diff
changeset
|
248 { |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
249 return new MyBuffers(_responseHeaderSize,_responseBufferSize); |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
250 } |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
251 |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
252 |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
253 // my own buffers |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
254 |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
255 protected Buffer newBuffer(int size) { |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
256 return new DirectNIOBuffer(size); |
907
bc4e299de953
remove AbstractNIOConnector
Franklin Schmidt <fschmidt@gmail.com>
parents:
906
diff
changeset
|
257 } |
909 | 258 |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
259 private class MyBuffers implements Buffers { |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
260 private final int headerSize; |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
261 private final int bufferSize; |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
262 |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
263 MyBuffers(int headerSize,int bufferSize) { |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
264 this.headerSize = headerSize; |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
265 this.bufferSize = bufferSize; |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
266 } |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
267 |
1016
8c13b9224cff
remove returnBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1011
diff
changeset
|
268 @Override |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
269 public Buffer getHeader() { |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
270 return new IndirectNIOBuffer(headerSize); |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
271 } |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
272 |
1016
8c13b9224cff
remove returnBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1011
diff
changeset
|
273 @Override |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
274 public Buffer getBuffer() { |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
275 return newBuffer(bufferSize); |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
276 } |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
277 |
1016
8c13b9224cff
remove returnBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
1011
diff
changeset
|
278 @Override |
1011
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
279 public Buffer getBuffer(int size) { |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
280 return newBuffer(size); |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
281 } |
4e7208df7741
remove PooledBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents:
1008
diff
changeset
|
282 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
283 } |