-
Notifications
You must be signed in to change notification settings - Fork 1
/
HttpServletManager.cpp
60 lines (45 loc) · 1.24 KB
/
HttpServletManager.cpp
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
/*
* File: HttpServletManager.cpp
* Author: try
*
* Created on 2011年7月11日, 上午8:58
*/
#include <stdlib.h>
#include "HttpServletManager.h"
#include "HttpServletFactory.h"
#include "CleanerTimer.h"
HttpServletManager HttpServletManager::instance;
HttpServletManager::HttpServletManager():factory(NULL) {
}
HttpServletManager::~HttpServletManager() {
}
void HttpServletManager::init(HttpServletFactory* factory){
HttpServletManager::instance.factory = factory;
CleanerTimer::instance.add(&HttpServletManager::instance);
}
HttpServlet* HttpServletManager::create(const char* path){
if(factory){
return factory->create(path);
}
LOG_ERROR("factory is NULL");
return NULL;
}
void HttpServletManager::recycle(HttpServlet* servlet){
if(factory){
freeQueue.push(new Entry(servlet, time(NULL)));
}
}
void HttpServletManager::cleanup(){
LOG_DEBUG("freeQueue.size():%d", freeQueue.size());
time_t ct = time(NULL);
while(!freeQueue.empty()){
Entry* e = freeQueue.front();
if(ct > e->t + HTTP_SERVLET_FREE_TIMEOUT){
factory->free(e->servlet);
freeQueue.pop();
delete e;
}else{
break;
}
}
}