You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2006/12/10 00:50:47 UTC

svn commit: r485092 - in /tomcat/connectors/trunk/jk/native/common: jk_lb_worker.c jk_lb_worker.h jk_status.c jk_util.c

Author: rjung
Date: Sat Dec  9 15:50:44 2006
New Revision: 485092

URL: http://svn.apache.org/viewvc?view=rev&rev=485092
Log:
Introduce general purpose functions for parsing
activation, state, method and lock strings.
Use them in jk_util and in status worker.
This enables to update via status worker additionally with
the string values, that it shows when listing workers.
Reorder constant arrays for these attributes
to put the order in sync with the integers
one can use when configuring.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
    tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h
    tomcat/connectors/trunk/jk/native/common/jk_status.c
    tomcat/connectors/trunk/jk/native/common/jk_util.c

Modified: tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c?view=diff&rev=485092&r1=485091&r2=485092
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c Sat Dec  9 15:50:44 2006
@@ -44,36 +44,36 @@
 #define JK_WORKER_USABLE_STICKY(w)   ((w)->state != JK_LB_STATE_ERROR && (w)->activation != JK_LB_ACTIVATION_STOPPED)
 
 static const char *lb_locking_type[] = {
-    "unknown",
     JK_LB_LOCK_TEXT_OPTIMISTIC,
     JK_LB_LOCK_TEXT_PESSIMISTIC,
+    "unknown",
     NULL
 };
 
 static const char *lb_method_type[] = {
-    "unknown",
     JK_LB_METHOD_TEXT_REQUESTS,
     JK_LB_METHOD_TEXT_TRAFFIC,
     JK_LB_METHOD_TEXT_BUSYNESS,
     JK_LB_METHOD_TEXT_SESSIONS,
+    "unknown",
     NULL
 };
 
 static const char *lb_state_type[] = {
-    "unknown",
     JK_LB_STATE_TEXT_NA,
     JK_LB_STATE_TEXT_OK,
     JK_LB_STATE_TEXT_RECOVER,
     JK_LB_STATE_TEXT_BUSY,
     JK_LB_STATE_TEXT_ERROR,
+    "unknown",
     NULL
 };
 
 static const char *lb_activation_type[] = {
-    "unknown",
     JK_LB_ACTIVATION_TEXT_ACTIVE,
     JK_LB_ACTIVATION_TEXT_DISABLED,
     JK_LB_ACTIVATION_TEXT_STOPPED,
+    "unknown",
     NULL
 };
 
@@ -115,22 +115,85 @@
     return lb_locking_type[p->lblock];
 }
 
+/* Return the int representation of the lb lock type */
+int jk_lb_get_lock_code(const char *v)
+{
+    if (!v)
+        return JK_LB_LOCK_DEF;
+    else if  (*v == 'o' || *v == 'O' || *v == '0')
+        return JK_LB_LOCK_OPTIMISTIC;
+    else if  (*v == 'p' || *v == 'P' || *v == '1')
+        return JK_LB_LOCK_PESSIMISTIC;
+    else
+        return JK_LB_LOCK_DEF;
+}
+
 /* Return the string representation of the lb method type */
 const char *jk_lb_get_method(lb_worker_t *p, jk_logger_t *l)
 {
     return lb_method_type[p->lbmethod];
 }
 
+/* Return the int representation of the lb lock type */
+int jk_lb_get_method_code(const char *v)
+{
+    if (!v)
+        return JK_LB_METHOD_DEF;
+    else if  (*v == 'r' || *v == 'R' || *v == '0')
+        return JK_LB_METHOD_REQUESTS;
+    else if  (*v == 't' || *v == 'T' || *v == '1')
+        return JK_LB_METHOD_TRAFFIC;
+    else if  (*v == 'b' || *v == 'B' || *v == '2')
+        return JK_LB_METHOD_BUSYNESS;
+    else if  (*v == 's' || *v == 'S' || *v == '3')
+        return JK_LB_METHOD_SESSIONS;
+    else
+        return JK_LB_METHOD_DEF;
+}
+
 /* Return the string representation of the balance worker state */
 const char *jk_lb_get_state(worker_record_t *p, jk_logger_t *l)
 {
     return lb_state_type[p->s->state];
 }
 
