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 org.apache.camel.AsyncCallback; 020 021/** 022 * SPI to plugin different reactive engines in the Camel routing engine. 023 */ 024public interface ReactiveExecutor { 025 026 /** 027 * Schedules the task to be run 028 * 029 * @param runnable the task 030 */ 031 default void schedule(Runnable runnable) { 032 schedule(runnable, null); 033 } 034 035 /** 036 * Schedules the task to be run 037 * 038 * @param runnable the task 039 * @param description a human readable description for logging purpose 040 */ 041 void schedule(Runnable runnable, String description); 042 043 /** 044 * Schedules the task to be prioritized and run asap 045 * 046 * @param runnable the task 047 */ 048 default void scheduleMain(Runnable runnable) { 049 scheduleMain(runnable, null); 050 } 051 052 /** 053 * Schedules the task to be prioritized and run asap 054 * 055 * @param runnable the task 056 * @param description a human readable description for logging purpose 057 */ 058 void scheduleMain(Runnable runnable, String description); 059 060 /** 061 * Schedules the task to run synchronously 062 * 063 * @param runnable the task 064 */ 065 default void scheduleSync(Runnable runnable) { 066 scheduleSync(runnable, null); 067 } 068 069 /** 070 * Schedules the task to run synchronously 071 * 072 * @param runnable the task 073 * @param description a human readable description for logging purpose 074 */ 075 void scheduleSync(Runnable runnable, String description); 076 077 /** 078 * Executes the next task (if supported by the reactive executor implementation) 079 * 080 * @return true if a task was executed or false if no more pending tasks 081 */ 082 boolean executeFromQueue(); 083 084 /** 085 * Schedules the callback to be run 086 * 087 * @param callback the callable 088 */ 089 default void callback(AsyncCallback callback) { 090 schedule(new Runnable() { 091 092 @Override 093 public void run() { 094 callback.done(false); 095 } 096 097 @Override 098 public String toString() { 099 return "Callback[" + callback + "]"; 100 } 101 }); 102 } 103 104}