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.management.mbean;
018
019import java.util.Set;
020
021import org.apache.camel.CamelContext;
022import org.apache.camel.api.management.ManagedResource;
023import org.apache.camel.api.management.mbean.ManagedAggregateProcessorMBean;
024import org.apache.camel.model.AggregateDefinition;
025import org.apache.camel.processor.aggregate.AggregateProcessor;
026import org.apache.camel.spi.ManagementStrategy;
027
028@ManagedResource(description = "Managed AggregateProcessor")
029public class ManagedAggregateProcessor extends ManagedProcessor implements ManagedAggregateProcessorMBean {
030    private final AggregateProcessor processor;
031
032    public ManagedAggregateProcessor(CamelContext context, AggregateProcessor processor, AggregateDefinition definition) {
033        super(context, processor, definition);
034        this.processor = processor;
035    }
036
037    @Override
038    public void init(ManagementStrategy strategy) {
039        super.init(strategy);
040    }
041
042    @Override
043    public AggregateProcessor getProcessor() {
044        return processor;
045    }
046
047    @Override
048    public AggregateDefinition getDefinition() {
049        return (AggregateDefinition) super.getDefinition();
050    }
051
052    @Override
053    public String getCorrelationExpressionLanguage() {
054        if (getDefinition().getCorrelationExpression() != null) {
055            return getDefinition().getCorrelationExpression().getExpressionType().getLanguage();
056        } else {
057            return null;
058        }
059    }
060
061    @Override
062    public String getCorrelationExpression() {
063        if (getDefinition().getCorrelationExpression() != null) {
064            return getDefinition().getCorrelationExpression().getExpressionType().getExpression();
065        } else {
066            return null;
067        }
068    }
069
070    @Override
071    public long getCompletionTimeout() {
072        return processor.getCompletionTimeout();
073    }
074
075    @Override
076    public String getCompletionTimeoutLanguage() {
077        if (getDefinition().getCompletionTimeoutExpression() != null) {
078            return getDefinition().getCompletionTimeoutExpression().getExpressionType().getLanguage();
079        } else {
080            return null;
081        }
082    }
083
084    @Override
085    public String getCompletionTimeoutExpression() {
086        if (getDefinition().getCompletionTimeoutExpression() != null) {
087            return getDefinition().getCompletionTimeoutExpression().getExpressionType().getExpression();
088        } else {
089            return null;
090        }
091    }
092
093    @Override
094    public long getCompletionInterval() {
095        return processor.getCompletionInterval();
096    }
097
098    @Override
099    public long getCompletionTimeoutCheckerInterval() {
100        return processor.getCompletionTimeoutCheckerInterval();
101    }
102
103    @Override
104    public int getCompletionSize() {
105        return processor.getCompletionSize();
106    }
107
108    @Override
109    public String getCompletionSizeExpressionLanguage() {
110        if (getDefinition().getCompletionSizeExpression() != null) {
111            return getDefinition().getCompletionSizeExpression().getExpressionType().getLanguage();
112        } else {
113            return null;
114        }
115    }
116
117    @Override
118    public String getCompletionSizeExpression() {
119        if (getDefinition().getCompletionSizeExpression() != null) {
120            return getDefinition().getCompletionSizeExpression().getExpressionType().getExpression();
121        } else {
122            return null;
123        }
124    }
125
126    @Override
127    public boolean isCompletionFromBatchConsumer() {
128        return processor.isCompletionFromBatchConsumer();
129    }
130
131    @Override
132    public boolean isCompletionOnNewCorrelationGroup() {
133        return processor.isCompletionOnNewCorrelationGroup();
134    }
135
136    @Override
137    public boolean isIgnoreInvalidCorrelationKeys() {
138        return processor.isIgnoreInvalidCorrelationKeys();
139    }
140
141    @Override
142    public Integer getCloseCorrelationKeyOnCompletion() {
143        return processor.getCloseCorrelationKeyOnCompletion();
144    }
145
146    @Override
147    public boolean isParallelProcessing() {
148        return processor.isParallelProcessing();
149    }
150
151    @Override
152    public boolean isOptimisticLocking() {
153        return processor.isOptimisticLocking();
154    }
155
156    @Override
157    public boolean isEagerCheckCompletion() {
158        return processor.isEagerCheckCompletion();
159    }
160
161    @Override
162    public String getCompletionPredicateLanguage() {
163        if (getDefinition().getCompletionPredicate() != null) {
164            return getDefinition().getCompletionPredicate().getExpressionType().getLanguage();
165        } else {
166            return null;
167        }
168    }
169
170    @Override
171    public String getCompletionPredicate() {
172        if (getDefinition().getCompletionPredicate() != null) {
173            return getDefinition().getCompletionPredicate().getExpressionType().getExpression();
174        } else {
175            return null;
176        }
177    }
178
179    @Override
180    public boolean isDiscardOnCompletionTimeout() {
181        return processor.isDiscardOnCompletionTimeout();
182    }
183
184    @Override
185    public boolean isForceCompletionOnStop() {
186        return processor.isCompletionFromBatchConsumer();
187    }
188
189    @Override
190    public boolean isCompleteAllOnStop() {
191        return processor.isCompleteAllOnStop();
192    }
193
194    @Override
195    public int getInProgressCompleteExchanges() {
196        return processor.getInProgressCompleteExchanges();
197    }
198
199    @Override
200    public int aggregationRepositoryGroups() {
201        Set<String> keys = processor.getAggregationRepository().getKeys();
202        if (keys != null) {
203            return keys.size();
204        } else {
205            return 0;
206        }
207    }
208
209    @Override
210    public int forceCompletionOfGroup(String key) {
211        if (processor.getAggregateController() != null) {
212            return processor.getAggregateController().forceCompletionOfGroup(key);
213        } else {
214            return 0;
215        }
216    }
217
218    @Override
219    public int forceCompletionOfAllGroups() {
220        if (processor.getAggregateController() != null) {
221            return processor.getAggregateController().forceCompletionOfAllGroups();
222        } else {
223            return 0;
224        }
225    }
226
227    @Override
228    public int forceDiscardingOfGroup(String key) {
229        if (processor.getAggregateController() != null) {
230            return processor.getAggregateController().forceDiscardingOfGroup(key);
231        } else {
232            return 0;
233        }
234    }
235
236    @Override
237    public int forceDiscardingOfAllGroups() {
238        if (processor.getAggregateController() != null) {
239            return processor.getAggregateController().forceDiscardingOfAllGroups();
240        } else {
241            return 0;
242        }
243    }
244
245    @Override
246    public int getClosedCorrelationKeysCacheSize() {
247        return processor.getClosedCorrelationKeysCacheSize();
248    }
249
250    @Override
251    public void clearClosedCorrelationKeysCache() {
252        processor.clearClosedCorrelationKeysCache();
253    }
254
255    @Override
256    public long getTotalIn() {
257        return processor.getStatistics().getTotalIn();
258    }
259
260    @Override
261    public long getTotalCompleted() {
262        return processor.getStatistics().getTotalCompleted();
263    }
264
265    @Override
266    public long getCompletedBySize() {
267        return processor.getStatistics().getCompletedBySize();
268    }
269
270    @Override
271    public long getCompletedByStrategy() {
272        return processor.getStatistics().getCompletedByStrategy();
273    }
274
275    @Override
276    public long getCompletedByInterval() {
277        return processor.getStatistics().getCompletedByInterval();
278    }
279
280    @Override
281    public long getCompletedByTimeout() {
282        return processor.getStatistics().getCompletedByTimeout();
283    }
284
285    @Override
286    public long getCompletedByPredicate() {
287        return processor.getStatistics().getCompletedByPredicate();
288    }
289
290    @Override
291    public long getCompletedByBatchConsumer() {
292        return processor.getStatistics().getCompletedByBatchConsumer();
293    }
294
295    @Override
296    public long getCompletedByForce() {
297        return processor.getStatistics().getCompletedByForce();
298    }
299
300    @Override
301    public long getDiscarded() {
302        return processor.getStatistics().getDiscarded();
303    }
304
305    @Override
306    public void resetStatistics() {
307        processor.getStatistics().reset();
308    }
309}