org.rhq.core.domain.resource.flyweight
Class FlyweightCache

java.lang.Object
  extended by org.rhq.core.domain.resource.flyweight.FlyweightCache

public class FlyweightCache
extends Object

A helper object to hold the cached instances of the flyweights. The keys in the maps are ids, values are the objects themselves.

The construct* methods are provided to correctly initialize instances of the flyweight types in the cache instance from a minimal set of data.


Constructor Summary
FlyweightCache()
           
 
Method Summary
 ResourceFlyweight constructResource(int id, String name, String uuid, String resourceKey, Integer parentId, int typeId, AvailabilityType currentAvailability)
          Constructs a fully initialized instance of the resource flyweight.
 ResourceFlyweight constructResource(Resource original)
           
 ResourceTypeFlyweight constructResourceType(int id, String name, String plugin, boolean singleton, ResourceCategory category, Integer subCategory)
          Constructs a fully initialized resource type flyweight.
 ResourceTypeFlyweight constructResourceType(ResourceType original)
           
 ResourceSubCategoryFlyweight constructSubCategory(int id, String name, Integer parentSubCategoryId, String parentSubCategoryName)
          An existing sub category is first looked up in this cache.
 ResourceSubCategoryFlyweight constructSubCategory(ResourceSubCategory original)
           
 Map<Integer,ResourceFlyweight> getResources()
           
 Map<Integer,ResourceTypeFlyweight> getResourceTypes()
           
 Map<Integer,ResourceSubCategoryFlyweight> getSubCategories()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlyweightCache

public FlyweightCache()
Method Detail

getResources

public Map<Integer,ResourceFlyweight> getResources()

getResourceTypes

public Map<Integer,ResourceTypeFlyweight> getResourceTypes()

getSubCategories

public Map<Integer,ResourceSubCategoryFlyweight> getSubCategories()

constructResource

public ResourceFlyweight constructResource(Resource original)
Parameters:
original - the resource
Returns:
the initialized resource flyweight
See Also:
#constructResource(int, String, String, Integer, int, AvailabilityType)

constructResource

public ResourceFlyweight constructResource(int id,
                                           String name,
                                           String uuid,
                                           String resourceKey,
                                           Integer parentId,
                                           int typeId,
                                           AvailabilityType currentAvailability)
Constructs a fully initialized instance of the resource flyweight. The resource type, sub-category and parent are looked up in this cache instance. If not found, new instances are created and added to this cache.

Note that if the parentId is not null and not found in this cache, a new flyweight is created for the parent, initialized only with the id.

The type is supposed to exist in this cache already. If it doesn't, no type is assigned to the returned resource flyweight.

If a corresponding flyweight for the provided resource id is already found in this cache, it is refreshed with the data provided to this call.

Parameters:
id - the resource id
name - the resource name
uuid - the resource uuid
resourceKey - the resource key
parentId - the id of the parent resource
typeId - the id of the resource type
currentAvailability - the availability of the resource
Returns:
the initialized resource flyweight

constructSubCategory

public ResourceSubCategoryFlyweight constructSubCategory(ResourceSubCategory original)
Parameters:
original -
Returns:
a fully initialized resource sub category flyweight
See Also:
#constructSubCategory(int, String, Integer, FlyweightCache)

constructSubCategory

public ResourceSubCategoryFlyweight constructSubCategory(int id,
                                                         String name,
                                                         Integer parentSubCategoryId,
                                                         String parentSubCategoryName)
An existing sub category is first looked up in this cache. If there already is a flyweight instance in this cache, its properties are updated with the provided values, otherwise a new instance is put in this cache.

If parent sub category id is not null but a corresponding flyweight doesn't exist in this cache yet, a new instance is put in this cache initialized with the parent id and name.

Parameters:
id -
name -
parentSubCategoryId -
parentSubCategoryName -
cache -
Returns:
a fully initialized resource sub category flyweight

constructResourceType

public ResourceTypeFlyweight constructResourceType(ResourceType original)
Parameters:
original - the original resource type
Returns:
a fully initialized resource type flyweight
See Also:
#construct(int, String, String, ResourceCategory, Integer, FlyweightCache)

constructResourceType

public ResourceTypeFlyweight constructResourceType(int id,
                                                   String name,
                                                   String plugin,
                                                   boolean singleton,
                                                   ResourceCategory category,
                                                   Integer subCategory)
Constructs a fully initialized resource type flyweight. If a flyweight instance is found in the cache under the provided id, a new instance is *NOT* created but rather the properties of that existing instance are updated with the provided values.

The subcategory is supposed to exist in the cache. If it doesn't the subcategory of the returned resource type flyweight is set to null.

Parameters:
id - the resource type id
name - the resource type name
plugin - the resource type plugin
singleton - true if the resource type is a singleton
category - the resource type category
subCategory - the id of the resource type sub category or null
cache - the flyweight cache
Returns:


Copyright © 2008-2011 Red Hat, Inc.. All Rights Reserved.