org.richfaces.application
Class ServiceTracker

java.lang.Object
  extended by org.richfaces.application.ServiceTracker

public final class ServiceTracker
extends java.lang.Object

Tracker class to provide access to various framework implementation services. Examples of such services are: SkinFactory, TBD.

Supports either direct placement of service implementation instances or lazy initialization via ServiceReference interface.

This class represents application-scoped object that is replicated into attributes of FacesContext during runtime for better performance.

No modifications operations are allowed after ServiceTracker is locked, and IllegalStateException is throws in this case.

Note: in initial state this class is not synchronized and presumes that all modification operations are done in a context of single-thread (in JSF initialization listener). In locked state read operations can be called from multiple threads concurrently without no need to synchronize explicitly.

Since:
4.0
Author:
Nick Belaevski

Method Summary
static java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object> getConcurrentStorage(javax.faces.context.FacesContext context)
          Returns ConcurrentMap stored in ServiceTracker.
static java.util.Collection<java.lang.Class<?>> getRegisteredServiceClasses(javax.faces.context.FacesContext context)
          Returns unmodifiable collection of registered service classes.
static
<T> T
getService(javax.faces.context.FacesContext context, java.lang.Class<T> serviceClass)
          Lookup registered service implementation by service class.
static java.util.Date getStartTime(javax.faces.context.FacesContext context)
          Returns ServiceTracker instantiation time.
static void lockModification(javax.faces.context.FacesContext context)
          Switches application-scoped ServiceTracker to locked state, preventing further modifications of registered services via setService(FacesContext, Class, Object) or setServiceReference(FacesContext, Class, ServiceReference) methods.
static void release(javax.faces.context.FacesContext context)
          Releases application-scoped ServiceTracker.
static
<T> void
setService(javax.faces.context.FacesContext context, java.lang.Class<T> serviceClass, T serviceImplementation)
          Registers service implementation for the given service class.
static
<T> void
setServiceReference(javax.faces.context.FacesContext context, java.lang.Class<T> serviceClass, ServiceReference<T> serviceReference)
          Registers ServiceReference for the given service class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getRegisteredServiceClasses

public static java.util.Collection<java.lang.Class<?>> getRegisteredServiceClasses(javax.faces.context.FacesContext context)
Returns unmodifiable collection of registered service classes.

Parameters:
context - current instance of FacesContext
Returns:
collection of registered service classes
Throws:
java.lang.NullPointerException - if context is null

getService

public static <T> T getService(javax.faces.context.FacesContext context,
                               java.lang.Class<T> serviceClass)
Lookup registered service implementation by service class.

Parameters:
context - current instance of FacesContext
serviceClass - class for which implementation has been registered.
Returns:
registered implementation or null
Throws:
java.lang.NullPointerException - if context or serviceClass is null

setService

public static <T> void setService(javax.faces.context.FacesContext context,
                                  java.lang.Class<T> serviceClass,
                                  T serviceImplementation)
Registers service implementation for the given service class.

Parameters:
context - current instance of FacesContext
serviceClass - class for which implementation is to be registered
serviceImplementation - service implementation
Throws:
java.lang.NullPointerException - if context, serviceClass or serviceImplementation is null
java.lang.IllegalStateException - if current ServiceTracker is in locked state.

setServiceReference

public static <T> void setServiceReference(javax.faces.context.FacesContext context,
                                           java.lang.Class<T> serviceClass,
                                           ServiceReference<T> serviceReference)
Registers ServiceReference for the given service class.

Parameters:
context - current instance of FacesContext
serviceClass - class for which reference is to be registered
serviceReference - instance of service reference
Throws:
java.lang.NullPointerException - if context, serviceClass or serviceReference is null
java.lang.IllegalStateException - if current ServiceTracker is in locked state.

release

public static void release(javax.faces.context.FacesContext context)

Releases application-scoped ServiceTracker.

Called during application shutdown; shouldn't be called explicitly by user.

Parameters:
context - current instance of FacesContext

lockModification

public static void lockModification(javax.faces.context.FacesContext context)

Switches application-scoped ServiceTracker to locked state, preventing further modifications of registered services via setService(FacesContext, Class, Object) or setServiceReference(FacesContext, Class, ServiceReference) methods.

Called at the beginning of the very first application request life cycle; shouldn't be called explicitly by user.

Parameters:
context - current instance of FacesContext

getStartTime

public static java.util.Date getStartTime(javax.faces.context.FacesContext context)
Returns ServiceTracker instantiation time. Corresponds to application initialization time.

Parameters:
context -
Returns:
instantiation time

getConcurrentStorage

public static java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object> getConcurrentStorage(javax.faces.context.FacesContext context)
Returns ConcurrentMap stored in ServiceTracker. This map is intended to be used as fast application-scoped storage.

Parameters:
context -
Returns:


Copyright © 2010 JBoss, a division of Red Hat, Inc.. All Rights Reserved.