Package com.yahoo.documentapi
Class VisitorDataHandler
- java.lang.Object
-
- com.yahoo.documentapi.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
-
-
Field Summary
Fields Modifier and Type Field Description protected VisitorControlSession
session
-
Constructor Summary
Constructors Constructor Description VisitorDataHandler()
Creates a new visitor data handler.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
ack(AckToken token)
Function used to ack data.VisitorResponse
getNext()
Returns the next response of this session.VisitorResponse
getNext(int timeoutMilliseconds)
Returns the next response of this session.void
onDone()
Called when visiting is done, to notify clients waiting on getNext().abstract void
onMessage(com.yahoo.messagebus.Message m, AckToken token)
Called when a data message is received.void
reset()
Called before the visitor starts.void
setSession(VisitorControlSession session)
Sets which session this visitor data handler belongs to.
-
-
-
Field Detail
-
session
protected VisitorControlSession session
-
-
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 waitingjava.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 receivedtoken
- 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.
-
-