Class DynamicRouterFilterService
java.lang.Object
org.apache.camel.component.dynamicrouter.filter.DynamicRouterFilterService
A service that manages the
PrioritizedFilters for dynamic router subscriptions.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDynamicRouterFilterService(Supplier<PrioritizedFilter.PrioritizedFilterFactory> filterFactorySupplier) Constructor that allows thePrioritizedFilter.PrioritizedFilterFactorysupplier to be specified. -
Method Summary
Modifier and TypeMethodDescriptionaddFilterForChannel(String id, int priority, org.apache.camel.Predicate predicate, String endpoint, String channel, boolean update) Creates aPrioritizedFilterfrom the supplied parameters, and adds it to the filters for the specified channel.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.createFilter(String id, int priority, org.apache.camel.Predicate predicate, String endpoint, PrioritizedFilterStatistics statistics) Convenience method to create aPrioritizedFilterfrom the supplied parameters.getFilterById(String filterId, String channel) Return the filter with the supplied filter identifier.Retrieves a copy of the filter map.getFiltersForChannel(String channel) Get a copy of thePrioritizedFilters for the specified channel.Retrieves a copy of the filter statistics map.getMatchingEndpointsForExchangeByChannel(org.apache.camel.Exchange exchange, String channel, boolean firstMatchOnly, boolean warnDroppedMessage) Match the exchange against allPrioritizedFilters 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.getStatisticsForChannel(String channel) Get a copy of thePrioritizedFilterStatisticsfor the specified channel.voidinitializeChannelFilters(String channel) Initialize the filter list for the specified channel.booleanremoveFilterById(String filterId, String channel) Removes a filter with the ID from the control message.
-
Constructor Details
-
DynamicRouterFilterService
public DynamicRouterFilterService() -
DynamicRouterFilterService
public DynamicRouterFilterService(Supplier<PrioritizedFilter.PrioritizedFilterFactory> filterFactorySupplier) Constructor that allows thePrioritizedFilter.PrioritizedFilterFactorysupplier to be specified.- Parameters:
filterFactorySupplier- thePrioritizedFilter.PrioritizedFilterFactorysupplier
-
-
Method Details
-
initializeChannelFilters
Initialize the filter list for the specified channel.- Parameters:
channel- channel to initialize filter list for
-
getFiltersForChannel
Get a copy of thePrioritizedFilters for the specified channel.- Parameters:
channel- channel to obtainPrioritizedFilters for- Returns:
PrioritizedFilters for the specified channel
-
getFilterMap
Retrieves a copy of the filter map.- Returns:
- a copy of the filter map
-
getStatisticsForChannel
Get a copy of thePrioritizedFilterStatisticsfor the specified channel.- Parameters:
channel- channel to obtainPrioritizedFilterStatisticsfor- Returns:
PrioritizedFilterStatisticsfor the specified channel
-
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 aPrioritizedFilterfrom the supplied parameters.- Parameters:
id- the filter identifierpriority- the filter prioritypredicate- the filter predicateendpoint- the filter endpoint- Returns:
- a
PrioritizedFilterbuilt from the supplied parameters
-
addFilterForChannel
public String addFilterForChannel(String id, int priority, org.apache.camel.Predicate predicate, String endpoint, String channel, boolean update) Creates aPrioritizedFilterfrom the supplied parameters, and adds it to the filters for the specified channel.- Parameters:
id- the filter identifierpriority- the filter prioritypredicate- the filter predicateendpoint- the filter endpointchannel- the channel that contains the filterupdate- flag if this is an update to the filter- Returns:
- the ID of the added filter
-
addFilterForChannel
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
Return the filter with the supplied filter identifier. If there is no such filter, then return null.- Parameters:
filterId- the filter identifierchannel- the channel that contains the filter- Returns:
- the filter with the supplied ID, or null
-
removeFilterById
Removes a filter with the ID from the control message. This does not remove thePrioritizedFilterStatisticsinstance, 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 allPrioritizedFilters 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 byDynamicRouterConstants.ORIGINAL_BODY_HEADER. The message body will be changed to a string indicating that "no filters matched" the exchange. If theDynamicRouterConfiguration.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 exchangechannel- the dynamic router channel to get filters forfirstMatchOnly- to only return the first matchwarnDroppedMessage- 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
-