Java Doc for DiscoverSingleton.java in  » Library » Apache-common-Discovery » org » apache » commons » discovery » tools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common Discovery » org.apache.commons.discovery.tools 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.discovery.tools.DiscoverSingleton

DiscoverSingleton
public class DiscoverSingleton (Code)

Discover singleton service providers. This

DiscoverSingleton instances are cached by the Discovery service, keyed by a combination of

  • thread context class loader,
  • groupContext, and
  • SPI.
This DOES allow multiple instances of a given singleton class to exist for different class loaders and different group contexts.

In the context of this package, a service interface is defined by a Service Provider Interface (SPI). The SPI is expressed as a Java interface, abstract class, or (base) class that defines an expected programming interface.

DiscoverSingleton provides the find methods for locating and instantiating a singleton instance of an implementation of a service (SPI). Each form of find varies slightly, but they all perform the same basic function. The simplest find methods are intended for direct use by components looking for a service. If you are not sure which finder(s) to use, you can narrow your search to one of these:

  • static Object find(Class spi);
  • static Object find(Class spi, Properties properties);
  • static Object find(Class spi, String defaultImpl);
  • static Object find(Class spi, Properties properties, String defaultImpl);
  • static Object find(Class spi, String propertiesFileName, String defaultImpl);
  • static Object find(String groupContext, Class spi, Properties properties, String defaultImpl);
  • static Object find(String groupContext, Class spi, String propertiesFileName, String defaultImpl);
The DiscoverSingleton.find methods proceed as follows:

  • Examine an internal cache to determine if the desired service was previously identified and instantiated. If found in cache, return it.
  • Get the name of an implementation class. The name is the first non-null value obtained from the following resources:
    • The value of the (scoped) system property whose name is the same as the SPI's fully qualified class name (as given by SPI.class.getName()). The ScopedProperties class provides a way to bind properties by classloader, in a secure hierarchy similar in concept to the way classloader find class and resource files. See ScopedProperties for more details.

      If the ScopedProperties are not set by users, then behaviour is equivalent to System.getProperty().

    • The value of a Properties properties property, if provided as a parameter, whose name is the same as the SPI's fully qualifed class name (as given by SPI.class.getName()).
    • The value obtained using the JDK1.3+ 'Service Provider' specification (http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html) to locate a service named SPI.class.getName(). This is implemented internally, so there is not a dependency on JDK 1.3+.
  • If the name of the implementation class is non-null, load that class. The class loaded is the first class loaded by the following sequence of class loaders:
    • Thread Context Class Loader
    • DiscoverSingleton's Caller's Class Loader
    • SPI's Class Loader
    • DiscoverSingleton's (this class or wrapper) Class Loader
    • System Class Loader
    An exception is thrown if the class cannot be loaded.
  • If the name of the implementation class is null, AND the default implementation class (defaultImpl) is null, then an exception is thrown.
  • If the name of the implementation class is null, AND the default implementation class (defaultImpl) is non-null, then load the default implementation class. The class loaded is the first class loaded by the following sequence of class loaders:
    • SPI's Class Loader
    • DiscoverSingleton's (this class or wrapper) Class Loader
    • System Class Loader

    This limits the scope in which the default class loader can be found to the SPI, DiscoverSingleton, and System class loaders. The assumption here is that the default implementation is closely associated with the SPI or system, and is not defined in the user's application space.

    An exception is thrown if the class cannot be loaded.

  • Verify that the loaded class implements the SPI: an exception is thrown if the loaded class does not implement the SPI.
  • Create an instance of the class.

