Class ODataCollectionDecoder

java.lang.Object
io.skipcheck.tm1.client.odata.ODataCollectionDecoder

public final class ODataCollectionDecoder extends Object
Decodes an OData collection response, {"@odata.context":..., "value":[...]}, item by item as the bytes arrive, without ever holding the whole response.

TM1 doesn't page its responses (odata.maxpagesize is ignored), so a collection such as a large dimension's elements arrives as one body of any size. This decoder feeds Jackson's non-blocking parser with each buffer as it comes, and emits each item of value as soon as it's complete. Demand is respected: buffers are only requested as items are consumed.

Top-level control information (@odata.nextLink, @odata.count, @odata.deltaLink and so on) is emitted as ODataCollectionDecoder.Event.Control events, wherever it appears in the body. follow(Flux, Function, ObjectMapper, Class, String, String) uses @odata.nextLink to fetch further pages.

A body that turns out to be an error, or that ends before the collection is complete, fails with a Tm1ProtocolException, even if items were already emitted (OData Part 1 §9.5).

Bytes that aren't UTF-8 are read as U+FFFD rather than failing the response: TM1 (11.8) sends them in the transaction log (Utf8Repair).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    An item or a piece of control information from a collection response.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> reactor.core.publisher.Flux<ODataCollectionDecoder.Event<T>>
    decode(reactor.core.publisher.Flux<DataBuffer> body, tools.jackson.databind.ObjectMapper mapper, Class<T> itemType, String method, String url)
    Decodes one response body.
    static <T> reactor.core.publisher.Flux<T>
    follow(reactor.core.publisher.Flux<DataBuffer> firstPage, Function<String, reactor.core.publisher.Flux<DataBuffer>> fetch, tools.jackson.databind.ObjectMapper mapper, Class<T> itemType, String method, String url)
    The items of a collection across all its pages: decodes firstPage, then, if it had an @odata.nextLink, the page fetch returns for that link, and so on.
    static <T> reactor.core.publisher.Flux<T>
    items(reactor.core.publisher.Flux<DataBuffer> body, tools.jackson.databind.ObjectMapper mapper, Class<T> itemType, String method, String url)
    Just the items of one response body.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • decode

      public static <T> reactor.core.publisher.Flux<ODataCollectionDecoder.Event<T>> decode(reactor.core.publisher.Flux<DataBuffer> body, tools.jackson.databind.ObjectMapper mapper, Class<T> itemType, String method, String url)
      Decodes one response body.
      Type Parameters:
      T - the type of the collection's items
      Parameters:
      body - the response body; each buffer is released once read
      mapper - the mapper to read items with
      itemType - the type to read each item as
      method - the request's method, for error messages
      url - the request's URL, for error messages
      Returns:
      the items and control information, in the order they appear in the body
    • items

      public static <T> reactor.core.publisher.Flux<T> items(reactor.core.publisher.Flux<DataBuffer> body, tools.jackson.databind.ObjectMapper mapper, Class<T> itemType, String method, String url)
      Just the items of one response body. Null members (possible in a collection of primitive values) are skipped, since a Reactor stream can't carry nulls; use decode(Flux, ObjectMapper, Class, String, String) to see them.
      Type Parameters:
      T - the type of the collection's items
      Parameters:
      body - the response body; each buffer is released once read
      mapper - the mapper to read items with
      itemType - the type to read each item as
      method - the request's method, for error messages
      url - the request's URL, for error messages
      Returns:
      the non-null items, in order
    • follow

      public static <T> reactor.core.publisher.Flux<T> follow(reactor.core.publisher.Flux<DataBuffer> firstPage, Function<String, reactor.core.publisher.Flux<DataBuffer>> fetch, tools.jackson.databind.ObjectMapper mapper, Class<T> itemType, String method, String url)
      The items of a collection across all its pages: decodes firstPage, then, if it had an @odata.nextLink, the page fetch returns for that link, and so on. Next links are opaque: they're passed to fetch exactly as received (OData Part 1 §11.2.6.7).
      Type Parameters:
      T - the type of the collection's items
      Parameters:
      firstPage - the first page's response body; each buffer is released once read
      fetch - fetches the page at a next link, returning its response body
      mapper - the mapper to read items with
      itemType - the type to read each item as
      method - the request's method, for error messages
      url - the first request's URL, for error messages; later pages use their next link
      Returns:
      the non-null items of every page, in order