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 int getCompletionSize() {
094        return processor.getCompletionSize();
095    }
096
097    public String getCompletionSizeExpressionLanguage() {
098        if (getDefinition().getCompletionSizeExpression() != null) {
099            return getDefinition().getCompletionSizeExpression().getExpressionType().getLanguage();
100        } else {
101            return null;
102        }
103    }
104
105    public String getCompletionSizeExpression() {
106        if (getDefinition().getCompletionSizeExpression() != null) {
107            return getDefinition().getCompletionSizeExpression().getExpressionType().getExpression();
108        } else {
109            return null;
110        }
111    }
112
113    public boolean isCompletionFromBatchConsumer() {
114        return processor.isCompletionFromBatchConsumer();
115    }
116
117    public boolean isIgnoreInvalidCorrelationKeys() {
118        return processor.isIgnoreInvalidCorrelationKeys();
119    }
120
121    public Integer getCloseCorrelationKeyOnCompletion() {
122        return processor.getCloseCorrelationKeyOnCompletion();
123    }
124
125    public boolean isParallelProcessing() {
126        return processor.isParallelProcessing();
127    }
128
129    public boolean isOptimisticLocking() {
130        return processor.isOptimisticLocking();
131    }
132
133    public boolean isEagerCheckCompletion() {
134        return processor.isEagerCheckCompletion();
135    }
136
137    @Override
138    public String getCompletionPredicateLanguage() {
139        if (getDefinition().getCompletionPredicate() != null) {
140            return getDefinition().getCompletionPredicate().getExpressionType().getLanguage();
141        } else {
142            return null;
143        }
144    }
145
146    public String getCompletionPredicate() {
147        if (getDefinition().getCompletionPredicate() != null) {
148            return getDefinition().getCompletionPredicate().getExpressionType().getExpression();
149        } else {
150            return null;
151        }
152    }
153
154    public boolean isDiscardOnCompletionTimeout() {
155        return processor.isDiscardOnCompletionTimeout();
156    }
157
158    public boolean isForceCompletionOnStop() {
159        return processor.isCompletionFromBatchConsumer();
160    }
161
162    public boolean isCompleteAllOnStop() {
163        return processor.isCompleteAllOnStop();
164    }
165
166    public int getInProgressCompleteExchanges() {
167        return processor.getInProgressCompleteExchanges();
168    }
169
170    public int aggregationRepositoryGroups() {
171        Set<String> keys = processor.getAggregationRepository().getKeys();
172        if (keys != null) {
173            return keys.size();
174        } else {
175            return 0;
176        }
177    }
178
179    public int forceCompletionOfGroup(String key) {
180        if (processor.getAggregateController() != null) {
181            return processor.getAggregateController().forceCompletionOfGroup(key);
182        } else {
183            return 0;
184        }
185    }
186
187    public int forceCompletionOfAllGroups() {
188        if (processor.getAggregateController() != null) {
189            return processor.getAggregateController().forceCompletionOfAllGroups();
190        } else {
191            return 0;
192        }
193    }
194
195    public int getClosedCorrelationKeysCacheSize() {
196        return processor.getClosedCorrelationKeysCacheSize();
197    }
198
199    public void clearClosedCorrelationKeysCache() {
200        processor.clearClosedCorrelationKeysCache();
201    }
202
203    public long getTotalIn() {
204        return processor.getStatistics().getTotalIn();
205    }
206
207    public long getTotalCompleted() {
208        return processor.getStatistics().getTotalCompleted();
209    }
210
211    public long getCompletedBySize() {
212        return processor.getStatistics().getCompletedBySize();
213    }
214
215    public long getCompletedByStrategy() {
216        return processor.getStatistics().getCompletedByStrategy();
217    }
218
219    public long getCompletedByInterval() {
220        return processor.getStatistics().getCompletedByInterval();
221    }
222
223    public long getCompletedByTimeout() {
224        return processor.getStatistics().getCompletedByTimeout();
225    }
226
227    public long getCompletedByPredicate() {
228        return processor.getStatistics().getCompletedByPredicate();
229    }
230
231    public long getCompletedByBatchConsumer() {
232        return processor.getStatistics().getCompletedByBatchConsumer();
233    }
234
235    public long getCompletedByForce() {
236        return processor.getStatistics().getCompletedByForce();
237    }
238
239    public void resetStatistics() {
240        processor.getStatistics().reset();
241    }
242}