users@glassfish.java.net

Re: IIS Integration problem with Load Balancing!

From: <glassfish_at_javadesktop.org>
Date: Sun, 02 Mar 2008 15:16:27 PST

thanks for your reply regarding the issue of the IIS integration problem with load balancing!

But I have also think the printf statements is the cause of the problem already and I have changed roundrobin.c as follow: (But the problem is still not resolved.)

/**
 *
 * Copyright 2000, 2001 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the proprietary information of Sun Microsystems, Inc.
 * Use is subject to license terms.
 *
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "loadbalancer.h"

const char* FILENAME = "C:\\Inetpub\\wwwroot\\sun-passthrough\\lbModule.log";
const char* HTTPS = "https://";
const char* HTTP = "http://";

//pointer to beginning of Http listeners
struct http_listener *http_listeners;
//pointer to beginning of Https listeners
struct http_listener *https_listeners;
//current position of Http listener
int currentHttpPos;
//current position of Https listener
int currentHttpsPos;
//number of active Http listeners
int activeHttpListSize;
//number of active Https listeners
int activeHttpsListSize;

char *logMessage;

int log(char* filename, char* message)
{
        FILE *fp = fopen(filename, "ab+");
        if( fp == NULL )
        {
                fprintf( fp, "Could not open file \"%s\"\n", filename );

                return EXIT_FAILURE;
        }
        else
        {
                fprintf( fp, "%s\n", message );
        }
        fclose(fp);
        return EXIT_SUCCESS;
}

/**
 *
 * Function Name: lb_policy_init
 *
 * Description : Initialization method for Userdefined load balancer module. Method called whenever there is a change in the active listener list.
 *
 */
int lb_policy_init(struct http_listener listener[], int noOfListeners)
{
        int x = 0;

        sprintf(logMessage, "There are %d listeners\n", noOfListeners);
        log(FILENAME, logMessage);

        //The list is parsed based on assumption that listeners is provided in below format
        //first all Http listeners
        //then all Https listeners
        //So two pointer and counts are maintained.
        //One for all Http listeners and other for all Https listeners
        http_listeners = listener;
        https_listeners = NULL;
        activeHttpsListSize = 0;
        for(x = 0; x < noOfListeners; x++)
        {
                sprintf(logMessage, "URL=%s weight=%d \n", listener[x].url, listener[x].weight);
                log(FILENAME, logMessage);
        }

        for(x = 0; x < noOfListeners; x++)
        {
                if(strstr(listener[x].url, HTTPS))
                {
                        https_listeners = &listener[x];
                        activeHttpListSize = x;
                        activeHttpsListSize = noOfListeners - activeHttpListSize;

                        break;
                }
        }

        currentHttpPos = -1;
        currentHttpsPos = -1;
        return 0;
}

/**
 *
 * Function Name: lb_decision
 *
 * Description : Decision method for choosing a listener for an incoming request. Method is called when a active listener is to be choosen for an incoming request.
 *
 */
char * lb_decision(int secure, char *url, struct header headers[], int noOfHeaders)
{
        int x;

        sprintf(logMessage, "Headers:\n");
        log(FILENAME, logMessage);

        for(x = 0; x < noOfHeaders; x++)
        {
                sprintf(logMessage, "%s=%s\n", headers[x].name,headers[x].value);
                log(FILENAME, logMessage);
        }

        if(secure && activeHttpsListSize > 0)
        {
                currentHttpsPos = (currentHttpsPos + 1) % activeHttpsListSize ;
                sprintf(logMessage, "Returning the listener (%s): %s\n", https_listeners[currentHttpsPos].name,
                        https_listeners[currentHttpsPos].url);
                log(FILENAME, logMessage);

                return https_listeners[currentHttpsPos].url;
        }
        else if(!secure && activeHttpListSize > 0)
        {
                currentHttpPos = (currentHttpPos + 1) % activeHttpListSize ;
                sprintf(logMessage, "Returning the listener (%s): %s\n", http_listeners[currentHttpPos].name,
                        http_listeners[currentHttpPos].url);
                log(FILENAME, logMessage);

                return http_listeners[currentHttpPos].url;
        }

        sprintf(logMessage, "Unable to find a matching daemon for the request %s\n", url);
        log(FILENAME, logMessage);

        return NULL;
}

Could you please direct me if there are any problem within this code?
[Message sent by forum member 'wpchau' (wpchau)]

http://forums.java.net/jive/thread.jspa?messageID=261896