}.start();
}
if (suspend_for>=0)
{
final AsyncContext async=wrap?request.startAsync(new HttpServletRequestWrapper(request),new HttpServletResponseWrapper(response)):request.startAsync();
if (suspend_for>0)
async.setTimeout(suspend_for);
async.addListener(__listener);
response.addHeader("history","suspend");
if (complete_after>0)
{
TimerTask complete = new TimerTask()
{
@Override
public void run()
{
try
{
response.setStatus(200);
response.getOutputStream().println("COMPLETED\n");
response.addHeader("history","complete");
async.complete();
}
catch(Exception e)
{
e.printStackTrace();
}
}
};
synchronized (_timer)
{
_timer.schedule(complete,complete_after);
}
}
else if (complete_after==0)
{
response.setStatus(200);
response.getOutputStream().println("COMPLETED\n");
response.addHeader("history","complete");
async.complete();
}
else if (resume_after>0)
{
TimerTask resume = new TimerTask()
{
@Override
public void run()
{
((HttpServletResponse)async.getResponse()).addHeader("history","resume");
if (path!=null)
{
int q=path.indexOf('?');
String uriInContext=(q>=0)
?URIUtil.encodePath(path.substring(0,q))+path.substring(q)
:URIUtil.encodePath(path);
async.dispatch(uriInContext);
}
else
async.dispatch();
}
};
synchronized (_timer)
{
_timer.schedule(resume,resume_after);
}
}
else if (resume_after==0)
{
((HttpServletResponse)async.getResponse()).addHeader("history","resume");
if (path!=null)
async.dispatch(path);
else
async.dispatch();
}
}
else if (sleep_for>=0)
{
try
{
Thread.sleep(sleep_for);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
response.setStatus(200);
response.getOutputStream().println("SLEPT\n");
}
else
{
response.setStatus(200);
response.getOutputStream().println("NORMAL\n");
}
}
else
{
response.addHeader("history","!initial");
if (suspend2_for>=0 && request.getAttribute("2nd")==null)
{
final AsyncContext async=wrap?request.startAsync(new HttpServletRequestWrapper(request),new HttpServletResponseWrapper(response)):request.startAsync();
async.addListener(__listener);
request.setAttribute("2nd","cycle");
if (suspend2_for>0)
{