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 
43 namespace 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 
63  time_t creationtime;
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 
75  DavixStuff* create();
76  void destroy(DavixStuff*);
77  bool isValid(DavixStuff*);
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 
97 class DavixGrabber : public PoolGrabber<DavixStuff*> {
98 public:
99  DavixGrabber(DavixCtxPool &pool, bool block = true) :
100  PoolGrabber<DavixStuff *>(pool, block) {}
101 };
102 
103 }
104 
105 
106 #endif
Convenience class that releases a resource on destruction.
Definition: poolcontainer.h:209
void setRequestParams(const Davix::RequestParams &params)
Implements a pool of whichever resource.
Definition: poolcontainer.h:38
Davix::RequestParams * parms
Definition: DavixPool.h:65
DavixStuff(Davix::RequestParams params)
Definition: DavixPool.h:50
Definition: DavixPool.h:48
time_t creationtime
Definition: DavixPool.h:63
void destroy(DavixStuff *)
Destroys an element.
~DavixStuff()
Definition: DavixPool.h:56
Davix::RequestParams params_
Definition: DavixPool.h:84
Logger::bitmask davixpoollogmask
Definition: DavixPool.h:71
Definition: DavixPool.h:90
bool isValid(DavixStuff *)
Check it is still valid.
unsigned long long bitmask
typedef for a bitmask (long long)
Definition: logger.h:79
Definition: DavixPool.h:97
std::string component
typedef for a component name (std:string)
Definition: logger.h:81
Davix::Context * ctx
Definition: DavixPool.h:64
void configure(const std::string &key, const std::string &value)
Logger::component davixpoollogname
std::string davix_cert_path
Definition: DavixPool.h:86
std::string davix_privkey_path
Definition: DavixPool.h:87
DavixStuff * create()
Creates an element.
DavixGrabber(DavixCtxPool &pool, bool block=true)
Definition: DavixPool.h:99
Definition: poolcontainer.h:20
DavixCtxPool(PoolElementFactory< DavixStuff * > *factory, int n)
Definition: DavixPool.h:92