annotate src/org/eclipse/jetty/server/handler/IdleTimeoutHandler.java @ 974:7422ca1ae146

remove Connection.isIdle()
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 15 Oct 2016 23:27:08 -0600
parents 3268ddf919d4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.server.handler;
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
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import javax.servlet.AsyncEvent;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import javax.servlet.AsyncListener;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import javax.servlet.ServletException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import javax.servlet.http.HttpServletRequest;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import javax.servlet.http.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import org.eclipse.jetty.io.EndPoint;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.server.AbstractHttpConnection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.server.Request;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 * Handler to adjust the idle timeout of requests while dispatched.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 * <p>Can be applied in jetty.xml with
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 * <pre>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 * &lt;Get id='handler' name='Handler'/>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 * &lt;Set name='Handler'>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 * &lt;New id='idleTimeoutHandler' class='org.eclipse.jetty.server.handler.IdleTimeoutHandler'>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 * &lt;Set name='Handler'>&lt;Ref id='handler'/>&lt;/Set>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 * &lt;Set name='IdleTimeoutMs'>5000&lt;/Set>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 * &lt;/New>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 * &lt;/Set>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 * </pre>
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 public class IdleTimeoutHandler extends HandlerWrapper
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 {
920
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 private int _idleTimeoutMs = 1000;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
50 private boolean _applyToAsync = false;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
53 public boolean isApplyToAsync()
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
55 return _applyToAsync;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
56 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57
920
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
58 /**
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
59 * Should the adjusted idle time be maintained for asynchronous requests
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 * @param applyToAsync true if alternate idle timeout is applied to asynchronous requests
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 */
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62 public void setApplyToAsync(boolean applyToAsync)
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 _applyToAsync = applyToAsync;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66
920
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 public long getIdleTimeoutMs()
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 return _idleTimeoutMs;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71
920
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 /**
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 * @param idleTimeoutMs The idle timeout in MS to apply while dispatched or async
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 */
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 public void setIdleTimeoutMs(int _idleTimeoutMs)
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 this._idleTimeoutMs = _idleTimeoutMs;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 }
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80
920
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 @Override
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84 AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 final EndPoint endp = connection==null?null:connection.getEndPoint();
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 final int idle_timeout;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 if (endp==null)
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 idle_timeout=-1;
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 else
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 idle_timeout=endp.getMaxIdleTime();
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 endp.setMaxIdleTime(_idleTimeoutMs);
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 }
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 try
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 super.handle(target,baseRequest,request,response);
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 }
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 finally
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 if (endp!=null)
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 {
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 endp.setMaxIdleTime(idle_timeout);
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 }
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 }
3268ddf919d4 remove AsyncContinuation.isAsyncStarted()
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 }