use the resource manager
963827
public static void useResource(String host, int port, String user, String password, Authentication authType)
    throws IOException, ParserConfigurationException
  {
    // create the client
    DatabaseClient client = DatabaseClientFactory.newClient(host, port, user, password, authType);

    // create the search collector
    SearchCollector collector = new SearchCollector(client);

    // search for documents to collect
    CollectorResults results = collector.collect(
      "neighborhood industry:\"Real Estate\"", 1, OPTIONS_NAME
    );

    System.out.println();
    System.out.println("search results:");
    System.out.println(results.getSearchResult(new StringHandle()).get());

    // iterate over the collected documents
    StringHandle resultHandle = new StringHandle();
    for (int i=1; results.hasNext(); i++) {
      System.out.println();
      System.out.println("matched document "+i+":");
      System.out.println(results.next(resultHandle).get());
    }

    // release the iterator resources
    results.close();

    // release the client
    client.release();
  }
1335985
def index_resources(self):
        
        if not self.__index_resources:
            self.__index_resources = IndexResources(self.__connection)
        return self.__index_resources
727417
def get_resource_manager(self, resource_type, data=None):
        
        if '.' in resource_type:
            provider_name, resource_type = resource_type.split('.', 1)
        else:
            provider_name = self.ctx.policy.provider_name

        provider_resources = clouds[provider_name].resources
        klass = provider_resources.get(resource_type)
        if klass is None:
            raise ValueError(resource_type)

        # if we're already querying via config carry it forward
        if not data and self.source_type == 'config' and getattr(
                klass.get_model(), 'config_type', None):
            return klass(self.ctx, {'source': self.source_type})
        return klass(self.ctx, data or {})
147975
def add_resources(self, resources):
    
    new_resources = self._build_resource_dictionary(resources)

    for key in new_resources:
      self._resources[key] = new_resources[key]
    self._dirty_attributes.add(u'resources')
706917
def _configure_manager(self):
        
        self._manager = ImageManager(self, resource_class=Image,
                response_key="", plural_response_key="images",
                uri_base="images")
        self._tasks_manager = ImageTasksManager(self, resource_class=ImageTask,
                response_key="", plural_response_key="tasks",
                uri_base="tasks")
        self._schema_manager = JSONSchemaManager(self, resource_class=None,
                response_key="", plural_response_key="", uri_base="schemas")
702477
def load_resources(bucket, prefix, region, account_config, accounts,
                   assume, start, end, resources, store, db, verbose, debug):
    """"""
    logging.basicConfig(level=(verbose and logging.DEBUG or logging.INFO))
    logging.getLogger('botocore').setLevel(logging.WARNING)
    logging.getLogger('s3transfer').setLevel(logging.WARNING)
    start = date_parse(start)
    end = date_parse(end)

    if not resources:
        resources = ['NetworkInterface', 'Instance', 'LoadBalancer']

    account_map = {}
    data = yaml.safe_load(account_config.read())
    for a in data.get('accounts', ()):
        if accounts and (a['name'] in accounts or a['account_id'] in accounts):
            account_map[a['account_id']] = a
        elif not accounts:
            account_map[a['account_id']] = a
    account_ids = list(account_map)

    executor = ProcessPoolExecutor
    if debug:
        from c7n.executor import MainThreadExecutor
        MainThreadExecutor.c7n_async = False
        executor = MainThreadExecutor

    stats = Counter()
    t = time.time()
    with executor(max_workers=multiprocessing.cpu_count()) as w:
        futures = {}
        for a in account_ids:
            for r in resources:
                futures[w.submit(
                    process_account_resources, a, bucket, prefix,
                    region, store, start, end, r)] = (a, r)

        indexer = RESOURCE_FILE_INDEXERS[r]
        for f in as_completed(futures):
            a, r = futures[f]
            if f.exception():
                log.error("account:%s error:%s", a, f.exception())
                continue
            files, dl_stats = f.result()
            idx_stats = indexer(db, resource_config_iter(files))
            log.info(
                "loaded account:%s files:%d bytes:%s events:%d resources:%d idx-time:%d dl-time:%d",
                account_map[a]['name'], len(files),
                human_size(dl_stats['DownloadSize'] + dl_stats['CacheSize']),
                idx_stats['Records'],
                idx_stats['RowCount'],
                idx_stats['IndexTime'],
                dl_stats['FetchTime'])
            stats.update(dl_stats)
            stats.update(idx_stats)
    log.info("Loaded %d resources across %d accounts in %0.2f",
             stats['RowCount'], len(account_ids), time.time() - t)
398219
public void getResources(Vector<URL> resources, String name)
  {
    Path path;

    path = getPath(name);

    if (path != null && path.canRead()) {
      try {
        resources.add(path.getNetURL());
      } catch (Exception e) {
      }
    }
  }
1337678
def client_resource_factory(self, res_spec, parent, logger):
        
        return KATCPClientResource(res_spec, parent=self, logger=logger)