+/* Return the int representation of the lb lock type */
+int jk_lb_get_state_code(const char *v)
+{
+    if (!v)
+        return JK_LB_STATE_DEF;
+    else if  (*v == 'n' || *v == 'N' || *v == '0')
+        return JK_LB_STATE_NA;
+    else if  (*v == 'o' || *v == 'O' || *v == '1')
+        return JK_LB_STATE_OK;
+    else if  (*v == 'r' || *v == 'R' || *v == '2')
+        return JK_LB_STATE_RECOVER;
+    else if  (*v == 'b' || *v == 'B' || *v == '3')
+        return JK_LB_STATE_BUSY;
+    else if  (*v == 'e' || *v == 'E' || *v == '4')
+        return JK_LB_STATE_ERROR;
+    else
+        return JK_LB_STATE_DEF;
+}
+
 /* Return the string representation of the balance worker activation */
 const char *jk_lb_get_activation(worker_record_t *p, jk_logger_t *l)
 {
     return lb_activation_type[p->s->activation];
+}
+
+int jk_lb_get_activation_code(const char *v)
+{
+    if (!v)
+        return JK_LB_ACTIVATION_DEF;
+    else if (*v == 'a' || *v == 'A' || *v == '0')
+        return JK_LB_ACTIVATION_ACTIVE;
+    else if (*v == 'd' || *v == 'D' || *v == '1')
+        return JK_LB_ACTIVATION_DISABLED;
+    else if (*v == 's' || *v == 'S' || *v == '2')
+        return JK_LB_ACTIVATION_STOPPED;
+    else
+        return JK_LB_ACTIVATION_DEF;
 }
 
 /* Update the load multipliers wrt. lb_factor */

Modified: tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h?view=diff&rev=485092&r1=485091&r2=485092
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_lb_worker.h Sat Dec  9 15:50:44 2006
@@ -39,10 +39,10 @@
 #define JK_LB_WORKER_TYPE     (5)
 #define JK_LB_DEF_DOMAIN_NAME ("unknown")
 
-#define JK_LB_METHOD_REQUESTS          (1)
-#define JK_LB_METHOD_TRAFFIC           (2)
-#define JK_LB_METHOD_BUSYNESS          (3)
-#define JK_LB_METHOD_SESSIONS          (4)
+#define JK_LB_METHOD_REQUESTS          (0)
+#define JK_LB_METHOD_TRAFFIC           (1)
+#define JK_LB_METHOD_BUSYNESS          (2)
+#define JK_LB_METHOD_SESSIONS          (3)
 #define JK_LB_METHOD_DEF               (JK_LB_METHOD_REQUESTS)
 #define JK_LB_METHOD_MAX               (JK_LB_METHOD_SESSIONS)
 #define JK_LB_METHOD_TEXT_REQUESTS     ("Request")
@@ -50,30 +50,35 @@
 #define JK_LB_METHOD_TEXT_BUSYNESS     ("Busyness")
 #define JK_LB_METHOD_TEXT_SESSIONS     ("Sessions")
 #define JK_LB_METHOD_TEXT_DEF          (JK_LB_METHOD_TEXT_REQUESTS)
-#define JK_LB_LOCK_OPTIMISTIC          (1)
-#define JK_LB_LOCK_PESSIMISTIC         (2)
+#define JK_LB_LOCK_OPTIMISTIC          (0)
+#define JK_LB_LOCK_PESSIMISTIC         (1)
 #define JK_LB_LOCK_DEF                 (JK_LB_LOCK_OPTIMISTIC)
 #define JK_LB_LOCK_MAX                 (JK_LB_LOCK_PESSIMISTIC)
 #define JK_LB_LOCK_TEXT_OPTIMISTIC     ("Optimistic")
 #define JK_LB_LOCK_TEXT_PESSIMISTIC    ("Pessimistic")
 #define JK_LB_LOCK_TEXT_DEF            (JK_LB_LOCK_TEXT_OPTIMISTIC)
