use of com.yahoo.documentapi.VisitorControlHandler in project vespa by vespa-engine.
the class OperationHandlerImpl method visit.
@Override
public VisitResult visit(RestUri restUri, String documentSelection, VisitOptions options) throws RestApiException {
VisitorParameters visitorParameters = createVisitorParameters(restUri, documentSelection, options);
VisitorControlHandler visitorControlHandler = new VisitorControlHandler();
visitorParameters.setControlHandler(visitorControlHandler);
LocalDataVisitorHandler localDataVisitorHandler = new LocalDataVisitorHandler();
visitorParameters.setLocalDataHandler(localDataVisitorHandler);
final VisitorSession visitorSession;
try {
visitorSession = documentAccess.createVisitorSession(visitorParameters);
// Not sure if this line is required
visitorControlHandler.setSession(visitorSession);
} catch (Exception e) {
throw new RestApiException(Response.createErrorResponse(500, "Failed during parsing of arguments for visiting: " + ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.VISITOR_ERROR));
}
try {
return doVisit(visitorControlHandler, localDataVisitorHandler, restUri);
} finally {
visitorSession.destroy();
}
}
use of com.yahoo.documentapi.VisitorControlHandler in project vespa by vespa-engine.
the class VdsVisitTarget method run.
@SuppressWarnings("unchecked")
public void run() throws Exception {
initShutdownHook();
log.log(LogLevel.DEBUG, "Starting VdsVisitTarget");
MessageBusParams mbusParams = new MessageBusParams(new LoadTypeSet());
mbusParams.getRPCNetworkParams().setIdentity(new Identity(slobrokAddress));
if (port > 0) {
mbusParams.getRPCNetworkParams().setListenPort(port);
}
access = new MessageBusDocumentAccess(mbusParams);
VdsVisitHandler handler;
Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(handlerClassName);
try {
// Any custom data handlers may have a constructor that takes in args,
// so that the user can pass cmd line options to them
Class<?>[] consTypes = new Class<?>[] { boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, int.class, String[].class };
Constructor<?> cons = cls.getConstructor(consTypes);
handler = (VdsVisitHandler) cons.newInstance(printIds, verbose, verbose, verbose, false, false, processTime, handlerArgs);
} catch (NoSuchMethodException e) {
// Retry, this time matching the StdOutVisitorHandler constructor
// arg list
Class<?>[] consTypes = new Class<?>[] { boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, int.class, boolean.class };
Constructor<?> cons = cls.getConstructor(consTypes);
handler = (VdsVisitHandler) cons.newInstance(printIds, verbose, verbose, verbose, false, false, processTime, false);
}
VisitorDataHandler dataHandler = handler.getDataHandler();
VisitorControlHandler controlHandler = handler.getControlHandler();
VisitorDestinationParameters params = new VisitorDestinationParameters("visit-destination", dataHandler);
session = access.createVisitorDestinationSession(params);
while (!controlHandler.isDone()) {
Thread.sleep(1000);
}
}
use of com.yahoo.documentapi.VisitorControlHandler in project vespa by vespa-engine.
the class VisitorControlHandlerTest method has_visited_any_buckets_is_false_if_no_bucket_stats_recorded.
@Test
public void has_visited_any_buckets_is_false_if_no_bucket_stats_recorded() {
VisitorControlHandler handler = new VisitorControlHandler();
assertFalse(handler.hasVisitedAnyBuckets());
}
use of com.yahoo.documentapi.VisitorControlHandler in project vespa by vespa-engine.
the class VisitorControlHandlerTest method has_visited_any_buckets_is_false_if_zero_buckets_visited.
@Test
public void has_visited_any_buckets_is_false_if_zero_buckets_visited() {
VisitorControlHandler handler = new VisitorControlHandler();
VisitorStatistics stats = new VisitorStatistics();
stats.setBucketsVisited(0);
handler.onVisitorStatistics(stats);
assertFalse(handler.hasVisitedAnyBuckets());
}
use of com.yahoo.documentapi.VisitorControlHandler in project vespa by vespa-engine.
the class VisitorControlHandlerTest method has_visited_any_buckets_is_true_if_more_than_zero_buckets_visited.
@Test
public void has_visited_any_buckets_is_true_if_more_than_zero_buckets_visited() {
VisitorControlHandler handler = new VisitorControlHandler();
VisitorStatistics stats = new VisitorStatistics();
stats.setBucketsVisited(1);
handler.onVisitorStatistics(stats);
assertTrue(handler.hasVisitedAnyBuckets());
}
Aggregations