Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/AsyncContinuation.java @ 937:0541b6034003
remove Continuation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 09 Oct 2016 21:41:28 -0600 |
parents | 237ace6e8bc2 |
children | a088981f9cd4 |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.server; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import org.eclipse.jetty.io.EndPoint; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
22 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
23 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 |
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
25 |
937 | 26 public final class AsyncContinuation |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 { |
865 | 28 private static final Logger LOG = LoggerFactory.getLogger(AsyncContinuation.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
865 | 30 private final static long DEFAULT_TIMEOUT=30000L; |
931
6f7e2ff51879
remove ContinuationThrowable
Franklin Schmidt <fschmidt@gmail.com>
parents:
930
diff
changeset
|
31 |
865 | 32 // STATES: |
33 // handling() suspend() unhandle() resume() complete() doComplete() | |
34 // startAsync() dispatch() | |
35 // IDLE DISPATCHED | |
36 // DISPATCHED ASYNCSTARTED UNCOMPLETED | |
37 // ASYNCSTARTED ASYNCWAIT REDISPATCHING COMPLETING | |
38 // REDISPATCHING REDISPATCHED | |
39 // ASYNCWAIT REDISPATCH COMPLETING | |
40 // REDISPATCH REDISPATCHED | |
41 // REDISPATCHED ASYNCSTARTED UNCOMPLETED | |
42 // COMPLETING UNCOMPLETED UNCOMPLETED | |
43 // UNCOMPLETED COMPLETED | |
44 // COMPLETED | |
45 private static final int __IDLE=0; // Idle request | |
46 private static final int __DISPATCHED=1; // Request dispatched to filter/servlet | |
47 private static final int __UNCOMPLETED=8; // Request is completable | |
48 private static final int __COMPLETED=9; // Request is complete | |
49 | |
50 /* ------------------------------------------------------------ */ | |
51 protected AbstractHttpConnection _connection; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 |
865 | 53 /* ------------------------------------------------------------ */ |
54 private int _state; | |
55 | |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
56 AsyncContinuation() |
865 | 57 { |
58 _state=__IDLE; | |
59 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
60 |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
61 protected synchronized void setConnection(final AbstractHttpConnection connection) |
865 | 62 { |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
63 _connection=connection; |
865 | 64 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
65 |
865 | 66 |
67 @Override | |
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
68 public synchronized String toString() |
865 | 69 { |
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
70 return super.toString()+"@"+getStatusString(); |
865 | 71 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
72 |
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
73 private synchronized String getStatusString() |
865 | 74 { |
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
75 return |
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
76 ((_state==__IDLE)?"IDLE": |
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
77 (_state==__DISPATCHED)?"DISPATCHED": |
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
78 (_state==__UNCOMPLETED)?"UNCOMPLETED": |
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
79 (_state==__COMPLETED)?"COMPLETE": |
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
80 ("UNKNOWN?"+_state)); |
865 | 81 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
82 |
929 | 83 protected synchronized void handling() |
865 | 84 { |
929 | 85 switch(_state) |
865 | 86 { |
929 | 87 case __IDLE: |
88 _state=__DISPATCHED; | |
89 return; | |
90 | |
91 default: | |
92 throw new IllegalStateException(this.getStatusString()); | |
865 | 93 } |
94 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
95 |
865 | 96 /* ------------------------------------------------------------ */ |
97 /** | |
98 * Signal that the HttpConnection has finished handling the request. | |
99 * For blocking connectors, this call may block if the request has | |
100 * been suspended (startAsync called). | |
101 * @return true if handling is complete, false if the request should | |
102 * be handled again (eg because of a resume that happened before unhandle was called) | |
103 */ | |
928 | 104 protected synchronized void unhandle() |
865 | 105 { |
928 | 106 switch(_state) |
865 | 107 { |
928 | 108 case __DISPATCHED: |
109 _state = __UNCOMPLETED; | |
110 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
111 |
928 | 112 default: |
113 throw new IllegalStateException(this.getStatusString()); | |
865 | 114 } |
115 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
116 |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
117 |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
118 protected synchronized void doComplete(Throwable ex) |
865 | 119 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
120 switch(_state) |
865 | 121 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
122 case __UNCOMPLETED: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
123 _state = __COMPLETED; |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
124 break; |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
125 |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
126 default: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
127 throw new IllegalStateException(this.getStatusString()); |
865 | 128 } |
129 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
130 |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
131 protected synchronized void recycle() |
865 | 132 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
133 switch(_state) |
865 | 134 { |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
135 case __DISPATCHED: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
136 throw new IllegalStateException(getStatusString()); |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
137 default: |
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
138 _state=__IDLE; |
865 | 139 } |
935
aa7dc1802d29
remove ContinuationListener
Franklin Schmidt <fschmidt@gmail.com>
parents:
934
diff
changeset
|
140 cancelTimeout(); |
865 | 141 } |
142 | |
936
237ace6e8bc2
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
935
diff
changeset
|
143 private void cancelTimeout() |
865 | 144 { |
145 EndPoint endp=_connection.getEndPoint(); | |
146 if (endp.isBlocking()) | |
147 { | |
148 synchronized(this) | |
149 { | |
150 this.notifyAll(); | |
151 } | |
152 } | |
153 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
154 |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
155 synchronized boolean isUncompleted() |
865 | 156 { |
934
fe461f7cfc8e
simplify AsyncContinuation
Franklin Schmidt <fschmidt@gmail.com>
parents:
933
diff
changeset
|
157 return _state==__UNCOMPLETED; |
865 | 158 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
159 } |