383036
def get_resources(cls):
        """"""
        plural_mappings = resource_helper.build_plural_mappings(
            {}, RESOURCE_ATTRIBUTE_MAP)
        if NEUTRON_VERSION.version[0] <= NEUTRON_NEWTON_VERSION.version[0]:
            attr.PLURALS.update(plural_mappings)
        action_map = {DEVICE: {'get_hosting_device_config': 'GET'}}
        return resource_helper.build_resource_info(plural_mappings,
                                                   RESOURCE_ATTRIBUTE_MAP,
                                                   constants.DEVICE_MANAGER,
                                                   action_map=action_map)
269486
def _configure_manager(self):
        
        self._manager = ContainerManager(self, resource_class=Container,
                response_key="", uri_base="")
608675
function handleResource( $tpl, &$resourceData, $method, &$extraParameters )
    {
        return $this->handleResourceData( $tpl, $this, $resourceData, $method, $extraParameters );
    }
927688
def do_open(self, args):
        """"""

        if not args:
            print('A resource name must be specified.')
            return

        if self.current:
            print('You can only open one resource at a time. Please close the current one first.')
            return

        if args.isdigit():
            try:
                args = self.resources[int(args)][0]
            except IndexError:
                print('Not a valid resource number. Use the command "list".')
                return

        try:
            self.current = self.resource_manager.open_resource(args)
            print('{} has been opened.\n'
                  'You can talk to the device using "write", "read" or "query".\n'
                  'The default end of message is added to each message.'.format(args))

            self.py_attr = []
            self.vi_attr = []
            for attr in getattr(self.current, 'visa_attributes_classes', ()):
                if attr.py_name:
                    self.py_attr.append(attr.py_name)
                self.vi_attr.append(attr.visa_name)

            self.prompt = '(open) '
        except Exception as e:
            print(e)
32196
def SaveResourceUsage(self, client_id, status):
    """"""
    # Per client stats.
    self.hunt_obj.ProcessClientResourcesStats(client_id, status)
    # Overall hunt resource usage.
    self.UpdateProtoResources(status)
647402
def copy_resources(self):
        """"""
        if not os.path.isdir('resources'):
            os.mkdir('resources')

        resource_dir = os.path.join(os.getcwd(), 'resources', '')
        copied_resources = []

        for resource in self.resources:
            src = os.path.join(EULER_DATA, 'resources', resource)
            if os.path.isfile(src):
                shutil.copy(src, resource_dir)
                copied_resources.append(resource)

        if copied_resources:
            copied = ', '.join(copied_resources)
            path = os.path.relpath(resource_dir, os.pardir)
            msg = "Copied {} to {}.".format(copied, path)

            click.secho(msg, fg='green')
