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