org.apache.camel.impl
Class DefaultStreamCachingStrategy

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.DefaultStreamCachingStrategy
All Implemented Interfaces:
CamelContextAware, Service, ShutdownableService, StreamCachingStrategy, StatefulService, StaticService, SuspendableService

public class DefaultStreamCachingStrategy
extends ServiceSupport
implements CamelContextAware, StreamCachingStrategy

Default implementation of StreamCachingStrategy


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.camel.spi.StreamCachingStrategy
StreamCachingStrategy.SpoolRule, StreamCachingStrategy.SpoolUsedHeapMemoryLimit, StreamCachingStrategy.Statistics
 
Field Summary
static String BUFFER_SIZE
          Deprecated. 
static String CIPHER_TRANSFORMATION
          Deprecated. 
static String TEMP_DIR
          Deprecated. 
static String THRESHOLD
          Deprecated. 
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
DefaultStreamCachingStrategy()
           
 
Method Summary
 void addSpoolRule(StreamCachingStrategy.SpoolRule rule)
          Adds the StreamCachingStrategy.SpoolRule rule to be used.
 StreamCache cache(Exchange exchange)
          Caches the body aas a StreamCache.
protected  String customResolveManagementName(String pattern)
           
protected  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
 int getBufferSize()
           
 CamelContext getCamelContext()
          Get the CamelContext
 String getSpoolChiper()
           
 File getSpoolDirectory()
           
 long getSpoolThreshold()
           
 StreamCachingStrategy.SpoolUsedHeapMemoryLimit getSpoolUsedHeapMemoryLimit()
           
 int getSpoolUsedHeapMemoryThreshold()
           
 StreamCachingStrategy.Statistics getStatistics()
          Gets the utilization statistics.
 boolean isAnySpoolRules()
           
 boolean isEnabled()
           
 boolean isRemoveSpoolDirectoryWhenStopping()
           
protected  String resolveSpoolDirectory(String path)
           
 void setAnySpoolRules(boolean anySpoolTasks)
          Sets whether if just any of the StreamCachingStrategy.SpoolRule rules returns true then StreamCachingStrategy.shouldSpoolCache(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 setCamelContext(CamelContext camelContext)
          Injects the CamelContext
 void setEnabled(boolean enabled)
          Sets whether the stream caching is enabled.
 void setRemoveSpoolDirectoryWhenStopping(boolean removeSpoolDirectoryWhenStopping)
          Whether to remove the temporary directory when stopping.
 void setSpoolChiper(String spoolChiper)
          Sets a chiper 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 spoolThreshold)
          Threshold in bytes when overflow to disk is activated.
 void setSpoolUsedHeapMemoryLimit(StreamCachingStrategy.SpoolUsedHeapMemoryLimit spoolUsedHeapMemoryLimit)
          Sets what the upper bounds should be when StreamCachingStrategy.setSpoolUsedHeapMemoryThreshold(int) is in use.
 void setSpoolUsedHeapMemoryThreshold(int spoolHeapMemoryWatermarkThreshold)
          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.
 String toString()
           
 
Methods inherited from class org.apache.camel.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, resume, shutdown, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Field Detail

THRESHOLD

@Deprecated
public static final String THRESHOLD
Deprecated. 
See Also:
Constant Field Values

BUFFER_SIZE

@Deprecated
public static final String BUFFER_SIZE
Deprecated. 
See Also:
Constant Field Values

TEMP_DIR

@Deprecated
public static final String TEMP_DIR
Deprecated. 
See Also:
Constant Field Values

CIPHER_TRANSFORMATION

@Deprecated
public static final String CIPHER_TRANSFORMATION
Deprecated. 
See Also:
Constant Field Values
Constructor Detail

DefaultStreamCachingStrategy

public DefaultStreamCachingStrategy()
Method Detail

getCamelContext

public CamelContext getCamelContext()
Description copied from interface: CamelContextAware
Get the CamelContext

Specified by:
getCamelContext in interface CamelContextAware
Returns:
camelContext the Camel context

setCamelContext

public void setCamelContext(CamelContext camelContext)
Description copied from interface: CamelContextAware
Injects the CamelContext

Specified by:
setCamelContext in interface CamelContextAware
Parameters:
camelContext - the Camel context

isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface StreamCachingStrategy

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: StreamCachingStrategy
Sets whether the stream caching is enabled.

Notice: This cannot be changed at runtime.

Specified by:
setEnabled in interface StreamCachingStrategy

setSpoolDirectory

public void setSpoolDirectory(String path)
Specified by:
setSpoolDirectory in interface StreamCachingStrategy

setSpoolDirectory

public void setSpoolDirectory(File path)
Description copied from interface: StreamCachingStrategy
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.

Specified by:
setSpoolDirectory in interface StreamCachingStrategy

getSpoolDirectory

public File getSpoolDirectory()
Specified by:
getSpoolDirectory in interface StreamCachingStrategy

getSpoolThreshold

public long getSpoolThreshold()
Specified by:
getSpoolThreshold in interface StreamCachingStrategy

getSpoolUsedHeapMemoryThreshold

public int getSpoolUsedHeapMemoryThreshold()
Specified by:
getSpoolUsedHeapMemoryThreshold in interface StreamCachingStrategy

