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.ManagedStreamCachingStrategyMBean;
022import org.apache.camel.spi.StreamCachingStrategy;
023
024@ManagedResource(description = "Managed StreamCachingStrategy")
025public class ManagedStreamCachingStrategy extends ManagedService implements ManagedStreamCachingStrategyMBean {
026
027    private final CamelContext camelContext;
028    private final StreamCachingStrategy streamCachingStrategy;
029
030    public ManagedStreamCachingStrategy(CamelContext camelContext, StreamCachingStrategy streamCachingStrategy) {
031        super(camelContext, streamCachingStrategy);
032        this.camelContext = camelContext;
033        this.streamCachingStrategy = streamCachingStrategy;
034    }
035
036    public CamelContext getCamelContext() {
037        return camelContext;
038    }
039
040    public StreamCachingStrategy getStreamCachingStrategy() {
041        return streamCachingStrategy;
042    }
043
044    public boolean isEnabled() {
045        return streamCachingStrategy.isEnabled();
046    }
047
048    public String getSpoolDirectory() {
049        return streamCachingStrategy.getSpoolDirectory().getPath();
050    }
051
052    public String getSpoolChiper() {
053        return streamCachingStrategy.getSpoolChiper();
054    }
055
056    public void setSpoolThreshold(long threshold) {
057        streamCachingStrategy.setSpoolThreshold(threshold);
058    }
059
060    public long getSpoolThreshold() {
061        return streamCachingStrategy.getSpoolThreshold();
062    }
063
064    public void setSpoolUsedHeapMemoryThreshold(int percentage) {
065        streamCachingStrategy.setSpoolUsedHeapMemoryThreshold(percentage);
066    }
067
068    public int getSpoolUsedHeapMemoryThreshold() {
069        return streamCachingStrategy.getSpoolUsedHeapMemoryThreshold();
070    }
071
072    public void setSpoolUsedHeapMemoryLimit(SpoolUsedHeapMemoryLimit limit) {
073        StreamCachingStrategy.SpoolUsedHeapMemoryLimit l;
074        if (limit == null) {
075            l = null;
076        } else {
077            switch (limit) {
078            case Committed:
079                l = StreamCachingStrategy.SpoolUsedHeapMemoryLimit.Committed;
080                break;
081            case Max:
082                l = StreamCachingStrategy.SpoolUsedHeapMemoryLimit.Max;
083                break;
084            default:
085                throw new IllegalStateException();
086            }
087        }
088        streamCachingStrategy.setSpoolUsedHeapMemoryLimit(l);
089    }
090
091    public SpoolUsedHeapMemoryLimit getSpoolUsedHeapMemoryLimit() {
092        StreamCachingStrategy.SpoolUsedHeapMemoryLimit l = streamCachingStrategy.getSpoolUsedHeapMemoryLimit();
093        if (l == null) {
094            return null;
095        } else {
096            switch (l) {
097            case Committed:
098                return SpoolUsedHeapMemoryLimit.Committed;
099            case Max:
100                return SpoolUsedHeapMemoryLimit.Max;
101            default:
102                throw new IllegalStateException();
103            }
104        }
105    }
106
107    public void setBufferSize(int bufferSize) {
108        streamCachingStrategy.setBufferSize(bufferSize);
109    }
110
111    public int getBufferSize() {
112        return streamCachingStrategy.getBufferSize();
113    }
114
115    public void setRemoveSpoolDirectoryWhenStopping(boolean remove) {
116        streamCachingStrategy.setRemoveSpoolDirectoryWhenStopping(remove);
117    }
118
119    public boolean isRemoveSpoolDirectoryWhenStopping() {
120        return streamCachingStrategy.isRemoveSpoolDirectoryWhenStopping();
121    }
122
123    public void setAnySpoolRules(boolean any) {
124        streamCachingStrategy.setAnySpoolRules(any);
125    }
126
127    public boolean isAnySpoolRules() {
128        return streamCachingStrategy.isAnySpoolRules();
129    }
130
131    public long getCacheMemoryCounter() {
132        return streamCachingStrategy.getStatistics().getCacheMemoryCounter();
133    }
134
135    public long getCacheMemorySize() {
136        return streamCachingStrategy.getStatistics().getCacheMemorySize();
137    }
138
139    public long getCacheMemoryAverageSize() {
140        return streamCachingStrategy.getStatistics().getCacheMemoryAverageSize();
141    }
142
143    public long getCacheSpoolCounter() {
144        return streamCachingStrategy.getStatistics().getCacheSpoolCounter();
145    }
146
147    public long getCacheSpoolSize() {
148        return streamCachingStrategy.getStatistics().getCacheSpoolSize();
149    }
150
151    public long getCacheSpoolAverageSize() {
152        return streamCachingStrategy.getStatistics().getCacheSpoolAverageSize();
153    }
154
155    public boolean isStatisticsEnabled() {
156        return streamCachingStrategy.getStatistics().isStatisticsEnabled();
157    }
158
159    public void setStatisticsEnabled(boolean enabled) {
160        streamCachingStrategy.getStatistics().setStatisticsEnabled(enabled);
161    }
162
163    public void resetStatistics() {
164        streamCachingStrategy.getStatistics().reset();
165    }
166
167}