From: Adam Dickmeiss Date: Wed, 26 Oct 2005 18:53:49 +0000 (+0000) Subject: Experiments with session map template. X-Git-Tag: YP2.0.0.2~169 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=b54482cdb759f092fcd07a9be4fdc8c28009b895;p=metaproxy-moved-to-github.git Experiments with session map template. --- diff --git a/etc/config1.xml b/etc/config1.xml index b768600..e828908 100644 --- a/etc/config1.xml +++ b/etc/config1.xml @@ -12,14 +12,17 @@ 210 - - mylog.log + + out.log + + + std::cerr - + @@ -29,6 +32,8 @@ + + mylog.log @@ -66,6 +71,42 @@ request-type Init,Search,HTTP,... origin IP of origin port Port + + +mother object filter-dom-hash + deletes pointers to contexts and filters on program exit +hash filter-type -> hash-filter-id -> Context + -> filter-binary-pointer + +moher object router pointer hash + +created in mother thread, read only structures. + +Context* filter.configure(dom ); + + + +process(Context con) + +where each filter can have is own context class + +yp2::filter::Log::Context : public Context + + +Filters are constructed with a FilterFactory class which exposes a +method + +Filter* createFilter(std::string type) + + .. which returns a filter +instance. (The interface pointer that is). The FilterFactory may later +offer function + loadModule(std::string filename); +or even + loadModules(std::string filenamemask); + + + --> diff --git a/src/Makefile.am b/src/Makefile.am index 51db6fb..30286b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.28 2005-10-26 14:12:00 marc Exp $ +## $Id: Makefile.am,v 1.29 2005-10-26 18:53:49 adam Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -19,7 +19,7 @@ libyp2_la_SOURCES = \ filter_virt_db.cpp filter_virt_db.hpp \ filter_z3950_client.cpp filter_z3950_client.hpp \ filter_backend_test.cpp filter_backend_test.hpp \ - test_util.cpp test_util.hpp + util.cpp util.hpp # Rules for programs.. @@ -44,6 +44,7 @@ check_PROGRAMS = \ test_filter_z3950_client \ test_filter_backend_test \ test_filter_virt_db \ + test_ses_map \ test_router_flexml TESTS=$(check_PROGRAMS) @@ -61,9 +62,9 @@ test_filter_log_SOURCES = test_filter_log.cpp test_filter_z3950_client_SOURCES = test_filter_z3950_client.cpp test_filter_backend_test_SOURCES = test_filter_backend_test.cpp test_filter_virt_db_SOURCES = test_filter_virt_db.cpp +test_ses_map_SOURCES = test_ses_map.cpp test_router_flexml_SOURCES = test_router_flexml.cpp - TESTLDADD = $(LDADD) -lboost_unit_test_framework test_filter1_LDADD = $(TESTLDADD) @@ -79,6 +80,7 @@ test_filter_log_LDADD = $(TESTLDADD) test_filter_z3950_client_LDADD = $(TESTLDADD) test_filter_backend_test_LDADD = $(TESTLDADD) test_filter_virt_db_LDADD = $(TESTLDADD) +test_ses_map_LDADD = $(TESTLDADD) test_router_flexml_LDADD = $(TESTLDADD) # doxygen target diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp index cace494..d7701ad 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -1,4 +1,4 @@ -/* $Id: ex_filter_frontend_net.cpp,v 1.13 2005-10-26 10:55:26 marc Exp $ +/* $Id: ex_filter_frontend_net.cpp,v 1.14 2005-10-26 18:53:49 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -103,7 +103,7 @@ int main(int argc, char **argv) // put Virt db filter in router yp2::filter::Virt_db filter_virt_db; filter_virt_db.add_map_db2vhost("Default", "indexdata.dk/gils"); - filter_virt_db.add_map_db2vhost("Local", "localhost:9999/Default"); + filter_virt_db.add_map_db2vhost("Local", "localhost:9100/Default"); router.append(filter_virt_db); diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index d8e9cdb..bab4687 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_backend_test.cpp,v 1.4 2005-10-25 21:32:01 adam Exp $ +/* $Id: filter_backend_test.cpp,v 1.5 2005-10-26 18:53:49 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -63,7 +63,7 @@ void yf::Backend_test::process(Package &package) const ODR odr = odr_createmem(ODR_ENCODE); if (apdu_req->which != Z_APDU_initRequest && - !m_p->m_sessions.active(package.session())) + !m_p->m_sessions.exist(package.session())) { apdu_res = zget_APDU(odr, Z_APDU_close); *apdu_res->u.close->closeReason = Z_Close_protocolError; diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index 6480379..9f8fe00 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_virt_db.cpp,v 1.8 2005-10-25 23:04:06 adam Exp $ +/* $Id: filter_virt_db.cpp,v 1.9 2005-10-26 18:53:49 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -29,13 +29,14 @@ namespace yp2 { namespace filter { struct Virt_db_set { Virt_db_set(yp2::Session &id, std::string setname, - std::string vhost); + std::string vhost, bool named_result_sets); Virt_db_set(); ~Virt_db_set(); yp2::Session m_backend_session; std::string m_backend_setname; std::string m_vhost; + bool m_named_result_sets; }; struct Virt_db_session { Virt_db_session(yp2::Session &id, bool use_vhost); @@ -68,8 +69,9 @@ namespace yp2 { } yf::Virt_db_set::Virt_db_set(yp2::Session &id, std::string setname, - std::string vhost) - : m_backend_session(id), m_backend_setname(setname), m_vhost(vhost) + std::string vhost, bool named_result_sets) + : m_backend_session(id), m_backend_setname(setname), m_vhost(vhost), + m_named_result_sets(named_result_sets) { } @@ -217,6 +219,7 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) std::string vhost; std::string database; std::string resultSetId = req->resultSetName; + bool support_named_result_sets = false; // whether backend supports it { boost::mutex::scoped_lock lock(m_sessions_mutex); @@ -335,6 +338,31 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) odr_destroy(odr); } + Z_GDU *gdu = init_package.response().get(); + // we hope to get an init response + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == + Z_APDU_initResponse) + { + if (ODR_MASK_GET(gdu->u.z3950->u.initResponse->options, + Z_Options_namedResultSets)) + support_named_result_sets = true; + } + else + { + ODR odr = odr_createmem(ODR_ENCODE); + Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse); + + Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records)); + apdu->u.searchResponse->records = rec; + rec->which = Z_Records_NSD; + rec->u.nonSurrogateDiagnostic = + zget_DefaultDiagFormat( + odr, YAZ_BIB1_DATABASE_UNAVAILABLE, database.c_str()); + package.response() = apdu; + + odr_destroy(odr); + return; + } } // sending search to backend Package search_package(id, package.origin()); @@ -377,7 +405,8 @@ void yf::Virt_db::Rep::search(Package &package, Z_APDU *apdu, bool &move_later) Ses_it it = m_sessions.find(package.session()); if (it != m_sessions.end()) it->second.m_sets[resultSetId] = - Virt_db_set(id, backend_resultSetId, vhost); + Virt_db_set(id, backend_resultSetId, vhost, + support_named_result_sets); } void yf::Virt_db::Rep::init(Package &package, Z_APDU *apdu, bool &move_later) diff --git a/src/session.hpp b/src/session.hpp index b4d8916..95de4e0 100644 --- a/src/session.hpp +++ b/src/session.hpp @@ -1,4 +1,4 @@ -/* $Id: session.hpp,v 1.10 2005-10-25 21:32:01 adam Exp $ +/* $Id: session.hpp,v 1.11 2005-10-26 18:53:49 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -74,22 +74,51 @@ namespace yp2 { template class session_map { public: void create(T &t, const yp2::Session &s) { - boost::mutex::scoped_lock lock(m_mutex); - m_map[s] = t; + boost::mutex::scoped_lock lock(m_map_mutex); + m_map[s] = SessionItem(t); }; void release(const yp2::Session &s) { - boost::mutex::scoped_lock lock(m_mutex); + boost::mutex::scoped_lock lock(m_map_mutex); m_map.erase(s); }; - bool active(const yp2::Session &s) { - typename std::map::const_iterator it; +#if 0 + T &get_session_data(const yp2::Session &s) { + boost::mutex::scoped_lock lock(m_map_mutex); + + typename std::map::const_iterator it; + it = m_map.find(s); + if (it == m_map.end()) + return 0; + boost::mutx::scoped_lock *scoped_ptr = + new boost::mutex::scoped_lock(it->second->m_item_mutex); + }; +#endif + bool exist(const yp2::Session &s) { + typename std::map::const_iterator it; it = m_map.find(s); return it == m_map.end() ? false : true; } private: - boost::mutex m_mutex; - std::mapm_map; + class SessionItem { + public: + SessionItem() {}; + SessionItem(T &t) : m_t(t) {}; + SessionItem &operator =(const SessionItem &s) { + if (this != &s) { + m_t = s.m_t; + } + return *this; + }; + SessionItem(const SessionItem &s) { + m_t = s.m_t; + }; + T m_t; + boost::mutex m_item_mutex; + }; + private: + boost::mutex m_map_mutex; + std::mapm_map; }; } diff --git a/src/test_filter_backend_test.cpp b/src/test_filter_backend_test.cpp index 93903ed..f1836b5 100644 --- a/src/test_filter_backend_test.cpp +++ b/src/test_filter_backend_test.cpp @@ -1,4 +1,4 @@ -/* $Id: test_filter_backend_test.cpp,v 1.3 2005-10-26 10:55:26 marc Exp $ +/* $Id: test_filter_backend_test.cpp,v 1.4 2005-10-26 18:53:49 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -8,7 +8,7 @@ #include #include -#include "test_util.hpp" +#include "util.hpp" #include "filter_backend_test.hpp" #include "filter_log.hpp" diff --git a/src/test_filter_virt_db.cpp b/src/test_filter_virt_db.cpp index 3c9a3d6..04bdca1 100644 --- a/src/test_filter_virt_db.cpp +++ b/src/test_filter_virt_db.cpp @@ -1,4 +1,4 @@ -/* $Id: test_filter_virt_db.cpp,v 1.6 2005-10-26 10:55:26 marc Exp $ +/* $Id: test_filter_virt_db.cpp,v 1.7 2005-10-26 18:53:49 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -8,7 +8,7 @@ #include #include -#include "test_util.hpp" +#include "util.hpp" #include "filter_virt_db.hpp" #include "filter_backend_test.hpp" #include "filter_log.hpp" diff --git a/src/test_ses_map.cpp b/src/test_ses_map.cpp new file mode 100644 index 0000000..6a89f83 --- /dev/null +++ b/src/test_ses_map.cpp @@ -0,0 +1,72 @@ +/* $Id: test_ses_map.cpp,v 1.1 2005-10-26 18:53:49 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ + +#include "config.hpp" +#include +#include + +#include "router.hpp" +#include "session.hpp" +#include "package.hpp" + +#include + +#include +#include +#define BOOST_AUTO_TEST_MAIN +#include + +#include +#include +#include +using namespace boost::unit_test; + + +namespace yp2 { + class SesMap; + + + class SesMap { + class Wrap { + public: + Wrap(const double &t) : m_t(t) { }; + double m_t; + boost::mutex m_mutex; + }; + private: + boost::mutex m_map_mutex; + public: + void create(SesMap &sm, const yp2::Session &s, double &t) { + boost::mutex::scoped_lock lock(m_map_mutex); + + boost::shared_ptr w_ptr(new Wrap(t)); + m_map_ptr[s] = w_ptr; + } + std::map >m_map_ptr; + }; +} + + +BOOST_AUTO_TEST_CASE( test_ses_map_1 ) +{ + try + { + yp2::SesMap ses_map; + } + catch ( ... ) { + BOOST_CHECK (false); + } +} + + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/src/test_util.cpp b/src/test_util.cpp deleted file mode 100644 index 0731cf3..0000000 --- a/src/test_util.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* $Id: test_util.cpp,v 1.1 2005-10-25 21:32:01 adam Exp $ - Copyright (c) 2005, Index Data. - -%LICENSE% - */ - -#include "config.hpp" - -#include -#include "test_util.hpp" - -bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { - YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); - - Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, q.c_str()); - if (!rpn) - { - yaz_pqf_destroy(pqf_parser); - return false; - } - yaz_pqf_destroy(pqf_parser); - Z_Query *query = (Z_Query *) odr_malloc(odr, sizeof(Z_Query)); - query->which = Z_Query_type_1; - query->u.type_1 = rpn; - - apdu->u.searchRequest->query = query; - return true; -} -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * c-file-style: "stroustrup" - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ diff --git a/src/test_util.hpp b/src/test_util.hpp deleted file mode 100644 index edfd9ad..0000000 --- a/src/test_util.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* $Id: test_util.hpp,v 1.1 2005-10-25 21:32:01 adam Exp $ - Copyright (c) 2005, Index Data. - -%LICENSE% - */ - -#ifndef TEST_UTIL_HPP -#define TEST_UTIL_HPP - -#include -#include -namespace yp2 { - struct util { - static bool pqf(ODR odr, Z_APDU *apdu, const std::string &q); - }; -} -#endif -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * c-file-style: "stroustrup" - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ diff --git a/src/util.cpp b/src/util.cpp new file mode 100644 index 0000000..a5eda13 --- /dev/null +++ b/src/util.cpp @@ -0,0 +1,36 @@ +/* $Id: util.cpp,v 1.1 2005-10-26 18:53:49 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ + +#include "config.hpp" + +#include +#include "util.hpp" + +bool yp2::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { + YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); + + Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, q.c_str()); + if (!rpn) + { + yaz_pqf_destroy(pqf_parser); + return false; + } + yaz_pqf_destroy(pqf_parser); + Z_Query *query = (Z_Query *) odr_malloc(odr, sizeof(Z_Query)); + query->which = Z_Query_type_1; + query->u.type_1 = rpn; + + apdu->u.searchRequest->query = query; + return true; +} +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/src/util.hpp b/src/util.hpp new file mode 100644 index 0000000..fa6f96b --- /dev/null +++ b/src/util.hpp @@ -0,0 +1,25 @@ +/* $Id: util.hpp,v 1.1 2005-10-26 18:53:49 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ + +#ifndef YP2_UTIL_HPP +#define YP2_UTIL_HPP + +#include +#include +namespace yp2 { + struct util { + static bool pqf(ODR odr, Z_APDU *apdu, const std::string &q); + }; +} +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */