source: FCSSimpleClient/trunk/src/test/java/eu/clarin/sru/client/fcs/TestThreadedClient.java @ 7280

Last change on this file since 7280 was 7280, checked in by Oliver Schonefeld, 2 years ago
  • cleanup
  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1/**
2 * This software is copyright (c) 2012-2022 by
3 *  - Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
4 * This is free software. You can redistribute it
5 * and/or modify it under the terms described in
6 * the GNU General Public License v3 of which you
7 * should have received a copy. Otherwise you can download
8 * it from
9 *
10 *   http://www.gnu.org/licenses/gpl-3.0.txt
11 *
12 * @copyright Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
13 *
14 * @license http://www.gnu.org/licenses/gpl-3.0.txt
15 *  GNU General Public License v3
16 */
17package eu.clarin.sru.client.fcs;
18
19import java.util.concurrent.ExecutionException;
20import java.util.concurrent.Future;
21
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25import eu.clarin.sru.client.SRUExplainRequest;
26import eu.clarin.sru.client.SRUExplainResponse;
27import eu.clarin.sru.client.SRUScanRequest;
28import eu.clarin.sru.client.SRUScanResponse;
29import eu.clarin.sru.client.SRUSearchRetrieveRequest;
30import eu.clarin.sru.client.SRUSearchRetrieveResponse;
31import eu.clarin.sru.client.SRUThreadedClient;
32
33@Deprecated
34public class TestThreadedClient {
35    private static final Logger logger =
36            LoggerFactory.getLogger(TestThreadedClient.class);
37
38    public static void main(String[] args) {
39        if (args.length > 0) {
40            logger.info("initializing client ...");
41
42            SRUThreadedClient client = new ClarinFCSClientBuilder()
43                    .addDefaultDataViewParsers()
44                    .unknownDataViewAsString()
45                    .enableLegacySupport()
46                    .registerExtraResponseDataParser(
47                            new ClarinFCSEndpointDescriptionParser())
48                    .buildThreadedClient();
49
50            try {
51                /*
52                 * the following requests will be run asynchronously and
53                 * concurrently
54                 */
55                logger.info("submitting 'explain' request ...");
56                SRUExplainRequest request1 = TestUtils.makeExplainRequest(args[0]);
57                Future<SRUExplainResponse> result1 = client.explain(request1);
58
59                logger.info("submitting 'scan' request ...");
60                SRUScanRequest request2 = TestUtils.makeScanRequest(args[0]);
61                Future<SRUScanResponse> result2 = client.scan(request2);
62
63                logger.info("submitting 'searchRetrieve' request ...");
64                SRUSearchRetrieveRequest request3 = TestUtils.makeSearchRequest(args[0], null);
65                Future<SRUSearchRetrieveResponse> result3 =
66                        client.searchRetrieve(request3);
67
68                /*
69                 * HACK: the following code is quick and dirty. Don't every busy
70                 * wait on responses like this in a real-world application!
71                 */
72                while (!(result1.isDone() && result2.isDone() &&
73                        result3.isDone())) {
74                    logger.debug("waiting for results ...");
75                    try {
76                        Thread.sleep(125);
77                    } catch (InterruptedException e) {
78                        /* IGNORE */
79                    }
80                }
81
82                try {
83                    TestUtils.printExplainResponse(result1.get());
84                } catch (ExecutionException e) {
85                    logger.error("some error occured while performing 'explain' request", e);
86                }
87                try {
88                    TestUtils.printScanResponse(result2.get());
89                } catch (ExecutionException e) {
90                    logger.error("some error occured while performing 'scan' request", e);
91                }
92                try {
93                    TestUtils.printSearchResponse(result3.get());
94                } catch (ExecutionException e) {
95                    logger.error("some error occured while performing 'searchRetrieve' request", e);
96                }
97            } catch (Exception e) {
98                logger.error("a fatal error occured while performing request", e);
99            }
100
101            client.shutdown();
102            logger.info("done");
103        } else {
104            System.err.println("missing args");
105            System.exit(64);
106        }
107    }
108
109
110
111
112    static {
113        org.apache.log4j.BasicConfigurator.configure(
114                new org.apache.log4j.ConsoleAppender(
115                        new org.apache.log4j.PatternLayout("%-5p [%t] %m%n"),
116                        org.apache.log4j.ConsoleAppender.SYSTEM_ERR));
117        org.apache.log4j.Logger logger =
118                org.apache.log4j.Logger.getRootLogger();
119        logger.setLevel(org.apache.log4j.Level.INFO);
120        logger.getLoggerRepository().getLogger("eu.clarin").setLevel(
121                org.apache.log4j.Level.DEBUG);
122    }
123
124}
Note: See TracBrowser for help on using the repository browser.