From 00438314438f3dde00b532ac5d8d28ccc35c7096 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Wed, 17 Feb 2010 04:14:31 +0000 Subject: Working queue and chat components. Added a few useful start/stop scripts. Fixed lifecycle code to call start/stop/restart functions before APR pools are cleaned up in both parent and child processes. Minor build script improvements. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@910819 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/server/mod-wiring.cpp | 104 ++++++++++++++-------------- 1 file changed, 53 insertions(+), 51 deletions(-) (limited to 'sca-cpp/trunk/modules/server/mod-wiring.cpp') diff --git a/sca-cpp/trunk/modules/server/mod-wiring.cpp b/sca-cpp/trunk/modules/server/mod-wiring.cpp index e21f8be773..c21b0fe254 100644 --- a/sca-cpp/trunk/modules/server/mod-wiring.cpp +++ b/sca-cpp/trunk/modules/server/mod-wiring.cpp @@ -82,7 +82,7 @@ int translateReference(request_rec *r) { // Find the requested component const ServerConf& sc = httpd::serverConf(r, &mod_tuscany_wiring); - const list rpath(httpd::pathValues(r->uri)); + const list rpath(pathValues(r->uri)); const list comp(assoctree(cadr(rpath), sc.references)); if (isNil(comp)) return HTTP_NOT_FOUND; @@ -147,20 +147,20 @@ int translateService(request_rec *r) { // Find the requested component const ServerConf& sc = httpd::serverConf(r, &mod_tuscany_wiring); - const list path(httpd::pathValues(r->uri)); - const list svc(assocPath(path, sc.services)); + const list p(pathValues(r->uri)); + const list svc(assocPath(p, sc.services)); if (isNil(svc)) return DECLINED; debug(svc, "modwiring::translateService::service"); // Build a component-name + path-info URI - const list target(cons(cadr(svc), httpd::pathInfo(path, car(svc)))); + const list target(cons(cadr(svc), httpd::pathInfo(p, car(svc)))); debug(target, "modwiring::translateService::target"); // Dispatch to the target component using a local internal redirect - const string p(httpd::path(target)); - debug(p, "modwiring::translateService::path"); - const string redir(string("/redirect:/components") + httpd::path(target)); + const string tp(path(target)); + debug(tp, "modwiring::translateService::path"); + const string redir(string("/redirect:/components") + tp); debug(redir, "modwiring::translateService::redirect"); r->filename = apr_pstrdup(r->pool, c_str(redir)); r->handler = "mod_tuscany_wiring"; @@ -216,7 +216,7 @@ const failable > readComponents(const string& path) { } /** - * Return a tree of component-name + references pairs. The references are + * Return a list of component-name + references pairs. The references are * arranged in trees of reference-name + reference-target pairs. */ const list componentReferenceToTargetTree(const value& c) { @@ -229,12 +229,8 @@ const list componentReferenceToTargetAssoc(const list& c) { return cons(componentReferenceToTargetTree(car(c)), componentReferenceToTargetAssoc(cdr(c))); } -const list componentReferenceToTargetTree(const list& c) { - return mkbtree(sort(componentReferenceToTargetAssoc(c))); -} - /** - * Return a tree of service-URI-path + component-name pairs. Service-URI-paths are + * Return a list of service-URI-path + component-name pairs. Service-URI-paths are * represented as lists of URI path fragments. */ const list defaultBindingURI(const string& cn, const string& sn) { @@ -247,7 +243,7 @@ const list bindingToComponentAssoc(const string& cn, const string& sn, co const value uri(scdl::uri(car(b))); if (isNil(uri)) return cons(mklist(defaultBindingURI(cn, sn), cn), bindingToComponentAssoc(cn, sn, cdr(b))); - return cons(mklist(httpd::pathValues(c_str(string(uri))), cn), bindingToComponentAssoc(cn, sn, cdr(b))); + return cons(mklist(pathValues(c_str(string(uri))), cn), bindingToComponentAssoc(cn, sn, cdr(b))); } const list serviceToComponentAssoc(const string& cn, const list& s) { @@ -266,10 +262,6 @@ const list uriToComponentAssoc(const list& c) { return append(serviceToComponentAssoc(scdl::name(car(c)), scdl::services(car(c))), uriToComponentAssoc(cdr(c))); } -const list uriToComponentTree(const list& c) { - return mkbtree(sort(uriToComponentAssoc(c))); -} - /** * Configure the components declared in the server's deployment composite. */ @@ -277,18 +269,55 @@ const bool confComponents(ServerConf& sc) { if (sc.contributionPath == "" || sc.compositeName == "") return true; - // Read the component configuration and store the references and service - // URIs in trees for fast retrieval later + // Read the component configuration and store the references and service URIs + // in trees for fast retrieval later const failable > comps = readComponents(sc.contributionPath + sc.compositeName); if (!hasContent(comps)) return true; - sc.references = componentReferenceToTargetTree(content(comps)); - debug(sc.references, "modwiring::confComponents::references"); - sc.services = uriToComponentTree(content(comps)); - debug(sc.services, "modwiring::confComponents::services"); + const list refs = componentReferenceToTargetAssoc(content(comps)); + debug(refs, "modwiring::confComponents::references"); + sc.references = mkbtree(sort(refs)); + + const list svcs = uriToComponentAssoc(content(comps)); + debug(svcs, "modwiring::confComponents::services"); + sc.services = mkbtree(sort(svcs)); return true; } +/** + * Called after all the configuration commands have been run. + * Process the server configuration and configure the wiring for the deployed components. + */ +int postConfig(unused apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp, server_rec *s) { + // Count the calls to post config, skip the first one as + // postConfig is always called twice + const string k("tuscany::modwiring::postConfig"); + const int count = (int)httpd::userData(k, s); + httpd::putUserData(k, (void*)(count + 1), s); + if (count == 0) + return OK; + + // Configure the wiring for the deployed components + ServerConf& sc = httpd::serverConf(s, &mod_tuscany_wiring); + debug(sc.wiringServerName, "modwiring::postConfig::wiringServerName"); + debug(sc.contributionPath, "modwiring::postConfig::contributionPath"); + debug(sc.compositeName, "modwiring::postConfig::compositeName"); + confComponents(sc); + return OK; +} + +/** + * Child process initialization. + */ +void childInit(apr_pool_t* p, server_rec* svr_rec) { + gc_scoped_pool pool(p); + ServerConf *conf = (ServerConf*)ap_get_module_config(svr_rec->module_config, &mod_tuscany_wiring); + if(conf == NULL) { + cerr << "[Tuscany] Due to one or more errors mod_tuscany_wiring loading failed. Causing apache to stop loading." << endl; + exit(APEXIT_CHILDFATAL); + } +} + /** * Configuration commands. */ @@ -328,33 +357,6 @@ const command_rec commands[] = { {NULL, NULL, NULL, 0, NO_ARGS, NULL} }; -int postConfig(unused apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp, server_rec *s) { - // Count the calls to post config, skip the first one as - // postConfig is always called twice - const string k("tuscany::modwiring::postConfig"); - const int count = httpd::userData(k, s); - httpd::putUserData(k, count +1, s); - if (count == 0) - return OK; - - // Configure the wiring for the deployed components - ServerConf& sc = httpd::serverConf(s, &mod_tuscany_wiring); - debug(sc.wiringServerName, "modwiring::postConfig::wiringServerName"); - debug(sc.contributionPath, "modwiring::postConfig::contributionPath"); - debug(sc.compositeName, "modwiring::postConfig::compositeName"); - confComponents(sc); - return OK; -} - -void childInit(apr_pool_t* p, server_rec* svr_rec) { - gc_scoped_pool pool(p); - ServerConf *conf = (ServerConf*)ap_get_module_config(svr_rec->module_config, &mod_tuscany_wiring); - if(conf == NULL) { - cerr << "[Tuscany] Due to one or more errors mod_tuscany_wiring loading failed. Causing apache to stop loading." << endl; - exit(APEXIT_CHILDFATAL); - } -} - void registerHooks(unused apr_pool_t *p) { ap_hook_post_config(postConfig, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_child_init(childInit, NULL, NULL, APR_HOOK_MIDDLE); -- cgit v1.2.3