Ejemplo n.º 1
0
bool m_dispatch::all_done(bool no_abort)
{ try
  { bool all_d=false;
    traceft("all_done start\n");
    while (!all_d)
    { all_d=true;
      if (!no_abort&&dispatch_abort) return false;
      for (unsigned i=0; i<max_disp; i++)
      { if (d[i])
        { if (d[i]->is_done()) 
          { if (d[i]->ex1)
            { char * t=last_error;
              last_error=alloccat(d[i]->ex1,"\n",t,0);
              if (t) free(t);
            }
            if (!d[i]->join(2000))
                traceft("all_done join failed\n");

            d[i]->Release();  
            d[i]=0; 
          } else
          { all_d=false;
            //traceft("nd %i ",i);
          }
        }
      } 
      //traceft("Sleep %i\n",all_d);
      MilliSleep(1000);
    }
    traceft("all_done end\n");
  } catch (...)
  { traceft("unknown exception in all_done\n");
  }
  return true;
}
Ejemplo n.º 2
0
int c_dispatch::run()
{ try
  { action();
  } catch (char *s )
  { ex1=strdup(s);
  } catch(IHRPC_Exception *e) 
  { StringBuffer s;
    ex1=alloccat(e->errorMessage(s).str()," ",id," ",0);
    e->Release();
  } catch(IJSOCK_Exception *e) 
  { StringBuffer s;
    ex1=alloccat(e->errorMessage(s).str()," ",id," ",0);
    e->Release();
  } 
  catch (IException *e)
  { StringBuffer s;
    ex1=alloccat(e->errorMessage(s).str()," ",id," ",0);
    e->Release();
  }
  catch (...)
  { traceft("unknown exception in c_dispatch::run\n");
  }
  if (ex1) traceft("%s exception %s\n",id?id:"",ex1);
  //traceft("c_dispatch run done\n");
  cs.enter();
  done=true;
  cs.leave();
  return 0;
}
Ejemplo n.º 3
0
void m_dispatch::dispatch(c_dispatch * disp)
{ while (1)
  {
    unsigned i=0;
    for (i=0; i<max_disp; i++)
    {  if (d[i]&&d[i]->is_done()) 
       { if (d[i]->ex1)
         { char * t=last_error;
           last_error=alloccat(d[i]->ex1,"\n",t,0);
                     //traceft("m_dispatch error added %s\n",d[i]->ex1);
           if (t) free(t);
         }
         if (!d[i]->join(2000))
            traceft("m_dispatch join failed");
         d[i]->Release();
         d[i]=0;
       }
    }
    for (i=0; i<max_disp; i++)
    {  if (!d[i])
       { d[i]=disp;
         d[i]->start();
         return;
       }
    }
    MilliSleep(1000);
  }
}
Ejemplo n.º 4
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf("frunagent <nodelist> start \"command\" [options] \n"
               "                     stop <commandid> [options]\n"
               "                     account <user> <password> <dir> [option]\n"
               "                     dir <dir> [option]\n"
               "                     alive <integer> [option]\n\n"
               "where <nodelist> is of the form h009100:h009119,h007010:h007020\n"
               "or 192.168.6.100:192.168.6.119,192.168.7.10:192.168.7.20\n"
               "or @filename where filename contains a file in the above format\n"
               "options: /n<number_of_thread> /t<call_time_out> /encrypt /o<replication_offset>\n"
              );
        return 255;
    }

    InitModuleObjects();

    StringBuffer tracepath;
    tracepath.append(".").append(PATHSEPCHAR).append("frunagent.txt");
    settrace(tracepath.str(),false);
    ECHO_TO_CONSOLE=true;

    try
    {
        setoptions(argc,argv);
        split_node x(argc,argv);
        if (argv[1][0]=='@')
        {
            StringBuffer b;
            b.loadFile(argv[1]+1);
            char *finger = (char *) b.str();
            while (*finger)
            {
                if (*finger == '\n')
                    *finger++ = ';';
                else if (*finger == '#')
                {
                    while (*finger && *finger != '\n')
                        *finger++ = ' ';
                }
                else
                    finger++;
            }
            x.split_nodes_ex(b.str(),replicationoffset);
        }
        else
            x.split_nodes_ex(argv[1],replicationoffset);
        disp->all_done_ex(false);
    }
    catch(IException *e)
    {
        pexception("",e);
        e->Release();
        res=255;
    }
    catch (...)
    {
        traceft("Caught unknown exception");
    }
#ifdef _TRACING
    traceflush();
#endif
    if (disp) delete disp;

    return res;
}