Interface StreamingHelper


@NoImplement @MinMuleVersion("4.4") public interface StreamingHelper
This class provides helper methods to deal with repeatable streaming resources which are contained into structures of arbitrary complexity.

As you know, when a parameter is resolved to a CursorProvider, the runtime automatically obtains a Cursor and injects that value instead. However, if that provider is embedded as the value of a Map or an arbitrary pojo, the runtime can't guess that's the case and go resolve it.

Same thing applies when a component is producing a result. The runtime automatically converts returned InputStream or PagingProvider instances into CursorProvider ones. However, if such instances are contained in some other value, that resolution won't happen automatically either.

For these border cases, this class provides some utilities to adapt the providers into cursors and vice versa

Since:
1.0
See Also:
  • CursorProvider
  • CursorStreamProvider
  • CursorIteratorProvider
  • Method Summary

    Modifier and Type
    Method
    Description
    If the value is a CursorProvider, a corresponding Cursor is returned.
    If the value is a repeatable streaming resource such as InputStream, Cursor, streaming iterators, etc., then an equivalent CursorProvider is returned.
    <K> Map<K,Object>
    resolveCursorProviders(Map<K,Object> map, boolean recursive)
    Inspects the values of the given map looking for repeatable streaming resources such as InputStream, Cursor, streaming iterators, etc., A new equivalent map is returned, except that such values have been replaced by CursorProvider instances.
    <K> Map<K,Object>
    resolveCursors(Map<K,Object> map, boolean recursive)
    Inspects the values of the given map looking for instances of CursorProvider.
  • Method Details

    • resolveCursors

      <K> Map<K,Object> resolveCursors(Map<K,Object> map, boolean recursive)
      Inspects the values of the given map looking for instances of CursorProvider. A new equivalent map is returned, except that the CursorProvider values have been replaced by obtained cursors. No side effect is applied on the original map.

      A best effort will be made for the returned map to be of the same class as the original one. If that's not possible (most likely because the class doesn't have an accessible default constructor), then the runtime will choose its own map implementation, but guarantying that the iterator order is respected.

      If the map contains a value of type Map and recursive is set to true, then that Map value will also be replaced by a new map which comes from recursively applying this same method.

      Type Parameters:
      K - the generic type of the map's keys
      Parameters:
      map - a Map which may contain values of CursorProvider type
      recursive - Whether to also use this method to replace values of type Map
      Returns:
      a new Map which doesn't have values of CursorProvider type
    • resolveCursorProviders

      <K> Map<K,Object> resolveCursorProviders(Map<K,Object> map, boolean recursive)
      Inspects the values of the given map looking for repeatable streaming resources such as InputStream, Cursor, streaming iterators, etc., A new equivalent map is returned, except that such values have been replaced by CursorProvider instances. No side effect is applied on the original map.

      For Cursor values, the same CursorProvider that already owns that Cursor is used. For other streaming values, the operation's repeatable streaming strategy will be used. If that strategy doesn't apply (e.g: the operation returns a PagingProvider but the streaming resource is an InputStream), then the system's default matching strategy will be used instead.

      A best effort will be made for the returned map to be of the same class as the original one. If that's not possible (most likely because the class doesn't have an accessible default constructor), then the runtime will choose its own map implementation, but guarantying that the iterator order is respected.

      If the map contains a value of type Map and recursive is set to true, then that Map value will also be replaced by a new map which comes from recursively applying this same method.

      Type Parameters:
      K - the generic type of the map's keys
      Parameters:
      map - a Map which may contain streaming values
      recursive - Whether to also use this method to replace values of type Map
      Returns:
      a new Map which streaming values may have been replaced by CursorProvider instances, depending on the component's configuration.
    • resolveCursor

      Object resolveCursor(Object value)
      If the value is a CursorProvider, a corresponding Cursor is returned. The same value is returned otherwise.
      Parameters:
      value - a value which may be a CursorProvider
      Returns:
      a Cursor or the input value
    • resolveCursorProvider

      Object resolveCursorProvider(Object value)
      If the value is a repeatable streaming resource such as InputStream, Cursor, streaming iterators, etc., then an equivalent CursorProvider is returned. If the value is not a repeatable streaming resource or the owning component is configured not to use repeatable streams, then the same value is returned.

      For Cursor values, the same CursorProvider that already owns that Cursor is used. For other streaming values, the operation's repeatable streaming strategy will be used. If that strategy doesn't apply (e.g: the operation returns a PagingProvider but the streaming resource is an InputStream), then the system's default matching strategy will be used instead.

      Parameters:
      value - a value which may be a repeatable streaming resource.
      Returns:
      a CursorProvider or the same input value