Class Meteor


  • public class Meteor
    extends java.lang.Object
    A Meteor is a simple class that can be used from a Servlet to suspend, broadcast and resume responses. A Meteor can be created by invoking the build() method.

    Meteor.build(HttpServletRequest).suspend(-1);

    A Meteor is usually created when an application needs to suspend a response. A Meteor instance can then be cached and re-used later for either broadcasting a message, or when an application needs to resume the suspended response.

    Author:
    Jeanfrancois Arcand
    • Method Detail

      • lookup

        public static Meteor lookup​(jakarta.servlet.http.HttpServletRequest r)
        Retrieve an instance of Meteor based on the HttpServletRequest.
        Parameters:
        r - HttpServletRequest
        Returns:
        a Meteor or null if not found
      • build

        public static Meteor build​(jakarta.servlet.http.HttpServletRequest r)
        Create a Meteor using the HttpServletRequest.
        Parameters:
        r - an HttpServletRequest
        Returns:
        a Meteor than can be used to resume, suspend and broadcast Object
      • build

        public static Meteor build​(jakarta.servlet.http.HttpServletRequest r,
                                   Serializer s)
        Create a Meteor using the HttpServletRequest and use the Serializer for writing the result of a broadcast operation using the HttpServletResponse.
        Parameters:
        r - an HttpServletRequest
        s - a Serializer used when writing broadcast events
        Returns:
        a Meteor than can be used to resume, suspend and broadcast Object
      • build

        public static Meteor build​(jakarta.servlet.http.HttpServletRequest req,
                                   java.util.List<BroadcastFilter> l,
                                   Serializer s)
        Create a Meteor using the HttpServletRequest and use a list of BroadcastFilter and Serializer for writing the result of a broadcast operation the HttpServletResponse.
        Parameters:
        req - an HttpServletRequest
        l - a list of BroadcastFilter
        s - a Serializer used when writing broadcast events
        Returns:
        a Meteor than can be used to resume, suspend and broadcast Object
      • suspend

        public Meteor suspend​(long l)
        Suspend the underlying HttpServletResponse. Passing a value of -1 suspends the response forever.
        Parameters:
        l - the maximum time a response stay suspended
        Returns:
        Meteor
      • resumeOnBroadcast

        public Meteor resumeOnBroadcast​(boolean resumeOnBroadcast)
        Resume the Meteor after the first broadcast operation. This is useful when long-polling is used.
        Parameters:
        resumeOnBroadcast -
        Returns:
        this
      • suspend

        public Meteor suspend​(long timeout,
                              java.util.concurrent.TimeUnit timeunit)
        Suspend the underlying HttpServletResponse. Passing a value of -1 suspends the response forever.
        Parameters:
        timeout - the maximum time a response stay suspended
        timeunit - The time unit of the timeout value
        Returns:
        Meteor
      • resume

        public Meteor resume()
        Resume the underlying HttpServletResponse.
        Returns:
        Meteor
      • broadcast

        public Meteor broadcast​(java.lang.Object o)
        Broadcast an Object to all suspended responses.
        Parameters:
        o - an Object
        Returns:
        Meteor
      • schedule

        public Meteor schedule​(java.lang.Object o,
                               long period)
        Schedule a periodic broadcast, in seconds.
        Parameters:
        o - an Object
        period - period in seconds
        Returns:
        Meteor
      • delayBroadadcast

        public Meteor delayBroadadcast​(java.lang.Object o,
                                       long period)
        Schedule a delayed broadcast, in seconds.
        Parameters:
        o - an Object
        period - period in seconds
        Returns:
        Meteor
      • attachement

        public java.lang.Object attachement()
        Return an Object with this Meteor.
        Returns:
        the Object
      • attach

        public void attach​(java.lang.Object o)
        Attach an Object with this Meteor.
      • destroy

        public void destroy()
        Mark this instance as destroyed. No more operations will be allowed.