Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FetchRequest

A parameterised query that can be used to search the topic tree.

A new request can be created using the fetchRequest method and modified to specify a range of topics and/or various levels of detail. The request can then be issued to the server using the fetch method supplying a topic selector which specifies the selection of topics. The results are returned via a Result.

As a minimum, the path and type of each selected topic will be returned. It is also possible to request that the topic values and/or properties are returned.

If values are selected then the topic types selected are naturally constrained by the provided dataType argument. So if DataTypes.string is specified, only STRING topics will be selected. However, if DataTypes.json is specified, all types compatible with JSON will be selected including STRING, INT64 and DOUBLE. See DataType.canReadAs for the class hierarchy of types.

To select topic types when values are not required, or to further constrain the selection when values are required, it is also possible to specify exactly which topic types to select.

The topics selected by the topic selector can be further restricted by range. A range is defined by a start path and an end path, and contains all paths in-between in path order. Given a topic tree containing the topics:

a, a/b, a/c, a/c/x, a/c/y, a/d, a/e, b, b/a/x, b/b/x, c

The range from a/c/y to b/a/x includes the topics with paths:

a/c/x, a/c/y, a/d, a/e, b, b/a/x

The start point of a range can be specified using from or after and an end point using to or before. from and to include any topic with the specified path in the selection, whereas after and before are non-inclusive and useful for paging through a potentially large range of topics. If no start point is specified, the start point is assumed to be the first topic of the topic tree, ordered by path name. Similarly, if no end point is specified, the end point is the last topic of the topic tree.

A limit on the number of results returned can be specified using first. This is advisable if the result set could potentially be large. The number of results returned is also limited by the session's maximum message size – see maximumResultSize. The result indicates whether the results have been limited via the hasMore method. If hasMore() returns true, further results can be retrieved by modifying the original query to request results after the last path received.

By default, results are returned in path order, earliest path first, starting from the beginning of any range specified. It is also possible to request results from the end of the range indicated by specifying a limit to the number of results using last. This method complements first, returning up to the specified number of results from the end of the range, but in reverse path order. This is useful for paging backwards through a range of topics.

It can be useful to explore an unknown topic tree in a breadth-first manner rather than the path order. This can be achieved using limitDeepBranches.

FetchRequest instances are immutable and can be safely shared and reused.

since

6.2

Hierarchy

  • FetchRequest

Index

Methods

Abstract after

  • Specifies a logical start point within the topic tree.

    If specified, only results for topics with a path that is lexically 'after' the specified path will be returned.

    This is the non inclusive equivalent of from and if used will override any previous from or after constraint.

    Parameters

    • topicPath: string

      the topic path after which results are to be returned

    Returns FetchRequest

    a new fetch request derived from this fetch request but selecting only topics after the specified path (not inclusive)

Abstract before

  • Specifies a logical end point within the topic tree.

    If specified, only results for topics with a path that is lexically 'before' the specified path will be returned.

    This is the non inclusive equivalent of to and if used will override any previous or before constraint.

    Parameters

    • topicPath: string

      the topic path before which results are to be returned

    Returns FetchRequest

    a new fetch request derived from this fetch request but selecting only topics before the specified path (not inclusive)

Abstract fetch

  • Sends a fetch request to the server.

    Results are returned for all topics matching the selector that satisfy the request constraints within any range defined by from/after and/or to/before.

    This function can take any number of arguments. Each argument can be a string or a TopicSelector. Alternatively, an array of strings and TopicSelectors can be passed as a single argument. At least one valid selector has to be specified.

    throws

    an IllegalArgumentError if the selector could not be parsed

    Parameters

    • topics: Array<TopicSelector | string>

      specifies a topic selector which selects the topics to be fetched

    Returns Result<FetchResult<any>>

    a Result that resolves with a FetchResult when a response is received from the server with the results of the fetch operation.

    If the task completes successfully, the FetchResult returned by the Result will be an object encapsulating all of the results.

    Otherwise, the Result will resolve with an Error. Common reasons for failure, listed by the error type, include:

  • Parameters

    Returns Result<FetchResult<any>>

Abstract first

  • Specifies a maximum number of topic results to be returned from the start of the required range.

    If this is not specified, the number of results returned will only be limited by other constraints of the request.

    This should be used to retrieve results in manageable batches and prevent very large result sets.

    If there are potentially more results that would satisfy the other constraints then the fetch result will indicate so via the hasMore method.

    If the count is set to zero, no results will be returned. In this case, hasMore can be used to check the existence of any topics matching the criteria without retrieving topic details.

    Either this or last may be specified. This will therefore override any previous last or first constraint.

    throws

    an IllegalArgumentError if the count is negative

    Parameters

    • count: number

      the non-negative maximum number of results to return from the start of the range

    Returns FetchRequest

    a new fetch request derived from this fetch request but selecting only the number of topics specified from the start of the range

Abstract from

  • Specifies a logical start point within the topic tree.

    If specified, only results for topics with a path that is lexically equal to or 'after' the specified path will be returned.

    This is the inclusive equivalent of after and if used will override any previous after or from constraint.

    Parameters

    • topicPath: string

      the topic path from which results are to be returned

    Returns FetchRequest

    a new fetch request derived from this fetch request but selecting only topics from the specified path onwards (inclusive)

Abstract last

  • Specifies a maximum number of topic results to be returned from the end of the required range.

    This is similar to first except that the specified number of results are returned from the end of the range. This is useful for paging backwards through a range of topics. Results are always returned in topic path order (not reverse order).

    Either this or first may be specified. This will therefore override any previous first or last constraint.

    throws

    an IllegalArgumentError if the count is negative

    Parameters

    • count: number

      the non-negative maximum number of results to return from the end of the range

    Returns FetchRequest

    a new fetch request derived from this fetch request but selecting only the number of topics specified from the end of the range

