aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-java/src/main/java/com/yahoo/vespaget/Main.java
blob: 6ef77ca97d34dc0ea94e0fc6d690b5c5bfa959e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespaget;

import com.yahoo.vespaclient.ClusterList;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * The vespa-get tool retrieves documents from a Vespa Document Storage cluster, and prints them to stdout as XML.
 *
 * @author bjorncs
 */
public class Main {

    public static void main(String[] args) {
        try {
            Logger.getLogger("").setLevel(Level.WARNING);
            CommandLineOptions options = new CommandLineOptions();
            ClientParameters params = options.parseCommandLineArguments(args);

            if (params.help) {
                options.printHelp();
            } else {
                DocumentRetriever documentRetriever = createDocumentRetriever(params);
                addShutdownHook(documentRetriever);
                documentRetriever.retrieveDocuments();
            }
        } catch (IllegalArgumentException e) {
            System.err.printf("Failed to parse command line arguments: %s.\n", e.getMessage());
        } catch (DocumentRetrieverException e) {
            System.err.printf("Failed to retrieve documents: %s\n", e.getMessage());
        }
    }

    private static void addShutdownHook(DocumentRetriever documentRetriever) {
        Runtime.getRuntime().addShutdownHook(new Thread(documentRetriever::shutdown));
    }

    private static DocumentRetriever createDocumentRetriever(ClientParameters params) {
        return new DocumentRetriever(
                new ClusterList("client"),
                new DocumentAccessFactory(),
                params
        );
    }
}