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