761607
private void processResources()
   {
      FastTrackTable table = m_data.getTable(FastTrackTableType.RESOURCES);
      for (MapRow row : table)
      {
         int uniqueID = row.getInt(ResourceField.RESOURCE_ID);
         if (uniqueID <= 0)
         {
            continue;
         }

         Resource resource = m_project.addResource();
         resource.setCode(row.getString(ResourceField.CODE));
         resource.setCostPerUse(row.getCurrency(ResourceField.PER_USE_COST));
         resource.setEmailAddress(row.getString(ResourceField.EMAIL_ADDRESS));
         resource.setFlag(1, row.getBoolean(ResourceField.FLAG_1));
         resource.setFlag(2, row.getBoolean(ResourceField.FLAG_2));
         resource.setFlag(3, row.getBoolean(ResourceField.FLAG_3));
         resource.setFlag(4, row.getBoolean(ResourceField.FLAG_4));
         resource.setFlag(5, row.getBoolean(ResourceField.FLAG_5));
         resource.setFlag(6, row.getBoolean(ResourceField.FLAG_6));
         resource.setFlag(7, row.getBoolean(ResourceField.FLAG_7));
         resource.setFlag(8, row.getBoolean(ResourceField.FLAG_8));
         resource.setFlag(9, row.getBoolean(ResourceField.FLAG_9));
         resource.setFlag(10, row.getBoolean(ResourceField.FLAG_10));
         resource.setFlag(11, row.getBoolean(ResourceField.FLAG_11));
         resource.setFlag(12, row.getBoolean(ResourceField.FLAG_12));
         resource.setFlag(13, row.getBoolean(ResourceField.FLAG_13));
         resource.setFlag(14, row.getBoolean(ResourceField.FLAG_14));
         resource.setFlag(15, row.getBoolean(ResourceField.FLAG_15));
         resource.setFlag(16, row.getBoolean(ResourceField.FLAG_16));
         resource.setFlag(17, row.getBoolean(ResourceField.FLAG_17));
         resource.setFlag(18, row.getBoolean(ResourceField.FLAG_18));
         resource.setFlag(19, row.getBoolean(ResourceField.FLAG_19));
         resource.setFlag(20, row.getBoolean(ResourceField.FLAG_20));
         resource.setGroup(row.getString(ResourceField.GROUP));
         resource.setGUID(row.getUUID(ResourceField._RESOURCE_GUID));
         resource.setInitials(row.getString(ResourceField.INITIALS));
         resource.setMaterialLabel(row.getString(ResourceField.MATERIAL_LABEL));
         resource.setName(row.getString(ResourceField.RESOURCE_NAME));
         resource.setNotes(row.getString(ResourceField.RESOURCE_NOTES));
         resource.setNumber(1, row.getDouble(ResourceField.NUMBER_1));
         resource.setNumber(2, row.getDouble(ResourceField.NUMBER_2));
         resource.setNumber(3, row.getDouble(ResourceField.NUMBER_3));
         resource.setNumber(4, row.getDouble(ResourceField.NUMBER_4));
         resource.setNumber(5, row.getDouble(ResourceField.NUMBER_5));
         resource.setNumber(6, row.getDouble(ResourceField.NUMBER_6));
         resource.setNumber(7, row.getDouble(ResourceField.NUMBER_7));
         resource.setNumber(8, row.getDouble(ResourceField.NUMBER_8));
         resource.setNumber(9, row.getDouble(ResourceField.NUMBER_9));
         resource.setNumber(10, row.getDouble(ResourceField.NUMBER_10));
         resource.setNumber(11, row.getDouble(ResourceField.NUMBER_11));
         resource.setNumber(12, row.getDouble(ResourceField.NUMBER_12));
         resource.setNumber(13, row.getDouble(ResourceField.NUMBER_13));
         resource.setNumber(14, row.getDouble(ResourceField.NUMBER_14));
         resource.setNumber(15, row.getDouble(ResourceField.NUMBER_15));
         resource.setNumber(16, row.getDouble(ResourceField.NUMBER_16));
         resource.setNumber(17, row.getDouble(ResourceField.NUMBER_17));
         resource.setNumber(18, row.getDouble(ResourceField.NUMBER_18));
         resource.setNumber(19, row.getDouble(ResourceField.NUMBER_19));
         resource.setNumber(20, row.getDouble(ResourceField.NUMBER_20));
         resource.setText(1, row.getString(ResourceField.TEXT_1));
         resource.setText(2, row.getString(ResourceField.TEXT_2));
         resource.setText(3, row.getString(ResourceField.TEXT_3));
         resource.setText(4, row.getString(ResourceField.TEXT_4));
         resource.setText(5, row.getString(ResourceField.TEXT_5));
         resource.setText(6, row.getString(ResourceField.TEXT_6));
         resource.setText(7, row.getString(ResourceField.TEXT_7));
         resource.setText(8, row.getString(ResourceField.TEXT_8));
         resource.setText(9, row.getString(ResourceField.TEXT_9));
         resource.setText(10, row.getString(ResourceField.TEXT_10));
         resource.setText(11, row.getString(ResourceField.TEXT_11));
         resource.setText(12, row.getString(ResourceField.TEXT_12));
         resource.setText(13, row.getString(ResourceField.TEXT_13));
         resource.setText(14, row.getString(ResourceField.TEXT_14));
         resource.setText(15, row.getString(ResourceField.TEXT_15));
         resource.setText(16, row.getString(ResourceField.TEXT_16));
         resource.setText(17, row.getString(ResourceField.TEXT_17));
         resource.setText(18, row.getString(ResourceField.TEXT_18));
         resource.setText(19, row.getString(ResourceField.TEXT_19));
         resource.setText(20, row.getString(ResourceField.TEXT_20));
         resource.setText(21, row.getString(ResourceField.TEXT_21));
         resource.setText(22, row.getString(ResourceField.TEXT_22));
         resource.setText(23, row.getString(ResourceField.TEXT_23));
         resource.setText(24, row.getString(ResourceField.TEXT_24));
         resource.setText(25, row.getString(ResourceField.TEXT_25));
         resource.setText(26, row.getString(ResourceField.TEXT_26));
         resource.setText(27, row.getString(ResourceField.TEXT_27));
         resource.setText(28, row.getString(ResourceField.TEXT_28));
         resource.setText(29, row.getString(ResourceField.TEXT_29));
         resource.setText(30, row.getString(ResourceField.TEXT_30));
         resource.setUniqueID(Integer.valueOf(uniqueID));
         m_eventManager.fireResourceReadEvent(resource);
      }
   }
345696
def resource(self, name):
        
        for resource in self.resources():
            if resource.name.lower() == name.lower():
                return resource
        raise NotFound('Unable to find resource %s' % name)
1207706
def resource(resource_id):
    """"""
    resource_obj = app.db.resource(resource_id)

    if 'raw' in request.args:
        return send_from_directory(os.path.dirname(resource_obj.path),
                                   os.path.basename(resource_obj.path))

    return render_template('resource.html', resource=resource_obj)