-#define JK_LB_STATE_NA                 (1)
-#define JK_LB_STATE_OK                 (2)
-#define JK_LB_STATE_RECOVER            (3)
-#define JK_LB_STATE_BUSY               (4)
-#define JK_LB_STATE_ERROR              (5)
+#define JK_LB_STATE_NA                 (0)
+#define JK_LB_STATE_OK                 (1)
+#define JK_LB_STATE_RECOVER            (2)
+#define JK_LB_STATE_BUSY               (3)
+#define JK_LB_STATE_ERROR              (4)
+#define JK_LB_STATE_DEF                (JK_LB_STATE_NA)
 #define JK_LB_STATE_TEXT_NA            ("N/A")
 #define JK_LB_STATE_TEXT_OK            ("OK")
 #define JK_LB_STATE_TEXT_RECOVER       ("REC")
 #define JK_LB_STATE_TEXT_BUSY          ("BSY")
 #define JK_LB_STATE_TEXT_ERROR         ("ERR")
-#define JK_LB_ACTIVATION_ACTIVE        (1)
-#define JK_LB_ACTIVATION_DISABLED      (2)
-#define JK_LB_ACTIVATION_STOPPED       (3)
+#define JK_LB_STATE_TEXT_MAX           (JK_LB_STATE_ERROR)
+#define JK_LB_STATE_TEXT_DEF           (JK_LB_STATE_TEXT_NA)
+#define JK_LB_ACTIVATION_ACTIVE        (0)
+#define JK_LB_ACTIVATION_DISABLED      (1)
+#define JK_LB_ACTIVATION_STOPPED       (2)
+#define JK_LB_ACTIVATION_DEF           (JK_LB_ACTIVATION_ACTIVE)
 #define JK_LB_ACTIVATION_MAX           (JK_LB_ACTIVATION_STOPPED)
 #define JK_LB_ACTIVATION_TEXT_ACTIVE   ("ACT")
 #define JK_LB_ACTIVATION_TEXT_DISABLED ("DIS")
 #define JK_LB_ACTIVATION_TEXT_STOPPED  ("STP")
+#define JK_LB_ACTIVATION_TEXT_DEF      (JK_LB_ACTIVATION_TEXT_ACTIVE)
 
 #define JK_LB_UINT64_STR_SZ          (21)
 #define JK_LB_NOTES_COUNT            (9)
@@ -149,9 +154,13 @@
                                 const char *name, jk_logger_t *l);
 
 const char *jk_lb_get_lock(lb_worker_t *p, jk_logger_t *l);
+int jk_lb_get_lock_code(const char *v);
 const char *jk_lb_get_method(lb_worker_t *p, jk_logger_t *l);
+int jk_lb_get_method_code(const char *v);
 const char *jk_lb_get_state(worker_record_t *p, jk_logger_t *l);
+int jk_lb_get_state_code(const char *v);
 const char *jk_lb_get_activation(worker_record_t *p, jk_logger_t *l);
+int jk_lb_get_activation_code(const char *v);
 void reset_lb_values(lb_worker_t *p, jk_logger_t *l);
 void jk_lb_pull(lb_worker_t * p, jk_logger_t *l);
 void jk_lb_push(lb_worker_t * p, jk_logger_t *l);

Modified: tomcat/connectors/trunk/jk/native/common/jk_status.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_status.c?view=diff&rev=485092&r1=485091&r2=485092
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_status.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_status.c Sat Dec  9 15:50:44 2006
@@ -1894,6 +1894,7 @@
 {
     const char *name = NULL;
     lb_worker_t *lb = NULL;
+    const char *arg;
     int i;
 
     JK_TRACE_ENTER(l);
@@ -1952,21 +1953,23 @@
                name, i);
         lb->sticky_session_force = i;
     }
