Search in sources :

Example 1 with RoutingSlipRouteStrategy

use of org.springframework.integration.routingslip.RoutingSlipRouteStrategy in project spring-integration by spring-projects.

the class RoutingSlipHeaderValueMessageProcessor method processMessage.

@Override
public Map<List<Object>, Integer> processMessage(Message<?> message) {
    // use a local variable to avoid the second access to volatile field on the happy path
    Map<List<Object>, Integer> routingSlip = this.routingSlip;
    if (routingSlip == null) {
        synchronized (this) {
            routingSlip = this.routingSlip;
            if (routingSlip == null) {
                List<Object> routingSlipPath = this.routingSlipPath;
                List<Object> routingSlipValues = new ArrayList<Object>(routingSlipPath.size());
                for (Object path : routingSlipPath) {
                    if (path instanceof String) {
                        String entry = (String) path;
                        if (this.beanFactory.containsBean(entry)) {
                            Object bean = this.beanFactory.getBean(entry);
                            if (!(bean instanceof MessageChannel || bean instanceof RoutingSlipRouteStrategy)) {
                                throw new IllegalArgumentException("The RoutingSlip can contain " + "only bean names of MessageChannel or RoutingSlipRouteStrategy: " + bean);
                            }
                            routingSlipValues.add(entry);
                        } else {
                            ExpressionEvaluatingRoutingSlipRouteStrategy strategy = new ExpressionEvaluatingRoutingSlipRouteStrategy(entry);
                            strategy.setBeanFactory(this.beanFactory);
                            try {
                                strategy.afterPropertiesSet();
                            } catch (Exception e) {
                                throw new IllegalStateException(e);
                            }
                            routingSlipValues.add(strategy);
                        }
                    } else {
                        routingSlipValues.add(path);
                    }
                }
                routingSlip = Collections.singletonMap(Collections.unmodifiableList(routingSlipValues), 0);
                this.routingSlip = routingSlip;
            }
        }
    }
    return routingSlip;
}
Also used : ExpressionEvaluatingRoutingSlipRouteStrategy(org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy) ExpressionEvaluatingRoutingSlipRouteStrategy(org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy) RoutingSlipRouteStrategy(org.springframework.integration.routingslip.RoutingSlipRouteStrategy) ArrayList(java.util.ArrayList) BeansException(org.springframework.beans.BeansException) MessageChannel(org.springframework.messaging.MessageChannel) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 BeansException (org.springframework.beans.BeansException)1 ExpressionEvaluatingRoutingSlipRouteStrategy (org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy)1 RoutingSlipRouteStrategy (org.springframework.integration.routingslip.RoutingSlipRouteStrategy)1 MessageChannel (org.springframework.messaging.MessageChannel)1