wt.admin.cache
Class DomainHierarchy

java.lang.Object
  extended bywt.admin.cache.DomainHierarchy
All Implemented Interfaces:
CacheUpdater

final class DomainHierarchy
extends Object
implements CacheUpdater

Manages a cache of AdministrativeDomains which is used for navigating domain hierarchies.

To limit the amount of memory consumed by cached AdministrativeDomain objects the property wt.admin.cache.maxDomains in wt.properties controls the maximum number of AdministrativeDomains that will be cached by this class.


Field Summary
(package private)  Cache ancestors
          Map of AdministrativeDomain ObjectIdentifier to Vector of ancestor AdministrativeDomain ObjectIdentifiers.
(package private)  Cache cachedDomains
          Map of AdministrativeDomain ObjectIdentifiers to AdministrativeDomain objects.
private static int changeCount
           
(package private)  Cache children
          Map of parent AdministrativeDomain ObjectIdentifiers to Vector of child AdministrativeDomain ObjectIdentifiers.
(package private)  Cache descendants
          Map of AdministrativeDomain ObjectIdentifier to Vector of descendant AdministrativeDomain ObjectIdentifiers.
(package private)  Cache domainNames
          Map of AdministrativeDomain ObjectIdentifiers to domain names.
(package private)  Cache domainPaths
          Map of AdministrativeDomain ObjectIdentifiers to the domain path relative to the domain's container.
(package private)  Cache domainsByPath
          Map of DomainPathKey to the AdministrativeDomain ObjectIdentifiers.
private static Object lock
           
private static int MAX_DOMAINS
           
(package private)  Cache parents
          Map of child AdministrativeDomain ObjectIdentifiers to parent AdministrativeDomain ObjectIdentifiers.
private static String RESOURCE
           
private static boolean VERBOSE
           
 
Constructor Summary
(package private) DomainHierarchy()
           
 
Method Summary
 void add(AdministrativeDomain domain)
          Caches a domain in response to a POST_STORE event on an AdministrativeDomain.
private  void addChildDomains(ObjectIdentifier oid, Vector descendent_oids)
          Builds a Vector of descendent ObjectIdentifiers for a domain by recursively adding the child ObjectIdentifiers to the descendents Vector.
 void delete(AdministrativeDomain domain)
          Deletes a cached domain in response to a REMOVE event on an AdministrativeDomain.
private  String genDomainPathRelativeToItsContainer(AdministrativeDomain inDomain)
           
 Vector getAncestorDomains(ObjectIdentifier oid)
          Gets the ObjectIdentifiers of the ancestor domains for the given domain.
 ObjectIdentifier getChildDomain(ObjectIdentifier parent_oid, String child_name, WTContainerRef child_container_ref)
          Returns the ObjectIdentifier of a named domain given the ObjectIdentifier of its parent domain.
private  Vector getChildDomains(ObjectIdentifier oid)
          Gets the ObjectIdentifiers of child domains for the domain with the given ObjectIdentifier.
 Vector getDescendentDomains(ObjectIdentifier oid)
          Gets the ObjectIdentifiers of the descendent domains for the given domain.
 AdministrativeDomain getDomain(ObjectIdentifier oid)
          Gets the AdministrativeDomain with the given ObjectIdentifier.
 AdministrativeDomain getDomain(String path, WTContainerRef containerRef)
          Gets the AdministrativeDomain with the given path relative to the given container.
 String getDomainName(ObjectIdentifier domain_oid)
          Gets the name of the AdministrativeDomain with the given ObjectIdentifier.
(package private)  ObjectIdentifier getDomainOID(String domainPath, WTContainerRef containerRef)
          Gets the Domain OID for the domain specified by the input domainPath and containerRef.
(package private)  String getDomainPath(AdministrativeDomain inDomain)
          Returns Domain Path for the input Domain object relative to the container domain resides in.
 ObjectIdentifier getParentDomain(ObjectIdentifier child_oid)
          Gets the ObjectIdentifier of a parent domain given the ObjectIdentifier of a child domain.
 void modify(AdministrativeDomain domain)
          Updates the cache in response to a POST_MODIFY event on an AdministrativeDomain.
 void move(AdministrativeDomain domain, AdminDomainRef old_parent, AdminDomainRef new_parent)
          Updates the cache in response to a POST_CHANGE_DOMAIN event on an AdministrativeDomain.
private  void pp(String msg)
           
private  Vector queryForChildren(ObjectIdentifier oid)
          Queries the database for AdministrativeDomains whose parent is the domain with the given ObjectIdentifier.
private  AdministrativeDomain restoreDomain(ObjectIdentifier oid)
          Gets an AdministrativeDomain from the database given an ObjectIdentifier
 void writeContents(OutputStream os)
          Writes the contents of this cache to an OutputStream for debugging purposes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

MAX_DOMAINS

private static int MAX_DOMAINS

VERBOSE

private static boolean VERBOSE

lock

