ATLAS Offline Software
Loading...
Searching...
No Matches
pool::MicroSessionManager Class Reference

MicroSessionManager is a class taking care of starting sessions for a given major technology and managing the individual database connections. More...

#include <MicroSessionManager.h>

Inheritance diagram for pool::MicroSessionManager:
Collaboration diagram for pool::MicroSessionManager:

Public Member Functions

 MicroSessionManager (DatabaseRegistry &registry, long technology)
 Constructor.
virtual ~MicroSessionManager ()
 Destructor.
bool connect (Io::IoFlag transType, int ageLimit)
 Connects to the storage service.
DatabaseHandlerconnect (Io::IoFlag transType, const std::string &fid, const std::string &pfn)
 Connects to a database.
void disconnect (DatabaseHandler *database)
 Disconnects from a database.
bool disconnectAll ()
 Disconnects from all the databases.
std::string fidForPfn (const std::string &pfn)
 Fetches the FID by trying to temporatily connect to a database.
template<class T>
attribute (const std::string &attributeName, const std::string &option="")
 Templated method to retrieve an attribute.
template<class T>
bool setAttribute (const std::string &attributeName, const T &atttibuteValue, const std::string &option="")
 Templated method to set an attribute.

Protected Member Functions

virtual bool attributeOfType (const std::string &attributeName, void *data, const std::type_info &typeInfo, const std::string &option) override
 The actual method returning the attribute data given a name.
virtual bool setAttributeOfType (const std::string &attributeName, const void *data, const std::type_info &typeInfo, const std::string &option) override
 The actual method setting the attribute data given a name.

Private Attributes

DatabaseRegistrym_registry
IStorageSvcm_storageSvc
bool m_inSession
long m_technology
std::set< DatabaseHandler * > m_databaseHandlers

Detailed Description

MicroSessionManager is a class taking care of starting sessions for a given major technology and managing the individual database connections.

Definition at line 31 of file MicroSessionManager.h.

Constructor & Destructor Documentation

◆ MicroSessionManager()

pool::MicroSessionManager::MicroSessionManager ( pool::DatabaseRegistry & registry,
long technology )

Constructor.

Definition at line 17 of file MicroSessionManager.cxx.

18 :
19 m_registry( registry ),
20 m_storageSvc( 0 ),
21 m_inSession( false ),
22 m_technology( technology ),
24{
25 m_storageSvc = createStorageSvc("StorageSvc");
26 if ( ! m_storageSvc ) {
27 throw std::runtime_error( "Could not create a StorageSvc object (APR: \" MicroSessionManager::MicroSessionManager \" from \" PersistencySvc \"" );
28 }
29}
std::set< DatabaseHandler * > m_databaseHandlers
IStorageSvc * createStorageSvc(const std::string &componentName)

◆ ~MicroSessionManager()

pool::MicroSessionManager::~MicroSessionManager ( )
virtual

Destructor.

Definition at line 32 of file MicroSessionManager.cxx.

33{
34 this->disconnectAll();
35 m_storageSvc->release();
36}
bool disconnectAll()
Disconnects from all the databases.

Member Function Documentation

◆ attribute()

template<class T>
T pool::ITechnologySpecificAttributes::attribute ( const std::string & attributeName,
const std::string & option = "" )
inlineinherited

Templated method to retrieve an attribute.

Definition at line 25 of file ITechnologySpecificAttributes.h.

26 {
27 T data;
28 const std::type_info& typeInfo = typeid(T);
29 if ( ! this->attributeOfType( attributeName,
30 static_cast< void* >( &data ),
31 typeInfo,
32 option ) ) {
33 std::ostringstream error;
34 error << "Failed to retrieve attribute " << attributeName << " of type " << typeInfo.name();
35 throw std::runtime_error( error.str() + " (APR: \" ITechnologySpecificAttributes \" from \" PersistencySvc \")");
36 }
37 return data;
38 }
virtual bool attributeOfType(const std::string &attributeName, void *data, const std::type_info &typeInfo, const std::string &option)=0
The actual method returning the attribute data given a name.
unsigned long long T

◆ attributeOfType()

bool pool::MicroSessionManager::attributeOfType ( const std::string & attributeName,
void * data,
const std::type_info & typeInfo,
const std::string & option )
overrideprotectedvirtual

The actual method returning the attribute data given a name.

Implements pool::ITechnologySpecificAttributes.

Definition at line 154 of file MicroSessionManager.cxx.

158{
159 if( !m_inSession ) {
160 return false;
161 }
162 pool::DbOption domainOption( attributeName, option );
163 if( !m_storageSvc->getDomainOption(domainOption).isSuccess() ) return false;
164 return domainOption.i_getValue(typeInfo, data).isSuccess();
165}

◆ connect() [1/2]

pool::DatabaseHandler * pool::MicroSessionManager::connect ( Io::IoFlag transType,
const std::string & fid,
const std::string & pfn )

Connects to a database.

Definition at line 50 of file MicroSessionManager.cxx.

53{
54 if( mode == Io::INVALID ) return 0;
55 if( m_databaseHandlers.empty() ) {
56 if( !m_inSession ) {
57 if( !m_storageSvc->startSession(mode, m_technology).isSuccess() ) {
58 return nullptr;
59 }
60 m_inSession = true;
61 }
62 }
63
64 pool::DatabaseHandler* db = 0;
65 try {
66 db = new pool::DatabaseHandler( *m_storageSvc,
68 fid,
69 pfn,
70 mode );
71 m_registry.registerDatabaseHandler( db );
72 m_databaseHandlers.insert( db );
73 } catch( const std::runtime_error& /* error */) {
74 delete db;
75 m_storageSvc->endSession().ignore();
76 m_inSession = false;
77 return nullptr;
78 }
79
80 if( m_databaseHandlers.empty() && m_inSession ) {
81 m_storageSvc->endSession().ignore();
82 m_inSession = false;
83 }
84 return db;
85}