setSpoolUsedHeapMemoryThreshold

public void setSpoolUsedHeapMemoryThreshold(int spoolHeapMemoryWatermarkThreshold)
Description copied from interface: StreamCachingStrategy
Sets a percentage (1-99) of used heap memory threshold to activate spooling to disk.

Specified by:
setSpoolUsedHeapMemoryThreshold in interface StreamCachingStrategy
Parameters:
spoolHeapMemoryWatermarkThreshold - percentage of used heap memory.

getSpoolUsedHeapMemoryLimit

public StreamCachingStrategy.SpoolUsedHeapMemoryLimit getSpoolUsedHeapMemoryLimit()
Specified by:
getSpoolUsedHeapMemoryLimit in interface StreamCachingStrategy

setSpoolUsedHeapMemoryLimit

public void setSpoolUsedHeapMemoryLimit(StreamCachingStrategy.SpoolUsedHeapMemoryLimit spoolUsedHeapMemoryLimit)
Description copied from interface: StreamCachingStrategy
Sets what the upper bounds should be when StreamCachingStrategy.setSpoolUsedHeapMemoryThreshold(int) is in use.

Specified by:
setSpoolUsedHeapMemoryLimit in interface StreamCachingStrategy
Parameters:
spoolUsedHeapMemoryLimit - the bounds

setSpoolThreshold

public void setSpoolThreshold(long spoolThreshold)
Description copied from interface: StreamCachingStrategy
Threshold in bytes when overflow to disk is activated.

The default threshold is StreamCache.DEFAULT_SPOOL_THRESHOLD bytes (eg 128kb). Use -1 to disable overflow to disk.

Specified by:
setSpoolThreshold in interface StreamCachingStrategy

getSpoolChiper

public String getSpoolChiper()
Specified by:
getSpoolChiper in interface StreamCachingStrategy

setSpoolChiper

public void setSpoolChiper(String spoolChiper)
Description copied from interface: StreamCachingStrategy
Sets a chiper name to use when spooling to disk to write with encryption.

By default the data is not encrypted.

Specified by:
setSpoolChiper in interface StreamCachingStrategy

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface StreamCachingStrategy

setBufferSize

public void setBufferSize(int bufferSize)
Description copied from interface: StreamCachingStrategy
Sets the buffer size to use when allocating in-memory buffers used for in-memory stream caches.

The default size is IOHelper.DEFAULT_BUFFER_SIZE

Specified by:
setBufferSize in interface StreamCachingStrategy

isRemoveSpoolDirectoryWhenStopping

public boolean isRemoveSpoolDirectoryWhenStopping()
Specified by:
isRemoveSpoolDirectoryWhenStopping in interface StreamCachingStrategy

setRemoveSpoolDirectoryWhenStopping

public void setRemoveSpoolDirectoryWhenStopping(boolean removeSpoolDirectoryWhenStopping)
Description copied from interface: StreamCachingStrategy
Whether to remove the temporary directory when stopping.

This option is default true

Specified by:
setRemoveSpoolDirectoryWhenStopping in interface StreamCachingStrategy

isAnySpoolRules

public boolean isAnySpoolRules()
Specified by:
isAnySpoolRules in interface StreamCachingStrategy

setAnySpoolRules

public void setAnySpoolRules(boolean anySpoolTasks)
Description copied from interface: StreamCachingStrategy
Sets whether if just any of the StreamCachingStrategy.SpoolRule rules returns true then StreamCachingStrategy.shouldSpoolCache(long) returns true. If this option is false, then all the StreamCachingStrategy.SpoolRule must return true.

The default value is false which means that all the rules must return true.

Specified by:
setAnySpoolRules in interface StreamCachingStrategy

getStatistics

public StreamCachingStrategy.Statistics getStatistics()
Description copied from interface: StreamCachingStrategy
Gets the utilization statistics.

Specified by:
getStatistics in interface StreamCachingStrategy

shouldSpoolCache

public boolean shouldSpoolCache(long length)
Description copied from interface: StreamCachingStrategy
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.

Specified by:
shouldSpoolCache in interface StreamCachingStrategy
Parameters:
length - the length of the stream
Returns:
true to spool the cache, or false to keep the cache in-memory

addSpoolRule

public void addSpoolRule(StreamCachingStrategy.SpoolRule rule)
Description copied from interface: StreamCachingStrategy
Adds the StreamCachingStrategy.SpoolRule rule to be used.

Specified by:
addSpoolRule in interface StreamCachingStrategy

cache

public StreamCache cache(Exchange exchange)
Description copied from interface: StreamCachingStrategy
Caches the body aas a StreamCache.

Specified by:
cache in interface StreamCachingStrategy
Parameters:
exchange - the exchange
Returns:
the body cached as a StreamCache, or null if not possible or no need to cache the body

resolveSpoolDirectory

protected String resolveSpoolDirectory(String path)

customResolveManagementName

protected String customResolveManagementName(String pattern)

doStart

protected void doStart()
                throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Specified by:
doStart in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Specified by:
doStop in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStart()

toString

public String toString()
Overrides:
toString in class Object


Apache Camel