source: SRUClient/tags/SRUClient-0.9.4/src/test/java/eu/clarin/sru/client/TestThreadedClient.java @ 5805

Last change on this file since 5805 was 5805, checked in by Oliver Schonefeld, 10 years ago
  • tag version 0.9.4
  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/**
2 * This software is copyright (c) 2012-2014 by
3 *  - 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 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;
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.fcs.ClarinFCSClientBuilder;
26import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescriptionParser;
27
28@Deprecated
29public class TestThreadedClient {
30    private static final Logger logger =
31            LoggerFactory.getLogger(TestThreadedClient.class);
32
33    public static void main(String[] args) {
34        if (args.length > 0) {
35            logger.info("initializing client ...");
36
37            SRUThreadedClient client = new ClarinFCSClientBuilder()
38                    .addDefaultDataViewParsers()
39                    .unknownDataViewAsString()
40                    .enableLegacySupport()
41                    .registerExtraResponseDataParser(
42                            new ClarinFCSEndpointDescriptionParser())
43                    .buildThreadedClient();
44
45            try {
46                /*
47                 * the following requests will be run asynchronously and
48                 * concurrently
49                 */
50                logger.info("submitting 'explain' request ...");
51                SRUExplainRequest request1 = TestUtils.makeExplainRequest(args[0]);
52                Future<SRUExplainResponse> result1 = client.explain(request1);
53
54                logger.info("submitting 'scan' request ...");
55                SRUScanRequest request2 = TestUtils.makeScanRequest(args[0]);
56                Future<SRUScanResponse> result2 = client.scan(request2);
57
58                logger.info("submitting 'searchRetrieve' request ...");
59                SRUSearchRetrieveRequest request3 = TestUtils.makeSearchRequest(args[0], null);
60                Future<SRUSearchRetrieveResponse> result3 =
61                        client.searchRetrieve(request3);
62
63                /*
64                 * HACK: the following code is quick and dirty. Don't every busy
65                 * wait on responses like this in a real-world application!
66                 */
67                while (!(result1.isDone() && result2.isDone() &&
68                        result3.isDone())) {
69                    logger.debug("waiting for results ...");
70                    try {
71                        Thread.sleep(125);
72                    } catch (InterruptedException e) {
73                        /* IGNORE */
74                    }
75                }
76
77                try {
78                    TestUtils.printExplainResponse(result1.get());
79                } catch (ExecutionException e) {
80                    logger.error("some error occured while performing 'explain' request", e);
81                }
82                try {
83                    TestUtils.printScanResponse(result2.get());
84                } catch (ExecutionException e) {
85                    logger.error("some error occured while performing 'scan' request", e);
86                }
87                try {
88                    TestUtils.printSearchResponse(result3.get());
89                } catch (ExecutionException e) {
90                    logger.error("some error occured while performing 'searchRetrieve' request", e);
91                }
92            } catch (Exception e) {
93                logger.error("a fatal error occured while performing request", e);
94            }
95
96            client.shutdown();
97            logger.info("done");
98        } else {
99            System.err.println("missing args");
100            System.exit(64);
101        }
102    }
103
104
105
106
107    static {
108        org.apache.log4j.BasicConfigurator.configure(
109                new org.apache.log4j.ConsoleAppender(
110                        new org.apache.log4j.PatternLayout("%-5p [%t] %m%n"),
111                        org.apache.log4j.ConsoleAppender.SYSTEM_ERR));
112        org.apache.log4j.Logger logger =
113                org.apache.log4j.Logger.getRootLogger();
114        logger.setLevel(org.apache.log4j.Level.INFO);
115        logger.getLoggerRepository().getLogger("eu.clarin").setLevel(
116                org.apache.log4j.Level.DEBUG);
117    }
118
119}
Note: See TracBrowser for help on using the repository browser.