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 */
017 package org.apache.camel;
018
019 /**
020 * An <b>asynchronous</b> processor which can process an {@link Exchange} in an asynchronous fashion
021 * and signal completion by invoking the {@link AsyncCallback}.
022 * <p/>
023 * Any processor can be coerced to have an {@link AsyncProcessor} interface by using the
024 * {@link org.apache.camel.impl.converter.AsyncProcessorTypeConverter#convert AsyncProcessorTypeConverter.covert}
025 * method.
026 * <p/>
027 * <b>Important:<b/> Use the {@link org.apache.camel.util.AsyncProcessorHelper#process(AsyncProcessor, Exchange, AsyncCallback)}
028 * method to invoke the process method, which ensure Camel have a chance to interweave and invoke it in a reliable manner.
029 * For example when using transactions all the invocations has to occur in synchronous manner to ensure the transaction
030 * work is done in the same thread, which is required by Spring TransactionManager.
031 *
032 * @version
033 */
034 public interface AsyncProcessor extends Processor {
035
036 /**
037 * Processes the message exchange.
038 * Similar to {@link Processor#process}, but the caller supports having the exchange asynchronously processed.
039 * <p/>
040 * If there was a failure processing then the caused {@link Exception} would be set on the {@link Exchange}.
041 *
042 * @param exchange the message exchange
043 * @param callback the {@link AsyncCallback} will be invoked when the processing of the exchange is completed.
044 * If the exchange is completed synchronously, then the callback is also invoked synchronously.
045 * The callback should therefore be careful of starting recursive loop.
046 * @return (doneSync) <tt>true</tt> to continue execute synchronously, <tt>false</tt> to continue being executed asynchronously
047 * @see org.apache.camel.util.AsyncProcessorHelper#process(AsyncProcessor, Exchange, AsyncCallback)
048 */
049 boolean process(Exchange exchange, AsyncCallback callback);
050 }