Class VisitorDataHandler

  • Direct Known Subclasses:
    DumpVisitorDataHandler, VisitorDataQueue

    public abstract class VisitorDataHandler
    extends java.lang.Object
    A data handler is a class that handles responses from a visitor. Different clients might want different interfaces. Some might want a callback interface, some might want a polling interface. Some want good control of acking, while others just want something simple.

    Use a data handler that fits your needs to be able to use visiting easily.

    Author:
    HÃ¥kon Humberset
    • Constructor Detail

      • VisitorDataHandler

        public VisitorDataHandler()
        Creates a new visitor data handler.
    • Method Detail

      • reset

        public void reset()
        Called before the visitor starts. Override this method if you need to reset local data. Remember to call the superclass' method as well.
      • setSession

        public void setSession​(VisitorControlSession session)
        Sets which session this visitor data handler belongs to. This is done by the session itself and should not be called manually. The session is needed for ack to work.
        Parameters:
        session - the session currently using this data handler
      • getNext

        public VisitorResponse getNext()
        Returns the next response of this session. This method returns immediately.
        Returns:
        the next response, or null if no response is ready at this time
        Throws:
        java.lang.UnsupportedOperationException - if data handler does not support the operation
      • getNext

        public VisitorResponse getNext​(int timeoutMilliseconds)
                                throws java.lang.InterruptedException
        Returns the next response of this session. This will block until a response is ready or the given timeout is reached.
        Parameters:
        timeoutMilliseconds - the max time to wait for a response. If the number is 0, this will block without any timeout limit
        Returns:
        the next response, or null if no response becomes ready before the timeout expires
        Throws:
        java.lang.InterruptedException - if this thread is interrupted while waiting
        java.lang.UnsupportedOperationException - if data handler does not support the operation
      • onDone

        public void onDone()
        Called when visiting is done, to notify clients waiting on getNext().
      • onMessage

        public abstract void onMessage​(com.yahoo.messagebus.Message m,
                                       AckToken token)
        Called when a data message is received. IMPORTANT: May be called concurrently from multiple threads. Any internal state mutations MUST be done in a thread-safe manner.
        Parameters:
        m - The message received
        token - A token to reply with when finished processing the message.
      • ack

        public void ack​(AckToken token)
        Function used to ack data. You need to ack data periodically, as storage will halt visiting when it has too much client requests pending.
        Parameters:
        token - The token to ack. Gotten from an earlier callback.