e3169b9cbe0617095979703d6d794c2d79e56099
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / CommandThread.java
1 package com.indexdata.mkjsf.pazpar2;\r
2 \r
3 import org.apache.log4j.Logger;\r
4 \r
5 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
6 \r
7 public class CommandThread extends Thread {\r
8 \r
9   private static Logger logger = Logger.getLogger(CommandThread.class);\r
10   Pazpar2Command command;\r
11   SearchClient client;\r
12   CommandResponse commandResponse = null;      \r
13   \r
14   public CommandThread (Pazpar2Command command, SearchClient client) {\r
15     this.command = command;\r
16     this.client = client;\r
17   }\r
18   \r
19   /**\r
20    * Runs the specified command using the specified Pazpar2 client\r
21    * Sets the Pazpar2 response as an XML response string to be retrieved by\r
22    * getResponse().\r
23    * \r
24    * In case of an exception, an error response is generated, the document\r
25    * element being the same as it would have been if successful (named after\r
26    * the command, that is).  \r
27    *  \r
28    */\r
29   public void run() {\r
30     \r
31     if (command.getCommandName().equals("search")) {\r
32       client.setSearchCommand(command);\r
33     }\r
34     long start = System.currentTimeMillis();\r
35     commandResponse = client.executeCommand(command);\r
36     long end = System.currentTimeMillis();\r
37     logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
38   }\r
39   \r
40   /**\r
41    * \r
42    * @return Pazpar2 response as an XML string, possibly a generated error XML\r
43    */\r
44   public CommandResponse getCommandResponse () {\r
45     return commandResponse;\r
46   }\r
47     \r
48   public Pazpar2Command getCommand() {\r
49     return command;\r
50   }\r
51 \r
52 }\r