util/dispatch/DispatchManager.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      DispatchManager.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Manager to retrieve the correct callback protocol implementation
00006 ------------------------------------------------------------------------------*/
00007 
00017 #include <util/dispatch/DispatchManager.h>
00018 //  #include <util/dispatch/ConnectionsHandler.h>
00019 #ifdef COMPILE_CORBA_PLUGIN
00020 #  include <client/protocol/corba/CorbaDriverFactory.h>
00021 #endif
00022 #ifdef COMPILE_SOCKET_PLUGIN
00023 #  include <client/protocol/socket/SocketDriverFactory.h>
00024 #endif
00025 #include <util/Global.h>
00026 
00027 namespace org { namespace xmlBlaster { namespace util { namespace dispatch {
00028 
00029 using namespace std;
00030 using namespace org::xmlBlaster::util;
00031 using namespace org::xmlBlaster::client::protocol;
00032 
00033 DispatchManager::DispatchManager(Global& global)
00034    : ME("DispatchManager"),
00035      global_(global),
00036      log_(global.getLog("org.xmlBlaster.util.dispatch"))
00037 {
00038    if (log_.call()) log_.call(ME, "::constructor");
00039 }
00040 
00041 
00042 DispatchManager::~DispatchManager()
00043 {
00044    if (log_.call()) log_.call(ME, "::destructor");
00045 }
00046 
00047 void DispatchManager::releasePlugin(const string& instanceName, const string& type, const string& version)
00048 {
00049    if (log_.call()) log_.call(ME, "::releasePlugin");
00050    if (log_.trace())
00051       log_.trace(ME, string("releasePlugin: type: '") + type + string("', version: '") + version + "' for instance '" + instanceName + "'");
00052    if (type == Constants::IOR) {
00053 #     ifdef COMPILE_CORBA_PLUGIN
00054       org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::getFactory(global_).killDriverInstance(&global_);
00055 #     endif
00056       return;
00057    }
00058    else if (type == Constants::SOCKET) {
00059 #     ifdef COMPILE_SOCKET_PLUGIN
00060       org::xmlBlaster::client::protocol::socket::SocketDriverFactory::getFactory(global_).killDriverInstance(&global_);
00061       return;
00062 #     endif
00063    }
00064    string embeddedMsg = string("plugin: '") + type +
00065                         string("' and version: '") + version +
00066                         string("' not supported");
00067    throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED,
00068                     "client-c++",
00069                     ME + string("::releasePlugin"),
00070                     "en",
00071                     global_.getVersion() + " " + global_.getBuildTimestamp(),
00072                     "",
00073                     "",
00074                     embeddedMsg);
00075 }
00076 
00077 I_XmlBlasterConnection& DispatchManager::getPlugin(const string& instanceName, const string& type, const string& version)
00078 {
00079    if (log_.call()) log_.call(ME, "::getPlugin");
00080    if (log_.trace())
00081       log_.trace(ME, string("getPlugin: type: '") + type + string("', version: '") + version + "' for instance '" + instanceName + "'");
00082    
00083    if (type == Constants::IOR) {
00084 #     ifdef COMPILE_CORBA_PLUGIN
00085       return org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::getFactory(global_).getDriverInstance(&global_);
00086 #     endif
00087    }
00088    else if (type == Constants::SOCKET) {
00089 #     ifdef COMPILE_SOCKET_PLUGIN
00090       return org::xmlBlaster::client::protocol::socket::SocketDriverFactory::getFactory(global_).getDriverInstance(&global_);
00091 #     endif
00092    }
00093 
00094    // add here other protocols ....
00095 
00096    string embeddedMsg = string("plugin: '") + type +
00097                         string("' and version: '") + version +
00098                         string("' not supported");
00099    throw XmlBlasterException(RESOURCE_CONFIGURATION_PLUGINFAILED,
00100                     "client-c++",
00101                     ME + string("::getPlugin"),
00102                     "en",
00103                     global_.getVersion() + " " + global_.getBuildTimestamp(),
00104                     "",
00105                     "",
00106                     embeddedMsg);
00107 }
00108 
00109 
00110 ConnectionsHandler* DispatchManager::getConnectionsHandler(const string& instanceName)
00111 {
00112    // it makes sense to have one per XmlBlasterAccess (must be destructed by the invoker of this method !!!)
00113    return new ConnectionsHandler(global_, instanceName);
00114 }
00115 
00116 
00117 }}}} // namespaces
00118