source: SRUClient/trunk/src/test/java/eu/clarin/sru/client/TestThreadedClient.java @ 5750

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