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 @Override 045 public boolean isEnabled() { 046 return streamCachingStrategy.isEnabled(); 047 } 048 049 @Override 050 public boolean isSpoolEnabled() { 051 return streamCachingStrategy.isSpoolEnabled(); 052 } 053 054 @Override 055 public String getSpoolDirectory() { 056 if (streamCachingStrategy.getSpoolDirectory() != null) { 057 return streamCachingStrategy.getSpoolDirectory().getPath(); 058 } else { 059 return null; 060 } 061 } 062 063 @Override 064 public String getSpoolCipher() { 065 return streamCachingStrategy.getSpoolCipher(); 066 } 067 068 @Override 069 public void setSpoolThreshold(long threshold) { 070 streamCachingStrategy.setSpoolThreshold(threshold); 071 } 072 073 @Override 074 public long getSpoolThreshold() { 075 return streamCachingStrategy.getSpoolThreshold(); 076 } 077 078 @Override 079 public void setSpoolUsedHeapMemoryThreshold(int percentage) { 080 streamCachingStrategy.setSpoolUsedHeapMemoryThreshold(percentage); 081 } 082 083 @Override 084 public int getSpoolUsedHeapMemoryThreshold() { 085 return streamCachingStrategy.getSpoolUsedHeapMemoryThreshold(); 086 } 087 088 @Override 089 public void setSpoolUsedHeapMemoryLimit(SpoolUsedHeapMemoryLimit limit) { 090 StreamCachingStrategy.SpoolUsedHeapMemoryLimit l; 091 if (limit == null) { 092 l = null; 093 } else { 094 switch (limit) { 095 case Committed: 096 l = StreamCachingStrategy.SpoolUsedHeapMemoryLimit.Committed; 097 break; 098 case Max: 099 l = StreamCachingStrategy.SpoolUsedHeapMemoryLimit.Max; 100 break; 101 default: 102 throw new IllegalStateException(); 103 } 104 } 105 streamCachingStrategy.setSpoolUsedHeapMemoryLimit(l); 106 } 107 108 @Override 109 public SpoolUsedHeapMemoryLimit getSpoolUsedHeapMemoryLimit() { 110 StreamCachingStrategy.SpoolUsedHeapMemoryLimit l = streamCachingStrategy.getSpoolUsedHeapMemoryLimit(); 111 if (l == null) { 112 return null; 113 } else { 114 switch (l) { 115 case Committed: 116 return SpoolUsedHeapMemoryLimit.Committed; 117 case Max: 118 return SpoolUsedHeapMemoryLimit.Max; 119 default: 120 throw new IllegalStateException(); 121 } 122 } 123 } 124 125 @Override 126 public void setBufferSize(int bufferSize) { 127 streamCachingStrategy.setBufferSize(bufferSize); 128 } 129 130 @Override 131 public int getBufferSize() { 132 return streamCachingStrategy.getBufferSize(); 133 } 134 135 @Override 136 public void setRemoveSpoolDirectoryWhenStopping(boolean remove) { 137 streamCachingStrategy.setRemoveSpoolDirectoryWhenStopping(remove); 138 } 139 140 @Override 141 public boolean isRemoveSpoolDirectoryWhenStopping() { 142 return streamCachingStrategy.isRemoveSpoolDirectoryWhenStopping(); 143 } 144 145 @Override 146 public void setAnySpoolRules(boolean any) { 147 streamCachingStrategy.setAnySpoolRules(any); 148 } 149 150 @Override 151 public boolean isAnySpoolRules() { 152 return streamCachingStrategy.isAnySpoolRules(); 153 } 154 155 @Override 156 public long getCacheMemoryCounter() { 157 return streamCachingStrategy.getStatistics().getCacheMemoryCounter(); 158 } 159 160 @Override 161 public long getCacheMemorySize() { 162 return streamCachingStrategy.getStatistics().getCacheMemorySize(); 163 } 164 165 @Override 166 public long getCacheMemoryAverageSize() { 167 return streamCachingStrategy.getStatistics().getCacheMemoryAverageSize(); 168 } 169 170 @Override 171 public long getCacheSpoolCounter() { 172 return streamCachingStrategy.getStatistics().getCacheSpoolCounter(); 173 } 174 175 @Override 176 public long getCacheSpoolSize() { 177 return streamCachingStrategy.getStatistics().getCacheSpoolSize(); 178 } 179 180 @Override 181 public long getCacheSpoolAverageSize() { 182 return streamCachingStrategy.getStatistics().getCacheSpoolAverageSize(); 183 } 184 185 @Override 186 public boolean isStatisticsEnabled() { 187 return streamCachingStrategy.getStatistics().isStatisticsEnabled(); 188 } 189 190 @Override 191 public void setStatisticsEnabled(boolean enabled) { 192 streamCachingStrategy.getStatistics().setStatisticsEnabled(enabled); 193 } 194 195 @Override 196 public void resetStatistics() { 197 streamCachingStrategy.getStatistics().reset(); 198 } 199 200}