private static Object lock

changeCount

private static int changeCount

children

Cache children
Map of parent AdministrativeDomain ObjectIdentifiers to Vector of child AdministrativeDomain ObjectIdentifiers.

The capacity of this cache is wt.admin.cache.maxDomains


parents

Cache parents
Map of child AdministrativeDomain ObjectIdentifiers to parent AdministrativeDomain ObjectIdentifiers.

The capacity of this cache is wt.admin.cache.maxDomains


ancestors

Cache ancestors
Map of AdministrativeDomain ObjectIdentifier to Vector of ancestor AdministrativeDomain ObjectIdentifiers.

The capacity of this cache is wt.admin.cache.maxDomains


descendants

Cache descendants
Map of AdministrativeDomain ObjectIdentifier to Vector of descendant AdministrativeDomain ObjectIdentifiers.

The capacity of this cache is wt.admin.cache.maxDomains


domainNames

Cache domainNames
Map of AdministrativeDomain ObjectIdentifiers to domain names.

The capacity of this cache is wt.admin.cache.maxDomains


domainPaths

Cache domainPaths
Map of AdministrativeDomain ObjectIdentifiers to the domain path relative to the domain's container. The domain paths in this cache do NOT include the container path.

The capacity of this cache is wt.admin.cache.maxDomains


domainsByPath

