From 1bd4f51772d44c9dcdf21f44ffb92cbc2c962eef Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 21 Jun 2006 09:16:53 +0000 Subject: [PATCH] Implement basic configuration of session_shared. --- etc/config-shared1.xml | 7 ++-- etc/config.xsd | 17 ++++++++-- src/filter_session_shared.cpp | 75 +++++++++++++++++++++++++++++++++++++---- src/filter_session_shared.hpp | 3 +- src/xmlutil.cpp | 11 +++++- src/xmlutil.hpp | 3 +- 6 files changed, 102 insertions(+), 14 deletions(-) diff --git a/etc/config-shared1.xml b/etc/config-shared1.xml index a7d6223..6d4c382 100644 --- a/etc/config-shared1.xml +++ b/etc/config-shared1.xml @@ -1,5 +1,5 @@ - + @@ -16,7 +16,10 @@ F - + + + + B diff --git a/etc/config.xsd b/etc/config.xsd index 1e4fd0d..e662e17 100644 --- a/etc/config.xsd +++ b/etc/config.xsd @@ -1,5 +1,5 @@ - + @@ -96,7 +95,19 @@ - + + + + + + + + + + + + + diff --git a/src/filter_session_shared.cpp b/src/filter_session_shared.cpp index b1351bd..4bf4e5c 100644 --- a/src/filter_session_shared.cpp +++ b/src/filter_session_shared.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_session_shared.cpp,v 1.13 2006-06-20 22:27:45 adam Exp $ +/* $Id: filter_session_shared.cpp,v 1.14 2006-06-21 09:16:54 adam Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -105,7 +105,10 @@ namespace metaproxy_1 { 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 { @@ -161,6 +164,9 @@ namespace metaproxy_1 { 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; }; } } @@ -369,10 +375,13 @@ yf::SessionShared::BackendInstancePtr yf::SessionShared::BackendClass::create_ba } -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() @@ -392,7 +401,10 @@ void yf::SessionShared::Rep::init(mp::Package &package, const Z_GDU *gdu, 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 " @@ -895,6 +907,9 @@ void yf::SessionShared::Rep::expire() 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)); } @@ -1023,6 +1038,54 @@ void yf::SessionShared::process(mp::Package &package) const 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; diff --git a/src/filter_session_shared.hpp b/src/filter_session_shared.hpp index 3043a78..9c76f69 100644 --- a/src/filter_session_shared.hpp +++ b/src/filter_session_shared.hpp @@ -1,4 +1,4 @@ -/* $Id: filter_session_shared.hpp,v 1.7 2006-06-19 23:54:02 adam Exp $ +/* $Id: filter_session_shared.hpp,v 1.8 2006-06-21 09:16:54 adam Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -40,6 +40,7 @@ namespace metaproxy_1 { ~SessionShared(); SessionShared(); void process(metaproxy_1::Package & package) const; + void configure(const xmlNode * ptr); private: boost::scoped_ptr m_p; }; diff --git a/src/xmlutil.cpp b/src/xmlutil.cpp index 0a333ea..7fa3667 100644 --- a/src/xmlutil.cpp +++ b/src/xmlutil.cpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.cpp,v 1.8 2006-06-19 13:08:00 adam Exp $ +/* $Id: xmlutil.cpp,v 1.9 2006-06-21 09:16:54 adam Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -32,6 +32,15 @@ bool mp_xml::get_bool(const xmlNode *ptr, bool default_value) return default_value; } +int mp_xml::get_int(const xmlNode *ptr, int default_value) +{ + if (ptr && ptr->type == XML_TEXT_NODE && ptr->content) + { + return atoi((const char *) ptr->content); + } + return default_value; +} + bool mp_xml::is_element(const xmlNode *ptr, const std::string &ns, const std::string &name) diff --git a/src/xmlutil.hpp b/src/xmlutil.hpp index 27d95af..ed27947 100644 --- a/src/xmlutil.hpp +++ b/src/xmlutil.hpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.hpp,v 1.7 2006-06-19 13:08:00 adam Exp $ +/* $Id: xmlutil.hpp,v 1.8 2006-06-21 09:16:54 adam Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -15,6 +15,7 @@ namespace metaproxy_1 { namespace xml { std::string get_text(const xmlNode *ptr); bool get_bool(const xmlNode *ptr, bool default_value); + int get_int(const xmlNode *ptr, int default_value); bool is_element(const xmlNode *ptr, const std::string &ns, const std::string &name); -- 1.7.10.4