Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/nio/SelectChannelConnector.java @ 875:b9aa175d9a29
remove Server.getThreadPool()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 04 Oct 2016 13:45:47 -0600 |
parents | 6b210bb66c63 |
children | df84a1741687 |
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.SelectionKey; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.nio.channels.ServerSocketChannel; |
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 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import org.eclipse.jetty.continuation.Continuation; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 import org.eclipse.jetty.io.AsyncEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import org.eclipse.jetty.io.ConnectedEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 import org.eclipse.jetty.io.Connection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import org.eclipse.jetty.io.EndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import org.eclipse.jetty.io.nio.AsyncConnection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.io.nio.SelectChannelEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.io.nio.SelectorManager; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import org.eclipse.jetty.io.nio.SelectorManager.SelectSet; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 import org.eclipse.jetty.server.AsyncHttpConnection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 import org.eclipse.jetty.server.Request; |
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 * Selecting NIO connector. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 * This connector uses efficient NIO buffers with a non blocking threading model. Direct NIO buffers |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 * are used and threads are only allocated to connections with requests. Synchronization is used to |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 * simulate blocking for the servlet API, and any unflushed content at the end of request handling |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 * is written asynchronously. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 * This connector is best used when there are a many connections that have idle periods. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 * When used with {@link org.eclipse.jetty.continuation.Continuation}, threadless waits are supported. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 * If a filter or servlet returns after calling {@link Continuation#suspend()} or when a |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 * runtime exception is thrown from a call to {@link Continuation#undispatch()}, Jetty will |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 * will not send a response to the client. Instead the thread is released and the Continuation is |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 * placed on the timer queue. If the Continuation timeout expires, or it's |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 * resume method is called, then the request is again allocated a thread and the request is retried. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 * The limitation of this approach is that request content is not available on the retried request, |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
60 * thus if possible it should be read after the continuation or saved as a request attribute or as the |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
61 * associated object of the Continuation instance. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
62 * </p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
63 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 * @org.apache.xbean.XBean element="nioConnector" description="Creates an NIO based socket connector" |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
65 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
66 public class SelectChannelConnector extends AbstractNIOConnector |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
67 { |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
68 protected ServerSocketChannel _acceptChannel; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
69 private int _lowResourcesConnections; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
70 private int _lowResourcesMaxIdleTime; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
71 private int _localPort=-1; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
72 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
73 private final SelectorManager _manager = new ConnectorSelectorManager(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
74 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
75 /* ------------------------------------------------------------------------------- */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
76 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
77 * Constructor. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
78 * |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
79 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
80 public SelectChannelConnector() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
81 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
82 _manager.setMaxIdleTime(getMaxIdleTime()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
83 addBean(_manager,true); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
84 setAcceptors(Math.max(1,(Runtime.getRuntime().availableProcessors()+3)/4)); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
85 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
86 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
87 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
88 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
89 public void accept(int acceptorID) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
90 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
91 ServerSocketChannel server; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
92 synchronized(this) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
93 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
94 server = _acceptChannel; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
95 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
96 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
97 if (server!=null && server.isOpen() && _manager.isStarted()) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
98 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
99 SocketChannel channel = server.accept(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
100 channel.configureBlocking(false); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
101 Socket socket = channel.socket(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
102 configure(socket); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
103 _manager.register(channel); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
104 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
105 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
106 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
107 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
108 public void close() throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
109 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
110 synchronized(this) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
111 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
112 if (_acceptChannel != null) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
113 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
114 removeBean(_acceptChannel); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
115 if (_acceptChannel.isOpen()) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
116 _acceptChannel.close(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
117 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
118 _acceptChannel = null; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
119 _localPort=-2; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
120 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
121 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
122 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
123 /* ------------------------------------------------------------------------------- */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
124 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
125 public void customize(EndPoint endpoint, Request request) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
126 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
127 request.setTimeStamp(System.currentTimeMillis()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
128 endpoint.setMaxIdleTime(_maxIdleTime); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
129 super.customize(endpoint, request); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
130 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
131 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
132 /* ------------------------------------------------------------------------------- */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
133 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
134 public void persist(EndPoint endpoint) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
135 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
136 AsyncEndPoint aEndp = ((AsyncEndPoint)endpoint); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
137 aEndp.setCheckForIdle(true); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
138 super.persist(endpoint); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
139 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
140 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
141 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
142 public SelectorManager getSelectorManager() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
143 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
144 return _manager; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
145 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
146 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
147 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
148 public synchronized Object getConnection() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
149 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
150 return _acceptChannel; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
151 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
152 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
153 /* ------------------------------------------------------------------------------- */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
154 public int getLocalPort() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
155 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
156 synchronized(this) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
157 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
158 return _localPort; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
159 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
160 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
161 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
162 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
163 public void open() throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
164 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
165 synchronized(this) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
166 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
167 if (_acceptChannel == null) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
168 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
169 // Create a new server socket |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
170 _acceptChannel = ServerSocketChannel.open(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
171 // Set to blocking mode |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
172 _acceptChannel.configureBlocking(true); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
173 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
174 // Bind the server socket to the local host and port |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
175 _acceptChannel.socket().setReuseAddress(getReuseAddress()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
176 InetSocketAddress addr = getHost()==null?new InetSocketAddress(getPort()):new InetSocketAddress(getHost(),getPort()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
177 _acceptChannel.socket().bind(addr,getAcceptQueueSize()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
178 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
179 _localPort=_acceptChannel.socket().getLocalPort(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
180 if (_localPort<=0) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
181 throw new IOException("Server channel not bound"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
182 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
183 addBean(_acceptChannel); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
184 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
185 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
186 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
188 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
189 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
190 public void setMaxIdleTime(int maxIdleTime) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
191 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
192 _manager.setMaxIdleTime(maxIdleTime); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
193 super.setMaxIdleTime(maxIdleTime); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
194 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
196 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
197 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
198 * @return the lowResourcesConnections |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
199 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
200 public int getLowResourcesConnections() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
201 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
202 return _lowResourcesConnections; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
203 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
204 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
205 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
206 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
207 * Set the number of connections, which if exceeded places this manager in low resources state. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
208 * This is not an exact measure as the connection count is averaged over the select sets. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
209 * @param lowResourcesConnections the number of connections |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
210 * @see #setLowResourcesMaxIdleTime(int) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
211 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
212 public void setLowResourcesConnections(int lowResourcesConnections) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
213 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
214 _lowResourcesConnections=lowResourcesConnections; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
215 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
216 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
217 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
218 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
219 * @return the lowResourcesMaxIdleTime |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
220 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
221 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
222 public int getLowResourcesMaxIdleTime() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
223 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
224 return _lowResourcesMaxIdleTime; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
225 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
226 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
227 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
228 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
229 * Set the period in ms that a connection is allowed to be idle when this there are more |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
230 * than {@link #getLowResourcesConnections()} connections. This allows the server to rapidly close idle connections |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
231 * in order to gracefully handle high load situations. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
232 * @param lowResourcesMaxIdleTime the period in ms that a connection is allowed to be idle when resources are low. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
233 * @see #setMaxIdleTime(int) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
234 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
235 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
236 public void setLowResourcesMaxIdleTime(int lowResourcesMaxIdleTime) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
237 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
238 _lowResourcesMaxIdleTime=lowResourcesMaxIdleTime; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
239 super.setLowResourcesMaxIdleTime(lowResourcesMaxIdleTime); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
240 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
241 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
242 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
243 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
244 /* |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
245 * @see org.eclipse.jetty.server.server.AbstractConnector#doStart() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
246 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
247 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
248 protected void doStart() throws Exception |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
249 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
250 _manager.setSelectSets(getAcceptors()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
251 _manager.setMaxIdleTime(getMaxIdleTime()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
252 _manager.setLowResourcesConnections(getLowResourcesConnections()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
253 _manager.setLowResourcesMaxIdleTime(getLowResourcesMaxIdleTime()); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
254 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
255 super.doStart(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
256 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
257 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
258 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
259 protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
260 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
261 SelectChannelEndPoint endp= new SelectChannelEndPoint(channel,selectSet,key, SelectChannelConnector.this._maxIdleTime); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
262 endp.setConnection(selectSet.getManager().newConnection(channel,endp, key.attachment())); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
263 return endp; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
264 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
265 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
266 /* ------------------------------------------------------------------------------- */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
267 protected void endPointClosed(SelectChannelEndPoint endpoint) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
268 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
269 connectionClosed(endpoint.getConnection()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
270 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
271 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
272 /* ------------------------------------------------------------------------------- */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
273 protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
274 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
275 return new AsyncHttpConnection(SelectChannelConnector.this,endpoint,getServer()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
276 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
277 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
278 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
279 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
280 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
281 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
282 private final class ConnectorSelectorManager extends SelectorManager |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
283 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
284 @Override |
865 | 285 public void execute(Runnable task) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
286 { |
865 | 287 getThreadPool().execute(task); |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
288 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
289 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
290 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
291 protected void endPointClosed(final SelectChannelEndPoint endpoint) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
292 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
293 SelectChannelConnector.this.endPointClosed(endpoint); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
294 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
295 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
296 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
297 protected void endPointOpened(SelectChannelEndPoint endpoint) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
298 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
299 // TODO handle max connections and low resources |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
300 connectionOpened(endpoint.getConnection()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
301 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
303 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
304 protected void endPointUpgraded(ConnectedEndPoint endpoint, Connection oldConnection) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
305 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
306 connectionUpgraded(oldConnection,endpoint.getConnection()); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
307 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
308 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
309 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
310 public AsyncConnection newConnection(SocketChannel channel,AsyncEndPoint endpoint, Object attachment) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
311 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
312 return SelectChannelConnector.this.newConnection(channel,endpoint); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
313 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
314 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
315 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
316 protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey sKey) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
317 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
318 return SelectChannelConnector.this.newEndPoint(channel,selectSet,sKey); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
319 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
320 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
321 } |