Package org.apache.camel.spi
Interface StreamCachingStrategy
-
- All Superinterfaces:
AutoCloseable
,Service
,StaticService
public interface StreamCachingStrategy extends StaticService
Strategy for using stream caching.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
StreamCachingStrategy.SpoolRule
Rule for determine if stream caching should be spooled to disk or kept in-memory.static class
StreamCachingStrategy.SpoolUsedHeapMemoryLimit
Used for selecting if the memory limit is committed or maximum heap memory setting.static interface
StreamCachingStrategy.Statistics
Utilization statistics of stream caching.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addSpoolRule(StreamCachingStrategy.SpoolRule rule)
Adds theStreamCachingStrategy.SpoolRule
rule to be used.StreamCache
cache(Exchange exchange)
Caches the body aas aStreamCache
.int
getBufferSize()
String
getSpoolCipher()
File
getSpoolDirectory()
long
getSpoolThreshold()
StreamCachingStrategy.SpoolUsedHeapMemoryLimit
getSpoolUsedHeapMemoryLimit()
int
getSpoolUsedHeapMemoryThreshold()
StreamCachingStrategy.Statistics
getStatistics()
Gets the utilization statistics.boolean
isAnySpoolRules()
boolean
isEnabled()
boolean
isRemoveSpoolDirectoryWhenStopping()
void
setAnySpoolRules(boolean any)
Sets whether if just any of theStreamCachingStrategy.SpoolRule
rules returns true thenshouldSpoolCache(long)
returns true.void
setBufferSize(int bufferSize)
Sets the buffer size to use when allocating in-memory buffers used for in-memory stream caches.void
setEnabled(boolean enabled)
Sets whether the stream caching is enabled.void
setRemoveSpoolDirectoryWhenStopping(boolean remove)
Whether to remove the temporary directory when stopping.void
setSpoolCipher(String cipher)
Sets a cipher name to use when spooling to disk to write with encryption.void
setSpoolDirectory(File path)
Sets the spool (temporary) directory to use for overflow and spooling to disk.void
setSpoolDirectory(String path)
void
setSpoolThreshold(long threshold)
Threshold in bytes when overflow to disk is activated.void
setSpoolUsedHeapMemoryLimit(StreamCachingStrategy.SpoolUsedHeapMemoryLimit bounds)
Sets what the upper bounds should be whensetSpoolUsedHeapMemoryThreshold(int)
is in use.void
setSpoolUsedHeapMemoryThreshold(int percentage)
Sets a percentage (1-99) of used heap memory threshold to activate spooling to disk.boolean
shouldSpoolCache(long length)
Determines if the stream should be spooled or not.
-
-
-
Method Detail
-
setEnabled
void setEnabled(boolean enabled)
Sets whether the stream caching is enabled. Notice: This cannot be changed at runtime.
-
isEnabled
boolean isEnabled()
-
setSpoolDirectory
void setSpoolDirectory(File path)
Sets the spool (temporary) directory to use for overflow and spooling to disk. If no spool directory has been explicit configured, then a temporary directory is created in the java.io.tmpdir directory.
-
getSpoolDirectory
File getSpoolDirectory()
-
setSpoolDirectory
void setSpoolDirectory(String path)
-
setSpoolThreshold
void setSpoolThreshold(long threshold)
Threshold in bytes when overflow to disk is activated. The default threshold isStreamCache.DEFAULT_SPOOL_THRESHOLD
bytes (eg 128kb). Use -1 to disable overflow to disk.
-
getSpoolThreshold
long getSpoolThreshold()
-
setSpoolUsedHeapMemoryThreshold
void setSpoolUsedHeapMemoryThreshold(int percentage)
Sets a percentage (1-99) of used heap memory threshold to activate spooling to disk.- Parameters:
percentage
- percentage of used heap memory.
-
getSpoolUsedHeapMemoryThreshold
int getSpoolUsedHeapMemoryThreshold()
-
setSpoolUsedHeapMemoryLimit
void setSpoolUsedHeapMemoryLimit(StreamCachingStrategy.SpoolUsedHeapMemoryLimit bounds)
Sets what the upper bounds should be whensetSpoolUsedHeapMemoryThreshold(int)
is in use.- Parameters:
bounds
- the bounds
-
getSpoolUsedHeapMemoryLimit
StreamCachingStrategy.SpoolUsedHeapMemoryLimit getSpoolUsedHeapMemoryLimit()
-
setBufferSize
void setBufferSize(int bufferSize)
Sets the buffer size to use when allocating in-memory buffers used for in-memory stream caches. The default size isIOHelper.DEFAULT_BUFFER_SIZE
-
getBufferSize
int getBufferSize()
-
setSpoolCipher
void setSpoolCipher(String cipher)
Sets a cipher name to use when spooling to disk to write with encryption. By default the data is not encrypted.
-
getSpoolCipher
String getSpoolCipher()
-
setRemoveSpoolDirectoryWhenStopping
void setRemoveSpoolDirectoryWhenStopping(boolean remove)
Whether to remove the temporary directory when stopping. This option is default true
-
isRemoveSpoolDirectoryWhenStopping
boolean isRemoveSpoolDirectoryWhenStopping()
-
setAnySpoolRules
void setAnySpoolRules(boolean any)
Sets whether if just any of theStreamCachingStrategy.SpoolRule
rules returns true thenshouldSpoolCache(long)
returns true. If this option is false, then all theStreamCachingStrategy.SpoolRule
must return true. The default value is false which means that all the rules must return true.
-
isAnySpoolRules
boolean isAnySpoolRules()
-
getStatistics
StreamCachingStrategy.Statistics getStatistics()
Gets the utilization statistics.
-
addSpoolRule
void addSpoolRule(StreamCachingStrategy.SpoolRule rule)
Adds theStreamCachingStrategy.SpoolRule
rule to be used.
-
shouldSpoolCache
boolean shouldSpoolCache(long length)
Determines if the stream should be spooled or not. For example if the stream length is over a threshold. This allows implementations to use custom strategies to determine if spooling is needed or not.- Parameters:
length
- the length of the stream- Returns:
- true to spool the cache, or false to keep the cache in-memory
-
cache
StreamCache cache(Exchange exchange)
Caches the body aas aStreamCache
.- Parameters:
exchange
- the exchange- Returns:
- the body cached as a
StreamCache
, or null if not possible or no need to cache the body
-
-