org.apache.camel.AggregationStrategy Java Examples

The following examples show how to use org.apache.camel.AggregationStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CamelMainSupport.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
public CamelMainSupport(Map<String, String> props, String fromUrl, String toUrl, String marshal, String unmarshal, int aggregationSize, long aggregationTimeout, CamelContext camelContext) throws Exception {
    camel = camelContext;
    camelMain = new Main() {
        @Override
        protected ProducerTemplate findOrCreateCamelTemplate() {
            return camel.createProducerTemplate();
        }

        @Override
        protected CamelContext createCamelContext() {
            return camel;
        }
    };

    camelMain.addMainListener(new CamelMainFinishedListener());
    camelMain.configure().setAutoConfigurationLogSummary(false);

    // reordering properties to place the one starting with "#class:" first
    LinkedHashMap<String, String> orderedProps = new LinkedHashMap<>();
    props.keySet().stream()
            .filter(k -> props.get(k).startsWith("#class:"))
            .forEach(k -> orderedProps.put(k, props.get(k)));
    props.keySet().stream()
            .filter(k -> !props.get(k).startsWith("#class:"))
            .forEach(k -> orderedProps.put(k, props.get(k)));

    Properties camelProperties = new OrderedProperties();
    camelProperties.putAll(orderedProps);

    LOG.info("Setting initial properties in Camel context: [{}]", camelProperties);
    this.camel.getPropertiesComponent().setInitialProperties(camelProperties);

    camelMain.init();
    //creating the actual route
    this.camel.addRoutes(new RouteBuilder() {
        public void configure() {
            RouteDefinition rd = from(fromUrl);
            if (marshal != null && unmarshal != null) {
                throw new UnsupportedOperationException("Uses of both marshal (i.e. " + marshal + ") and unmarshal (i.e. " + unmarshal + ") is not supported");
            } else if (marshal != null) {
                LOG.info("Creating Camel route from({}).marshal().custom({}).to({})", fromUrl, marshal, toUrl);
                camel.getRegistry().bind(marshal, lookupAndInstantiateDataformat(marshal));
                rd.marshal().custom(marshal);
            } else if (unmarshal != null) {
                LOG.info("Creating Camel route from({}).unmarshal().custom({}).to({})", fromUrl, unmarshal, toUrl);
                camel.getRegistry().bind(unmarshal, lookupAndInstantiateDataformat(unmarshal));
                rd.unmarshal().custom(unmarshal);
            } else {
                LOG.info("Creating Camel route from({}).to({})", fromUrl, toUrl);
            }
            if (camel.getRegistry().lookupByName("aggregate") != null) {
                AggregationStrategy s = (AggregationStrategy) camel.getRegistry().lookupByName("aggregate");
                rd.aggregate(s).constant(true).completionSize(aggregationSize).completionTimeout(aggregationTimeout).toD(toUrl);
            } else {
                rd.toD(toUrl);
            }
        }
    });
}
 
Example #2
Source File: AggregateStepHandler.java    From syndesis with Apache License 2.0 4 votes vote down vote up
AggregationOption(StrategySupplier<AggregationStrategy> strategySupplier) {
    this(strategySupplier, (strategy, stepProperties) -> strategy);
}
 
Example #3
Source File: AggregateStepHandler.java    From syndesis with Apache License 2.0 4 votes vote down vote up
<T extends AggregationStrategy> AggregationOption(StrategySupplier<T> strategySupplier, StrategyConfigurer<T> configurer) {
    this.strategySupplier = (StrategySupplier<AggregationStrategy>) strategySupplier;
    this.configurer = (StrategyConfigurer<AggregationStrategy>) configurer;
}
 
Example #4
Source File: AggregateStepHandler.java    From syndesis with Apache License 2.0 4 votes vote down vote up
public AggregationStrategy getStrategy(Map<String, String> stepProperties) {
    return configurer.apply(strategySupplier.get(), stepProperties);
}