Search in sources :

Example 1 with VisitorControlHandler

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();
    }
}
Also used : VisitorSession(com.yahoo.documentapi.VisitorSession) VisitorParameters(com.yahoo.documentapi.VisitorParameters) VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler) DocumentAccessException(com.yahoo.documentapi.DocumentAccessException)

Example 2 with VisitorControlHandler

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);
    }
}
Also used : MessageBusDocumentAccess(com.yahoo.documentapi.messagebus.MessageBusDocumentAccess) Constructor(java.lang.reflect.Constructor) VisitorDestinationParameters(com.yahoo.documentapi.VisitorDestinationParameters) MessageBusParams(com.yahoo.documentapi.messagebus.MessageBusParams) VisitorDataHandler(com.yahoo.documentapi.VisitorDataHandler) Identity(com.yahoo.messagebus.network.Identity) LoadTypeSet(com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet) VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler)

Example 3 with VisitorControlHandler

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());
}
Also used : VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler) Test(org.junit.Test)

Example 4 with VisitorControlHandler

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());
}
Also used : VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler) Test(org.junit.Test)

Example 5 with VisitorControlHandler

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());
}
Also used : VisitorStatistics(com.yahoo.vdslib.VisitorStatistics) VisitorControlHandler(com.yahoo.documentapi.VisitorControlHandler) Test(org.junit.Test)

Aggregations

VisitorControlHandler (com.yahoo.documentapi.VisitorControlHandler)5 Test (org.junit.Test)3 VisitorStatistics (com.yahoo.vdslib.VisitorStatistics)2 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)1 VisitorDataHandler (com.yahoo.documentapi.VisitorDataHandler)1 VisitorDestinationParameters (com.yahoo.documentapi.VisitorDestinationParameters)1 VisitorParameters (com.yahoo.documentapi.VisitorParameters)1 VisitorSession (com.yahoo.documentapi.VisitorSession)1 MessageBusDocumentAccess (com.yahoo.documentapi.messagebus.MessageBusDocumentAccess)1 MessageBusParams (com.yahoo.documentapi.messagebus.MessageBusParams)1 LoadTypeSet (com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet)1 Identity (com.yahoo.messagebus.network.Identity)1 Constructor (java.lang.reflect.Constructor)1