Package com.yahoo.documentapi
Class VisitorControlHandler
- java.lang.Object
-
- com.yahoo.documentapi.VisitorControlHandler
-
public class VisitorControlHandler extends java.lang.Object
A class for controlling a visitor supplied through visitor parameters when creating the visitor session. The class defines callbacks for reporting progress and that the visitor is done. If you want to reimplement the default behavior of those callbacks, you can write your own subclass.- Author:
- HÃ¥kon Humberset
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VisitorControlHandler.CompletionCode
Possible completion codes for visiting.class
VisitorControlHandler.Result
The result of the visitor, containing a completion code and an optional error message.
-
Constructor Summary
Constructors Constructor Description VisitorControlHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Abort this visitorProgressToken
getProgress()
VisitorControlHandler.Result
getResult()
com.yahoo.vdslib.VisitorStatistics
getVisitorStatistics()
boolean
hasVisitedAnyBuckets()
Returns true iff the statistics reported by the visiting session indicates at least one bucket has been completely visited.boolean
isDone()
void
onDone(VisitorControlHandler.CompletionCode code, java.lang.String message)
Callback called when the visitor is done.void
onProgress(ProgressToken token)
Callback called when progress has changed.void
onVisitorError(java.lang.String message)
Callback for visitor error messages.void
onVisitorStatistics(com.yahoo.vdslib.VisitorStatistics vs)
Callback for visitor statistics updates.void
reset()
Called before the visitor starts.void
setSession(VisitorControlSession session)
void
waitUntilDone()
Waits until visiting is done.boolean
waitUntilDone(long timeoutMs)
Waits until visiting is done, or the given timeout (in ms) expires.boolean
waitUntilDone(java.time.Duration timeout)
Waits until visiting is done, or the given timeout (in ms) expires.
-
-
-
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.
-
onProgress
public void onProgress(ProgressToken token)
Callback called when progress has changed.- Parameters:
token
- the most recent progress token for this visitor
-
onVisitorError
public void onVisitorError(java.lang.String message)
Callback for visitor error messages.- Parameters:
message
- the error message
-
onVisitorStatistics
public void onVisitorStatistics(com.yahoo.vdslib.VisitorStatistics vs)
Callback for visitor statistics updates.- Parameters:
vs
- The current statistics for this visitor.
-
hasVisitedAnyBuckets
public boolean hasVisitedAnyBuckets()
Returns true iff the statistics reported by the visiting session indicates at least one bucket has been completely visited. Not thread safe, so should only be called on a quiescent session after waitUntilDone has completed successfully.
-
onDone
public void onDone(VisitorControlHandler.CompletionCode code, java.lang.String message)
Callback called when the visitor is done.- Parameters:
code
- the completion codemessage
- an optional error message
-
setSession
public void setSession(VisitorControlSession session)
- Parameters:
session
- the visitor session used for this visitor
-
getProgress
public ProgressToken getProgress()
- Returns:
- Retrieves the last progress token gotten for this visitor. If visitor has not been started, returns null.
-
getVisitorStatistics
public com.yahoo.vdslib.VisitorStatistics getVisitorStatistics()
-
isDone
public boolean isDone()
- Returns:
- True if the visiting is done (either by error or success).
-
waitUntilDone
public boolean waitUntilDone(java.time.Duration timeout) throws java.lang.InterruptedException
Waits until visiting is done, or the given timeout (in ms) expires. Will wait forever if timeout is 0.- Parameters:
timeout
- Maximum time duration to wait before returning.- Returns:
- True if visiting is done (either by error or success), false if session has timed out.
- Throws:
java.lang.InterruptedException
- If an interrupt signal was received while waiting.
-
waitUntilDone
public boolean waitUntilDone(long timeoutMs) throws java.lang.InterruptedException
Waits until visiting is done, or the given timeout (in ms) expires. Will wait forever if timeout is 0.- Parameters:
timeoutMs
- The maximum amount of milliseconds to wait.- Returns:
- True if visiting is done (either by error or success), false if session has timed out.
- Throws:
java.lang.InterruptedException
- If an interrupt signal was received while waiting. TODO deprecate this in favor of waitUntilDone(Duration)
-
waitUntilDone
public void waitUntilDone() throws java.lang.InterruptedException
Waits until visiting is done. Session timeout implicitly completes the visitor session, but will set an unsuccessful result code.- Throws:
java.lang.InterruptedException
- If an interrupt signal was received while waiting.
-
abort
public void abort()
Abort this visitor
-
getResult
public VisitorControlHandler.Result getResult()
- Returns:
- The result of the visiting, if done. If not done, returns null.
-
-