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);
}
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;
}
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;
}
Aggregations