org.carrot2.core
Class ControllerFactory

java.lang.Object
  extended by org.carrot2.core.ControllerFactory

public final class ControllerFactory
extends Object

Creates Controllers in a number of common configurations. The most useful configurations are:


Method Summary
static Controller create(boolean componentPooling, Class<? extends IProcessingComponent>... cachedProcessingComponents)
          Creates a controller with the specified pooling and caching settings.
static Controller create(int instancePoolSize, Class<? extends IProcessingComponent>... cachedProcessingComponents)
          Creates a controller with the specified fixed-size pooling and caching settings.
static Controller createCaching(Class<? extends IProcessingComponent>... cachedProcessingComponents)
          Creates a controller with no processing component pooling but with results caching.
static Controller createCachingPooling(Class<? extends IProcessingComponent>... cachedProcessingComponents)
          Creates a controller with processing component pooling and results caching.
static Controller createPooling()
          Creates a controller with processing component pooling but with no results caching.
static Controller createPooling(int instancePoolSize)
          Creates a controller with processing component pooling but with no results caching.
static Controller createSimple()
          Creates a controller with no processing component pooling and no results caching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createSimple

public static Controller createSimple()
Creates a controller with no processing component pooling and no results caching. The returned controller will instantiate new processing component instances for each processing request and will not perform any caching of the processing results.

This controller is useful for one-time processing or fast experiments with the code. For long-running applications (e.g. web applications), consider using a controller with component pooling and/or caching.

See Also:
createPooling(), createCaching(Class...), create(boolean, Class...)

createPooling

public static Controller createPooling()
Creates a controller with processing component pooling but with no results caching. The returned controller will maintain an internal pool of processing components, so that they are reused between processing requests. Soft references are used to cache component instances. There is no upper bound on the number of instances the pool may cache.

Use this controller in long-running applications and when your processing components are expensive to create. For applications that handle large numbers of repeated requests, consider using a caching and pooling controller.

See Also:
create(boolean, Class...), createPooling(int)

createPooling

public static Controller createPooling(int instancePoolSize)
Creates a controller with processing component pooling but with no results caching. The returned controller will maintain an internal fixed-size, hard-referenced pool of processing components, so that they are reused between processing requests.

Use this controller in long-running applications and when your processing components are expensive to create. For applications that handle large numbers of repeated requests, consider using a caching and pooling controller.

Parameters:
instancePoolSize - Number of instances created for a single component class-ID pair. For computational components it is sensible to set this pool to the number of CPU cores available on the machine.
See Also:
create(int, Class...), createPooling(), Runtime.availableProcessors()

createCaching

public static Controller createCaching(Class<? extends IProcessingComponent>... cachedProcessingComponents)
Creates a controller with no processing component pooling but with results caching. The returned controller will maintain a cache of the processing results. For each component whose results are to be cached, if there comes a repeated request for processing with that component with the same set of input attributes, the result will be returned from the cache. The returned controller will instantiate new processing components object for each processing request whose result has not yet been cached.

Uses of this specific controller are rather limited. Use it if your application is handling large numbers of repeated requests but you don't want to have the components pooled for some reason. Make sure the processing components are cheap to create, otherwise performance will suffer.

Parameters:
cachedProcessingComponents - classes of components whose output should be cached by the controller. If a superclass is provided here, e.g. IDocumentSource, all its subclasses will be subject to caching. If IProcessingComponent is provided here, output of all components will be cached.

createCachingPooling

public static Controller createCachingPooling(Class<? extends IProcessingComponent>... cachedProcessingComponents)
Creates a controller with processing component pooling and results caching. The returned controller combines processing component pooling and processing results caching.

Use this component in long-running applications that handle repeated requests.

Parameters:
cachedProcessingComponents - classes of components whose output should be cached by the controller. If a superclass is provided here, e.g. IDocumentSource, all its subclasses will be subject to caching. If IProcessingComponent is provided here, output of all components will be cached.

create

public static Controller create(boolean componentPooling,
                                Class<? extends IProcessingComponent>... cachedProcessingComponents)
Creates a controller with the specified pooling and caching settings.

Parameters:
componentPooling - if true, component pooling will be performed (soft pool), otherwise no component pool will be used.
cachedProcessingComponents - classes of components whose output should be cached by the controller. If a superclass is provided here, e.g. IDocumentSource, all its subclasses will be subject to caching. If IProcessingComponent is provided here, output of all components will be cached.

create

public static Controller create(int instancePoolSize,
                                Class<? extends IProcessingComponent>... cachedProcessingComponents)
Creates a controller with the specified fixed-size pooling and caching settings.

Parameters:
instancePoolSize - Number of instances created for a single component class-ID pair. For computational components it is sensible to set this pool to the number of CPU cores available on the machine.
cachedProcessingComponents - classes of components whose output should be cached by the controller. If a superclass is provided here, e.g. IDocumentSource, all its subclasses will be subject to caching. If IProcessingComponent is provided here, output of all components will be cached.


Copyright (c) Dawid Weiss, Stanislaw Osinski