1   //========================================================================
2   //Copyright 2004-2008 Mort Bay Consulting Pty. Ltd.
3   //------------------------------------------------------------------------
4   //Licensed under the Apache License, Version 2.0 (the "License");
5   //you may not use this file except in compliance with the License.
6   //You may obtain a copy of the License at 
7   //http://www.apache.org/licenses/LICENSE-2.0
8   //Unless required by applicable law or agreed to in writing, software
9   //distributed under the License is distributed on an "AS IS" BASIS,
10  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  //See the License for the specific language governing permissions and
12  //limitations under the License.
13  //========================================================================
14  
15  package org.mortbay.jetty;
16  
17  import org.mortbay.util.ajax.Continuation;
18  
19  public class Servlet3Continuation implements Continuation
20  {
21      Request _request;
22      Object _object;
23      RetryRequest _retry;
24      
25      Servlet3Continuation(Request request)
26      {
27          _request=request;
28      }
29      
30      public Object getObject()
31      {
32          return _object;
33      }
34  
35      public boolean isExpired()
36      {
37          return _request.isTimeout();
38      }
39  
40      public boolean isNew()
41      {
42          return _retry==null;
43      }
44  
45      public boolean isPending()
46      {
47          return _request.isSuspended() || !_request.isInitial();
48      }
49  
50      public boolean isResumed()
51      {
52          return _request.isResumed();
53      }
54  
55      public void reset()
56      {
57          _request.reset();
58      }
59  
60      public void resume()
61      {
62          System.err.println("Resume");
63          _request.resume();
64      }
65  
66      public void setMutex(Object mutex)
67      {
68      }
69  
70      public void setObject(Object o)
71      {
72          _object=o;
73      }
74  
75      public boolean suspend(long timeout)
76      {
77          System.err.println(_request);
78          if (!_request.isInitial()&&(_request.isResumed()||_request.isTimeout()))
79              return _request.isResumed();
80  
81          _request.suspend(timeout);
82          if (_retry==null)
83              _retry=new RetryRequest();
84          throw _retry;
85          
86      }
87  
88  }