001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025/**
026 * Indicates that this method is to be used as a 
027 * <a href="http://camel.apache.org/recipient-list.html">Dynamic Recipient List</a> routing the incoming message
028 * to one or more endpoints.
029 *
030 * When a message {@link org.apache.camel.Exchange} is received from an {@link org.apache.camel.Endpoint} then the
031 * <a href="http://camel.apache.org/bean-integration.html">Bean Integration</a>
032 * mechanism is used to map the incoming {@link org.apache.camel.Message} to the method parameters.
033 *
034 * The return value of the method is then converted to either a {@link java.util.Collection} or array of objects where each
035 * element is converted to an {@link Endpoint} or a {@link String}, or if it is not a collection/array then it is converted
036 * to an {@link Endpoint} or {@link String}.
037 *
038 * Then for each endpoint or URI the message is forwarded a separate copy.
039 */
040@Retention(RetentionPolicy.RUNTIME)
041@Documented
042@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR })
043public @interface RecipientList {
044
045    /**
046     * Id of {@link CamelContext} to use
047     */
048    String context() default "";
049
050    /**
051     * Delimiter used if the Expression returned multiple endpoints. Can be turned off using the value <tt>false</tt>.
052     * <p/>
053     * The default value is ,
054     */
055    String delimiter() default ",";
056
057    /**
058     * If enabled then sending messages to the recipients occurs concurrently.
059     * Note the caller thread will still wait until all messages has been fully processed, before it continues.
060     * Its only the sending and processing the replies from the recipients which happens concurrently.
061     */
062    boolean parallelProcessing() default false;
063
064    /**
065     * If enabled then the aggregate method on AggregationStrategy can be called concurrently.
066     * Notice that this would require the implementation of AggregationStrategy to be implemented as thread-safe.
067     * By default this is false meaning that Camel synchronizes the call to the aggregate method.
068     * Though in some use-cases this can be used to archive higher performance when the AggregationStrategy is implemented as thread-safe.
069     */
070    boolean parallelAggregate() default false;
071
072    /**
073     * Will now stop further processing if an exception or failure occurred during processing of an
074     * {@link org.apache.camel.Exchange} and the caused exception will be thrown.
075     * <p/>
076     * Will also stop if processing the exchange failed (has a fault message) or an exception
077     * was thrown and handled by the error handler (such as using onException). In all situations
078     * the recipient list will stop further processing. This is the same behavior as in pipeline, which
079     * is used by the routing engine.
080     * <p/>
081     * The default behavior is to <b>not</b> stop but continue processing till the end
082     */
083    boolean stopOnException() default false;
084
085    /**
086     * If enabled, unwind exceptions occurring at aggregation time to the error handler when parallelProcessing is used.
087     * Currently, aggregation time exceptions do not stop the route processing when parallelProcessing is used.
088     * Enabling this option allows to work around this behavior.
089     *
090     * The default value is <code>false</code> for the sake of backward compatibility.
091     */
092    boolean stopOnAggregateException() default false;
093
094    /**
095     * If enabled then Camel will process replies out-of-order, eg in the order they come back.
096     * If disabled, Camel will process replies in the same order as defined by the recipient list.
097     */
098    boolean streaming() default false;
099
100    /**
101     * Whether to ignore the invalidate endpoint exception when try to create a producer with that endpoint
102     */
103    boolean ignoreInvalidEndpoints() default false;
104
105    /**
106     * Sets a reference to the AggregationStrategy to be used to assemble the replies from the recipients, into a single outgoing message from the RecipientList.
107     * By default Camel will use the last reply as the outgoing message. You can also use a POJO as the AggregationStrategy
108     */
109    String strategyRef() default "";
110
111    /**
112     * Refers to a custom Thread Pool to be used for parallel processing.
113     * Notice if you set this option, then parallel processing is automatic implied, and you do not have to enable that option as well.
114     */
115    String executorServiceRef() default "";
116
117    /**
118     * Sets a total timeout specified in millis, when using parallel processing.
119     * If the Recipient List hasn't been able to send and process all replies within the given timeframe,
120     * then the timeout triggers and the Recipient List breaks out and continues.
121     * Notice if you provide a TimeoutAwareAggregationStrategy then the timeout method is invoked before breaking out.
122     * If the timeout is reached with running tasks still remaining, certain tasks for which it is difficult for Camel
123     * to shut down in a graceful manner may continue to run. So use this option with a bit of care.
124     */
125    long timeout() default 0;
126
127    /**
128     * Uses the {@link Processor} when preparing the {@link org.apache.camel.Exchange} to be send.
129     * This can be used to deep-clone messages that should be send, or any custom logic needed before
130     * the exchange is send.
131     */
132    String onPrepareRef() default "";
133
134    /**
135     * Shares the {@link org.apache.camel.spi.UnitOfWork} with the parent and each of the sub messages.
136     * Recipient List will by default not share unit of work between the parent exchange and each recipient exchange.
137     * This means each sub exchange has its own individual unit of work.
138     */
139    @Deprecated
140    boolean shareUnitOfWork() default false;
141}