1 /*-----------------------------------------------------------------------------
2 Name: QueueFactory.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Factory to create different queue implementations
6 -----------------------------------------------------------------------------*/
7
8 #ifndef _UTIL_PARSER_PARSERFACTORY_C
9 #define _UTIL_PARSER_PARSERFACTORY_C
10
11 #if defined(_WIN32)
12 #pragma warning(disable:4786)
13 #endif
14
15 #include <util/ErrorCode.h>
16 #include <util/XmlBlasterException.h>
17 #include <util/Global.h>
18 #include <util/queue/QueueFactory.h>
19 #include <util/queue/RamQueuePlugin.h>
20 #include <util/queue/CacheQueuePlugin.h>
21 #if defined (XMLBLASTER_PERSISTENT_QUEUE) || defined (XMLBLASTER_PERSISTENT_QUEUE_SQLITE3)
22 # include <util/queue/SQLiteQueuePlugin.h>
23 #endif
24 #include <string>
25
26
27 namespace org { namespace xmlBlaster { namespace util { namespace queue {
28
29 using namespace std;
30 using namespace org::xmlBlaster::util;
31
32 QueueFactory* QueueFactory::factory_ = NULL;
33
34 QueueFactory& QueueFactory::getFactory()
35 {
36 if (factory_ == NULL) {
37 factory_ = new QueueFactory();
38 org::xmlBlaster::util::Object_Lifetime_Manager::instance()->manage_object("XB_QueueFactory", factory_); // if not pre-allocated.
39 }
40 return *factory_;
41 }
42
43 QueueFactory::QueueFactory() :
44 ME("QueueFactory")
45 {
46 }
47
48 QueueFactory::QueueFactory(const QueueFactory& factory) :
49 ME(factory.ME)
50 {
51 throw util::XmlBlasterException(INTERNAL_NOTIMPLEMENTED, ME, "private copy constructor");
52 }
53
54 QueueFactory& QueueFactory::operator =(const QueueFactory&)
55 {
56 throw util::XmlBlasterException(INTERNAL_NOTIMPLEMENTED, ME, "private assignement operator");
57 }
58
59 QueueFactory::~QueueFactory()
60 {
61 }
62
63 I_Queue& QueueFactory::getPlugin(org::xmlBlaster::util::Global& global, const org::xmlBlaster::util::qos::storage::QueuePropertyBase& property, const string& type, const string& /*version*/)
64 {
65 org::xmlBlaster::util::I_Log& log = global.getLog("org.xmlBlaster.queue");
66 if (log.call()) log.call(ME, string("getPlugin: type: '") + property.getType() + string("', version: '") + property.getVersion() + "' ...");
67 string typ = type.empty() ? property.getType() : type;
68
69 if (typ == Constants::CACHE) {
70 return *(new CacheQueuePlugin(global, property));
71 }
72 else if (typ == Constants::RAM) {
73 return *(new RamQueuePlugin(global, property));
74 }
75 else if (typ == Constants::SQLITE) {
76 # if defined(XMLBLASTER_PERSISTENT_QUEUE) || defined(XMLBLASTER_PERSISTENT_QUEUE_SQLITE3)
77 return *(new SQLiteQueuePlugin(global, property)); //#ifdef XMLBLASTER_PERSISTENT_QUEUE
78 # else
79 log.error(ME, "Please compile with -DXMLBLASTER_PERSISTENT_QUEUE_SQLITE3=1 defined to have SQLite persistent queue support");
80 # endif
81 }
82 string embeddedMsg = string("Plugin: '") + property.getType() +
83 string("' and version: '") + property.getVersion() +
84 string("' is not supported");
85 throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED,
86 "client-c++",
87 ME + string("::getPlugin"),
88 "en",
89 global.getVersion() + " " + global.getBuildTimestamp(),
90 "",
91 "",
92 embeddedMsg);
93 }
94
95 void QueueFactory::releasePlugin(I_Queue *queueP)
96 {
97 if (queueP) {
98 delete queueP;
99 }
100 }
101
102
103 }}}} // namespace
104
105 #endif
syntax highlighted by Code2HTML, v. 0.9.1