Class DynamicRouterFilterService

java.lang.Object
org.apache.camel.component.dynamicrouter.filter.DynamicRouterFilterService

public class DynamicRouterFilterService extends Object
A service that manages the PrioritizedFilters for dynamic router subscriptions.
  • Constructor Details

  • Method Details

    • initializeChannelFilters

      public void initializeChannelFilters(String channel)
      Initialize the filter list for the specified channel.
      Parameters:
      channel - channel to initialize filter list for
    • getFiltersForChannel

      public Collection<PrioritizedFilter> getFiltersForChannel(String channel)
      Get a copy of the PrioritizedFilters for the specified channel.
      Parameters:
      channel - channel to obtain PrioritizedFilters for
      Returns:
      PrioritizedFilters for the specified channel
    • getFilterMap

      Retrieves a copy of the filter map.
      Returns:
      a copy of the filter map
    • getStatisticsForChannel

      public List<PrioritizedFilterStatistics> getStatisticsForChannel(String channel)
      Get a copy of the PrioritizedFilterStatistics for the specified channel.
      Parameters:
      channel - channel to obtain PrioritizedFilterStatistics for
      Returns:
      PrioritizedFilterStatistics for the specified channel
    • getFilterStatisticsMap

      public Map<String,List<PrioritizedFilterStatistics>> getFilterStatisticsMap()
      Retrieves a copy of the filter statistics map.
      Returns:
      a copy of the filter statistics map
    • createFilter

      public PrioritizedFilter createFilter(String id, int priority, org.apache.camel.Predicate predicate, String endpoint, PrioritizedFilterStatistics statistics)
      Convenience method to create a PrioritizedFilter from the supplied parameters.
      Parameters:
      id - the filter identifier
      priority - the filter priority
      predicate - the filter predicate
      endpoint - the filter endpoint
      Returns:
      a PrioritizedFilter built from the supplied parameters
    • addFilterForChannel

      public String addFilterForChannel(String id, int priority, org.apache.camel.Predicate predicate, String endpoint, String channel, boolean update)
      Creates a PrioritizedFilter from the supplied parameters, and adds it to the filters for the specified channel.
      Parameters:
      id - the filter identifier
      priority - the filter priority
      predicate - the filter predicate
      endpoint - the filter endpoint
      channel - the channel that contains the filter
      update - flag if this is an update to the filter
      Returns:
      the ID of the added filter
    • addFilterForChannel

      public String addFilterForChannel(PrioritizedFilter filter, String channel, boolean update)
      Adds the filter to the list of filters, and ensure that the filters are sorted by priority after the insertion.
      Parameters:
      filter - the filter to add
      Returns:
      the ID of the added filter
    • getFilterById

      public PrioritizedFilter getFilterById(String filterId, String channel)
      Return the filter with the supplied filter identifier. If there is no such filter, then return null.
      Parameters:
      filterId - the filter identifier
      channel - the channel that contains the filter
      Returns:
      the filter with the supplied ID, or null
    • removeFilterById

      public boolean removeFilterById(String filterId, String channel)
      Removes a filter with the ID from the control message. This does not remove the PrioritizedFilterStatistics instance, because the statistics still represent actions that happened, so they should remain for statistics reporting.
      Parameters:
      filterId - the ID of the filter to remove
    • getMatchingEndpointsForExchangeByChannel

      public String getMatchingEndpointsForExchangeByChannel(org.apache.camel.Exchange exchange, String channel, boolean firstMatchOnly, boolean warnDroppedMessage)
      Match the exchange against all PrioritizedFilters for the specified channel to determine if any of them are suitable to handle the exchange, then create a comma-delimited string of the filters' endpoints.

      SIDE-EFFECT: If there are no matching filters, this method will modify the Exchange! Without a matching filter, a message would otherwise be dropped without any notification, including log messages. Instead, if no matching filters can be found, this method will store the original message body in a header named by DynamicRouterConstants.ORIGINAL_BODY_HEADER. The message body will be changed to a string indicating that "no filters matched" the exchange. If the DynamicRouterConfiguration.isWarnDroppedMessage() flag is set to true, the message will be logged as a warning. Otherwise, it will be logged at the DEBUG level.

      Parameters:
      exchange - the message exchange
      channel - the dynamic router channel to get filters for
      firstMatchOnly - to only return the first match
      warnDroppedMessage - if there are no matching filters found, this flag determines if the message will be logged as a warning; otherwise, it will be logged at the DEBUG level
      Returns:
      a comma-delimited string of endpoints from matching filters