@WebServlet(asyncSupported=true)
public class AsyncWrapperServlet
extends javax.servlet.http.HttpServlet
HttpServlet
within a Hystrix thread pool. Subclass this,
create a no-arg constructor in the subclass, and pass the HttpServlet to wrap to the superclass. Then configure the
new subclass to run in web.xml, instead of the old (wrapped) servlet. If you want to control which thread pool a
request ends up executing within, make the wrapped servlet implement
HystrixAwareServlet.getCommandGroupKey(javax.servlet.http.HttpServletRequest)
.Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_COMMAND_GROUP_KEY |
static int |
DEFAULT_CORE_POOL_SIZE |
static long |
DEFAULT_TIMEOUT |
Constructor and Description |
---|
AsyncWrapperServlet(javax.servlet.http.HttpServlet wrappedServlet) |
AsyncWrapperServlet(javax.servlet.http.HttpServlet wrappedServlet,
long timeoutMillis,
int corePoolSize) |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
protected String |
getCommandGroupKey(javax.servlet.http.HttpServlet srv,
javax.servlet.http.HttpServletRequest req) |
void |
init() |
void |
init(javax.servlet.ServletConfig config) |
protected Runnable |
onAfterCommandExecute()
Note that this is called from
service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) , i.e. |
protected void |
onAfterCommandSubmit()
Useful? for subclasses, but really mostly for testing.
|
protected Runnable |
onBeforeCommandSubmit()
Note that this is called from
service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) , i.e. |
protected void |
onHystrixCompleted(javax.servlet.AsyncContext asyncContext)
Override this method if you want to do some extra work when Hystrix is notified that the processing of the
request/response is done.
|
protected void |
onHystrixError(javax.servlet.AsyncContext asyncContext,
Throwable throwable)
Override this method if you want to do some extra work when Hystrix has caught an exception from
HystrixCommand.run() , or if the operation has timed out. |
protected void |
onHystrixNext(javax.servlet.AsyncContext asyncContext,
Object o)
Override this method if you want to do some extra work when Hystrix is notified that the processing of the
request/response is done.
|
protected void |
onServletCompleted(javax.servlet.AsyncEvent asyncEvent)
Override this method if you want to do some extra work when
AsyncContext.complete() has
been called. |
protected void |
onServletError(javax.servlet.AsyncEvent asyncEvent)
Override this method if you want to do some extra work when the servlet container has caught an exception from
service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) . |
protected void |
onServletTimeout(javax.servlet.AsyncEvent asyncEvent)
Override this method if you want to do some extra work when the servlet container has timed out the request.
|
void |
service(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
public static final String DEFAULT_COMMAND_GROUP_KEY
public static final long DEFAULT_TIMEOUT
public static final int DEFAULT_CORE_POOL_SIZE
public AsyncWrapperServlet(javax.servlet.http.HttpServlet wrappedServlet)
public AsyncWrapperServlet(javax.servlet.http.HttpServlet wrappedServlet, long timeoutMillis, int corePoolSize)
public void init() throws javax.servlet.ServletException
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
public void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
service
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException
protected String getCommandGroupKey(javax.servlet.http.HttpServlet srv, javax.servlet.http.HttpServletRequest req)
protected Runnable onBeforeCommandSubmit()
service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
, i.e. by the servlet container thread. The Runnable returned is called
by the Hystrix thread (in a try-catch block, with logging), at the beginning of
HystrixCommand.run()
.protected void onAfterCommandSubmit()
service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
, i.e. by the servlet container thread.protected Runnable onAfterCommandExecute()
service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
, i.e. by the servlet container thread. The Runnable returned is called
by the Hystrix thread (in a try-catch block, with logging, inside a finally block), at the end of HystrixCommand.run()
.protected void onServletCompleted(javax.servlet.AsyncEvent asyncEvent) throws IOException
AsyncContext.complete()
has
been called.asyncEvent
- the AsyncEvent indicating that an asynchronous operation has been completedIOException
- if an I/O related error has occurred during the processing of the given AsyncEventprotected void onServletTimeout(javax.servlet.AsyncEvent asyncEvent) throws IOException
AsyncContext.complete()
is called. Failure to do so will result in strange errors.asyncEvent
- the AsyncEvent indicating that an asynchronous operation has timed outIOException
- if an I/O related error has occurred during the processing of the given AsyncEventprotected void onServletError(javax.servlet.AsyncEvent asyncEvent) throws IOException
service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
. It is HIGHLY recommended to call the implementation in this superclass
as well, to be certain that AsyncContext.complete()
is called. Failure to do so will result
in strange errors.asyncEvent
- the AsyncEvent indicating that an asynchronous operation has failed to completeIOException
- if an I/O related error has occurred during the processing of the given AsyncEventprotected void onHystrixCompleted(javax.servlet.AsyncContext asyncContext)
AsyncContext.complete()
is called. Failure to do so will result in strange
errors.asyncContext
- The AsyncContext to complete.protected void onHystrixError(javax.servlet.AsyncContext asyncContext, Throwable throwable)
HystrixCommand.run()
, or if the operation has timed out. It is HIGHLY recommended to call
the implementation in this superclass as well, to be certain that AsyncContext.complete()
is called. Failure to do so will result in strange errors.asyncContext
- The AsyncContext to complete.throwable
- The Throwable caught.protected void onHystrixNext(javax.servlet.AsyncContext asyncContext, Object o)
AsyncContext.complete()
is called. Failure to do so will result in strange
errors.asyncContext
- The AsyncContext to complete.o
- In our implementation, a dummy object that is not useful in any way.Copyright © 2015. All rights reserved.