⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jk_workerenv.c

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ========================================================================= * *                                                                           * *                 The Apache Software License,  Version 1.1                 * *                                                                           * *          Copyright (c) 1999-2002 The Apache Software Foundation.          * *                           All rights reserved.                            * *                                                                           * * ========================================================================= * *                                                                           * * Redistribution and use in source and binary forms,  with or without modi- * * fication, are permitted provided that the following conditions are met:   * *                                                                           * * 1. Redistributions of source code  must retain the above copyright notice * *    notice, this list of conditions and the following disclaimer.          * *                                                                           * * 2. Redistributions  in binary  form  must  reproduce the  above copyright * *    notice,  this list of conditions  and the following  disclaimer in the * *    documentation and/or other materials provided with the distribution.   * *                                                                           * * 3. The end-user documentation  included with the redistribution,  if any, * *    must include the following acknowlegement:                             * *                                                                           * *       "This product includes  software developed  by the Apache  Software * *        Foundation <http://www.apache.org/>."                              * *                                                                           * *    Alternately, this acknowlegement may appear in the software itself, if * *    and wherever such third-party acknowlegements normally appear.         * *                                                                           * * 4. The names  "The  Jakarta  Project",  "Jk",  and  "Apache  Software     * *    Foundation"  must not be used  to endorse or promote  products derived * *    from this  software without  prior  written  permission.  For  written * *    permission, please contact <apache@apache.org>.                        * *                                                                           * * 5. Products derived from this software may not be called "Apache" nor may * *    "Apache" appear in their names without prior written permission of the * *    Apache Software Foundation.                                            * *                                                                           * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL * * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY * * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL * * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, * * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE * * POSSIBILITY OF SUCH DAMAGE.                                               * *                                                                           * * ========================================================================= * *                                                                           * * This software  consists of voluntary  contributions made  by many indivi- * * duals on behalf of the  Apache Software Foundation.  For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>.   * *                                                                           * * ========================================================================= *//*************************************************************************** * Description: Workers controller                                         * * Author:      Gal Shachor <shachor@il.ibm.com>                           * * Author:      Henri Gomez <hgomez@slib.fr>                               * * Version:     $Revision: 1.59 $                                           * ***************************************************************************/#include "jk_env.h"#include "jk_workerEnv.h" #include "jk_config.h"#include "jk_worker.h"#include "jk_shm.h"#include "jk_channel.h"#include "jk_registry.h"#define DEFAULT_WORKER              ("lb")static void jk2_workerEnv_close(jk_env_t *env, jk_workerEnv_t *wEnv);static void jk2_workerEnv_initHandlers(jk_env_t *env, jk_workerEnv_t *wEnv);static int  jk2_workerEnv_init1(jk_env_t *env, jk_workerEnv_t *wEnv);/* ==================== Setup ==================== */static int JK_METHOD jk2_workerEnv_setAttribute( struct jk_env *env, struct jk_bean *mbean,                                       char *name, void *valueP){    jk_workerEnv_t *wEnv=mbean->object;    char *value=valueP;    /** XXX Should it be per/uri ?     */    if( strcmp( name, "logger" )==0 ) {        wEnv->logger_name = value;    } else if( strcmp( name, "sslEnable" )==0 ) {        wEnv->ssl_enable = JK_TRUE;    } else if( strcmp( name, "timing" )==0 ) {        wEnv->timing= atoi( value );    } else if( strcmp( name, "httpsIndicator" )==0 ) {        wEnv->https_indicator = value;    } else if( strcmp( name, "certsIndicator" )==0 ) {        wEnv->certs_indicator = value;    } else if( strcmp( name, "cipherIndicator" )==0 ) {        wEnv->cipher_indicator = value;    } else if( strcmp( name, "sessionIndicator" )==0 ) {        wEnv->session_indicator = value;    } else if( strcmp( name, "keySizeIndicator" )==0 ) {        wEnv->key_size_indicator = value;    } else if( strcmp( name, "forwardKeySize" ) == 0 ) {        wEnv->options |= JK_OPT_FWDKEYSIZE;    /* Small change in how we treat options: we have a default,       and assume that any option declared by user has the intention       of overriding the default ( "-Option == no option, leave the       default    */    } else  if( strcmp( name, "forwardURICompat" )==0 ) {        wEnv->options &= ~JK_OPT_FWDURIMASK;        wEnv->options |=JK_OPT_FWDURICOMPAT;    } else if( strcmp( name, "forwardURICompatUnparsed" )==0 ) {        wEnv->options &= ~JK_OPT_FWDURIMASK;        wEnv->options |=JK_OPT_FWDURICOMPATUNPARSED;    } else if( strcmp( name, "forwardURIEscaped" )==0 ) {        wEnv->options &= ~JK_OPT_FWDURIMASK;        wEnv->options |= JK_OPT_FWDURIESCAPED;    } else {         return JK_ERR;    }    return JK_OK;}static void jk2_workerEnv_close(jk_env_t *env, jk_workerEnv_t *wEnv){    int sz;    int i;        sz = wEnv->worker_map->size(env, wEnv->worker_map);    for(i = 0 ; i < sz ; i++) {        jk_worker_t *w = wEnv->worker_map->valueAt(env, wEnv->worker_map, i);        if(w) {            env->l->jkLog(env, env->l, JK_LOG_DEBUG,                          "destroy worker %s\n",                          wEnv->worker_map->nameAt(env, wEnv->worker_map, i));            if( w->mbean->destroy !=NULL )                 w->mbean->destroy(env,w->mbean);        }    }    env->l->jkLog(env, env->l, JK_LOG_DEBUG,                  "workerEnv.close() done %d\n", sz);     wEnv->worker_map->clear(env, wEnv->worker_map);}static void jk2_workerEnv_checkSpace(jk_env_t *env, jk_pool_t *pool,                                     void ***tableP, int *sizeP, int id){    void **newTable;    int i;    int newSize=id+4;        if( *sizeP > id ) return;    /* resize the table */    newTable=(void **)pool->calloc( env, pool, newSize * sizeof( void *));    for( i=0; i<*sizeP; i++ ) {        newTable[i]= (*tableP)[i];    }    *tableP=newTable;    *sizeP=newSize;}static int jk2_workerEnv_initWorker(jk_env_t *env,                                    jk_workerEnv_t *wEnv, jk_worker_t *w ){    int rc;        if( (w == NULL) || (w->mbean == NULL) ) return JK_ERR;        if( w->mbean->disabled ) return JK_OK;            w->workerEnv=wEnv;    if( w->mbean->state >= JK_STATE_INIT ) return JK_OK;    if( w->mbean->init == NULL )        return JK_OK;    rc=w->mbean->init(env, w->mbean );            if( rc == JK_OK ) {        w->mbean->state=JK_STATE_INIT;    } else {        w->mbean->state=JK_STATE_DISABLED;        w->mbean->disabled=JK_TRUE;        env->l->jkLog(env, env->l, JK_LOG_ERROR,                      "workerEnv.initWorkers() init failed for %s\n",                       w->mbean->name);     }     return JK_OK;}static int jk2_workerEnv_initWorkers(jk_env_t *env,                                     jk_workerEnv_t *wEnv){    int i;    jk_worker_t *lb=wEnv->defaultWorker;    for( i=0; i< wEnv->worker_map->size( env, wEnv->worker_map ); i++ ) {        char *name= wEnv->worker_map->nameAt( env, wEnv->worker_map, i );        jk_worker_t *w= wEnv->worker_map->valueAt( env, wEnv->worker_map, i );        jk2_workerEnv_initWorker( env, wEnv, w );    }    return JK_OK;}static int jk2_workerEnv_initChannel(jk_env_t *env,                                     jk_workerEnv_t *wEnv, jk_channel_t *ch){    int rc=JK_OK;        ch->workerEnv=wEnv;    if( ch->mbean->disabled ) return JK_OK;        if( ch->mbean->init != NULL ) {        rc=ch->mbean->init(env, ch->mbean);        if(rc!=JK_OK) {            env->l->jkLog(env, env->l, JK_LOG_ERROR,                          "workerEnv.initChannel() init failed for %s\n",                           ch->mbean->name);            /* Disable the associated worker */            ch->worker->channel=NULL;            ch->worker->channelName=NULL;        }        jk2_workerEnv_initWorker( env, wEnv, ch->worker );    }        return rc;}static int jk2_workerEnv_initChannels(jk_env_t *env,                                      jk_workerEnv_t *wEnv){    int i;    for( i=0; i< wEnv->channel_map->size( env, wEnv->channel_map ); i++ ) {        char *name= wEnv->channel_map->nameAt( env, wEnv->channel_map, i );        jk_channel_t *ch= wEnv->channel_map->valueAt( env, wEnv->channel_map, i );        jk2_workerEnv_initChannel( env, wEnv, ch );    }    return JK_OK;}static void jk2_workerEnv_initHandlers(jk_env_t *env, jk_workerEnv_t *wEnv){    /* Find the max message id */    /* XXX accessing private data... env most provide some method to get this */    jk_map_t *registry=env->_registry;    int size=registry->size( env, registry );    int i;        for( i=0; i<size; i++ ) {        jk_handler_t *handler;        char *name= registry->nameAt( env, registry, i );        if( strncmp( name, "handler.", 8 ) == 0 ) {            jk_bean_t *jkb=env->createBean2(env, wEnv->pool, name, ""  );            if( jkb==NULL || jkb->object==NULL )                continue;            handler=(jk_handler_t *)jkb->object;            handler->init( env, handler, wEnv );        }    }}static int jk2_workerEnv_registerHandler(jk_env_t *env, jk_workerEnv_t *wEnv,                                         const char *type,                                         const char *name, int preferedId,                                         jk_handler_callback callback,                                         char *signature){        jk_handler_t *h=(jk_handler_t *)wEnv->pool->calloc( env, wEnv->pool, sizeof( jk_handler_t));    h->name=(char *)name;    h->messageId=preferedId;    h->callback=callback;    h->workerEnv=wEnv;    jk2_workerEnv_checkSpace( env, wEnv->pool,                              (void ***)&wEnv->handlerTable,                              &wEnv->lastMessageId,                              h->messageId );    wEnv->handlerTable[ h->messageId ]=h;    /*wEnv->l->jkLog( wEnv->l, JK_LOG_INFO, "Registered %s %d\n",*/    /*           handler->name, handler->messageId); */    return JK_OK;}/** Called from the parent, in a multi-process server. */static int jk2_workerEnv_parentInit(jk_env_t *env, jk_workerEnv_t *wEnv){    char *configFile;        env->l->init( env, env->l );    configFile=wEnv->config->file;    if(  configFile == NULL ) {        wEnv->config->setPropertyString( env, wEnv->config,                                         "config.file",                                         "${serverRoot}/conf/workers2.properties" );        configFile=wEnv->config->file;    }    if( wEnv->shm->mbean->disabled )        wEnv->shm=NULL;        if( wEnv->shm != NULL && ! wEnv->shm->mbean->disabled ) {        wEnv->shm->init( env, wEnv->shm );    }        if( wEnv->shm != NULL && wEnv->shm->head != NULL ) {        wEnv->shm->reset( env, wEnv->shm);        if( wEnv->mbean->debug > 0 )            env->l->jkLog(env, env->l, JK_LOG_DEBUG, "workerEnv.init() Reset shm\n" );    }	return JK_OK;}/** Normal child init */static int jk2_workerEnv_init(jk_env_t *env, jk_workerEnv_t *wEnv){    char *configFile;    jk_bean_t *jkb;       /* We need to pid here - Linux will return the pid of the thread if       called after init(), and we'll not be able to locate the slot id       This is part of the workarounds needed for Apache2's removal of       child_num from connection.    */    wEnv->childProcessId=getpid();        configFile=wEnv->config->file;    if(  configFile == NULL ) {        wEnv->config->setPropertyString( env, wEnv->config,                                         "config.file",                                         "${serverRoot}/conf/workers2.properties" );        configFile=wEnv->config->file;    }    jkb=env->createBean2(env, wEnv->mbean->pool,"threadMutex", NULL);    if( jkb != NULL ) {        wEnv->cs=jkb->object;        jkb->init(env, jkb );    }    if( wEnv->logger_name!=NULL){        jkb=env->getBean(env,wEnv->logger_name);        if (jkb == NULL){            jkb=env->createBean( env, env->globalPool, wEnv->logger_name);        }        env->alias( env, wEnv->logger_name, "logger");        env->l = jkb->object;    }    env->l->init( env, env->l );    /* Set default worker. It'll be used for all uris that have no worker     */    if( wEnv->defaultWorker == NULL ) {        jk_worker_t *w=wEnv->worker_map->get( env, wEnv->worker_map, "lb:lb" );                if( w==NULL ) {            jk_bean_t *jkb=env->createBean2(env, wEnv->pool, "lb", "lb" );            w=jkb->object;            if( wEnv->mbean->debug > 0 )                env->l->jkLog(env, env->l, JK_LOG_DEBUG, "workerEnv.init() create default worker %s\n",  jkb->name );        }        wEnv->defaultWorker= w;    }    if( wEnv->vm != NULL  && ! wEnv->vm->mbean->disabled ) {        wEnv->vm->init( env, wEnv->vm );    }    jk2_workerEnv_initChannels( env, wEnv );    jk2_workerEnv_initWorkers( env, wEnv );    jk2_workerEnv_initHandlers( env, wEnv );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -