Search in sources :

Example 1 with ServiceBean

use of com.alibaba.dubbo.config.spring.ServiceBean in project uavstack by uavorg.

the class DubboIT method doProfiling.

/**
 * collect all ServiceBeans for later profiling
 *
 * @param args
 */
@SuppressWarnings("rawtypes")
public void doProfiling(Object[] args) {
    InterceptContext ic = InterceptSupport.instance().getThreadLocalContext(Event.WEBCONTAINER_STARTED);
    @SuppressWarnings("unchecked") Map<String, DubboServiceProfileInfo> list = (Map<String, DubboServiceProfileInfo>) ic.get(HookConstants.DUBBO_PROFILE_LIST);
    if (null == list) {
        list = new HashMap<String, DubboServiceProfileInfo>();
        ic.put(HookConstants.DUBBO_PROFILE_LIST, list);
    }
    ServiceBean sb = (ServiceBean) args[0];
    String serviceClass = sb.getInterface();
    String serviceImplClass = sb.getRef().getClass().getName();
    // the refclass is enhance by SpringCGLIB, className like "ServiceImplClass$$EnhancerBySpringCGLIB$$2a862c3d"
    if (serviceImplClass.indexOf("$$") > -1) {
        serviceImplClass = serviceImplClass.substring(0, serviceImplClass.indexOf("$$"));
    }
    String group = (sb.getGroup() == null) ? "" : sb.getGroup();
    if (sb.getGroup() == null && sb.getProvider() != null && sb.getProvider().getGroup() != null) {
        group = sb.getProvider().getGroup();
    }
    String version = (sb.getVersion() == null) ? "" : sb.getVersion();
    if (sb.getVersion() == null && sb.getProvider() != null && sb.getProvider().getVersion() != null) {
        version = sb.getProvider().getVersion();
    }
    String serviceKey = serviceClass;
    if (!"".equals(group) && !"".equals(version)) {
        serviceKey += ":" + group + ":" + version;
    } else if (!"".equals(group) && "".equals(version)) {
        serviceKey += ":" + group;
    } else if ("".equals(group) && !"".equals(version)) {
        serviceKey += ":none:" + version;
    }
    if (list.containsKey(serviceKey)) {
        return;
    }
    DubboServiceProfileInfo dspi = new DubboServiceProfileInfo();
    String dbAppId = sb.getApplication().getName();
    if (sb.getApplication().getVersion() != null) {
        dbAppId += "-" + sb.getApplication().getVersion();
    }
    dspi.setAppId(appId);
    dspi.setDbAppId(dbAppId);
    dspi.setServiceClass(serviceClass);
    dspi.setServiceImplClass(serviceImplClass);
    dspi.setGroup(group);
    dspi.setVersion(version);
    @SuppressWarnings("unchecked") List<URL> urlList = sb.getExportedUrls();
    if (urlList != null) {
        for (URL url : urlList) {
            DubboServiceProfileInfo.Protocol pro = new DubboServiceProfileInfo.Protocol();
            pro.setPort(url.getPort());
            pro.setpName(url.getProtocol());
            int pathLength = url.getPath().length();
            // 长度加1为了去除反斜杠/
            int interfaceLength = url.getServiceInterface().length() + 1;
            String contextpath = null;
            if (pathLength > interfaceLength + 1) {
                contextpath = url.getPath().substring(0, pathLength - interfaceLength);
            }
            pro.setContextpath(contextpath);
            pro.setCharset(url.getParameter("charset"));
            // dubbo当前默认的序列化方式为hessian2,不知道日后会不会变,故此处不进行默认赋值
            pro.setSerialization(url.getParameter("serialization"));
            dspi.addProtocol(pro);
        }
    }
    list.put(serviceKey, dspi);
}
Also used : DubboServiceProfileInfo(com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo) URL(com.alibaba.dubbo.common.URL) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) ServiceBean(com.alibaba.dubbo.config.spring.ServiceBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ServiceBean

use of com.alibaba.dubbo.config.spring.ServiceBean in project incubator-dubbo-spring-boot-project by apache.

the class DubboMvcEndpoint method shutdown.

@RequestMapping(value = DUBBO_SHUTDOWN_ENDPOINT_URI, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public DeferredResult shutdown() throws Exception {
    DeferredResult result = new DeferredResult();
    Map<String, Object> shutdownCountData = new LinkedHashMap<>();
    // registries
    int registriesCount = getRegistries().size();
    // protocols
    int protocolsCount = getProtocolConfigsBeanMap().size();
    ProtocolConfig.destroyAll();
    shutdownCountData.put("registries", registriesCount);
    shutdownCountData.put("protocols", protocolsCount);
    // Service Beans
    Map<String, ServiceBean> serviceBeansMap = getServiceBeansMap();
    if (!serviceBeansMap.isEmpty()) {
        for (ServiceBean serviceBean : serviceBeansMap.values()) {
            serviceBean.destroy();
        }
    }
    shutdownCountData.put("services", serviceBeansMap.size());
    // Reference Beans
    ReferenceAnnotationBeanPostProcessor beanPostProcessor = getReferenceAnnotationBeanPostProcessor();
    int referencesCount = beanPostProcessor.getReferenceBeans().size();
    beanPostProcessor.destroy();
    shutdownCountData.put("references", referencesCount);
    // Set Result to complete
    Map<String, Object> shutdownData = new TreeMap<>();
    shutdownData.put("shutdown.count", shutdownCountData);
    result.setResult(shutdownData);
    return result;
}
Also used : ReferenceAnnotationBeanPostProcessor(com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor) ServiceBean(com.alibaba.dubbo.config.spring.ServiceBean) DubboEndpoint(com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) DeferredResult(org.springframework.web.context.request.async.DeferredResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ServiceBean

use of com.alibaba.dubbo.config.spring.ServiceBean in project incubator-dubbo-spring-boot-project by apache.

the class DubboMvcEndpoint method services.

@RequestMapping(value = DUBBO_SERVICES_ENDPOINT_URI, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Map<String, Object>> services() {
    Map<String, ServiceBean> serviceBeansMap = getServiceBeansMap();
    Map<String, Map<String, Object>> servicesMetadata = new LinkedHashMap<>(serviceBeansMap.size());
    for (Map.Entry<String, ServiceBean> entry : serviceBeansMap.entrySet()) {
        String serviceBeanName = entry.getKey();
        ServiceBean serviceBean = entry.getValue();
        Map<String, Object> serviceBeanMetadata = resolveBeanMetadata(serviceBean);
        Object service = resolveServiceBean(serviceBeanName, serviceBean);
        if (service != null) {
            // Add Service implementation class
            serviceBeanMetadata.put("serviceClass", service.getClass().getName());
        }
        servicesMetadata.put(serviceBeanName, serviceBeanMetadata);
    }
    return servicesMetadata;
}
Also used : ServiceBean(com.alibaba.dubbo.config.spring.ServiceBean) ConcurrentMap(java.util.concurrent.ConcurrentMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ServiceBean (com.alibaba.dubbo.config.spring.ServiceBean)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DubboEndpoint (com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint)1 URL (com.alibaba.dubbo.common.URL)1 ReferenceAnnotationBeanPostProcessor (com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor)1 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)1 DubboServiceProfileInfo (com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 MvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint)1 DeferredResult (org.springframework.web.context.request.async.DeferredResult)1