00001 /*----------------------------------------------------------------------------- 00002 Name: QueueFactory.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Factory to create different queue implementations 00006 -----------------------------------------------------------------------------*/ 00007 00008 #ifndef _UTIL_PARSER_PARSERFACTORY_C 00009 #define _UTIL_PARSER_PARSERFACTORY_C 00010 00011 #if defined(_WIN32) 00012 #pragma warning(disable:4786) 00013 #endif 00014 00015 #include <util/ErrorCode.h> 00016 #include <util/XmlBlasterException.h> 00017 #include <util/Global.h> 00018 #include <util/queue/QueueFactory.h> 00019 #include <util/queue/RamQueuePlugin.h> 00020 #include <util/queue/CacheQueuePlugin.h> 00021 #ifdef XMLBLASTER_PERSISTENT_QUEUE 00022 # include <util/queue/SQLiteQueuePlugin.h> 00023 #endif 00024 #include <string> 00025 00026 00027 namespace org { namespace xmlBlaster { namespace util { namespace queue { 00028 00029 using namespace std; 00030 using namespace org::xmlBlaster::util; 00031 00032 QueueFactory* QueueFactory::factory_ = NULL; 00033 00034 QueueFactory& QueueFactory::getFactory() 00035 { 00036 if (factory_ == NULL) { 00037 factory_ = new QueueFactory(); 00038 org::xmlBlaster::util::Object_Lifetime_Manager::instance()->manage_object("XB_QueueFactory", factory_); // if not pre-allocated. 00039 } 00040 return *factory_; 00041 } 00042 00043 QueueFactory::QueueFactory() : 00044 ME("QueueFactory") 00045 { 00046 } 00047 00048 QueueFactory::QueueFactory(const QueueFactory& factory) : 00049 ME(factory.ME) 00050 { 00051 throw util::XmlBlasterException(INTERNAL_NOTIMPLEMENTED, ME, "private copy constructor"); 00052 } 00053 00054 QueueFactory& QueueFactory::operator =(const QueueFactory&) 00055 { 00056 throw util::XmlBlasterException(INTERNAL_NOTIMPLEMENTED, ME, "private assignement operator"); 00057 } 00058 00059 QueueFactory::~QueueFactory() 00060 { 00061 } 00062 00063 I_Queue& QueueFactory::getPlugin(org::xmlBlaster::util::Global& global, const org::xmlBlaster::util::qos::storage::QueuePropertyBase& property, const string& type, const string& /*version*/) 00064 { 00065 org::xmlBlaster::util::I_Log& log = global.getLog("org.xmlBlaster.queue"); 00066 if (log.call()) log.call(ME, string("getPlugin: type: '") + property.getType() + string("', version: '") + property.getVersion() + "' ..."); 00067 string typ = type.empty() ? property.getType() : type; 00068 00069 if (typ == Constants::CACHE) { 00070 return *(new CacheQueuePlugin(global, property)); 00071 } 00072 else if (typ == Constants::RAM) { 00073 return *(new RamQueuePlugin(global, property)); 00074 } 00075 else if (typ == Constants::SQLITE) { 00076 # ifdef XMLBLASTER_PERSISTENT_QUEUE 00077 return *(new SQLiteQueuePlugin(global, property)); //#ifdef XMLBLASTER_PERSISTENT_QUEUE 00078 # else 00079 log.error(ME, "Please compile with -DXMLBLASTER_PERSISTENT_QUEUE=1 defined to have SQLite persistent queue support"); 00080 # endif 00081 } 00082 string embeddedMsg = string("Plugin: '") + property.getType() + 00083 string("' and version: '") + property.getVersion() + 00084 string("' is not supported"); 00085 throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED, 00086 "client-c++", 00087 ME + string("::getPlugin"), 00088 "en", 00089 global.getVersion() + " " + global.getBuildTimestamp(), 00090 "", 00091 "", 00092 embeddedMsg); 00093 } 00094 00095 void QueueFactory::releasePlugin(I_Queue *queueP) 00096 { 00097 if (queueP) { 00098 delete queueP; 00099 } 00100 } 00101 00102 00103 }}}} // namespace 00104 00105 #endif