Cache domainsByPath
Map of DomainPathKey to the AdministrativeDomain ObjectIdentifiers. The DomainPathKey consists of the domain path and the container reference the domain path is relative to (i.e., the domain's container reference).

The capacity of this cache is wt.admin.cache.maxDomains


cachedDomains

Cache cachedDomains
Map of AdministrativeDomain ObjectIdentifiers to AdministrativeDomain objects.

The capacity of this cache is wt.admin.cache.maxDomains

Constructor Detail

DomainHierarchy

DomainHierarchy()
Method Detail

getParentDomain

public ObjectIdentifier getParentDomain(ObjectIdentifier child_oid)
                                 throws WTException
Gets the ObjectIdentifier of a parent domain given the ObjectIdentifier of a child domain. If the child domain's parent is not in the cache, the database is queried and the parent is added to the cache.

Parameters:
child_oid - an ObjectIdentifier for a child domain
Returns:
the ObjectIdentifier of the child's parent domain
Throws:
WTException - if a low level error occurs

getChildDomain

public ObjectIdentifier getChildDomain(ObjectIdentifier parent_oid,
                                       String child_name,
                                       WTContainerRef child_container_ref)
                                throws WTException
Returns the ObjectIdentifier of a named domain given the ObjectIdentifier of its parent domain. If the desired child domain is not in the cache, the database is queried and the child is added to the cache.

Parameters:
parent_oid - the ObjectIdentifier of the parent domain
child_name - the name of the child domain
child_container_ref - the reference for the container the child domain resides in
Returns:
the ObjectIdentifier of the child domain; returns null if the domain does not exist
Throws:
WTException - if a low level error occurs

getAncestorDomains

public Vector getAncestorDomains(ObjectIdentifier oid)
                          throws WTException
Gets the ObjectIdentifiers of the ancestor domains for the given domain.

Parameters:
oid - the ObjectIdentifier of the domain
Returns:
the ObjectIdentifiers of the ancestor domains for the given domain
Throws:
WTException - if a low level error occurs

getDescendentDomains

public Vector getDescendentDomains(ObjectIdentifier oid)
                            throws WTException
Gets the ObjectIdentifiers of the descendent domains for the given domain.

Parameters:
oid - the ObjectIdentifier of the domain
Returns:
the ObjectIdentifiers of the descendent domains for the given domain
Throws:
WTException - if a low level error occurs

getDomain

public AdministrativeDomain getDomain(ObjectIdentifier oid)
                               throws WTException
Gets the AdministrativeDomain with the given ObjectIdentifier. If cachedDomains doesn't contain the AdministrativeDomain then it is queried from the database and added to it.

Parameters:
oid - an ObjectIdentifier for a AdministrativeDomain
Returns:
the AdministrativeDomain object, else null if the AdministrativeDomain doesn't exist
Throws:
WTException - if a low level error occurs

getDomain

public AdministrativeDomain getDomain(String path,
                                      WTContainerRef containerRef)
                               throws WTException
Gets the AdministrativeDomain with the given path relative to the given container. If cachedDomains doesn't contain the AdministrativeDomain then it is queried from the database and added to it.

Parameters:
path - a path for an AdministrativeDomain. The path must be an unescaped domain path.
containerRef - the container reference for the Container the path is relative to.
Returns:
the AdministrativeDomain object, else null if the AdministrativeDomain doesn't exist
Throws:
WTException - if a low level error occurs

getDomainName

public String getDomainName(ObjectIdentifier domain_oid)
                     throws WTException,
                            ObjectNoLongerExistsException
Gets the name of the AdministrativeDomain with the given ObjectIdentifier. If domainNames doesn't contain the name then the database is queried for the domain and the name is added to the cache.

Returns:
the domain's name
Throws:
ObjectNoLongerExistsException - if the requested domain is not found in the database
WTException - if a low level error occurs

add

public void add(AdministrativeDomain domain)
Caches a domain in response to a POST_STORE event on an AdministrativeDomain.

Specified by:
add in interface CacheUpdater
Parameters:
domain - a new AdministrativeDomain

delete

public void delete(AdministrativeDomain domain)
Deletes a cached domain in response to a REMOVE event on an AdministrativeDomain.

If the deleted domain is a key in any of the caches, the entry is removed.

Specified by:
delete in interface CacheUpdater
Parameters:
domain - a deleted AdministrativeDomain

modify

public void modify(AdministrativeDomain domain)
Updates the cache in response to a POST_MODIFY event on an AdministrativeDomain. Only the cachedDomains, domainNames, domainsByPath, and domainPaths caches need to be updated. If the parent domain for an AdministrativeDomain is changed, a POST_CHANGE_DOMAIN event will always be generated and will cause the other caches to be updated.

Specified by:
modify in interface CacheUpdater
Parameters:
domain - a modified AdministrativeDomain

move

public void move(AdministrativeDomain domain,
                 AdminDomainRef old_parent,
                 AdminDomainRef new_parent)
Updates the cache in response to a POST_CHANGE_DOMAIN event on an AdministrativeDomain.

If the old_parent or new_parent is a key in children then removes the AdministrativeDomain being moved from the old_parent's children and adds it to the new_parent's children. If the AdministrativeDomain being moved is a key in parents its value is set to new_parent. If the AdministrativeDomain being moved is a key in domainPaths, remove the cached paths for the domain and add the new path to domainPaths and domainsByPath.

Specified by:
move in interface CacheUpdater
Parameters:
domain - a moved AdministrativeDomain
old_parent - the old parent AdministrativeDomain
new_parent - the new parent AdministrativeDomain

writeContents

public void writeContents(OutputStream os)
                   throws IOException
Writes the contents of this cache to an OutputStream for debugging purposes

Specified by:
writeContents in interface CacheUpdater
Parameters:
os - an OutputStream to write the contents of a cache to
Throws:
IOException - if there is an I/O error

addChildDomains

private void addChildDomains(ObjectIdentifier oid,
                             Vector descendent_oids)
                      throws WTException
Builds a Vector of descendent ObjectIdentifiers for a domain by recursively adding the child ObjectIdentifiers to the descendents Vector.

Parameters:
oid - an ObjectIdentifier for an AdministrativeDomain
descendent_oids - a Vector of descendent ObjectIdentifiers
Throws:
WTException - if a low level error occurs

getChildDomains

private Vector getChildDomains(ObjectIdentifier oid)
                        throws WTException
Gets the ObjectIdentifiers of child domains for the domain with the given ObjectIdentifier. If the child domains are not in the cache, the database is queried and the children are added to the cache.

Parameters:
oid - the ObjectIdentifier of an AdministrativeDomain
Returns:
the ObjectIdentifiers of the child domains
Throws:
WTException - if a low level error occurs

queryForChildren

private Vector queryForChildren(ObjectIdentifier oid)
                         throws WTException
Queries the database for AdministrativeDomains whose parent is the domain with the given ObjectIdentifier.

Parameters:
oid - the ObjectIdentifier for an AdministrativeDomain
Returns:
the ObjectIdentifiers of the child AdministrativeDomains
Throws:
WTException - if a low level error occurs

restoreDomain

private AdministrativeDomain restoreDomain(ObjectIdentifier oid)
                                    throws WTException
Gets an AdministrativeDomain from the database given an ObjectIdentifier

Parameters:
oid - an ObjectIdentifier for an AdministrativeDomain
Returns:
the restored AdministrativeDomain object
Throws:
ObjectNoLongerExistsException - if the requested AdministrativeDomain is not found in the database
WTException - if a low level error occurs

getDomainPath

String getDomainPath(AdministrativeDomain inDomain)
               throws WTException
Returns Domain Path for the input Domain object relative to the container domain resides in.

Parameters:
inDomain - The AdministrativeDomain to get the path for.
Throws:
WTException

getDomainOID

ObjectIdentifier getDomainOID(String domainPath,
                              WTContainerRef containerRef)
                        throws WTException
Gets the Domain OID for the domain specified by the input domainPath and containerRef.

Parameters:
domainPath - Required. Must be a valid, unescaped domain path. (i.e., doesn't contain [Container Path]) The path must be relative to the Container referenced by the input containerRef.
containerRef - Required. Container Reference for the container the domain resides in.
Throws:
WTException

genDomainPathRelativeToItsContainer

private String genDomainPathRelativeToItsContainer(AdministrativeDomain inDomain)
                                            throws WTException
Throws:
WTException

pp

private final void pp(String msg)