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    public void init(ManagementStrategy strategy) {
038        super.init(strategy);
039    }
040
041    public AggregateProcessor getProcessor() {
042        return processor;
043    }
044
045    @Override
046    public AggregateDefinition getDefinition() {
047        return (AggregateDefinition) super.getDefinition();
048    }
049
050    public String getCorrelationExpressionLanguage() {
051        if (getDefinition().getCorrelationExpression() != null) {
052            return getDefinition().getCorrelationExpression().getExpressionType().getLanguage();
053        } else {
054            return null;
055        }
056    }
057
058    public String getCorrelationExpression() {
059        if (getDefinition().getCorrelationExpression() != null) {
060            return getDefinition().getCorrelationExpression().getExpressionType().getExpression();
061        } else {
062            return null;
063        }
064    }
065
066    public long getCompletionTimeout() {
067        return processor.getCompletionTimeout();
068    }
069
070    public String getCompletionTimeoutLanguage() {
071        if (getDefinition().getCompletionTimeoutExpression() != null) {
072            return getDefinition().getCompletionTimeoutExpression().getExpressionType().getLanguage();
073        } else {
074            return null;
075        }
076    }
077
078    public String getCompletionTimeoutExpression() {
079        if (getDefinition().getCompletionTimeoutExpression() != null) {
080            return getDefinition().getCompletionTimeoutExpression().getExpressionType().getExpression();
081        } else {
082            return null;
083        }
084    }
085
086    public long getCompletionInterval() {
087        return processor.getCompletionInterval();
088    }
089
090    public long getCompletionTimeoutCheckerInterval() {
091        return processor.getCompletionTimeoutCheckerInterval();
092    }
093
094    public int getCompletionSize() {
095        return processor.getCompletionSize();
096    }
097
098    public String getCompletionSizeExpressionLanguage() {
099        if (getDefinition().getCompletionSizeExpression() != null) {
100            return getDefinition().getCompletionSizeExpression().getExpressionType().getLanguage();
101        } else {
102            return null;
103        }
104    }
105
106    public String getCompletionSizeExpression() {
107        if (getDefinition().getCompletionSizeExpression() != null) {
108            return getDefinition().getCompletionSizeExpression().getExpressionType().getExpression();
109        } else {
110            return null;
111        }
112    }
113
114    public boolean isCompletionFromBatchConsumer() {
115        return processor.isCompletionFromBatchConsumer();
116    }
117
118    public boolean isCompletionOnNewCorrelationGroup() {
119        return processor.isCompletionOnNewCorrelationGroup();
120    }
121
122    public boolean isIgnoreInvalidCorrelationKeys() {
123        return processor.isIgnoreInvalidCorrelationKeys();
124    }
125
126    public Integer getCloseCorrelationKeyOnCompletion() {
127        return processor.getCloseCorrelationKeyOnCompletion();
128    }
129
130    public boolean isParallelProcessing() {
131        return processor.isParallelProcessing();
132    }
133
134    public boolean isOptimisticLocking() {
135        return processor.isOptimisticLocking();
136    }
137
138    public boolean isEagerCheckCompletion() {
139        return processor.isEagerCheckCompletion();
140    }
141
142    @Override
143    public String getCompletionPredicateLanguage() {
144        if (getDefinition().getCompletionPredicate() != null) {
145            return getDefinition().getCompletionPredicate().getExpressionType().getLanguage();
146        } else {
147            return null;
148        }
149    }
150
151    public String getCompletionPredicate() {
152        if (getDefinition().getCompletionPredicate() != null) {
153            return getDefinition().getCompletionPredicate().getExpressionType().getExpression();
154        } else {
155            return null;
156        }
157    }
158
159    public boolean isDiscardOnCompletionTimeout() {
160        return processor.isDiscardOnCompletionTimeout();
161    }
162
163    public boolean isForceCompletionOnStop() {
164        return processor.isCompletionFromBatchConsumer();
165    }
166
167    public boolean isCompleteAllOnStop() {
168        return processor.isCompleteAllOnStop();
169    }
170
171    public int getInProgressCompleteExchanges() {
172        return processor.getInProgressCompleteExchanges();
173    }
174
175    public int aggregationRepositoryGroups() {
176        Set<String> keys = processor.getAggregationRepository().getKeys();
177        if (keys != null) {
178            return keys.size();
179        } else {
180            return 0;
181        }
182    }
183
184    public int forceCompletionOfGroup(String key) {
185        if (processor.getAggregateController() != null) {
186            return processor.getAggregateController().forceCompletionOfGroup(key);
187        } else {
188            return 0;
189        }
190    }
191
192    public int forceCompletionOfAllGroups() {
193        if (processor.getAggregateController() != null) {
194            return processor.getAggregateController().forceCompletionOfAllGroups();
195        } else {
196            return 0;
197        }
198    }
199
200    public int getClosedCorrelationKeysCacheSize() {
201        return processor.getClosedCorrelationKeysCacheSize();
202    }
203
204    public void clearClosedCorrelationKeysCache() {
205        processor.clearClosedCorrelationKeysCache();
206    }
207
208    public long getTotalIn() {
209        return processor.getStatistics().getTotalIn();
210    }
211
212    public long getTotalCompleted() {
213        return processor.getStatistics().getTotalCompleted();
214    }
215
216    public long getCompletedBySize() {
217        return processor.getStatistics().getCompletedBySize();
218    }
219
220    public long getCompletedByStrategy() {
221        return processor.getStatistics().getCompletedByStrategy();
222    }
223
224    public long getCompletedByInterval() {
225        return processor.getStatistics().getCompletedByInterval();
226    }
227
228    public long getCompletedByTimeout() {
229        return processor.getStatistics().getCompletedByTimeout();
230    }
231
232    public long getCompletedByPredicate() {
233        return processor.getStatistics().getCompletedByPredicate();
234    }
235
236    public long getCompletedByBatchConsumer() {
237        return processor.getStatistics().getCompletedByBatchConsumer();
238    }
239
240    public long getCompletedByForce() {
241        return processor.getStatistics().getCompletedByForce();
242    }
243
244    public void resetStatistics() {
245        processor.getStatistics().reset();
246    }
247}