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.Collection; 020 021import org.apache.camel.Endpoint; 022import org.apache.camel.Exchange; 023import org.apache.camel.StaticService; 024 025/** 026 * A repository which tracks in flight {@link Exchange}s. 027 * 028 * @version 029 */ 030public interface InflightRepository extends StaticService { 031 032 /** 033 * Information about the inflight exchange. 034 */ 035 interface InflightExchange { 036 037 /** 038 * The exchange being inflight 039 */ 040 Exchange getExchange(); 041 042 /** 043 * The duration in millis the exchange has been inflight 044 */ 045 long getDuration(); 046 047 /** 048 * The elapsed time in millis processing the exchange at the current node 049 */ 050 long getElapsed(); 051 052 /** 053 * The id of the node from the route where the exchange currently is being processed 054 * <p/> 055 * Is <tt>null</tt> if message history is disabled. 056 */ 057 String getNodeId(); 058 059 /** 060 * The id of the route where the exchange originates (started) 061 */ 062 String getFromRouteId(); 063 064 /** 065 * The id of the route where the exchange currently is being processed 066 * <p/> 067 * Is <tt>null</tt> if message history is disabled. 068 * @deprecated use {@link #getAtRouteId()} 069 */ 070 @Deprecated 071 String getRouteId(); 072 073 /** 074 * The id of the route where the exchange currently is being processed 075 * <p/> 076 * Is <tt>null</tt> if message history is disabled. 077 */ 078 String getAtRouteId(); 079 080 } 081 082 /** 083 * Adds the exchange to the inflight registry to the total counter 084 * 085 * @param exchange the exchange 086 */ 087 void add(Exchange exchange); 088 089 /** 090 * Removes the exchange from the inflight registry to the total counter 091 * 092 * @param exchange the exchange 093 */ 094 void remove(Exchange exchange); 095 096 /** 097 * Adds the exchange to the inflight registry associated to the given route 098 * 099 * @param exchange the exchange 100 * @param routeId the id of the route 101 */ 102 void add(Exchange exchange, String routeId); 103 104 /** 105 * Removes the exchange from the inflight registry removing association to the given route 106 * 107 * @param exchange the exchange 108 * @param routeId the id of the route 109 */ 110 void remove(Exchange exchange, String routeId); 111 112 /** 113 * Current size of inflight exchanges. 114 * <p/> 115 * Will return 0 if there are no inflight exchanges. 116 * 117 * @return number of exchanges currently in flight. 118 */ 119 int size(); 120 121 /** 122 * Will always return 0 due method is deprecated. 123 * @deprecated will be removed in a future Camel release. 124 */ 125 @Deprecated 126 int size(Endpoint endpoint); 127 128 /** 129 * Adds the route from the in flight registry. 130 * <p/> 131 * Is used for initializing up resources 132 * 133 * @param routeId the id of the route 134 */ 135 void addRoute(String routeId); 136 137 /** 138 * Removes the route from the in flight registry. 139 * <p/> 140 * Is used for cleaning up resources to avoid leaking. 141 * 142 * @param routeId the id of the route 143 */ 144 void removeRoute(String routeId); 145 146 /** 147 * Current size of inflight exchanges which are from the given route. 148 * <p/> 149 * Will return 0 if there are no inflight exchanges. 150 * 151 * @param routeId the id of the route 152 * @return number of exchanges currently in flight. 153 */ 154 int size(String routeId); 155 156 /** 157 * A <i>read-only</i> browser of the {@link InflightExchange}s that are currently inflight. 158 */ 159 Collection<InflightExchange> browse(); 160 161 /** 162 * A <i>read-only</i> browser of the {@link InflightExchange}s that are currently inflight that started from the given route. 163 * 164 * @param fromRouteId the route id, or <tt>null</tt> for all routes. 165 */ 166 Collection<InflightExchange> browse(String fromRouteId); 167 168 /** 169 * A <i>read-only</i> browser of the {@link InflightExchange}s that are currently inflight. 170 * 171 * @param limit maximum number of entries to return 172 * @param sortByLongestDuration to sort by the longest duration. Set to <tt>true</tt> to include the exchanges that has been inflight the longest time, 173 * set to <tt>false</tt> to sort by exchange id 174 */ 175 Collection<InflightExchange> browse(int limit, boolean sortByLongestDuration); 176 177 /** 178 * A <i>read-only</i> browser of the {@link InflightExchange}s that are currently inflight that started from the given route. 179 * 180 * @param fromRouteId the route id, or <tt>null</tt> for all routes. 181 * @param limit maximum number of entries to return 182 * @param sortByLongestDuration to sort by the longest duration. Set to <tt>true</tt> to include the exchanges that has been inflight the longest time, 183 * set to <tt>false</tt> to sort by exchange id 184 */ 185 Collection<InflightExchange> browse(String fromRouteId, int limit, boolean sortByLongestDuration); 186 187 /** 188 * Gets the oldest {@link InflightExchange} that are currently inflight that started from the given route. 189 * 190 * @param fromRouteId the route id, or <tt>null</tt> for all routes. 191 * @return the oldest, or <tt>null</tt> if none inflight 192 */ 193 InflightExchange oldest(String fromRouteId); 194 195}