-    i = status_get_int(p, JK_STATUS_ARG_LB_METHOD,
-                       lb->lbmethod, l);
-    if (i != lb->lbmethod && i > 0 && i <= JK_LB_METHOD_MAX) {
-        jk_log(l, JK_LOG_INFO,
-               "setting 'method' for lb worker '%s' to '%i'",
-               name, i);
-        lb->lbmethod = i;
+    if (status_get_string(p, JK_STATUS_ARG_LB_METHOD, NULL, &arg, l) == JK_TRUE) {
+        i = jk_lb_get_method_code(arg);
+        if (i != lb->lbmethod && i >= 0 && i <= JK_LB_METHOD_MAX) {
+            lb->lbmethod = i;
+            jk_log(l, JK_LOG_INFO,
+                   "setting 'method' for lb worker '%s' to '%s'",
+                   name, jk_lb_get_method(lb, l));
+        }
     }
-    i = status_get_int(p, JK_STATUS_ARG_LB_LOCK,
-                       lb->lblock, l);
-    if (i != lb->lblock && i > 0 && i <= JK_LB_LOCK_MAX) {
-        jk_log(l, JK_LOG_INFO,
-               "setting 'lock' for lb worker '%s' to '%i'",
-               name, i);
-        lb->lblock = i;
+    if (status_get_string(p, JK_STATUS_ARG_LB_LOCK, NULL, &arg, l) == JK_TRUE) {
+        i = jk_lb_get_lock_code(arg);
+        if (i != lb->lblock && i >= 0 && i <= JK_LB_LOCK_MAX) {
+            lb->lblock = i;
+            jk_log(l, JK_LOG_INFO,
+                   "setting 'lock' for lb worker '%s' to '%s'",
+                   name, jk_lb_get_lock(lb, l));
+        }
     }
     lb->sequence++;
     jk_lb_push(lb, l);
@@ -1989,14 +1992,15 @@
                "committing changes for sub worker '%s' of lb worker '%s'",
                wr->s->name, lb_name);
 
-    i = status_get_int(p, JK_STATUS_ARG_LBM_ACTIVATION,
-                       wr->s->activation, l);
-    if (i != wr->s->activation && i > 0 && i<= JK_LB_ACTIVATION_MAX) {
-        wr->s->activation = i;
-        jk_log(l, JK_LOG_INFO,
-               "setting 'activation' for sub worker '%s' of lb worker '%s' to '%s'",
-               wr->s->name, lb_name, jk_lb_get_activation(wr, l));
-        rc |= 1;
+    if (status_get_string(p, JK_STATUS_ARG_LBM_ACTIVATION, NULL, &arg, l) == JK_TRUE) {
+        i = jk_lb_get_activation_code(arg);
+        if (i != wr->s->activation && i >= 0 && i <= JK_LB_ACTIVATION_MAX) {
+            wr->s->activation = i;
+            jk_log(l, JK_LOG_INFO,
+                   "setting 'activation' for sub worker '%s' of lb worker '%s' to '%s'",
+                   wr->s->name, lb_name, jk_lb_get_activation(wr, l));
+            rc |= 1;
+        }
     }
     i = status_get_int(p, JK_STATUS_ARG_LBM_FACTOR,
                        wr->s->lb_factor, l);
@@ -2118,17 +2122,7 @@
             worker_record_t *wr = &(lb->lb_workers[j]);
             snprintf(vname, 32-1, "" JK_STATUS_ARG_MULT_VALUE_BASE "%d", j);
 
-            if (!strcmp(attribute, JK_STATUS_ARG_LBM_ACTIVATION)) {
-                i = status_get_int(p, vname, wr->s->activation, l);
-                if (i != wr->s->activation && i > 0 && i<= JK_LB_ACTIVATION_MAX) {
-                    wr->s->activation = i;
-                    jk_log(l, JK_LOG_INFO,
-                           "setting 'activation' for sub worker '%s' of lb worker '%s' to '%s'",
-                           wr->s->name, name, jk_lb_get_activation(wr, l));
-                    rc = 1;
-                }
-            }
-            else if (!strcmp(attribute, JK_STATUS_ARG_LBM_FACTOR)) {
+            if (!strcmp(attribute, JK_STATUS_ARG_LBM_FACTOR)) {
                 i = status_get_int(p, vname, wr->s->lb_factor, l);
                 if (i != wr->s->lb_factor && i > 0) {
                     jk_log(l, JK_LOG_INFO,
@@ -2149,7 +2143,19 @@
             }
             else {
                 int rv = status_get_string(p, vname, NULL, &arg, l);
-                if (!strcmp(attribute, JK_STATUS_ARG_LBM_ROUTE)) {
+                if (!strcmp(attribute, JK_STATUS_ARG_LBM_ACTIVATION)) {
+                    if (rv == JK_TRUE) {
+                        i = jk_lb_get_activation_code(arg);
+                        if (i != wr->s->activation && i >= 0 && i <= JK_LB_ACTIVATION_MAX) {
+                            wr->s->activation = i;
+                            jk_log(l, JK_LOG_INFO,
+                                   "setting 'activation' for sub worker '%s' of lb worker '%s' to '%s'",
+                                   wr->s->name, name, jk_lb_get_activation(wr, l));
+                            rc = 1;
+                        }
+                    }
+                }
+                else if (!strcmp(attribute, JK_STATUS_ARG_LBM_ROUTE)) {
                     if (rv == JK_TRUE) {
                         if (strncmp(wr->s->route, arg, JK_SHM_STR_SIZ)) {
                             jk_log(l, JK_LOG_INFO,

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_util.c?view=diff&rev=485092&r1=485091&r2=485092
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.c Sat Dec  9 15:50:44 2006
@@ -897,21 +897,14 @@
     MAKE_WORKER_PARAM(ACTIVATION_OF_WORKER);
     v = jk_map_get_string(m, buf, NULL);
     if (v) {
-        if (*v == 'a' || *v == 'A')
-            return JK_LB_ACTIVATION_ACTIVE;
-        else if (*v == 's' || *v == 'S')
-            return JK_LB_ACTIVATION_STOPPED;
-        else if (*v == 'd' || *v == 'D')
-            return JK_LB_ACTIVATION_DISABLED;
-        else
-            return JK_LB_ACTIVATION_ACTIVE;
+        return jk_lb_get_activation_code(v);
     }
     else if (jk_get_is_worker_stopped(m, wname))
         return JK_LB_ACTIVATION_STOPPED;
     else if (jk_get_is_worker_disabled(m, wname))
         return JK_LB_ACTIVATION_DISABLED;
     else
-        return JK_LB_ACTIVATION_ACTIVE;
+        return JK_LB_ACTIVATION_DEF;
 }
 
 int jk_get_lb_factor(jk_map_t *m, const char *wname)
@@ -978,18 +971,7 @@
 
     MAKE_WORKER_PARAM(METHOD_OF_WORKER);
     v = jk_map_get_string(m, buf, NULL);
-    if (!v)
-        return JK_LB_METHOD_DEF;
-    else if  (*v == 'r' || *v == 'R' || *v == '0')
-        return JK_LB_METHOD_REQUESTS;
-    else if  (*v == 't' || *v == 'T' || *v == '1')
-        return JK_LB_METHOD_TRAFFIC;
-    else if  (*v == 'b' || *v == 'B' || *v == '2')
-        return JK_LB_METHOD_BUSYNESS;
-    else if  (*v == 's' || *v == 'S' || *v == '3')
-        return JK_LB_METHOD_SESSIONS;
-    else
-        return JK_LB_METHOD_DEF;
+    return jk_lb_get_method_code(v);
 }
 
 int jk_get_lb_lock(jk_map_t *m, const char *wname)
@@ -1002,14 +984,7 @@
 
     MAKE_WORKER_PARAM(LOCK_OF_WORKER);
     v = jk_map_get_string(m, buf, NULL);
-    if (!v)
-        return JK_LB_LOCK_DEF;
-    else if  (*v == 'o' || *v == 'O' || *v == '0')
-        return JK_LB_LOCK_OPTIMISTIC;
-    else if  (*v == 'p' || *v == 'P' || *v == '1')
-        return JK_LB_LOCK_PESSIMISTIC;
-    else
-        return JK_LB_LOCK_DEF;
+    return jk_lb_get_lock_code(v);
 }
 
 int jk_get_max_packet_size(jk_map_t *m, const char *wname)



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org