Abstract limitDeepBranches

  • limitDeepBranches(deepBranchDepth: number, deepBranchLimit: number): FetchRequest
  • Specifies a limit on the number of results returned for each deep branch.

    A deep branch has a root path that has a number of parts equal to the deepBranchDepth parameter. The deepBranchLimit specifies the maximum number of results for each deep branch.

    This method is particularly useful for incrementally exploring a topic tree from the root, allowing a breadth-first search strategy.

    For example, given a topic tree containing the topics with the following paths:

    x/0
    x/x/1
    x/x/x/2
    y/y/y/y/3
    y/y/y/4
    z/5
    z/z/6

    Then

    session.fetchRequest().limitDeepBranches(1, 1).fetch("?.//");

    will return results with the paths x/0, y/y/y/y/3, and z/5. The application can then determine the roots of the tree are x, y, and z.

    The deepBranchLimit parameter can usefully be set to 0. For example, given the same example topic tree,

    session.fetchRequest().limitDeepBranches(3, 0).fetch("?.//");

    will only return results having paths with fewer than three parts; namely x/0, and z/5.

    The fetch result does not indicate whether this option caused some results to be filtered from deep branches. It has no affect on the hasMore() result. If the result set contains deepBranchLimit results for a particular deep branch, some topics from that branch may have been filtered.

    throws

    an IllegalArgumentError if either parameter is negative

    since

    6.4

    Parameters

    • deepBranchDepth: number

      the number of parts in the root path of a branch for it to be considered deep

    • deepBranchLimit: number

      the maximum number of results to return for each deep branch

    Returns FetchRequest

    a new fetch request derived from this fetch request but restricting the number of results for deep branches

Abstract maximumResultSize

  • Specifies the maximum data size of the result set.

    This may be used to constrain the size of the result. If not specified then by default the maximum message size for the session (as specified by Options.maxMessageSize is used.

    throws

    an IllegalArgumentError if the maximum size is negative

    Parameters

    • maximumSize: number

      the maximum size of the result set in bytes. If a value greater than the session's maximum message size is specified, the maximum message size will be used.

    Returns FetchRequest

    a new fetch request derived from this fetch request but constraining the size of the result to the specified maximum

Abstract to

  • Specifies a logical end point within the topic tree.

    If specified, only results for topics with a path that is lexically equal to or 'before' the specified path will be returned.

    This is the inclusive equivalent of before and if used will override any previous before or to constraint.

    Parameters

    • topicPath: string

      the topic path to which results are to be returned

    Returns FetchRequest

    a new fetch request derived from this fetch request but selecting only topics including and before the specified path (inclusive)

Abstract topicTypes

  • Specifies that only topics of the specified topic types should be returned.

    If this is not specified, all types will be returned (unless constrained by withValues).

    This may be used instead to further constrain the results when using withValues. For example, you can specify {diffusion.datatypes.DataType.json} to withValues then specify JSON here to ensure that only JSON topics are returned and not those topics that are logically value subtypes of JSON (e.g. STRING).

    If withValues has been specified then the types specified here must be compatible with the value class specified.

    throws

    an IllegalArgumentError if invalid topic types are specified

    Parameters

    Returns FetchRequest

    a new fetch request derived from this fetch request but specifying that only topics of the specified topic types should be returned.

Abstract withProperties

  • Specifies that all properties associated with each topic's specification should be returned.

    Returns FetchRequest

    a new fetch request derived from this fetch request but specifying that topic specification properties should be returned.

Abstract withSizes

  • Specifies that topic sizes should be returned.

    For time series topics this will fetch the size (in bytes) of the last event, the number of events, and the total size of all events.

    For all other topics this will fetch the size (in bytes) of the topic value, or 0 if the topic has no value.

    since

    6.11

    Returns FetchRequest

    a new fetch request derived from this fetch request but specifying that topic sizes should be returned.

Abstract withUnpublishedDelayedTopics

  • Include the details of reference topics that are not yet published.

    Topic views that use the delay by clause create reference topics in an unpublished state. The topics are published once the delay time has expired. A topic in the unpublished state prevents a lower priority topic view from creating a reference topic with the same path.

    A reference topic in the unpublished state which matches the query will only be included in the fetch results if the session has READ_TOPIC permission for the reference's source topic as well as READ_TOPIC permission for the reference topic. Requiring READ_TOPIC permission for the source topic ensures less privileged sessions cannot derive information from the existence of the reference topic before the delay time has expired.

    since

    6.5

    Returns FetchRequest

    a new fetch request derived from this fetch request, additionally specifying that unpublished reference topics should be included in the results

Abstract withValues

  • Specifies that values should be returned for selected topics, constraining the selection to only those topics with a data type compatible with the specified DataType.

    The specified value constrains the topic types. So, any topic types specified in a previous call to topicTypes that cannot be read as the specified class will be removed from the list of topic types.

    throws

    an IllegalArgumentError if the data type is not compatible with any topic types.

    Parameters

    • Optional dataType: DataType<any, any, any> | AnyDataType

      the type of values. If no value is specified this will cancel any previous call (topic types will remain unchanged).

    Returns FetchRequest

    a new fetch request derived from this fetch request but specifying that only topics compatible with the specified class should be returned with values.

Static getAllTypes

  • Return a set of all topic types that can be fetched.

    Returns Set<TopicType>

    the topic types that can be fetched by a FetchRequest