#include <CondCore/DBCommon/interface/ConnectionHandler.h>
Public Member Functions | |
void | connect (cond::DBSession *session) |
global connect delegate all the registered proxy to connect if timeOutInSec !=0, cleanup idle connections with given parameter | |
ConnectionHandler () | |
contructor | |
void | disconnectAll () |
manually disconnect all and clean the registry as well. Otherwise, all connections will be closed and cleaned in the destructor | |
Connection * | getConnection (const std::string &name) |
query connection | |
void | registerConnection (const std::string &userconnect, cond::DBSession &session, int timeOutInSec=0) |
register userconnection string. This method will translate the userconnect to the real connect using technology proxy. It also initialised the session for the given technology. timeout value can be -1,0 and n sec | |
void | registerConnection (const std::string &name, const std::string &con, int timeOutInSec=0) |
register connection with a given name and timeout value. timeout value can be -1,0 and n sec | |
void | removeConnection (const std::string &name) |
remove connection from connection pool | |
Static Public Member Functions | |
static ConnectionHandler & | Instance () |
Private Member Functions | |
ConnectionHandler (ConnectionHandler &) | |
hide copy constructor | |
ConnectionHandler & | operator= (const ConnectionHandler &) |
hide assign op | |
~ConnectionHandler () | |
hide destructor | |
Private Attributes | |
std::map< std::string, cond::Connection * > | m_registry |
registry of real connection handles |
Definition at line 19 of file ConnectionHandler.h.
cond::ConnectionHandler::ConnectionHandler | ( | ) | [inline] |
cond::ConnectionHandler::ConnectionHandler | ( | ConnectionHandler & | ) | [private] |
hide copy constructor
ConnectionHandler::~ConnectionHandler | ( | ) | [private] |
hide destructor
Definition at line 89 of file ConnectionHandler.cc.
References disconnectAll(), and m_registry.
00089 { 00090 if( m_registry.size() != 0){ 00091 this->disconnectAll(); 00092 } 00093 }
void ConnectionHandler::connect | ( | cond::DBSession * | session | ) |
global connect delegate all the registered proxy to connect if timeOutInSec !=0, cleanup idle connections with given parameter
Definition at line 69 of file ConnectionHandler.cc.
References it, and m_registry.
Referenced by cond::service::PoolDBOutputService::PoolDBOutputService().
00069 { 00070 std::map<std::string,cond::Connection*>::iterator it; 00071 std::map<std::string,cond::Connection*>::iterator itEnd=m_registry.end(); 00072 for(it=m_registry.begin();it!=itEnd;++it){ 00073 it->second->connect(session); 00074 } 00075 }
void ConnectionHandler::disconnectAll | ( | ) |
manually disconnect all and clean the registry as well. Otherwise, all connections will be closed and cleaned in the destructor
Definition at line 77 of file ConnectionHandler.cc.
References it, and m_registry.
Referenced by ~ConnectionHandler().
00077 { 00078 if( m_registry.size()==0 ) return; 00079 std::map<std::string,cond::Connection*>::iterator it; 00080 std::map<std::string,cond::Connection*>::iterator itEnd=m_registry.end(); 00081 for(it=m_registry.begin();it!=itEnd;++it){ 00082 if(it->second!=0){ 00083 delete it->second; 00084 it->second=0; 00085 } 00086 } 00087 m_registry.clear(); 00088 }
cond::Connection * ConnectionHandler::getConnection | ( | const std::string & | name | ) |
query connection
Definition at line 95 of file ConnectionHandler.cc.
References it, and m_registry.
Referenced by cond::RDBMS::getDB(), cond::service::PoolDBOutputService::PoolDBOutputService(), and cond::RDBMS::setLogger().
00095 { 00096 std::map<std::string,cond::Connection*>::iterator it=m_registry.find(name); 00097 if( it!=m_registry.end() ){ 00098 return it->second; 00099 } 00100 return 0; 00101 }
cond::ConnectionHandler & ConnectionHandler::Instance | ( | ) | [static] |
Definition at line 46 of file ConnectionHandler.cc.
References me.
Referenced by PoolDBESSource::fillRecordToIOVInfo(), cond::RDBMS::getDB(), cond::service::PoolDBOutputService::initDB(), PoolDBESSource::PoolDBESSource(), cond::service::PoolDBOutputService::PoolDBOutputService(), PoolDBESSource::registerProxies(), PoolDBESSource::setIntervalFor(), and cond::RDBMS::setLogger().
00046 { 00047 //std::cout<<"in ConnectionHandler::Instance"<<std::endl; 00048 /*if(!edmplugin::PluginManager::isAvailable()){ 00049 edmplugin::PluginManager::Config config; 00050 const char* path = getenv("LD_LIBRARY_PATH"); 00051 std::string spath(path? path: ""); 00052 std::string::size_type last=0; 00053 std::string::size_type i=0; 00054 std::vector<std::string> paths; 00055 while( (i=spath.find_first_of(':',last))!=std::string::npos) { 00056 paths.push_back(spath.substr(last,i-last)); 00057 last = i+1; 00058 //std::cout <<paths.back()<<std::endl; 00059 } 00060 paths.push_back(spath.substr(last,std::string::npos)); 00061 config.searchPath(paths); 00062 edmplugin::PluginManager::configure(config); 00063 } 00064 */ 00065 static cond::ConnectionHandler me; 00066 return me; 00067 }
ConnectionHandler& cond::ConnectionHandler::operator= | ( | const ConnectionHandler & | ) | [private] |
hide assign op
void ConnectionHandler::registerConnection | ( | const std::string & | userconnect, | |
cond::DBSession & | session, | |||
int | timeOutInSec = 0 | |||
) |
register userconnection string. This method will translate the userconnect to the real connect using technology proxy. It also initialised the session for the given technology. timeout value can be -1,0 and n sec
Definition at line 15 of file ConnectionHandler.cc.
References Exception, DBSPlugin::get(), m_registry, p, and ptr.
00017 { 00018 std::string realconnect(userconnect); 00019 std::string protocol; 00020 std::size_t pos=userconnect.find_first_of(':'); 00021 if( pos!=std::string::npos ){ 00022 protocol=userconnect.substr(0,pos); 00023 std::size_t p=protocol.find_first_of('_'); 00024 if(p!=std::string::npos){ 00025 protocol=protocol.substr(0,p); 00026 } 00027 }else{ 00028 throw cond::Exception("connection string format error"); 00029 } 00030 //std::cout<<"userconnect "<<userconnect<<std::endl; 00031 //std::cout<<"protocol "<<protocol<<std::endl; 00032 std::auto_ptr<cond::TechnologyProxy> ptr(cond::TechnologyProxyFactory::get()->create(protocol,userconnect)); 00033 realconnect=ptr->getRealConnectString(); 00034 //std::cout<<"realconnect "<<realconnect<<std::endl; 00035 m_registry.insert(std::make_pair<std::string,cond::Connection*>(userconnect, new cond::Connection(realconnect,connectionTimeOutInSec))); 00036 ptr->setupSession(session); 00037 }
void ConnectionHandler::registerConnection | ( | const std::string & | name, | |
const std::string & | con, | |||
int | timeOutInSec = 0 | |||
) |
register connection with a given name and timeout value. timeout value can be -1,0 and n sec
Definition at line 9 of file ConnectionHandler.cc.
References m_registry.
Referenced by cond::RDBMS::getDB(), cond::service::PoolDBOutputService::PoolDBOutputService(), and cond::RDBMS::setLogger().
00011 { 00012 m_registry.insert(std::make_pair<std::string,cond::Connection*>(name, new cond::Connection(con,connectionTimeoutInSec))); 00013 }
void ConnectionHandler::removeConnection | ( | const std::string & | name | ) |
remove connection from connection pool
Definition at line 39 of file ConnectionHandler.cc.
References m_registry.
00039 { 00040 std::map<std::string,cond::Connection*>::iterator pos=m_registry.find(name); 00041 if( pos!=m_registry.end() ){ 00042 m_registry.erase(pos); 00043 } 00044 }
std::map<std::string,cond::Connection*> cond::ConnectionHandler::m_registry [private] |
registry of real connection handles
Definition at line 51 of file ConnectionHandler.h.
Referenced by connect(), disconnectAll(), getConnection(), registerConnection(), removeConnection(), and ~ConnectionHandler().