X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ffilter_multi.cpp;h=f02ecc76ce8f5021ebe4383c6457541fd2322f95;hb=9b8466644a970341459fd3fe3b270defd337ed48;hp=ff69a5b99fb1659230f9902d3ff2144a751950f9;hpb=873ade0594902585596f39645598427d9e961e9a;p=metaproxy-moved-to-github.git diff --git a/src/filter_multi.cpp b/src/filter_multi.cpp index ff69a5b..f02ecc7 100644 --- a/src/filter_multi.cpp +++ b/src/filter_multi.cpp @@ -1,9 +1,26 @@ -/* $Id: filter_multi.cpp,v 1.26 2007-03-07 22:50:12 adam Exp $ +/* $Id: filter_multi.cpp,v 1.28 2007-11-18 10:44:40 adam Exp $ Copyright (c) 2005-2007, Index Data. - See the LICENSE file for details +This file is part of Metaproxy. + +Metaproxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Metaproxy; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ +#include + #include "config.hpp" #include "filter.hpp" @@ -31,7 +48,10 @@ namespace yf = mp::filter; namespace metaproxy_1 { namespace filter { - + enum multi_merge_type { + round_robin, + serve_order + }; struct Multi::BackendSet { BackendPtr m_backend; int m_count; @@ -57,6 +77,7 @@ namespace metaproxy_1 { ~FrontendSet(); void round_robin(int pos, int number, std::list &job); + void serve_order(int pos, int number, std::list &job); std::list m_backend_sets; std::string m_setname; @@ -104,6 +125,7 @@ namespace metaproxy_1 { boost::condition m_cond_session_ready; std::map m_clients; bool m_hide_unavailable; + multi_merge_type m_merge_type; }; } } @@ -111,6 +133,7 @@ namespace metaproxy_1 { yf::Multi::Rep::Rep() { m_hide_unavailable = false; + m_merge_type = round_robin; } bool yf::Multi::BackendSet::operator < (const BackendSet &k) const @@ -237,6 +260,32 @@ void yf::Multi::Frontend::multi_move(std::list &blist) g.join_all(); } +void yf::Multi::FrontendSet::serve_order(int start, int number, + std::list &jobs) +{ + int i; + for (i = 0; i < number; i++) + { + std::list::const_iterator bsit; + int voffset = 0; + int offset = start + i - 1; + for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end(); + bsit++) + { + if (offset >= voffset && offset < voffset + bsit->m_count) + { + PresentJob job; + job.m_backend = bsit->m_backend; + job.m_inside_pos = 0; + job.m_pos = offset - voffset + 1; + jobs.push_back(job); + break; + } + voffset += bsit->m_count; + } + } +} + void yf::Multi::FrontendSet::round_robin(int start, int number, std::list &jobs) { @@ -617,7 +666,21 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) std::list jobs; int start = *req->resultSetStartPoint; int number = *req->numberOfRecordsRequested; - it->second.round_robin(start, number, jobs); + + if (m_p->m_merge_type == round_robin) + it->second.round_robin(start, number, jobs); + else if (m_p->m_merge_type == serve_order) + it->second.serve_order(start, number, jobs); + + if (0) + { + std::list::const_iterator jit; + for (jit = jobs.begin(); jit != jobs.end(); jit++) + { + yaz_log(YLOG_LOG, "job pos=%d inside_pos=%d", + jit->m_pos, jit->m_inside_pos); + } + } std::list present_backend_list; @@ -1126,12 +1189,24 @@ void mp::filter::Multi::configure(const xmlNode * ptr) { m_p->m_hide_unavailable = true; } + else if (!strcmp((const char *) ptr->name, "mergetype")) + { + std::string mergetype = mp::xml::get_text(ptr); + if (mergetype == "roundrobin") + m_p->m_merge_type = round_robin; + else if (mergetype == "serveorder") + m_p->m_merge_type = serve_order; + else + throw mp::filter::FilterException + ("Bad mergetype " + mergetype + " in multi filter"); + + } else { throw mp::filter::FilterException ("Bad element " + std::string((const char *) ptr->name) - + " in virt_db filter"); + + " in multi filter"); } } }