dmlite 0.6
DavixPool.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 CERN
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18
19
20/// @file DomeDavixPool.h
21/// @brief Pool of davix contexts
22/// @author Fabrizio Furano <furano@cern.ch>
23/// @date Jan 2016
24
25
26
27#ifndef UTILS_DAVIXPOOL_H
28#define UTILS_DAVIXPOOL_H
29
30
31#ifdef __APPLE__
32#include <bsm/audit_errno.h>
33#endif
34
35#include <algorithm>
36#include <stdlib.h>
37#include "utils/logger.h"
38#include "utils/poolcontainer.h"
39#include "utils/Config.hh"
40
41#include <davix/davix.hpp>
42
43namespace dmlite {
44
47
48 class DavixStuff {
49 public:
50 DavixStuff(Davix::RequestParams params) {
51 ctx = new Davix::Context();
52 parms = new Davix::RequestParams(params);
53 creationtime = time(0);
54 }
55
57 delete parms;
58 delete ctx;
59 parms = 0;
60 ctx = 0;
61 }
62
64 Davix::Context *ctx;
65 Davix::RequestParams *parms;
66 };
67
68 /// Factory for davix contexts
69 /// This is just mechanics of how the Poolcontainer class works
70 /// and wraps the creation of the actual instances
71 class DavixCtxFactory: public dmlite::PoolElementFactory<DavixStuff *> {
72 public:
74
78
79 void configure(const std::string &key, const std::string &value);
80 void setRequestParams(const Davix::RequestParams &params);
81 protected:
82 //boost::mutex mtx;
83 private:
84 Davix::RequestParams params_;
85
86 std::string davix_cert_path;
87 std::string davix_privkey_path;
88 };
89
90 class DavixCtxPool : public dmlite::PoolContainer<DavixStuff *> {
91 public:
93 dmlite::PoolContainer<DavixStuff *>(factory, n) { }
94 };
95
96
97class DavixGrabber : public PoolGrabber<DavixStuff*> {
98public:
99 DavixGrabber(DavixCtxPool &pool, bool block = true) :
100 PoolGrabber<DavixStuff *>(pool, block) {}
101};
102
103}
104
105
106#endif
unsigned long long bitmask
typedef for a bitmask (long long)
Definition logger.h:79
std::string component
typedef for a component name (std:string)
Definition logger.h:81
Definition DavixPool.h:71
void configure(const std::string &key, const std::string &value)
void destroy(DavixStuff *)
Destroys an element.
std::string davix_cert_path
Definition DavixPool.h:86
DavixStuff * create()
Creates an element.
void setRequestParams(const Davix::RequestParams &params)
Davix::RequestParams params_
Definition DavixPool.h:84
bool isValid(DavixStuff *)
Check it is still valid.
std::string davix_privkey_path
Definition DavixPool.h:87
Definition DavixPool.h:90
DavixCtxPool(PoolElementFactory< DavixStuff * > *factory, int n)
Definition DavixPool.h:92
Definition DavixPool.h:97
DavixGrabber(DavixCtxPool &pool, bool block=true)
Definition DavixPool.h:99
Definition DavixPool.h:48
Davix::RequestParams * parms
Definition DavixPool.h:65
~DavixStuff()
Definition DavixPool.h:56
time_t creationtime
Definition DavixPool.h:63
Davix::Context * ctx
Definition DavixPool.h:64
DavixStuff(Davix::RequestParams params)
Definition DavixPool.h:50
Implements a pool of whichever resource.
Definition poolcontainer.h:38
Definition poolcontainer.h:20
Convenience class that releases a resource on destruction.
Definition poolcontainer.h:209
Namespace for the dmlite C++ API.
Definition authn.h:16
Logger::component davixpoollogname
Logger::bitmask davixpoollogmask