Interface SilverpeasServerEventContext

  • All Known Implementing Classes:
    SilverpeasAsyncContext, SilverpeasWebSocketContext

    public interface SilverpeasServerEventContext
    Definition of a Server Event context.

    Servent Event can be requested from different kinds of WEB context:

    • SSE, Server Sent Event, which is using HTTP protocol
    • WebSocket, which is using the websocket one. Technically, on client side, a WebSocket MUST be created to mimic an EventSource behavior.

    This interface allows to handle these contexts by Silverpeas's Server Event API, regardless the WEB context.

    Author:
    silveryocha
    • Method Detail

      • getRequestURI

        String getRequestURI()
        Gets the request URI from which the context has been initialized (HTTP or WEBSOCKET).
        Returns:
        a string representing a URI.
      • getSessionId

        String getSessionId()
        Gets the session identifier linked to the context.

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

        Returns:
        a session identifier as string.
      • getUser

        User getUser()
        Gets the user identifier linked to the context.
        Returns:
        a user identifier as string.
      • setLastServerEventId

        void setLastServerEventId​(Long lastServerEventId)
        Sets the last server event identifier known before a network breakdown.
        Parameters:
        lastServerEventId - a long representing a unique identifier (from server starting).
      • getLastServerEventId

        Long getLastServerEventId()
        Gets the last server event identifier known before a network breakdown.
        Returns:
        an identifier as string.
      • isSendPossible

        boolean isSendPossible()
        Indicates if the sending is yet possible.
        Returns:
        true if possible, false otherwise.
      • sendEvent

        boolean sendEvent​(String name,
                          long id,
                          String data)
                   throws IOException
        Sends the given using elements of the context.

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

        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
      • closeOnPreviousCheckFailure

        default void closeOnPreviousCheckFailure()
        Performs a check on the context and close it if a failure is detected.

        By default, noting is performed.

      • sendHeartbeatIfEnabled

        default void sendHeartbeatIfEnabled()
        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.