use of com.alipay.sofa.rpc.interceptor.TripleServerInterceptor in project sofa-rpc by sofastack.
the class TripleServer method registerProcessor.
@Override
public void registerProcessor(ProviderConfig providerConfig, Invoker instance) {
Object ref = providerConfig.getRef();
this.lock.lock();
try {
// wrap invoker to support unique id
UniqueIdInvoker oldInvoker = this.invokerMap.putIfAbsent(providerConfig.getInterfaceId(), new UniqueIdInvoker());
if (null != oldInvoker) {
// we only need register given invoker into unique id invoker.
if (!oldInvoker.registerInvoker(providerConfig, instance)) {
throw new IllegalStateException("Can not expose service with interface:" + providerConfig.getInterfaceId() + " and unique id: " + providerConfig.getUniqueId());
}
return;
}
UniqueIdInvoker uniqueIdInvoker = this.invokerMap.get(providerConfig.getInterfaceId());
if (!uniqueIdInvoker.registerInvoker(providerConfig, instance)) {
throw new IllegalStateException("Can not expose service with interface:" + providerConfig.getInterfaceId() + " and unique id: " + providerConfig.getUniqueId());
}
// create service definition
ServerServiceDefinition serviceDef;
if (SofaProtoUtils.isProtoClass(ref)) {
// refer is BindableService
this.setBindableProxiedImpl(providerConfig, uniqueIdInvoker);
BindableService bindableService = (BindableService) providerConfig.getRef();
serviceDef = bindableService.bindService();
} else {
GenericServiceImpl genericService = new GenericServiceImpl(uniqueIdInvoker, providerConfig.getProxyClass());
genericService.setProxiedImpl(genericService);
serviceDef = buildSofaServiceDef(genericService, providerConfig);
}
List<TripleServerInterceptor> interceptorList = buildInterceptorChain(serviceDef);
ServerServiceDefinition serviceDefinition = ServerInterceptors.intercept(serviceDef, interceptorList);
this.serviceInfo.put(providerConfig, serviceDefinition);
ServerServiceDefinition ssd = this.handlerRegistry.addService(serviceDefinition);
if (ssd != null) {
throw new IllegalStateException("Can not expose service with same name:" + serviceDefinition.getServiceDescriptor().getName());
}
this.invokerCnt.incrementAndGet();
} catch (Exception e) {
String msg = "Register triple service error";
LOGGER.error(msg, e);
this.serviceInfo.remove(providerConfig);
throw new SofaRpcRuntimeException(msg, e);
} finally {
this.lock.unlock();
}
}
use of com.alipay.sofa.rpc.interceptor.TripleServerInterceptor in project sofa-rpc by sofastack.
the class TripleServer method buildInterceptorChain.
/**
* build chain
*
* @param serviceDef
* @return
*/
protected List<TripleServerInterceptor> buildInterceptorChain(ServerServiceDefinition serviceDef) {
List<TripleServerInterceptor> interceptorList = new ArrayList<>();
interceptorList.add(new ServerReqHeaderInterceptor(serviceDef));
return interceptorList;
}
Aggregations