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 | */ |
---|
17 | package eu.clarin.sru.client.fcs; |
---|
18 | |
---|
19 | import java.util.concurrent.ExecutionException; |
---|
20 | import java.util.concurrent.Future; |
---|
21 | |
---|
22 | import org.slf4j.Logger; |
---|
23 | import org.slf4j.LoggerFactory; |
---|
24 | |
---|
25 | import eu.clarin.sru.client.SRUExplainRequest; |
---|
26 | import eu.clarin.sru.client.SRUExplainResponse; |
---|
27 | import eu.clarin.sru.client.SRUScanRequest; |
---|
28 | import eu.clarin.sru.client.SRUScanResponse; |
---|
29 | import eu.clarin.sru.client.SRUSearchRetrieveRequest; |
---|
30 | import eu.clarin.sru.client.SRUSearchRetrieveResponse; |
---|
31 | import eu.clarin.sru.client.SRUThreadedClient; |
---|
32 | import eu.clarin.sru.client.fcs.ClarinFCSClientBuilder; |
---|
33 | import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescriptionParser; |
---|
34 | |
---|
35 | @Deprecated |
---|
36 | public class TestThreadedClient { |
---|
37 | private static final Logger logger = |
---|
38 | LoggerFactory.getLogger(TestThreadedClient.class); |
---|
39 | |
---|
40 | public static void main(String[] args) { |
---|
41 | if (args.length > 0) { |
---|
42 | logger.info("initializing client ..."); |
---|
43 | |
---|
44 | SRUThreadedClient client = new ClarinFCSClientBuilder() |
---|
45 | .addDefaultDataViewParsers() |
---|
46 | .unknownDataViewAsString() |
---|
47 | .enableLegacySupport() |
---|
48 | .registerExtraResponseDataParser( |
---|
49 | new ClarinFCSEndpointDescriptionParser()) |
---|
50 | .buildThreadedClient(); |
---|
51 | |
---|
52 | try { |
---|
53 | /* |
---|
54 | * the following requests will be run asynchronously and |
---|
55 | * concurrently |
---|
56 | */ |
---|
57 | logger.info("submitting 'explain' request ..."); |
---|
58 | SRUExplainRequest request1 = TestUtils.makeExplainRequest(args[0]); |
---|
59 | Future<SRUExplainResponse> result1 = client.explain(request1); |
---|
60 | |
---|
61 | logger.info("submitting 'scan' request ..."); |
---|
62 | SRUScanRequest request2 = TestUtils.makeScanRequest(args[0]); |
---|
63 | Future<SRUScanResponse> result2 = client.scan(request2); |
---|
64 | |
---|
65 | logger.info("submitting 'searchRetrieve' request ..."); |
---|
66 | SRUSearchRetrieveRequest request3 = TestUtils.makeSearchRequest(args[0], null); |
---|
67 | Future<SRUSearchRetrieveResponse> result3 = |
---|
68 | client.searchRetrieve(request3); |
---|
69 | |
---|
70 | /* |
---|
71 | * HACK: the following code is quick and dirty. Don't every busy |
---|
72 | * wait on responses like this in a real-world application! |
---|
73 | */ |
---|
74 | while (!(result1.isDone() && result2.isDone() && |
---|
75 | result3.isDone())) { |
---|
76 | logger.debug("waiting for results ..."); |
---|
77 | try { |
---|
78 | Thread.sleep(125); |
---|
79 | } catch (InterruptedException e) { |
---|
80 | /* IGNORE */ |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | try { |
---|
85 | TestUtils.printExplainResponse(result1.get()); |
---|
86 | } catch (ExecutionException e) { |
---|
87 | logger.error("some error occured while performing 'explain' request", e); |
---|
88 | } |
---|
89 | try { |
---|
90 | TestUtils.printScanResponse(result2.get()); |
---|
91 | } catch (ExecutionException e) { |
---|
92 | logger.error("some error occured while performing 'scan' request", e); |
---|
93 | } |
---|
94 | try { |
---|
95 | TestUtils.printSearchResponse(result3.get()); |
---|
96 | } catch (ExecutionException e) { |
---|
97 | logger.error("some error occured while performing 'searchRetrieve' request", e); |
---|
98 | } |
---|
99 | } catch (Exception e) { |
---|
100 | logger.error("a fatal error occured while performing request", e); |
---|
101 | } |
---|
102 | |
---|
103 | client.shutdown(); |
---|
104 | logger.info("done"); |
---|
105 | } else { |
---|
106 | System.err.println("missing args"); |
---|
107 | System.exit(64); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | static { |
---|
115 | org.apache.log4j.BasicConfigurator.configure( |
---|
116 | new org.apache.log4j.ConsoleAppender( |
---|
117 | new org.apache.log4j.PatternLayout("%-5p [%t] %m%n"), |
---|
118 | org.apache.log4j.ConsoleAppender.SYSTEM_ERR)); |
---|
119 | org.apache.log4j.Logger logger = |
---|
120 | org.apache.log4j.Logger.getRootLogger(); |
---|
121 | logger.setLevel(org.apache.log4j.Level.INFO); |
---|
122 | logger.getLoggerRepository().getLogger("eu.clarin").setLevel( |
---|
123 | org.apache.log4j.Level.DEBUG); |
---|
124 | } |
---|
125 | |
---|
126 | } |
---|