Class Processors

java.lang.Object
com.tangosol.util.Processors

public class Processors extends Object
Simple InvocableMap.EntryProcessor DSL.

Contains factory methods and entry processor classes that are used to implement functionality exposed via different variants of NamedCache API.

Since:
14.1.1.0
Author:
mk 2019.07.26
  • Constructor Details

    • Processors

      public Processors()
  • Method Details

    • asynchronous

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> asynchronous(InvocableMap.EntryProcessor<K,V,R> processor)
      Construct an asynchronous processor for a given processor.
      Type Parameters:
      K - the type of the Map entry key
      V - the type of the Map entry value
      R - the type of value returned by the EntryProcessor
      Parameters:
      processor - the underlying InvocableMap.EntryProcessor
      Returns:
      an aynchronous processor for a given processor
      See Also:
    • asynchronous

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> asynchronous(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId)
      Construct an asynchronous processor for a given processor with unit-of-order id.
      Type Parameters:
      K - the type of the Map entry key
      V - the type of the Map entry value
      R - the type of value returned by the EntryProcessor
      Parameters:
      processor - the underlying InvocableMap.EntryProcessor
      iUnitOrderId - the unit-of-order id for this processor
      Returns:
      an aynchronous processor for a given processor with unit-of-order id
      See Also:
    • singleEntryAsynchronous

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> singleEntryAsynchronous(InvocableMap.EntryProcessor<K,V,R> processor)
      Construct a single entry asynchronous processor for a given processor.
      Parameters:
      processor - the underlying InvocableMap.EntryProcessor
      Returns:
      a single entry asynchronous processor for a given processor
      See Also:
    • singleEntryAsynchronous

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> singleEntryAsynchronous(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId)
      Construct a single entry asynchronous for a given processor with unit-of-order id.
      Parameters:
      processor - the underlying InvocableMap.EntryProcessor
      iUnitOrderId - the unit-of-order id for this processor
      Returns:
      a single entry asynchronous processor for a given processor unit-of-order id
      See Also:
    • streamingAsynchronous

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> streamingAsynchronous(InvocableMap.EntryProcessor<K,V,R> processor, Consumer<? super Map.Entry<? extends K,? extends R>> onPartial)
      Construct a streaming asynchronous processor for a given processor and one or more callbacks.

      Important Note: All provided callbacks must be non-blocking. For example, any use of NamedCache API is completely disallowed.

      Parameters:
      processor - the underlying InvocableMap.EntryProcessor
      onPartial - a user-defined callback that will be called for each partial result
      Returns:
      a streaming asynchronous processor for a given processor and one or more callbacks
      See Also:
    • streamingAsynchronous

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> streamingAsynchronous(InvocableMap.EntryProcessor<K,V,R> processor, int iUnitOrderId, Consumer<? super Map.Entry<? extends K,? extends R>> onPartial)
      Construct a streaming asynchronous processor for a given processor and one or more callbacks.

      Important Note: All provided callbacks must be non-blocking. For example, any use of NamedCache API is completely disallowed.

      Parameters:
      processor - the underlying InvocableMap.EntryProcessor
      iUnitOrderId - the unit-of-order id for this processor
      onPartial - a user-defined callback that will be called for each partial result
      Returns:
      a streaming asynchronous processor for a given processor and one or more callbacks
      See Also:
    • composite

      public static <K, V> InvocableMap.EntryProcessor<K,V,Object> composite(InvocableMap.EntryProcessor<K,V,?>[] aProcessor)
      Construct a composite processor for the specified array of individual entry processors.

      The result of the composite processor execution is an array of results returned by the individual EntryProcessor invocations.

      Type Parameters:
      K - the type of the Map entry key
      V - the type of the Map entry value
      Parameters:
      aProcessor - the entry processor array
      Returns:
      a composite processor for the specified array of individual entry processors.
      See Also:
    • conditional

      public static <K, V, T> InvocableMap.EntryProcessor<K,V,T> conditional(Filter<V> filter, InvocableMap.EntryProcessor<K,V,T> processor)
      Construct a conditional processor for a specified filter and the processor.

      The specified entry processor gets invoked if and only if the filter applied to the InvocableMap entry evaluates to true; otherwise the result of the process invocation will return null.

      Type Parameters:
      K - the type of the Map entry key
      V - the type of the Map entry value
      T - the type of value returned by the EntryProcessor
      Parameters:
      filter - the filter
      processor - the entry processor
      Returns:
      a conditional processor for a specified filter and the processor.
      See Also:
    • put

      public static <K, V> InvocableMap.EntryProcessor<K,V,V> put(Filter filter, V value)
      Construct a put processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to true. The result of the process invocation does not return any result.
      Type Parameters:
      V - the type of the Map entry value
      Parameters:
      filter - the filter to evaluate an entry
      value - a value to update an entry with
      Returns:
      a put processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to true
    • put

      public static <K, V> InvocableMap.EntryProcessor<K,V,V> put(Filter filter, V value, boolean fReturn)
      Construct a put processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to true. This processor optionally returns the current value as a result of the invocation if it has not been updated (the filter evaluated to false).
      Type Parameters:
      V - the type of the Map entry value
      Parameters:
      filter - the filter to evaluate an entry
      value - a value to update an entry with
      fReturn - specifies whether or not the processor should return the current value in case it has not been updated
      Returns:
      a put processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to true.
    • putAll

      public static <K, V> InvocableMap.EntryProcessor<K,V,V> putAll(Filter filter, Map<? extends K,? extends V> map)
      Construct a putAll processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to true. The new value is extracted from the specified map based on the entry's key.
      Type Parameters:
      K - the type of the Map entry key
      V - the type of the Map entry value
      Parameters:
      filter - the filter to evaluate all supplied entries
      map - a map of values to update entries with
      Returns:
      a putAll processor that updates an entry with a new value if and only if the filter applied to the entry evaluates to true.
    • remove

      public static <K, V> InvocableMap.EntryProcessor<K,V,Boolean> remove()
      Construct a remove processor that unconditionally removes an InvocableMap entry. The invocation of the created processor does not return any result.
      Returns:
      a remove processor that unconditionally removes an InvocableMap entry
    • remove

      public static <K, V> InvocableMap.EntryProcessor<K,V,V> remove(boolean fReturn)
      Construct a remove processor that unconditionally removes an InvocableMap entry, and optionally returns the removed value.
      Parameters:
      fReturn - the flag specifying whether to return the value that was removed
      Returns:
      a remove processor that unconditionally removes an InvocableMap entry
    • remove

      public static <K, V> InvocableMap.EntryProcessor<K,V,V> remove(Filter filter)
      Construct a remove processor that removes an InvocableMap entry if and only if the filter applied to the entry evaluates to true. The invocation of the created processor does not return any result.

      Note: If the goal is to remove entries from a map based on a certain criteria, it is significantly more efficient to pass the processor created by the remove() method to InvocableMap.invokeAll(Filter, EntryProcessor). That way filtering will be performed ahead of time, using any available indexes for optimization, so the number of entries the processor is executed against will be reduced. The processor returned by this method should only be used when that is not possible.

      Parameters:
      filter - the filter to evaluate an entry
      Returns:
      a remove processor that removes an InvocableMap entry if and only if the filter applied to the entry evaluates to true.
    • remove

      public static <K, V> InvocableMap.EntryProcessor<K,V,V> remove(Filter filter, boolean fReturn)
      Construct a remove processor that removes an InvocableMap entry if and only if the filter applied to the entry evaluates to true. This processor may optionally return the current value as a result of the invocation if it has not been removed (the filter evaluated to false).

      Note: If the goal is to remove entries from a map based on a certain criteria, it is significantly more efficient to pass the processor created by the remove() method to InvocableMap.invokeAll(Filter, EntryProcessor). That way filtering will be performed ahead of time, using any available indexes for optimization, so the number of entries the processor is executed against will be reduced. The processor returned by this method should only be used when that is not possible.

      Parameters:
      filter - the filter to evaluate an entry
      fReturn - specifies whether or not the processor should return the current value if it has not been removed
      Returns:
      a remove processor that removes an InvocableMap entry if and only if the filter applied to the entry evaluates to true.
    • extract

      public static <K, V, T, R> InvocableMap.EntryProcessor<K,V,R> extract(ValueExtractor<? super T,? extends R> extractor)
      Construct an extract processor based on the specified ValueExtractor.
      Parameters:
      extractor - a Extractor object; passing null is equivalent to using the IdentityExtractor
      Returns:
      an extract processor based on the specified extractor.
      See Also:
    • extract

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> extract(String sName)
      Construct an extract processor for a given property or method name.
      Parameters:
      sName - a property or method name to make a ValueExtractor for; this parameter can also be a dot-delimited sequence of names which would result in an ExtractorProcessor based on the ChainedExtractor that is based on an array of corresponding ValueExtractor objects
      Returns:
      an extract processor for a given property or method name
      See Also:
    • increment

      public static <K, V, N extends Number> InvocableMap.EntryProcessor<K,V,N> increment(String sName, N numInc, boolean fPostIncrement)
      Construct an increment processor that will increment a property value by a specified amount, returning either the old or the new value as specified. The Java type of the numInc parameter will dictate the Java type of the original and the new value.
      Parameters:
      sName - the property name
      numInc - the Number representing the magnitude and sign of the increment
      fPostIncrement - pass true to return the value as it was before it was incremented, or pass false to return the value as it is after it is incremented
      Returns:
      an increment processor
      See Also:
    • increment

      public static <K, V, N extends Number> InvocableMap.EntryProcessor<K,V,N> increment(PropertyManipulator manipulator, N numInc, boolean fPostIncrement)
      Construct an increment processor that will increment a property value by a specified amount, returning either the old or the new value as specified. The Java type of the numInc parameter will dictate the Java type of the original and the new value.
      Parameters:
      manipulator - the Manipulator; could be null
      numInc - the Number representing the magnitude and sign of the increment
      fPostIncrement - pass true to return the value as it was before it was incremented, or pass false to return the value as it is after it is incremented
      Returns:
      an increment processor
      See Also:
    • multiply

      public static <K, V, N extends Number> InvocableMap.EntryProcessor<K,V,N> multiply(String sName, N numFactor, boolean fPostFactor)
      Construct a multiply processor that will multiply a property value by a specified factor, returning either the old or the new value as specified. The Java type of the original property value will dictate the way the specified factor is interpreted. For example, applying a factor of Double(0.5) to a property value of Integer(4) will result in a new property value of Integer(2).
      If the original property value is null, the Java type of the numFactor parameter will dictate the Java type of the new value.
      Parameters:
      sName - the property name
      numFactor - the Number representing the magnitude and sign of the multiplier
      fPostFactor - pass true to return the value as it was before it was multiplied, or pass false to return the value as it is after it is multiplied
      Returns:
      a multiply processor that will multiply a property value by a specified factor, returning either the old or the new value as specified
      See Also:
    • multiply

      public static <K, V, N extends Number> InvocableMap.EntryProcessor<K,V,N> multiply(PropertyManipulator<V,N> manipulator, N numFactor, boolean fPostFactor)
      Construct a multiply processor that will multiply a property value by a specified factor, returning either the old or the new value as specified. The Java type of the original property value will dictate the way the specified factor is interpreted. For example, applying a factor of Double(0.5) to a property value of Integer(4) will result in a new property value of Integer(2).
      If the original property value is null, the Java type of the numFactor parameter will dictate the Java type of the new value.
      Parameters:
      manipulator - the Manipulator; could be null
      numFactor - the Number representing the magnitude and sign of the multiplier
      fPostFactor - pass true to return the value as it was before it was multiplied, or pass false to return the value as it is after it is multiplied
      Returns:
      a multiply processor that will multiply a property value by a specified factor, returning either the old or the new value as specified
      See Also:
    • preload

      public static <K, V> InvocableMap.EntryProcessor<K,V,V> preload()
      Construct the preload request processor.
      Returns:
      a preload request processor
      See Also:
    • priority

      public static <K, V, T> InvocableMap.EntryProcessor<K,V,T> priority(InvocableMap.EntryProcessor<K,V,T> processor)
      Construct a priority processor for a given processor.
      Parameters:
      processor - the processor wrapped by this priority processor
      Returns:
      a priority processor.
      See Also:
    • manipulate

      public static <V, R> PropertyManipulator<V,R> manipulate(String sName)
      Construct a property manipulate processor for the specified property name.
      Parameters:
      sName - a property name
      Returns:
      a property manipulate processor for the specified property name
      See Also:
    • manipulate

      public static <V, R> PropertyManipulator<V,R> manipulate(String sName, boolean fUseIs)
      Construct a property manipulate processor for the specified property name.

      This constructor assumes that the corresponding property getter will have a name of either ("get" + sName) or ("is + sName) and the corresponding property setter's name will be ("set + sName).

      Parameters:
      sName - a property name
      fUseIs - if true, the getter method will be prefixed with "is" rather than "get"
      Returns:
      a property manipulate processor for the specified property name
      See Also:
    • script

      public static <K, V, R> InvocableMap.EntryProcessor<K,V,R> script(String sLanguage, String sName, Object... aoArgs)
      Construct an EntryProcessor that is implemented in a script using the specified language.
      Type Parameters:
      K - the type of key that the InvocableMap.EntryProcessor will receive
      V - the type of value that the InvocableMap.EntryProcessor will receive
      R - the type of result that the InvocableMap.EntryProcessor will return
      Parameters:
      sLanguage - the string specifying one of the supported languages
      sName - the name of the InvocableMap.EntryProcessor that needs to be evaluated
      aoArgs - the arguments to be passed to the InvocableMap.EntryProcessor
      Returns:
      An instance of script processor
      Throws:
      ScriptException - if the script cannot be loaded or any errors occur during its execution
      IllegalArgumentException - if the specified language is not supported
      See Also:
    • touch

      public static <K, V> InvocableMap.EntryProcessor<K,V,Void> touch()
      Construct a touch processor.
      Returns:
      a touch processor
      See Also:
    • update

      public static <K, V, T> InvocableMap.EntryProcessor<K,V,Boolean> update(ValueUpdater<V,T> updater, T value)
      Construct an update processor based on the specified ValueUpdater.
      Parameters:
      updater - a ValueUpdater object; passing null will simpy replace the entry's value with the specified one instead of updating it
      value - the value to update the target entry with
      Returns:
      an update processor
      See Also:
    • update

      public static <K, V, T> InvocableMap.EntryProcessor<K,V,Boolean> update(String sMethod, T value)
      Construct an update processor for a given method name. The method must have a single parameter of a Java type compatible with the specified value type.
      Parameters:
      sMethod - a method name to make an ValueUpdater for; this parameter can also be a dot-delimited sequence of method names which would result in using a CompositeUpdater
      value - the value to update the target entry with
      Returns:
      an update processor for a given method name
      See Also:
    • versionedPut

      public static <K, V extends Versionable> InvocableMap.EntryProcessor<K,V,V> versionedPut(V oValue)
      Construct a versioned put processor that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry's value (which must exist). The result of the process invocation does not return any result.
      Parameters:
      oValue - a Versionable value to update an entry with
      Returns:
      a versioned put
      See Also:
    • versionedPut

      public static <K, V extends Versionable> InvocableMap.EntryProcessor<K,V,V> versionedPut(V oValue, boolean fAllowInsert, boolean fReturn)
      Construct a versioned put processor that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry's value. This processor optionally returns the current value as a result of the invocation if it has not been updated (the versions did not match).
      Parameters:
      oValue - a value to update an entry with
      fAllowInsert - specifies whether or not an insert should be allowed (no currently existing value)
      fReturn - specifies whether or not the processor should return the current value in case it has not been updated
      Returns:
      a versioned put
      See Also:
    • versionedPutAll

      public static <K, V extends Versionable> InvocableMap.EntryProcessor<K,V,V> versionedPutAll(Map<? extends K,? extends V> map)
      Construct a versioned putAll processor that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry's value (which must exist). The result of the process invocation does not return any result.
      Parameters:
      map - a map of values to update entries with
      Returns:
      a versioned putAll processor
      See Also:
    • versionedPutAll

      public static <K, V extends Versionable> InvocableMap.EntryProcessor<K,V,V> versionedPutAll(Map<? extends K,? extends V> map, boolean fAllowInsert, boolean fReturn)
      Construct a versioned putAll processor that updates an entry with a new value if and only if the version of the new value matches to the version of the current entry's value (which must exist). This processor optionally returns a map of entries that have not been updated (the versions did not match).
      Parameters:
      map - a map of values to update entries with
      fAllowInsert - specifies whether or not an insert should be allowed (no currently existing value)
      fReturn - specifies whether or not the processor should return the entries that have not been updated
      Returns:
      a versioned putAll processor
      See Also: