tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hgo...@apache.org
Subject cvs commit: jakarta-tomcat/proposals/web-connector/native/common jk_worker.c jk_worker.h jk_worker_list.h
Date Thu, 03 May 2001 14:38:27 GMT
hgomez      01/05/03 07:38:27

  Added:       proposals/web-connector/native/common jk_worker.c
                        jk_worker.h jk_worker_list.h
  Log:
  worker stuff
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat/proposals/web-connector/native/common/jk_worker.c
  
  Index: jk_worker.c
  ===================================================================
  /*
   * Copyright (c) 1997-1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *
   * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called "Apache JServ"
   *    nor may "Apache" nor "Apache JServ" appear in their names without 
   *    prior written permission of the Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "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 JAVA APACHE PROJECT 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
   * individuals on behalf of the Java Apache Group. For more information
   * on the Java Apache Project and the Apache JServ Servlet Engine project,
   * please see <http://java.apache.org/>.
   *
   */
  
  /***************************************************************************
   * Description: Workers controller                                         *
   * Author:      Gal Shachor <shachor@il.ibm.com>                           *
   * Version:     $Revision: 1.1 $                                           *
   ***************************************************************************/
  
  #define _PLACE_WORKER_LIST_HERE
  #include "jk_worker_list.h"
  #include "jk_worker.h"
  #include "jk_util.h"
  
  static void close_workers(void);
  
  static worker_factory get_factory_for(char *type);
  
  static int build_worker_map(jk_map_t *init_data, 
                              char **worker_list, 
                              unsigned num_of_workers,
                              jk_logger_t *l);
  
  int wc_open(jk_map_t *init_data,
              jk_logger_t *l)
  {
      char **worker_list  = NULL;
      unsigned num_of_workers = 0;
  
      jk_log(l, JK_LOG_DEBUG, "Into wc_open\n"); 
  
      if(!map_alloc(&worker_map)) {
          return JK_FALSE;
      }
      
      if(!jk_get_worker_list(init_data, 
                             &worker_list, 
                             &num_of_workers)) {
          return JK_FALSE;
      }
      
      if(!build_worker_map(init_data, 
                           worker_list, 
                           num_of_workers,
                           l)) {
          close_workers();
          return JK_FALSE;
      }
  
      jk_log(l, JK_LOG_DEBUG, "wc_open, done\n"); 
      return JK_TRUE;
  }
  
  
  void wc_close(jk_logger_t *l)
  {
      jk_log(l, JK_LOG_DEBUG, "Into wc_close\n"); 
      close_workers();
      jk_log(l, JK_LOG_DEBUG, "wc_close, done\n"); 
  }
  
  jk_worker_t *wc_get_worker_for_name(const char *name, 
                                      jk_logger_t *l)
  {
      jk_worker_t * rc;
  
      if(!name) {
          jk_log(l, JK_LOG_ERROR, "wc_get_worker_for_name NULL name\n"); 
      }
  
      jk_log(l, JK_LOG_DEBUG, "Into wc_get_worker_for_name %s\n", name); 
  
      rc = map_get(worker_map, name, NULL);
  
      jk_log(l, JK_LOG_DEBUG, "wc_get_worker_for_name, done %s found a worker\n", 
          rc ? "" : "did not"); 
      return rc;
  }
  
  
  int wc_create_worker(const char *name, 
                       jk_map_t *init_data,
                       jk_worker_t **rc,
                       jk_logger_t *l)
  {
      jk_log(l, JK_LOG_DEBUG, "Into wc_create_worker\n"); 
  
      if(rc) {
          char *type = jk_get_worker_type(init_data, name);
          worker_factory fac = get_factory_for(type);
          jk_worker_t *w = NULL;
  
          *rc = NULL;
  
          if(!fac) {
              jk_log(l, JK_LOG_ERROR, "wc_create_worker NULL factory for %s\n", type); 
              return JK_FALSE;
          }
  
          jk_log(l, JK_LOG_DEBUG, "wc_create_worker, about to create instance %s of %s\n",

                 name, type);         
  
          if(!fac(&w, name, l) || !w) {
              jk_log(l, JK_LOG_ERROR, "wc_create_worker factory for %s failed for %s\n", 
                     type, name); 
              return JK_FALSE;
          }
          
          jk_log(l, JK_LOG_DEBUG, "wc_create_worker, about to validate and init %s\n", name);
        
          if(!w->validate(w, init_data, l)) {
              w->destroy(&w, l);
              jk_log(l, JK_LOG_ERROR, "wc_create_worker validate failed for %s\n", 
                     name); 
              return JK_FALSE;
          }
      
          if(!w->init(w, init_data, l)) {
              w->destroy(&w, l);
              jk_log(l, JK_LOG_ERROR, "wc_create_worker init failed for %s\n", 
                     name); 
              return JK_FALSE;
          }
  
          *rc = w;
          jk_log(l, JK_LOG_DEBUG, "wc_create_worker, done\n"); 
          return JK_TRUE;
      }
  
      jk_log(l, JK_LOG_ERROR, "wc_create_worker, NUll input\n"); 
      return JK_FALSE;
  }
  
  static void close_workers(void)
  {
      int sz = map_size(worker_map);
      if(sz > 0) {
          int i;
          for(i = 0 ; i < sz ; i++) {
              jk_worker_t *w = map_value_at(worker_map, i);
              if(w) {
                  w->destroy(&w, NULL);
              }
          }
      }
      map_free(&worker_map);
  }
  
  static int build_worker_map(jk_map_t *init_data, 
                              char **worker_list, 
                              unsigned num_of_workers,
                              jk_logger_t *l)
  {
      unsigned i;
  
      jk_log(l, JK_LOG_DEBUG, 
             "Into build_worker_map, creating %d workers\n", num_of_workers); 
  
      for(i = 0 ; i < num_of_workers ; i++) {
          jk_worker_t *w = NULL;
  
          jk_log(l, JK_LOG_DEBUG, 
                 "build_worker_map, creating worker %s\n", worker_list[i]); 
  
          if(wc_create_worker(worker_list[i], init_data, &w, l)) {
              jk_worker_t *oldw = NULL;
              if(!map_put(worker_map, worker_list[i], w, (void *)&oldw)) {
                  w->destroy(&w, l);
                  return JK_FALSE;
              }
  
              jk_log(l, JK_LOG_DEBUG, 
                     "build_worker_map, removing old %s worker \n", worker_list[i]); 
              if(oldw) {
                  oldw->destroy(&oldw, l);
              }
          } else {        
              jk_log(l, JK_LOG_ERROR, "build_worker_map failed to create worker%s\n", 
                     worker_list[i]); 
              return JK_FALSE;
          }
      }
  
      jk_log(l, JK_LOG_DEBUG, "build_worker_map, done\n"); 
      return JK_TRUE;
  }
  
  static worker_factory get_factory_for(char *type)
  {
      worker_factory_record_t *factory = &worker_factories[0];
      while(factory->name) {
          if(0 == strcmp(factory->name, type)) {
              return factory->fac;
          }
  
          factory ++;
      }
  
      return NULL;
  }
  
  
  
  1.1                  jakarta-tomcat/proposals/web-connector/native/common/jk_worker.h
  
  Index: jk_worker.h
  ===================================================================
  /*
   * Copyright (c) 1997-1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *
   * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called "Apache JServ"
   *    nor may "Apache" nor "Apache JServ" appear in their names without 
   *    prior written permission of the Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "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 JAVA APACHE PROJECT 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
   * individuals on behalf of the Java Apache Group. For more information
   * on the Java Apache Project and the Apache JServ Servlet Engine project,
   * please see <http://java.apache.org/>.
   *
   */
  
  /***************************************************************************
   * Description: Workers controller header file                             *
   * Author:      Gal Shachor <shachor@il.ibm.com>                           * 
   * Version:     $Revision: 1.1 $                                               *
   ***************************************************************************/
  
  #ifndef JK_WORKER_H
  #define JK_WORKER_H
  
  #include "jk_logger.h"
  #include "jk_service.h"
  #include "jk_map.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif /* __cplusplus */
  
  int wc_open(jk_map_t *init_data,
              jk_logger_t *l);
  
  void wc_close(jk_logger_t *l);
  
  jk_worker_t *wc_get_worker_for_name(const char *name, 
                                      jk_logger_t *l);
  
  int wc_create_worker(const char *name, 
                       jk_map_t *init_data,
                       jk_worker_t **rc,
                       jk_logger_t *l);
  
  
  #ifdef __cplusplus
  }
  #endif /* __cplusplus */
  
  #endif /* JK_WORKER_H */
  
  
  
  1.1                  jakarta-tomcat/proposals/web-connector/native/common/jk_worker_list.h
  
  Index: jk_worker_list.h
  ===================================================================
  /*
   * Copyright (c) 1997-1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *
   * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called "Apache JServ"
   *    nor may "Apache" nor "Apache JServ" appear in their names without 
   *    prior written permission of the Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "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 JAVA APACHE PROJECT 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
   * individuals on behalf of the Java Apache Group. For more information
   * on the Java Apache Project and the Apache JServ Servlet Engine project,
   * please see <http://java.apache.org/>.
   *
   */
  
  /***************************************************************************
   * Description: Worker list                                                *
   * Author:      Gal Shachor <shachor@il.ibm.com>                           *
   * Version:     $Revision: 1.1 $                                           *
   ***************************************************************************/
  
  /*
   * This file includes a list of all the possible workers in the jk library
   * plus their factories. 
   *
   * If you want to add a worker just place it in the worker_factories array
   * with its unique name and factory.
   *
   * If you want to remove a worker, hjust comment out its line in the 
   * worker_factories array as well as its header file. For example, look
   * at what we have done to the ajp23 worker.
   *
   * Note: This file should be included only in the jk_worker controller.
   * Currently the jk_worker controller is located in jk_worker.c
   */
  #ifdef _PLACE_WORKER_LIST_HERE
      #ifndef _JK_WORKER_LIST_H
      #define _JK_WORKER_LIST_H
  
          #include "jk_ajp12_worker.h"
          #include "jk_ajp13_worker.h"
          /* #include "jk_ajp23_worker.h" */
          #ifndef HPUX11GCC
              #include "jk_jni_worker.h"
          #endif
          #include "jk_lb_worker.h"
  
          struct worker_factory_record {
              const char *name;
              worker_factory fac;
          };
          typedef struct worker_factory_record worker_factory_record_t;
  
          static jk_map_t *worker_map;
  
          static worker_factory_record_t worker_factories[] = {
              /*
               * AJPv12 worker, this is the stable worker.
               */
              { JK_AJP12_WORKER_NAME, ajp12_worker_factory},
              /*
               * AJPv13 worker, fast bi-directional worker.
               */
              { JK_AJP13_WORKER_NAME, ajp13_worker_factory},
  
              /*
               * Sample commented out (and deprecated) factory.
               */
              /*{ JK_AJP23_WORKER_NAME, ajp23_worker_factory},*/
  
              /*
               * In process JNI based worker. Requires the server to be 
               * multithreaded and to use native threads.
               */
              #ifndef HPUX11GCC
                  { JK_JNI_WORKER_NAME, jni_worker_factory},
              #endif
              /*
               * Load balancing worker. Performs round robin with sticky 
               * session load balancing.
               */
              { JK_LB_WORKER_NAME, lb_worker_factory},
  
              /*
               * Marks the end of the worker factory list.
               */
              { NULL, NULL}
      };
      #endif /* _JK_WORKER_LIST_H */
  #endif /* _PLACE_WORKER_LIST_HERE */
  
  

Mime
View raw message