org.quattor.pan.cache
Class AbstractCache<T extends TaskResult>

java.lang.Object
  extended by org.quattor.pan.cache.AbstractCache<T>
Direct Known Subclasses:
BuildCache, CompileCache, Valid1Cache, Valid2Cache

public abstract class AbstractCache<T extends TaskResult>
extends java.lang.Object

A cache that maps a key, typically an object or template name, to an associated task. The task is one that compiles, builds, or validates the named entity. Any attempt to retrieve something from the cache will return with the associated task, creating a new task if one doesn't already exist. The client can wait on the task for the entity to become available.

Author:
loomis

Field Summary
protected  Compiler compiler
          Reference to the compiler associated with this cache.
 
Constructor Summary
protected AbstractCache(Compiler compiler, int size)
          Initializes the internal reference to the associated Compiler and creates a cache with the given initial size.
 
Method Summary
protected abstract  Task<T> createTask(java.lang.String key)
          Creates a new task to be put into the cache, if necessary.
protected abstract  TaskResult.ResultType getExecutorQueueType()
          Subclasses must return the executor queue type for the particular class.
 java.util.concurrent.Future<T> retrieve(java.lang.String key)
          Returns directly the Future associated with the key or null if an entry does not exist.
 java.util.concurrent.Future<T> retrieve(java.lang.String key, boolean executeInline)
          Returns a Future corresponding to the named object template; this will add a new entry if one does not yet exist for the given key.
 T waitForResult(java.lang.String key)
          A convenience method that will retrieve (or create) the task associated with the key, wait for a result to be ready, and process any thrown exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compiler

protected final Compiler compiler
Reference to the compiler associated with this cache.

Constructor Detail

AbstractCache

protected AbstractCache(Compiler compiler,
                        int size)
Initializes the internal reference to the associated Compiler and creates a cache with the given initial size.

Parameters:
compiler - Compiler related to this cache
size - number of initial entries
Method Detail

retrieve

public java.util.concurrent.Future<T> retrieve(java.lang.String key,
                                               boolean executeInline)
Returns a Future corresponding to the named object template; this will add a new entry if one does not yet exist for the given key.

Parameters:
key - key to use for the lookup, typically an object or template name
executeInline - If the client is going to wait for the task to complete, then it can indicate that the task can be run inline.
Returns:
Future that references the compiled template

waitForResult

public T waitForResult(java.lang.String key)
                                   throws java.lang.RuntimeException,
                                          ValidationException
A convenience method that will retrieve (or create) the task associated with the key, wait for a result to be ready, and process any thrown exceptions.

Parameters:
key - Key for the associated task, usually an object or template name
Returns:
T the result associated with the given key
Throws:
java.lang.RuntimeException
ValidationException

retrieve

public java.util.concurrent.Future<T> retrieve(java.lang.String key)
Returns directly the Future associated with the key or null if an entry does not exist. This method will not create a task for a non-existent entry. This method is primarily used for testing.

Parameters:
key - Key to use for the entity lookup.
Returns:
Future for the named template or null if it is not in the cache

createTask

protected abstract Task<T> createTask(java.lang.String key)
Creates a new task to be put into the cache, if necessary. Concrete implementations must supply a method that generates a task that will return the appropriate type.

Parameters:
key - Key used to generate the associated task.
Returns:
new task associated with the given key

getExecutorQueueType

protected abstract TaskResult.ResultType getExecutorQueueType()
Subclasses must return the executor queue type for the particular class.

Returns:
executor queue type to use for created tasks


Copyright © 2011 Quattor. All Rights Reserved.