-/* $Id: filter_session_shared.cpp,v 1.13 2006-06-20 22:27:45 adam Exp $
- Copyright (c) 2005-2006, Index Data.
+/* $Id: filter_session_shared.cpp,v 1.17 2007-02-23 18:58:44 marc Exp $
+ Copyright (c) 2005-2007, Index Data.
See the LICENSE file for details
*/
time_t m_backend_expiry_ttl;
size_t m_backend_set_max;
public:
- BackendClass(const yazpp_1::GDU &init_request);
+ BackendClass(const yazpp_1::GDU &init_request,
+ int resultset_ttl,
+ int resultset_max,
+ int session_ttl);
~BackendClass();
};
class SessionShared::FrontendSet {
BackendClassMap m_backend_map;
boost::mutex m_mutex_backend_map;
boost::thread_group m_thrds;
+ int m_resultset_ttl;
+ int m_resultset_max;
+ int m_session_ttl;
};
}
}
}
-yf::SessionShared::BackendClass::BackendClass(const yazpp_1::GDU &init_request)
+yf::SessionShared::BackendClass::BackendClass(const yazpp_1::GDU &init_request,
+ int resultset_ttl,
+ int resultset_max,
+ int session_ttl)
: m_named_result_sets(false), m_init_request(init_request),
- m_sequence_top(0), m_backend_set_ttl(30),
- m_backend_expiry_ttl(30), m_backend_set_max(10)
+ m_sequence_top(0), m_backend_set_ttl(resultset_ttl),
+ m_backend_expiry_ttl(session_ttl), m_backend_set_max(resultset_max)
{}
yf::SessionShared::BackendClass::~BackendClass()
it = m_backend_map.find(k);
if (it == m_backend_map.end())
{
- BackendClassPtr b(new BackendClass(gdu->u.z3950));
+ BackendClassPtr b(new BackendClass(gdu->u.z3950,
+ m_resultset_ttl,
+ m_resultset_max,
+ m_session_ttl));
m_backend_map[k] = b;
frontend->m_backend_class = b;
std::cout << "SessionShared::Rep::init new session "
}
bool yf::SessionShared::BackendSet::search(
- Package &frontend_package,
+ mp::Package &frontend_package,
const Z_APDU *frontend_apdu,
const BackendInstancePtr bp)
{
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec += 30;
boost::thread::sleep(xt);
- std::cout << "." << std::endl;
+ //std::cout << "." << std::endl;
BackendClassMap::const_iterator b_it = m_backend_map.begin();
for (; b_it != m_backend_map.end(); b_it++)
yf::SessionShared::Rep::Rep()
{
+ m_resultset_ttl = 30;
+ m_resultset_max = 10;
+ m_session_ttl = 90;
yf::SessionShared::Worker w(this);
m_thrds.add_thread(new boost::thread(w));
}
m_p->release_frontend(package);
}
+void yf::SessionShared::configure(const xmlNode *ptr)
+{
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) ptr->name, "resultset"))
+ {
+ const struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "ttl"))
+ m_p->m_resultset_ttl =
+ mp::xml::get_int(attr->children, 30);
+ else if (!strcmp((const char *) attr->name, "max"))
+ {
+ m_p->m_resultset_max =
+ mp::xml::get_int(attr->children, 10);
+ }
+ else
+ throw mp::filter::FilterException(
+ "Bad attribute " + std::string((const char *)
+ attr->name));
+ }
+ }
+ else if (!strcmp((const char *) ptr->name, "session"))
+ {
+ const struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "ttl"))
+ m_p->m_session_ttl =
+ mp::xml::get_int(attr->children, 120);
+ else
+ throw mp::filter::FilterException(
+ "Bad attribute " + std::string((const char *)
+ attr->name));
+ }
+ }
+ else
+ {
+ throw mp::filter::FilterException("Bad element "
+ + std::string((const char *)
+ ptr->name));
+ }
+ }
+}
+
static mp::filter::Base* filter_creator()
{
return new mp::filter::SessionShared;