public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
passenger / ext / apache2 / ApplicationPool.h
100644 60 lines (45 sloc) 1.333 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef _PASSENGER_APPLICATION_POOL_H_
#define _PASSENGER_APPLICATION_POOL_H_
 
#include <boost/shared_ptr.hpp>
#include <map>
 
#include "Application.h"
#include "SpawnManager.h"
 
namespace Passenger {
 
using namespace std;
using namespace boost;
 
// TODO: document this
class ApplicationPool {
private:
  typedef map<string, ApplicationPtr> ApplicationMap;
 
  SpawnManager spawnManager;
  ApplicationMap apps;
  
  string normalizePath(const string &path) {
    // TODO
    return path;
  }
  
public:
  ApplicationPool(const string &spawnManagerCommand, const string &logFile = "")
    : spawnManager(spawnManagerCommand, logFile) {}
  
  ApplicationPtr get(const string &appRoot) {
    return get(appRoot, "");
  }
  
  // TODO: improve algorithm
  // TODO: make thread-safe
  // TODO: make it possible to share an ApplicationPool between processes
  ApplicationPtr get(const string &appRoot, const string &username) {
    string normalizedAppRoot(normalizePath(appRoot));
    //scoped_lock l(lock);
    
    ApplicationPtr app;
    ApplicationMap::iterator it(apps.find(appRoot));
    if (it == apps.end()) {
      app = spawnManager.spawn(appRoot, username);
      apps[appRoot] = app;
    } else {
      app = it->second;
    }
    return app;
  }
};
 
typedef shared_ptr<ApplicationPool> ApplicationPoolPtr;
 
}; // namespace Passenger
 
#endif /* _PASSENGER_APPLICATION_POOL_H_ */