◆ connect() [2/2]

bool pool::MicroSessionManager::connect ( Io::IoFlag transType,
int ageLimit )

Connects to the storage service.

Definition at line 40 of file MicroSessionManager.cxx.

41{
42 if( !m_inSession ) {
43 m_inSession = m_storageSvc->startSession(mode, m_technology, ageLimit).isSuccess();
44 }
45 return m_inSession;
46}

◆ disconnect()

void pool::MicroSessionManager::disconnect ( pool::DatabaseHandler * database)

Disconnects from a database.

Definition at line 89 of file MicroSessionManager.cxx.

90{
91 std::set< pool::DatabaseHandler* >::iterator idb = m_databaseHandlers.find( database );
92 if ( idb != m_databaseHandlers.end() ) {
93 m_registry.deregisterDatabaseHandler( *idb );
94 delete *idb;
95 m_databaseHandlers.erase( idb );
96 }
97 if( m_databaseHandlers.empty() && m_inSession ) {
98 m_storageSvc->endSession().ignore();
99 m_inSession = false;
100 }
101}

◆ disconnectAll()

bool pool::MicroSessionManager::disconnectAll ( )

Disconnects from all the databases.

Definition at line 105 of file MicroSessionManager.cxx.

106{
107 bool ret = true;
108 for ( std::set< pool::DatabaseHandler* >::iterator idb = m_databaseHandlers.begin();
109 idb != m_databaseHandlers.end(); ++idb ) {
110 m_registry.deregisterDatabaseHandler( *idb );
111 ret = (*idb)->disconnectTransaction();
112 delete *idb;
113 }
114 m_databaseHandlers.clear();
115
116 if( m_inSession ) {
117 ret = ret and m_storageSvc->endSession().isSuccess();
118 m_inSession = false;
119 }
120 return ret;
121}

◆ fidForPfn()

std::string pool::MicroSessionManager::fidForPfn ( const std::string & pfn)

Fetches the FID by trying to temporatily connect to a database.

Definition at line 124 of file MicroSessionManager.cxx.

125{
126 if ( m_databaseHandlers.empty() ) {
127 Io::IoFlag mode = Io::READ;
128 if( !m_storageSvc->startSession(mode, m_technology).isSuccess() ) {
129 return "";
130 }
131 }
132
133 std::string fid = "";
134 pool::FileDescriptor fd( pfn, pfn );
135 // this is only a temporary FID so use a special pattern to make that clear
136 fd.setFID( fd.FID().substr(0,24) + "0FF0FF0FF0FF" );
137 if( m_storageSvc->existsConnection(fd).isSuccess() ) {
138 if ( m_storageSvc->connect(Io::READ, fd).isSuccess() ) {
139 DbDatabase dbH( fd.dbc()->handle() );
140 if ( ! dbH.param( "FID", fid ).isSuccess() ) fid = "";
141 m_storageSvc->disconnect( fd ).ignore();
142 }
143 }
144
145 if( m_databaseHandlers.empty() ) {
146 m_storageSvc->endSession().ignore();
147 m_inSession = false;
148 }
149
150 return fid;
151}

◆ setAttribute()

template<class T>
bool pool::ITechnologySpecificAttributes::setAttribute ( const std::string & attributeName,
const T & atttibuteValue,
const std::string & option = "" )
inlineinherited

Templated method to set an attribute.

Definition at line 41 of file ITechnologySpecificAttributes.h.

43 {
44 return this->setAttributeOfType( attributeName,
45 static_cast< const void* >( &atttibuteValue ),
46 typeid(T),
47 option );
48 }
virtual bool setAttributeOfType(const std::string &attributeName, const void *data, const std::type_info &typeInfo, const std::string &option)=0
The actual method setting the attribute data given a name.

◆ setAttributeOfType()

bool pool::MicroSessionManager::setAttributeOfType ( const std::string & attributeName,
const void * data,
const std::type_info & typeInfo,
const std::string & option )
overrideprotectedvirtual

The actual method setting the attribute data given a name.

Implements pool::ITechnologySpecificAttributes.

Definition at line 168 of file MicroSessionManager.cxx.

172{
173 if( !m_inSession ) {
174 return false;
175 }
176 pool::DbOption domainOption( attributeName, option );
177 if( !domainOption.i_setValue( typeInfo, const_cast<void*>( data ) ).isSuccess() ) return false;
178 return m_storageSvc->setDomainOption(domainOption).isSuccess();
179}

Member Data Documentation

◆ m_databaseHandlers

std::set<DatabaseHandler*> pool::MicroSessionManager::m_databaseHandlers
private

Definition at line 73 of file MicroSessionManager.h.

◆ m_inSession

bool pool::MicroSessionManager::m_inSession
private

Definition at line 71 of file MicroSessionManager.h.

◆ m_registry

DatabaseRegistry& pool::MicroSessionManager::m_registry
private

Definition at line 69 of file MicroSessionManager.h.

◆ m_storageSvc

IStorageSvc* pool::MicroSessionManager::m_storageSvc
private

Definition at line 70 of file MicroSessionManager.h.

◆ m_technology

long pool::MicroSessionManager::m_technology
private

Definition at line 72 of file MicroSessionManager.h.


The documentation for this class was generated from the following files: