BiodbRequestScheduler {biodb} | R Documentation

## Class for handling requests.

### Description

Class for handling requests.

Class for handling requests.

### Details

This class handles GET and POST requests, as well as file downloading. Each remote database connection instance creates an instance of `BiodbRequestScheduler` for handling database connection. A timer is used to schedule connections, and avoid sending too much requests to the database. This class is not meant to be used directly by the library user. See section Fields for a list of the constructor's parameters.

### Methods

#### Public methods

- `BiodbRequestScheduler$new()`

- `BiodbRequestScheduler$sendSoapRequest()`

- `BiodbRequestScheduler$sendRequest()`

- `BiodbRequestScheduler$downloadFile()`

- `BiodbRequestScheduler$notifyConnUrlsUpdated()`

- `BiodbRequestScheduler$notifyConnSchedulerFrequencyUpdated()`

- `BiodbRequestScheduler$getUrlString()`

- `BiodbRequestScheduler$getUrl()`

- `BiodbRequestScheduler$findRule()`

- `BiodbRequestScheduler$getConnectorRules()`

- `BiodbRequestScheduler$registerConnector()`

- `BiodbRequestScheduler$unregisterConnector()`

- `BiodbRequestScheduler$getAllRules()`

- `BiodbRequestScheduler$clone()`

#### Method `new()`

New instance initializer. BiodbRequestScheduler class must not be instantiated direrctly. Instead, use the getRequestScheduler() method from BiodbMain.

##### Usage

    BiodbRequestScheduler$new(bdb)

##### Arguments

`bdb`

  The BiodbMain instance.

##### Returns

Nothing.

#### Method `sendSoapRequest()`

Sends a SOAP request to a URL. Returns the string result.

##### Usage

    BiodbRequestScheduler$sendSoapRequest(
      url,
      soap.request,
      soap.action = NA_character_,
      encoding = integer()
    )

##### Arguments

`url`

  The URL to access, as a character string.

`soap.request`

  The XML SOAP request to send, as a character string.

`soap.action`

  The SOAP action to contact, as a character string.

`encoding`

  The encoding to use.

##### Returns

The results returned by the contacted server, as a single string value.

#### Method `sendRequest()`

Sends a request, and returns content result.

##### Usage

    BiodbRequestScheduler$sendRequest(request, cache.read = TRUE)

##### Arguments

`request`

  A BiodbRequest instance.

`cache.read`

  If set to TRUE, the cache system will be used. In case the same request has already been run and its results saved into the cache, then the request is not run again, the targeted server not contacted, and the results are directly loaded from the cache system.

##### Returns

The results returned by the contacted server, as a single string value.

#### Method `downloadFile()`

Downloads the content of a URL and save it into the specified destination file.

##### Usage

    BiodbRequestScheduler$downloadFile(url, dest.file)

##### Arguments

`url`

  The URL to access, as a BiodbUrl object.

`dest.file`

  A path to a destination file.

##### Returns

Nothing.

#### Method `notifyConnUrlsUpdated()`

Call back function called when connector URLs are changed.

##### Usage

    BiodbRequestScheduler$notifyConnUrlsUpdated(conn)

##### Arguments

`conn`

  The connector instance for which the URLs were changed.

##### Returns

Nothing.

#### Method `notifyConnSchedulerFrequencyUpdated()`

Call back function called when connector T and N parameters (frequency) are changed.

##### Usage

    BiodbRequestScheduler$notifyConnSchedulerFrequencyUpdated(conn)

##### Arguments

`conn`

  The connector instance for which the frequency were changed.

##### Returns

Nothing.

#### Method `getUrlString()`

Builds a URL object, using a base URL and parameters to be passed.

##### Usage

    BiodbRequestScheduler$getUrlString(url, params = list())

##### Arguments

`url`

  A URL string.

`params`

  A list of URL parameters.

##### Returns

A BiodUrl object.

#### Method `getUrl()`

Sends a request and get the result.

##### Usage

    BiodbRequestScheduler$getUrl(
      url,
      params = list(),
      method = c("get", "post"),
      header = character(),
      body = character(),
      encoding = integer()
    )

##### Arguments

`url`

  A URL string.

`params`

  A list of URL parameters.

`method`

  The method to use. Either 'get' or 'post'.

`header`

  The header to send.

`body`

  The body to send.

`encoding`

  The encoding to use.

##### Returns

The results of the request.

#### Method `findRule()`

Searches for a rule by host name.

##### Usage

    BiodbRequestScheduler$findRule(url, create = TRUE)

##### Arguments

`url`

  The host URL.

`create`

  Sets to TRUE to create a rule when none exists.

##### Returns

A BiodbRequestSchedulerRule object.

#### Method `getConnectorRules()`

Gets the rules associates with a connector.

##### Usage

    BiodbRequestScheduler$getConnectorRules(conn)

##### Arguments

`conn`

  A valid connector object.

##### Returns

A list of rules.

#### Method `registerConnector()`

Registers a new connector with the scheduler.

##### Usage

    BiodbRequestScheduler$registerConnector(conn)

##### Arguments

`conn`

  A valid connector object.

##### Returns

Nothing.

#### Method `unregisterConnector()`

Unregisters a connector from this scheduler.

##### Usage

    BiodbRequestScheduler$unregisterConnector(conn)

##### Arguments

`conn`

  A valid connector object.

##### Returns

Nothing.

#### Method `getAllRules()`

Gets all defined rules.

##### Usage

    BiodbRequestScheduler$getAllRules()

##### Returns

The list of all rules.

#### Method `clone()`

The objects of this class are cloneable with this method.

##### Usage

    BiodbRequestScheduler$clone(deep = FALSE)

##### Arguments

`deep`

  Whether to make a deep clone.

### See Also

`BiodbRequestSchedulerRule`.

### Examples

    # Create an instance with default settings:
    mybiodb <- biodb::newInst()

    # Get the scheduler
    sched <- mybiodb$getRequestScheduler()

    # Create a request object
    u <- 'https://www.ebi.ac.uk/webservices/chebi/2.0/test/getCompleteEntity'
    url <- BiodbUrl$new(url=u)
    url$setParam('chebiId', 15440)
    request <- BiodbRequest$new(method='get', url=url)

    # Send request
    sched$sendRequest(request)

    # Terminate instance.
    mybiodb$terminate()
    mybiodb <- NULL

[Package biodb version 1.2.2 Index]