int32_t registerService(const std::string& host, const int32_t port) {
   // Your implementation goes here
   printf("registerService\n");
   pair<string,int> host_tuple(host,port);
   boost::shared_ptr<TTransport> socket(new TSocket(host,port));
   boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
   boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
   boost::shared_ptr<RemoteInfixSearchClient> client(new RemoteInfixSearchClient(protocol));
   thrift_container_t container;
   container.host = host;
   container.port = port;
   container.socket = socket;
   container.transport = transport;
   container.protocol = protocol;
   container.client = client;
   bool found = false;
   for(host_list_t::iterator it = host_list.begin();it!=host_list.end();++it){
     thrift_container_t container = *it;
     if(container.host.compare(host)==0 && container.port==port){
       printf("Found a matching entry\n");
       found = true;
       break;
     }
   }
   if(!found) host_list.push_back(container);
   printf("There are now %u workers\n",(uint)host_list.size());
 }
 int32_t deregisterService(const std::string& host, const int32_t port) {
   // Your implementation goes here
   printf("deregisterService\n");
   pair<string,int> host_tuple(host,port);
   host_list_t::iterator it = host_list.begin();
   while(it!=host_list.end()){
     thrift_container_t container = *it;
     if(container.host.compare(host)==0 && container.port==port){
       printf("Found a matching entry\n");
       it = host_list.erase(it);
     }else{
       ++it;
     }
   }
   printf("There are now %u workers\n",(uint)host_list.size());
 }
Ejemplo n.º 3
0
    bool server_control_executor::is_host_in_list(
        const std::string& _hn,
        const host_list_t& _hosts ) {
        for ( size_t i = 0;
                i < _hosts.size();
                ++i ) {
            if ( compare_host_names(
                        _hn,
                        _hosts[ i ] ) ) {
                return true;
            }

        } // for i

        return false;

    } // is_host_in_list
  void findMatches(std::vector<std::string> & _return, const std::string& key) {
    // Your implementation goes here
    printf("findMatches\n");
    if(service_type ==  TYPE_SLAVE){
      search.find_path(key,_return);
      for(int i=0;i<_return.size();++i){
        _return[i] = search.extract_row(_return[i]);
      }
    }else{
      if(host_list.size()>0){
        _return.clear();
        list<delegator_t *> delegator_list;
        for(host_list_t::iterator it = host_list.begin();it!=host_list.end();++it){
          thrift_container_t container = *it;
          delegator_t * delegator = new delegator_t(container,key);
          delegator_list.push_back(delegator);
        }
        findMatchesThreaded(_return,key,delegator_list);
        for(list<delegator_t *>::iterator it = delegator_list.begin();
        it!=delegator_list.end();++it){
          delegator_t * delegator = *it;
          for(vector<string>::iterator it = delegator->matches.begin();
          it!=delegator->matches.end();++it){
             _return.push_back(*it);
          }
          delete(delegator);
//          try {
//            printf("Trying host %s port %d\n",container.host.data(),container.port);
//            container.transport->open();
//            vector<string> matches;
//            container.client->findMatches(matches,key);
//            container.transport->close();
//            for(vector<string>::iterator it = matches.begin();it!=matches.end();++it){
//              _return.push_back(*it);
//            }
//          }catch(TException & tx){
//            cout<<"ERROR: "<<tx.what()<<endl;
//          }
        }
      }
    }
  }