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

    // create the CSV splitter
    OpenCSVBatcher splitter = new OpenCSVBatcher(client);
    splitter.setHasHeader(true);

    // acquire the CSV input
    InputStream listingStream = Util.openStream(
      "data"+File.separator+"listings.csv");
    if (listingStream == null)
      throw new RuntimeException("Could not read example listings");

    // write the CSV input to the database
    long docs = splitter.write(
      new InputStreamReader(listingStream), "/listings/", "listing"
    );

    System.out.println("split CSV file into "+docs+" documents");
    XMLDocumentManager docMgr = client.newXMLDocumentManager();
    StringHandle       handle = new StringHandle();
    for (int i=1; i <= docs; i++) {
      System.out.println(
        docMgr.read("/listings/listing"+i+".xml", handle).get()
      );
    }

    // release the client
    client.release();
  }
608675
function handleResource( $tpl, &$resourceData, $method, &$extraParameters )
    {
        return $this->handleResourceData( $tpl, $this, $resourceData, $method, $extraParameters );
    }
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")
32196
def SaveResourceUsage(self, client_id, status):
    """"""
    # Per client stats.
    self.hunt_obj.ProcessClientResourcesStats(client_id, status)
    # Overall hunt resource usage.
    self.UpdateProtoResources(status)
1335618
private void readResources()
   {
      for (MapRow row : getTable("RTAB"))
      {
         Resource resource = m_projectFile.addResource();
         setFields(RESOURCE_FIELDS, row, resource);
         m_eventManager.fireResourceReadEvent(resource);
         // TODO: Correctly handle calendar
      }
   }
408124
def open(self, name, mode='r', *args, **kwargs):
        '''  '''
        fname = self.lookup(name)
        if not fname: raise IOError("Resource %r not found." % name)
        return self.opener(fname, mode=mode, *args, **kwargs)
723522
def _configure_manager(self):
        
        self._manager = CloudDatabaseManager(self,
                resource_class=CloudDatabaseInstance, response_key="instance",
                uri_base="instances")
        self._flavor_manager = BaseManager(self,
                resource_class=CloudDatabaseFlavor, response_key="flavor",
                uri_base="flavors")
        self._backup_manager = CloudDatabaseBackupManager(self,
                resource_class=CloudDatabaseBackup, response_key="backup",
                uri_base="backups")
482423
def close(self):
        
        try:
            logger.debug('Closing ResourceManager (session: %s)', self.session)
            # Cleanly close all resources when closing the manager.
            for resource in self._created_resources:
                resource.close()
            self.visalib.close(self.session)
            self.session = None
            self.visalib.resource_manager = None
        except errors.InvalidSession:
            pass
269486
def _configure_manager(self):
        
        self._manager = ContainerManager(self, resource_class=Container,
                response_key="", uri_base="")
514630
def _get_storage_manager(resource):
    """"""
    for manager in (AmazonS3, ArvadosKeep, SevenBridges, DNAnexus, AzureBlob, GoogleCloud, RegularServer):
        if manager.check_resource(resource):
            return manager()

    raise ValueError("Unexpected object store  %(resource)s" %
                     {"resource": resource})
655850
def _load_resources(self):
        """"""

        for t in self.doc.find('Root.Table'):
            for c in t.find('Table.Column'):
                if c.get_value('datatype') == 'geometry':
                    c['transform'] = '^empty_str'
                    c['datatype'] = 'text'

        return super()._load_resources()
646910
function resourceHandler( $resourceName )
    {
        if ( isset( $this->Resources[$resourceName] ) &&
             is_object( $this->Resources[$resourceName] ) )
        {
            return $this->Resources[$resourceName];
        }
        return $this->DefaultResource;
    }
1103395
def get_resources(resources)
      # prefetch api resources, skip missing APIs
      resource_apis = apis(resources.map(&:apiVersion), prefetch_resources: true, skip_missing: true)

      # map each resource to excon request options, or nil if resource is not (yet) defined
      requests = resources.zip(resource_apis).map{ |resource, api_client|
        next nil unless api_client.api_resources?

        resource_client = api_client.client_for_resource(resource)

        {
          method: 'GET',
          path: resource_client.path(resource.metadata.name, namespace: resource.metadata.namespace),
          response_class: resource_client.resource_class
        }
      }

      # map non-nil requests to response objects, or nil for nil request options
      Util.compact_map(requests) { |reqs|
        @transport.requests(*reqs, skip_missing: true)
      }
    end
581727
def make_resource_handle(self, resource_key, **variables):
        
        if variables.get("repository_type", self.name()) != self.name():
            raise ResourceError("repository_type mismatch - requested %r, "
                                "repository_type is %r"
                                % (variables["repository_type"], self.name()))

        variables["repository_type"] = self.name()

        if variables.get("location", self.location) != self.location:
            raise ResourceError("location mismatch - requested %r, repository "
                                "location is %r" % (variables["location"],
                                                    self.location))
        variables["location"] = self.location

        resource_cls = self.pool.get_resource_class(resource_key)
        variables = resource_cls.normalize_variables(variables)
        return ResourceHandle(resource_key, variables)
1150339
public static void registerResource(Object resource, TaskManager tm) {
		if (resource == null) return;
		synchronized (resources) {
			resources.put(resource, tm);
		}
	}
346235
private Resource getResource(
      final JobSubmissionEvent jobSubmissionEvent) {

    return new Resource()
        .setMemory(jobSubmissionEvent.getDriverMemory().get())
        .setvCores(jobSubmissionEvent.getDriverCPUCores().get());
  }
205018
def lock(resources, *args, **kwargs):
    
    # all resources are locked if nothing is specified
    if not resources:
        client = redis.Redis(decode_responses=True, **kwargs)
        resources = find_resources(client)

    if not resources:
        return

    # create one process per pid
    locker = Locker(**kwargs)
    while len(resources) > 1:
        pid = os.fork()
        resources = resources[:1] if pid else resources[1:]

    # at this point there is only one resource - lock it down
    resource = resources[0]
    try:
        print('{}: acquiring'.format(resource))
        with locker.lock(resource, label='lock tool'):
            print('{}: locked'.format(resource))
            try:
                signal.pause()
            except KeyboardInterrupt:
                print('{}: released'.format(resource))
    except KeyboardInterrupt:
        print('{}: canceled'.format(resource))