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.util.concurrent.CompletableFuture; 020 021/** 022 * An <b>asynchronous</b> processor which can process an {@link Exchange} in an asynchronous fashion 023 * and signal completion by invoking the {@link AsyncCallback}. 024 * <p/> 025 * Any processor can be coerced to have an {@link AsyncProcessor} interface by using the 026 * {@link org.apache.camel.support.AsyncProcessorConverterHelper#convert AsyncProcessorConverterHelper.convert} 027 * method. 028 */ 029public interface AsyncProcessor extends Processor { 030 031 /** 032 * Processes the message exchange. 033 * Similar to {@link Processor#process}, but the caller supports having the exchange asynchronously processed. 034 * <p/> 035 * If there was a failure processing then the caused {@link Exception} would be set on the {@link Exchange}. 036 * 037 * @param exchange the message exchange 038 * @param callback the {@link AsyncCallback} will be invoked when the processing of the exchange is completed. 039 * If the exchange is completed synchronously, then the callback is also invoked synchronously. 040 * The callback should therefore be careful of starting recursive loop. 041 * @return (doneSync) <tt>true</tt> to continue execute synchronously, <tt>false</tt> to continue being executed asynchronously 042 */ 043 boolean process(Exchange exchange, AsyncCallback callback); 044 045 CompletableFuture<Exchange> processAsync(Exchange exchange); 046 047}