CORBA::Object_ptr AWSLoadBalancing::selectObject()
{
ServerListIterator *srvIter;
Server *srvObj;
Server *minSrvObj;
CORBA::Object_var objVar;
objVar = NULL;
/*
* Find the server object with the smallest load
*/
minSrvObj = NULL;
srvIter = m_serverList.elements();
while ( srvIter->hasMoreElements( ) )
{
srvObj = srvIter->nextElement( );
/*
* If the server has not updated load information
* within the specified update interval, then do not
* consider it.
*/
if (srvObj->getTimeSinceLastUpdate( ) <
2*m_timer->getUpdateInterval( ))
{
/*
* If no initial server is set or the load factor on
* this server is smaller than the minimum, save this
* server as the new minimum.
*/
if ( (minSrvObj == NULL)
|| (srvObj->getLoadFactor( ) <
minSrvObj->getLoadFactor( ))
)
minSrvObj = srvObj;
}
}
delete srvIter;
/*
* Get the next object from the chosen server
*/
if (minSrvObj != NULL)
objVar = minSrvObj->selectObject( );
return (objVar != NULL ?
CORBA::Object::_duplicate( objVar ) : NULL);
}