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