<!-- provider's application name, used for tracing dependency relationship --> <dubbo:application name="demo-provider"/> <!-- use multicast registry center to export service --> <dubbo:registry address="multicast://224.5.6.7:1234"/> <!-- use dubbo protocol to export service on port 20880 --> <dubbo:protocol name="dubbo" port="20880"/> <!-- service implementation, as same as regular local bean --> <bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/> <!-- declare the service interface to be exported --> <dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService"/>
<!-- consumer's application name, used for tracing dependency relationship (not a matching criterion), don't set it same as provider --> <dubbo:application name="demo-consumer"/> <!-- use multicast registry center to discover service --> <dubbo:registry address="multicast://224.5.6.7:1234"/> <!-- generate proxy for the remote service, then demoService can be used in the same way as the local regular interface --> <dubbo:reference id="demoService" check="false" interface="com.alibaba.dubbo.demo.DemoService"/>
public class ProviderMethodModel { private transient final Method method; private final String methodName; private final String[] methodArgTypes; private final String serviceName; public ProviderMethodModel(Method method, String serviceName) { this.method = method; this.serviceName = serviceName; this.methodName = method.getName(); this.methodArgTypes = getArgTypes(method); }
public class ProviderModel { private final String serviceName; private final Object serviceInstance; private final ServiceConfig metadata; private final Map<String, List<ProviderMethodModel>> methods = new HashMap<String, List<ProviderMethodModel>>(); public ProviderModel(String serviceName, ServiceConfig metadata, Object serviceInstance) { if (null == serviceInstance) { throw new IllegalArgumentException("Service[" + serviceName + "]Target is NULL."); } this.serviceName = serviceName; this.metadata = metadata; this.serviceInstance = serviceInstance; initMethod(); }
/** * full qualified class name -> provided service */ private static final ConcurrentMap<String, ProviderModel> providedServices = new ConcurrentHashMap<String, ProviderModel>(); /** * full qualified class name -> subscribe service */ private static final ConcurrentMap<String, ConsumerModel> consumedServices = new ConcurrentHashMap<String, ConsumerModel>();
public @interface Service { Class<?> interfaceClass() default void.class; String interfaceName() default ""; String version() default ""; String group() default ""; String path() default "";
public ServiceConfig(Service service) { appendAnnotation(Service.class, service); }
能夠發現使用annotation方式標註server,經過反射對server進行解析,放到對應對model中。app