Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java @ 889:5731a7707466
remove _forwarded
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 06 Oct 2016 23:24:30 -0600 |
parents | 1aa58272794f |
children | 769040d68b0a |
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.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.net.InetSocketAddress; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.net.Socket; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.nio.channels.ByteChannel; |
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.ServerSocketChannel; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import java.nio.channels.SocketChannel; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import java.util.Set; |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
29 import java.util.concurrent.ConcurrentHashMap; |
865 | 30 import java.util.concurrent.RejectedExecutionException; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import org.eclipse.jetty.http.HttpException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import org.eclipse.jetty.io.Buffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.io.ConnectedEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.io.Connection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import org.eclipse.jetty.io.EndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 import org.eclipse.jetty.io.EofException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 import org.eclipse.jetty.io.nio.ChannelEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 import org.eclipse.jetty.server.BlockingHttpConnection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 import org.eclipse.jetty.server.Request; |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
41 import org.eclipse.jetty.server.Server; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
42 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
43 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 /* ------------------------------------------------------------------------------- */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 /** Blocking NIO connector. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 * This connector uses efficient NIO buffers with a traditional blocking thread model. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 * Direct NIO buffers are used and a thread is allocated per connections. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 * This connector is best used when there are a few very active connections. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 * @org.apache.xbean.XBean element="blockingNioConnector" description="Creates a blocking NIO based socket connector" |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 public class BlockingChannelConnector extends AbstractNIOConnector |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 { |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
60 private static final Logger LOG = LoggerFactory.getLogger(BlockingChannelConnector.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
61 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
62 private transient ServerSocketChannel _acceptChannel; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
63 private final Set<BlockingChannelEndPoint> _endpoints = new ConcurrentHashMap<BlockingChannelEndPoint,Boolean>().newKeySet(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
65 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
66 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
67 /** Constructor. |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
68 * |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
69 */ |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
70 public BlockingChannelConnector(Server server,int port) |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
71 { |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
72 super(server,port); |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
73 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
74 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
75 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
76 public Object getConnection() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
77 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
78 return _acceptChannel; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
79 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
81 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
82 /** |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
83 * @see org.eclipse.jetty.server.AbstractConnector#doStart() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
84 */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
85 @Override |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
86 protected void doStart() throws Exception |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
87 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
88 super.doStart(); |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
89 server.threadPool.execute(new Runnable() |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
90 { |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
91 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
92 public void run() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
93 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
94 while (isRunning()) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
95 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
96 try |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
97 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
98 Thread.sleep(400); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
99 long now=System.currentTimeMillis(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
100 for (BlockingChannelEndPoint endp : _endpoints) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
101 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
102 endp.checkIdleTimestamp(now); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
103 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
104 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
105 catch(InterruptedException e) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
106 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
107 LOG.trace("",e); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
108 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
109 catch(Exception e) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
110 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
111 LOG.warn("",e); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
112 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
113 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
114 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
115 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
116 }); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
117 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
118 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
119 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
120 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
121 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
122 public void open() throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
123 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
124 // Create a new server socket and set to non blocking mode |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
125 _acceptChannel= ServerSocketChannel.open(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
126 _acceptChannel.configureBlocking(true); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
127 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
128 // Bind the server socket to the local host and port |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
129 InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port); |
888
1aa58272794f
remove _acceptQueueSize
Franklin Schmidt <fschmidt@gmail.com>
parents:
887
diff
changeset
|
130 _acceptChannel.socket().bind(addr,0); |
840
0f53601ea489
remove ConcurrentHashSet
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 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
133 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
134 public void close() throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
135 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
136 if (_acceptChannel != null) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
137 _acceptChannel.close(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
138 _acceptChannel=null; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
139 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
140 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
141 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
142 @Override |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
143 public void accept(int acceptorID) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
144 throws IOException, InterruptedException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
145 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
146 SocketChannel channel = _acceptChannel.accept(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
147 channel.configureBlocking(true); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
148 Socket socket=channel.socket(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
149 configure(socket); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
150 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
151 BlockingChannelEndPoint connection=new BlockingChannelEndPoint(channel); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
152 connection.dispatch(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
153 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
154 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
155 /* ------------------------------------------------------------------------------- */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
156 @Override |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
157 public void customize(EndPoint endpoint, Request request) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
158 throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
159 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
160 super.customize(endpoint, request); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
161 endpoint.setMaxIdleTime(_maxIdleTime); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
162 configure(((SocketChannel)endpoint.getTransport()).socket()); |
0f53601ea489
remove ConcurrentHashSet
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 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
165 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
166 /* ------------------------------------------------------------------------------- */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
167 public int getLocalPort() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
168 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
169 if (_acceptChannel==null || !_acceptChannel.isOpen()) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
170 return -1; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
171 return _acceptChannel.socket().getLocalPort(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
172 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
173 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
174 /* ------------------------------------------------------------------------------- */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
175 /* ------------------------------------------------------------------------------- */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
176 /* ------------------------------------------------------------------------------- */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
177 private class BlockingChannelEndPoint extends ChannelEndPoint implements Runnable, ConnectedEndPoint |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
178 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
179 private Connection _connection; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
180 private int _timeout; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
181 private volatile long _idleTimestamp; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
182 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
183 BlockingChannelEndPoint(ByteChannel channel) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
184 throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
185 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
186 super(channel,BlockingChannelConnector.this._maxIdleTime); |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
187 _connection = new BlockingHttpConnection(BlockingChannelConnector.this,this,server); |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
188 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
189 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
190 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
191 /** Get the connection. |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
192 * @return the connection |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
193 */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
194 public Connection getConnection() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
195 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
196 return _connection; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
197 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
198 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
199 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
200 public void setConnection(Connection connection) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
201 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
202 _connection=connection; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
203 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
204 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
205 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
206 public void checkIdleTimestamp(long now) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
207 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
208 if (_idleTimestamp!=0 && _timeout>0 && now>(_idleTimestamp+_timeout)) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
209 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
210 idleExpired(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
211 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
212 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
213 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
214 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
215 protected void idleExpired() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
216 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
217 try |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
218 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
219 super.close(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
220 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
221 catch (IOException e) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
222 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
223 LOG.trace("",e); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
224 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
225 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
226 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
227 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
228 void dispatch() throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
229 { |
865 | 230 try { |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
231 server.threadPool.execute(this); |
865 | 232 } catch(RejectedExecutionException e) { |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
233 LOG.warn("dispatch failed for {}",_connection); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
234 super.close(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
235 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
236 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
237 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
238 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
239 /** |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
240 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#fill(org.eclipse.jetty.io.Buffer) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
241 */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
242 @Override |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
243 public int fill(Buffer buffer) throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
244 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
245 _idleTimestamp=System.currentTimeMillis(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
246 return super.fill(buffer); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
247 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
249 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
250 /** |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
251 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#flush(org.eclipse.jetty.io.Buffer) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
252 */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
253 @Override |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
254 public int flush(Buffer buffer) throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
255 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
256 _idleTimestamp=System.currentTimeMillis(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
257 return super.flush(buffer); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
258 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
259 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
260 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
261 /** |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
262 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#flush(org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
263 */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
264 @Override |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
265 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
266 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
267 _idleTimestamp=System.currentTimeMillis(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
268 return super.flush(header,buffer,trailer); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
269 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
270 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
271 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
272 public void run() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
273 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
274 try |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
275 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
276 _timeout=getMaxIdleTime(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
277 connectionOpened(_connection); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
278 _endpoints.add(this); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
279 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
280 while (isOpen()) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
281 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
282 _idleTimestamp=System.currentTimeMillis(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
283 if (_connection.isIdle()) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
284 { |
887
df84a1741687
make Connector reference to server explicit
Franklin Schmidt <fschmidt@gmail.com>
parents:
865
diff
changeset
|
285 if (server.isLowOnThreads()) |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
286 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
287 int lrmit = getLowResourcesMaxIdleTime(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
288 if (lrmit>=0 && _timeout!= lrmit) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
289 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
290 _timeout=lrmit; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
291 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
292 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
293 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
294 else |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
295 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
296 if (_timeout!=getMaxIdleTime()) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
297 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
298 _timeout=getMaxIdleTime(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
299 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
300 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
301 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
302 _connection = _connection.handle(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
303 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
304 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
305 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
306 catch (EofException e) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
307 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
308 LOG.debug("EOF", e); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
309 try{BlockingChannelEndPoint.this.close();} |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
310 catch(IOException e2){LOG.trace("",e2);} |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
311 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
312 catch (HttpException e) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
313 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
314 LOG.debug("BAD", e); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
315 try{super.close();} |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
316 catch(IOException e2){LOG.trace("",e2);} |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
317 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
318 catch(Throwable e) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
319 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
320 LOG.warn("handle failed",e); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
321 try{super.close();} |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
322 catch(IOException e2){LOG.trace("",e2);} |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
323 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
324 finally |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
325 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
326 connectionClosed(_connection); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
327 _endpoints.remove(this); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
328 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
329 // wait for client to close, but if not, close ourselves. |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
330 try |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
331 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
332 if (!_socket.isClosed()) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
333 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
334 long timestamp=System.currentTimeMillis(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
335 int max_idle=getMaxIdleTime(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
336 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
337 _socket.setSoTimeout(getMaxIdleTime()); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
338 int c=0; |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
339 do |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
340 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
341 c = _socket.getInputStream().read(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
342 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
343 while (c>=0 && (System.currentTimeMillis()-timestamp)<max_idle); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
344 if (!_socket.isClosed()) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
345 _socket.close(); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
346 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
347 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
348 catch(IOException e) |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
349 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
350 LOG.trace("",e); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
351 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
352 } |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
353 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
354 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
355 /* ------------------------------------------------------------ */ |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
356 @Override |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
357 public String toString() |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
358 { |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
359 return String.format("BCEP@%x{l(%s)<->r(%s),open=%b,ishut=%b,oshut=%b}-{%s}", |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
360 hashCode(), |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
361 _socket.getRemoteSocketAddress(), |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
362 _socket.getLocalSocketAddress(), |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
363 isOpen(), |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
364 isInputShutdown(), |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
365 isOutputShutdown(), |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
366 _connection); |
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
367 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
368 |
840
0f53601ea489
remove ConcurrentHashSet
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
369 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
370 } |