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.spi; 018 019import java.util.concurrent.CompletableFuture; 020 021import org.apache.camel.AsyncCallback; 022import org.apache.camel.AsyncProcessor; 023import org.apache.camel.AsyncProducer; 024import org.apache.camel.Endpoint; 025import org.apache.camel.Exchange; 026import org.apache.camel.ExchangePattern; 027import org.apache.camel.Processor; 028import org.apache.camel.Service; 029 030public interface ProducerCache extends Service { 031 032 AsyncProducer acquireProducer(Endpoint endpoint); 033 034 void releaseProducer(Endpoint endpoint, AsyncProducer producer); 035 036 Exchange send(Endpoint endpoint, Exchange exchange, Processor resultProcessor); 037 038 CompletableFuture<Exchange> asyncSendExchange(Endpoint endpoint, ExchangePattern pattern, 039 Processor processor, Processor resultProcessor, Exchange inExchange, CompletableFuture<Exchange> exchangeFuture); 040 041 Object getSource(); 042 043 int size(); 044 045 int getCapacity(); 046 047 long getHits(); 048 049 long getMisses(); 050 051 long getEvicted(); 052 053 void resetCacheStatistics(); 054 055 void purge(); 056 057 void cleanUp(); 058 059 boolean isEventNotifierEnabled(); 060 061 void setEventNotifierEnabled(boolean eventNotifierEnabled); 062 063 EndpointUtilizationStatistics getEndpointUtilizationStatistics(); 064 065 boolean doInAsyncProducer(Endpoint endpoint, Exchange exchange, AsyncCallback callback, AsyncProducerCallback asyncProducerCallback); 066 067 /** 068 * Callback for sending a exchange message to a endpoint using an {@link AsyncProcessor} capable producer. 069 * <p/> 070 * Using this callback as a template pattern ensures that Camel handles the resource handling and will 071 * start and stop the given producer, to avoid resource leaks. 072 * 073 */ 074 interface AsyncProducerCallback { 075 076 /** 077 * Performs operation on the given producer to send the given exchange. 078 * 079 * @param asyncProducer the async producer, is never <tt>null</tt> 080 * @param exchange the exchange to process 081 * @param callback the async callback 082 * @return (doneSync) <tt>true</tt> to continue execute synchronously, <tt>false</tt> to continue being executed asynchronously 083 */ 084 boolean doInAsyncProducer(AsyncProducer asyncProducer, Exchange exchange, AsyncCallback callback); 085 } 086 087}