Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

UnicastRequestHandler.cc

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: UnicastRequestHandler.cc,v 1.3 2004/05/19 15:56:59 mmarsh Exp $
00008 //
00009 // $Log: UnicastRequestHandler.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:59  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:51  mmarsh
00014 // *** empty log message ***
00015 //
00016 //
00017 
00018 #include "UnicastRequestHandler.h"
00019 #include "UnicastRequestEvent.h"
00020 #include "ServerState.h"
00021 
00022 #include "ServerExceptions.h"
00023 
00024 #include <sys/time.h>
00025 
00026 using namespace CODEX_Server;
00027 
00029 bool
00030 UnicastRequestHandler::handler( UnicastRequestEvent& event )
00031 {
00032    // If the unicast does not reach a quorum, the event will be
00033    // re-queued.
00034    CODEX_Quorum::QuorumSystem* qs = ServerState::instance()->quorumSystem();
00035    if ( 0 == qs )
00036    {
00037       throw NoQuorumSystemException( __FILE__ , __LINE__ );
00038    }
00039    try
00040    {
00041       struct timeval tv;
00042       gettimeofday(&tv,0);
00043       if ( ( tv.tv_sec - event.time() ) < 3 )
00044       {
00045          return false;
00046       }
00047       event.updateTime( tv.tv_sec );
00048       if ( ! event.bcast() )
00049       {
00050          event.setBcast();
00051          bool bVal = qs->unicastMessage( event.messages(),
00052                                          event.retVals(),
00053                                          event.cb() );
00054          bool retVal = false;
00055          CODEX_Quorum::ReturnVector::const_iterator itr =
00056             event.retVals().begin();
00057          CODEX_Quorum::ReturnVector::const_iterator end =
00058             event.retVals().end();
00059          unsigned int nGood = 0;
00060          for ( ; itr != end ; ++itr )
00061          {
00062             if ( itr->returnCode() ==
00063                  CODEX_Quorum::RemoteServerReturn::kSuccess )
00064             {
00065                ++nGood;
00066             }
00067          }
00068          if ( nGood >= qs->quorumSize() )
00069          {
00070             retVal = true;
00071          }
00072          if ( retVal )
00073          {
00074             sendEvent( 0, event.source() );
00075          }
00076          return retVal;
00077       }
00078       else
00079       {
00080          // If the request ID is no longer registered, we don't need
00081          // to send the message again.
00082          if ( ( 0 != event.cb() ) &&
00083               ( ! qs->keyRegistered(event.key()) ) )
00084          {
00085             sendEvent( 0, event.source() );
00086             return true;
00087          }
00088          bool bVal = qs->unicastMessage( event.messages(),
00089                                          event.retVals(),
00090                                          0 );
00091          bool retVal = false;
00092          CODEX_Quorum::ReturnVector::const_iterator itr =
00093             event.retVals().begin();
00094          CODEX_Quorum::ReturnVector::const_iterator end =
00095             event.retVals().end();
00096          unsigned int nGood = 0;
00097          for ( ; itr != end ; ++itr )
00098          {
00099             if ( itr->returnCode() ==
00100                  CODEX_Quorum::RemoteServerReturn::kSuccess )
00101             {
00102                ++nGood;
00103             }
00104          }
00105          if ( nGood >= qs->quorumSize() )
00106          {
00107             retVal = true;
00108          }
00109          if ( retVal )
00110          {
00111             sendEvent( 0, event.source() );
00112          }
00113          return retVal;
00114       }
00115    }
00116    catch ( ... )
00117    {
00118       return false;
00119    }
00120 }

Generated on Fri May 6 17:41:27 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1