Package com.yahoo.documentapi
Class VisitorDataHandler
java.lang.Object
com.yahoo.documentapi.VisitorDataHandler
- Direct Known Subclasses:
DumpVisitorDataHandler
,VisitorDataQueue
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Function used to ack data.getNext()
Returns the next response of this session.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
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 Details
-
session
-
-
Constructor Details
-
VisitorDataHandler
public VisitorDataHandler()Creates a new visitor data handler.
-
-
Method Details
-
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
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
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:
UnsupportedOperationException
- if data handler does not support the operation
-
getNext
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:
InterruptedException
- if this thread is interrupted while waitingUnsupportedOperationException
- if data handler does not support the operation
-
onDone
public void onDone()Called when visiting is done, to notify clients waiting on getNext(). -
onMessage
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
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.
-