Class SilverpeasAsyncContext

  • All Implemented Interfaces:
    javax.servlet.AsyncContext, SilverpeasServerEventContext

    public class SilverpeasAsyncContext
    extends Object
    implements javax.servlet.AsyncContext
    This is a wrap of a AsyncContext instance.

    All Server Event requests performed from a HTTP Server Sent Event WEB API MUST be wrapped by this implementation and registered by SilverpeasServerEventContextManager.

    Author:
    Yohann Chastagnier
    • Method Detail

      • wrap

        public static SilverpeasAsyncContext wrap​(SilverLogger silverLogger,
                                                  javax.servlet.AsyncContext asyncContext,
                                                  String userSessionId,
                                                  User user)
                                           throws javax.servlet.ServletException
        Wraps the given instance. Nothing is wrapped if the given instance is a wrapped one.
        Parameters:
        silverLogger - the sse silverpeas logger.
        asyncContext - the instance to wrap.
        userSessionId - the identifier or the user session.
        user - the identifier of th user linked to the async request.
        Returns:
        the wrapped given instance.
        Throws:
        javax.servlet.ServletException
      • sendHeartbeatIfEnabled

        public void sendHeartbeatIfEnabled()
        Description copied from interface: SilverpeasServerEventContext
        Sends 'heartbeat' event if it has been indicated to the context that it MUST have theis behavior.

        This is useful for old WEB browser implementations which do not implement entirely server event API.

        By default, noting is performed.

        Specified by:
        sendHeartbeatIfEnabled in interface SilverpeasServerEventContext
      • isSendPossible

        public boolean isSendPossible()
        Indicates if sending is possible according to the state of the context.
        Specified by:
        isSendPossible in interface SilverpeasServerEventContext
        Returns:
        true if send is possible, false otherwise.
      • getRequest

        public javax.servlet.http.HttpServletRequest getRequest()
        Specified by:
        getRequest in interface javax.servlet.AsyncContext
      • getResponse

        public javax.servlet.http.HttpServletResponse getResponse()
        Specified by:
        getResponse in interface javax.servlet.AsyncContext
      • hasOriginalRequestAndResponse

        public boolean hasOriginalRequestAndResponse()
        Specified by:
        hasOriginalRequestAndResponse in interface javax.servlet.AsyncContext
      • dispatch

        public void dispatch()
        Specified by:
        dispatch in interface javax.servlet.AsyncContext
      • dispatch

        public void dispatch​(String path)
        Specified by:
        dispatch in interface javax.servlet.AsyncContext
      • dispatch

        public void dispatch​(javax.servlet.ServletContext context,
                             String path)
        Specified by:
        dispatch in interface javax.servlet.AsyncContext
      • complete

        public void complete()
        Specified by:
        complete in interface javax.servlet.AsyncContext
      • setHeartbeat

        public void setHeartbeat​(boolean heartbeat)
      • isComplete

        public boolean isComplete()
      • start

        public void start​(Runnable run)
        Specified by:
        start in interface javax.servlet.AsyncContext
      • addListener

        public void addListener​(javax.servlet.AsyncListener listener)
        Specified by:
        addListener in interface javax.servlet.AsyncContext
      • addListener

        public void addListener​(javax.servlet.AsyncListener listener,
                                javax.servlet.ServletRequest servletRequest,
                                javax.servlet.ServletResponse servletResponse)
        Specified by:
        addListener in interface javax.servlet.AsyncContext
      • createListener

        public <T extends javax.servlet.AsyncListener> T createListener​(Class<T> clazz)
                                                                 throws javax.servlet.ServletException
        Specified by:
        createListener in interface javax.servlet.AsyncContext
        Throws:
        javax.servlet.ServletException
      • getTimeout

        public long getTimeout()
        Specified by:
        getTimeout in interface javax.servlet.AsyncContext
      • setTimeout

        public void setTimeout​(long timeout)
        Specified by:
        setTimeout in interface javax.servlet.AsyncContext
      • hashCode

        public int hashCode()
      • equals

        public boolean equals​(Object obj)
      • toString

        public String toString()
      • getSessionId

        public String getSessionId()
        Description copied from interface: SilverpeasServerEventContext
        Gets the session identifier linked to the context.

        Be careful, according to the WEB context, the session identifier is not necessarily the JSESSIONID.

        Specified by:
        getSessionId in interface SilverpeasServerEventContext
        Returns:
        a session identifier as string.
      • setLastServerEventId

        public void setLastServerEventId​(Long lastServerEventId)
        Sets the last server event identifier.
        Specified by:
        setLastServerEventId in interface SilverpeasServerEventContext
        Parameters:
        lastServerEventId - a last event identifier as long, can be null.
      • getWrappedInstance

        protected W getWrappedInstance()
      • sendEvent

        public boolean sendEvent​(String name,
                                 long id,
                                 String data)
                          throws IOException
        Description copied from interface: SilverpeasServerEventContext
        Sends the given using elements of the context.

        If sending has not been done, then context is removed from the context manager.

        Specified by:
        sendEvent in interface SilverpeasServerEventContext
        Parameters:
        name - the name of the event.
        id - the unique identifier of the event (from the start of the server).
        data - the data sent with the event.
        Returns:
        true if send has been done, false otherwise.
        Throws:
        IOException