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 org.apache.camel.CamelContext;
020import org.apache.camel.api.management.ManagedResource;
021import org.apache.camel.api.management.mbean.ManagedResequencerMBean;
022import org.apache.camel.model.ProcessorDefinition;
023import org.apache.camel.processor.Resequencer;
024import org.apache.camel.processor.StreamResequencer;
025
026/**
027 * @version 
028 */
029@ManagedResource(description = "Managed Resequencer")
030public class ManagedResequencer extends ManagedProcessor implements ManagedResequencerMBean {
031    private final Resequencer processor;
032    private final StreamResequencer streamProcessor;
033    private final String expression;
034
035    public ManagedResequencer(CamelContext context, Resequencer processor, ProcessorDefinition<?> definition) {
036        super(context, processor, definition);
037        this.processor = processor;
038        this.streamProcessor = null;
039        this.expression = processor.getExpression().toString();
040    }
041
042    public ManagedResequencer(CamelContext context, StreamResequencer processor, ProcessorDefinition<?> definition) {
043        super(context, processor, definition);
044        this.processor = null;
045        this.streamProcessor = processor;
046        this.expression = streamProcessor.getExpression().toString();
047    }
048
049    @Override
050    public String getExpression() {
051        return expression;
052    }
053
054    @Override
055    public Integer getBatchSize() {
056        if (processor != null) {
057            return processor.getBatchSize();
058        } else {
059            return null;
060        }
061    }
062
063    @Override
064    public Long getTimeout() {
065        if (processor != null) {
066            return processor.getBatchTimeout();
067        } else {
068            return streamProcessor.getTimeout();
069        }
070    }
071
072    @Override
073    public Boolean isAllowDuplicates() {
074        if (processor != null) {
075            return processor.isAllowDuplicates();
076        } else {
077            return null;
078        }
079    }
080
081    @Override
082    public Boolean isReverse() {
083        if (processor != null) {
084            return processor.isReverse();
085        } else {
086            return null;
087        }
088    }
089
090    @Override
091    public Boolean isIgnoreInvalidExchanges() {
092        if (processor != null) {
093            return processor.isIgnoreInvalidExchanges();
094        } else {
095            return streamProcessor.isIgnoreInvalidExchanges();
096        }
097    }
098
099    @Override
100    public Integer getCapacity() {
101        if (processor != null) {
102            return null;
103        } else {
104            return streamProcessor.getCapacity();
105        }
106    }
107
108    @Override
109    public Boolean isRejectOld() {
110        if (processor != null) {
111            return null;
112        } else {
113            return streamProcessor.isRejectOld();
114        }
115    }
116}