Variances for various forms of the find methods are discussed with each such method. Variances include the following concepts:

  • rootFinderClass - a wrapper encapsulating a finder method (factory or other helper class). The root finder class is used to determine the 'real' caller, and hence the caller's class loader - thereby preserving knowledge that is relevant to finding the correct/expected implementation class.
  • propertiesFileName - Properties may be specified directly, or by property file name. A property file is loaded using the same sequence of class loaders used to load the SPI implementation:
    • Thread Context Class Loader
    • DiscoverSingleton's Caller's Class Loader
    • SPI's Class Loader
    • DiscoverSingleton's (this class) Class Loader
    • System Class Loader
  • groupContext - differentiates service providers for different logical groups of service users, that might otherwise be forced to share a common service and, more importantly, a common configuration of that service.

    The groupContext is used to qualify the name of the property file name: groupContext + '.' + propertiesFileName. If that file is not found, then the unqualified propertyFileName is used.

    In addition, groupContext is used to qualify the name of the system property used to find the service implementation by prepending the value of groupContext to the property name: groupContext> + '.' + SPI.class.getName(). Again, if a system property cannot be found by that name, then the unqualified property name is used.

IMPLEMENTATION NOTE - This implementation is modelled after the SAXParserFactory and DocumentBuilderFactory implementations (corresponding to the JAXP pluggability APIs) found in Apache Xerces.


author:
   Richard A. Sitze
author:
   Craig R. McClanahan
author:
   Costin Manolache
version:
   $Revision: 480374 $ $Date: 2006-11-28 19:33:25 -0800 (Tue, 28 Nov 2006) $




Method Summary
public static  Objectfind(Class spiClass)
     Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
public static  Objectfind(Class spiClass, Properties properties)
     Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
public static  Objectfind(Class spiClass, String defaultImpl)
     Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  defaultImpl - Default implementation.
public static  Objectfind(Class spiClass, Properties properties, String defaultImpl)
     Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation.
public static  Objectfind(Class spiClass, String propertiesFileName, String defaultImpl)
     Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  propertiesFileName - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation.
public static  Objectfind(ClassLoaders loaders, SPInterface spi, PropertiesHolder properties, DefaultClassHolder defaultImpl)
     Find implementation of SPI.
Parameters:
  spi - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation.
public static synchronized  voidrelease()
     Release all internal references to previously created service instances associated with the current thread context class loader.
public static synchronized  voidrelease(Class spiClass)
     Release any internal references to a previously created service instance associated with the current thread context class loader.



Method Detail
find
public static Object find(Class spiClass) throws DiscoveryException(Code)
Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



find
public static Object find(Class spiClass, Properties properties) throws DiscoveryException(Code)
Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



find
public static Object find(Class spiClass, String defaultImpl) throws DiscoveryException(Code)
Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



find
public static Object find(Class spiClass, Properties properties, String defaultImpl) throws DiscoveryException(Code)
Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



find
public static Object find(Class spiClass, String propertiesFileName, String defaultImpl) throws DiscoveryException(Code)
Find implementation of SPI.
Parameters:
  spiClass - Service Provider Interface Class.
Parameters:
  propertiesFileName - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



find
public static Object find(ClassLoaders loaders, SPInterface spi, PropertiesHolder properties, DefaultClassHolder defaultImpl) throws DiscoveryException(Code)
Find implementation of SPI.
Parameters:
  spi - Service Provider Interface Class.
Parameters:
  properties - Used to determine name of SPI implementation,and passed to implementation.init() method ifimplementation implements Service interface.
Parameters:
  defaultImpl - Default implementation. Instance of a class implementing the SPI.
exception:
  DiscoveryException - Thrown if the name of a class implementingthe SPI cannot be found, if the class cannot be loaded andinstantiated, or if the resulting class does not implement(or extend) the SPI.



release
public static synchronized void release()(Code)
Release all internal references to previously created service instances associated with the current thread context class loader. The release() method is called for service instances that implement the Service interface. This is useful in environments like servlet containers, which implement application reloading by throwing away a ClassLoader. Dangling references to objects in that class loader would prevent garbage collection.



release
public static synchronized void release(Class spiClass)(Code)
Release any internal references to a previously created service instance associated with the current thread context class loader. If the SPI instance implements Service, then call release().



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.