Java Service provider Framework _effective Java 2.0_item 1 Knowledge points __java

Source: Internet
Author: User

Article Author: Tyan
Blog: noahsnail.com 1. Service Provider Framework Introduction 1.1 What is a service provider framework

Service Provider Framework English is a service Provider framework, mainly refers to: multiple service providers to implement a services, the system for the client to provide multiple implementations and decoupling them from multiple implementations. Service provider changes are transparent to their clients, providing better scalability. JDBC,JMS, for example, uses the service provider framework. 1.2 Components of the service provider framework

The service provider framework has four main components:

Service Interface: Services interface, the service through the abstract unified Declaration, for the client calls, the individual service providers specifically implemented.

Provider Registration API: The service Provider registration API, which is used by the system to register the service provider so that clients can access the services it implements.

Services Access API: Service access APIs, user clients get the appropriate services.

Service Provider Interface: Services provider interfaces, which are responsible for creating instances of their service implementations. (not required) 2. Service Provider Framework Implementation

Service Interface:

Service Interface Public
interface Service {
    ...//service-specific methods Go-here
}

Provider Registration APIs and Service Access APIs:

Noninstantiable Class for service registration and access public class services {private services () {}//Preven TS Instantiation (Item 4)//Maps service names to services private static final map<string, provider> Prov

    Iders = new concurrenthashmap<string, provider> ();

    public static final String default_provider_name = "<def>"; Provider registration API public static void Registerdefaultprovider (Provider p) {Registerprovider (DEFAULT
    _provider_name, p);
    public static void Registerprovider (String name, Provider p) {providers.put (name, p);
    //Service Access API public static Service newinstance () {return newinstance (default_provider_name);
        The public static Service newinstance (String name) {Provider p = providers.get (name); if (p = = null) throw new IllegalArgumentException ("No provider registered with Name:" + Name
       ); return P.newservice (); }
}

Service Provider Interface:

Service Provider Interface Public
interface Provider {
    service newservice ();
}
3. Service Provider Architecture Chart

Resources:

1, http://blog.csdn.net/zl3450341/article/details/7227197

2, http://liwenshui322.iteye.com/blog/1267202

3, effective Java 2.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.