1 /*-----------------------------------------------------------------------------
2 Name: EmbeddedServer.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Testing the Timeout Features
6 -----------------------------------------------------------------------------*/
7
8 #ifndef _UTIL_EMBEDDEDSERVER_H
9 #define _UTIL_EMBEDDEDSERVER_H
10
11 #include <util/xmlBlasterDef.h>
12 #include <client/XmlBlasterAccess.h>
13 #include <util/XmlBlasterException.h>
14 #include <util/thread/ThreadImpl.h>
15
16 /**
17 * Embedds an xmlBlaster server so that you can control its start and stop from within a c++ program.
18 * Is not supported on Windows CE
19 * @author <a href='mailto:laghi@swissinfo.org'>Michele Laghi</a>
20 */
21
22 namespace org { namespace xmlBlaster { namespace util {
23
24 class EmbeddedServer;
25
26 class EmbeddedServerRunner : public org::xmlBlaster::util::thread::Thread
27 {
28 private:
29 const std::string ME;
30 EmbeddedServer& owner_;
31 public:
32
33 EmbeddedServerRunner(EmbeddedServer& owner);
34
35 /**
36 * This method is invoked by the start method. Note that it is invoked only if the current thread is not
37 * already running.
38 */
39 void run();
40 };
41
42 class Dll_Export EmbeddedServer
43 {
44 friend class EmbeddedServerRunner;
45 private:
46 std::string ME;
47 org::xmlBlaster::util::Global& global_;
48 org::xmlBlaster::util::I_Log& log_;
49 bool isRunning_;
50 std::string applArguments_;
51 std::string jvmArguments_;
52 org::xmlBlaster::client::XmlBlasterAccess* externalAccess_;
53 EmbeddedServerRunner* runner_;
54 public:
55 /**
56 * To start the server, you need a java virtual machine, the xmlBlaster server installed and in the
57 * CLASSPATH. Alternatively you can pass these parameters to the jvm with the 'applArguments'
58 * programmatically. You also can pass application parameters to the xmlBlaster. For example you could
59 * set traces to true (-trace true).
60 *
61 * Note that it uses the user 'embeddedTester' to check if a connection exists (if a server is
62 * responding) and a user 'embeddedKiller' to kill the server. If you have configured an authentication
63 * service for xmlBlaster make sure that these users have credentials and that 'embeddedKiller' has
64 * authorization to kill the server.
65 *
66 * @param glob the global variable
67 * @param jvmArguments the arguments to pass to the java virtual machine.
68 * @param applArguments the arguments to pass to the application.
69 * @param externalAccess the pointer to the external org::xmlBlaster::client::XmlBlasterAccess object. If this is NULL, then an
70 * own instance is created each time, otherwise the external is used. This parameter is needed
71 * where the communication protocol does not support multithreading.
72 */
73 EmbeddedServer(org::xmlBlaster::util::Global& glob, const std::string& jvmArguments = "", const std::string& applArguments="", org::xmlBlaster::client::XmlBlasterAccess* externalAccess=NULL);
74
75 virtual ~EmbeddedServer();
76
77 /**
78 * This method shuts down the xmlBlaster server which is responding to the request. If the current
79 * embedded server is running it shuts it down. If the current embedded server is not running, this
80 * method will make a try to kill it only if the 'shutdownExternal' flag has been set to 'true'. This
81 * flag defaults to 'false'.
82 * The method returns 'true' if a server was shutdown, 'false' otherwise.
83 * It blocks until the thread really has stopped (it joins the thread)
84 */
85 bool stop(bool shutdownExternal=false, bool warnIfNotRunning=true);
86
87 /**
88 * @param blockUntilUp if set to 'true' the method blocks until the server really is reacheable
89 * (i.e. a client has successfully been able to connect)
90 */
91 bool start(bool blockUntilUp=true);
92
93 /**
94 * This method can be used to check if a server is already running and responding to requests.
95 */
96 bool isSomeServerResponding() const;
97 };
98
99 }}}
100
101
102 #endif
syntax highlighted by Code2HTML, v. 0.9.1