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