com.alibaba.dubbo.rpc.RpcResult类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(308)

本文整理了Java中com.alibaba.dubbo.rpc.RpcResult类的一些代码示例,展示了RpcResult类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RpcResult类的具体详情如下:
包路径:com.alibaba.dubbo.rpc.RpcResult
类名称:RpcResult

RpcResult介绍

[英]RPC Result.
[中]RPC结果。

代码示例

代码示例来源:origin: liuyangming/ByteTCC

public Result providerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException {
  CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
  CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
  RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();
  String instanceId = StringUtils.trimToEmpty(invocation.getAttachment(RemoteCoordinator.class.getName()));
  this.registerRemoteParticipantIfNecessary(instanceId);
  RpcResult result = new RpcResult();
  CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult();
  wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());
  result.setException(null);
  result.setValue(wrapped);
  return result;
}

代码示例来源:origin: liuyangming/ByteTCC

public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException {
  CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
  CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
  RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();
  Map<String, String> attachments = invocation.getAttachments();
  attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier());
  RpcResult result = (RpcResult) invoker.invoke(invocation);
  Object value = result.getValue();
  if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) {
    CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value;
    result.setValue(null);
    result.setException(null);
    if (wrapped.isFailure()) {
      result.setException(wrapped.getError());
    } else {
      result.setValue(wrapped.getValue());
    }
  }
  return result;
}

代码示例来源:origin: liuyangming/ByteTCC

public Result wrapResultForProvider(Invoker<?> invoker, Invocation invocation, String propagatedBy,
    boolean attachRequired) {
  try {
    RpcResult result = (RpcResult) invoker.invoke(invocation);
    if (result.hasException()) {
      return this.createErrorResultForProvider(result.getException(), propagatedBy, attachRequired);
    } else {
      return this.convertResultForProvider(result, propagatedBy, attachRequired);
    }
  } catch (Throwable rex) {
    return this.createErrorResultForProvider(rex, propagatedBy, attachRequired);
  }
}

代码示例来源:origin: alibaba/Sentinel

private static void registerFallback() {
    // Register fallback handler for consumer.
    // If you only want to handle degrading, you need to
    // check the type of BlockException.
    DubboFallbackRegistry.setConsumerFallback((a, b, ex) ->
      new RpcResult("Error: " + ex.getClass().getTypeName()));
  }
}

代码示例来源:origin: com.alibaba/dubbo

RpcResult result = new RpcResult();
  result.setValue(null);
  return result;
} else if (mock.startsWith(Constants.RETURN_PREFIX)) {
    Type[] returnTypes = RpcUtils.getReturnTypes(invocation);
    Object value = parseMockValue(mock, returnTypes);
    return new RpcResult(value);
  } catch (Exception ew) {
    throw new RpcException("mock return invoke error. method :" + invocation.getMethodName() + ", mock:" + mock + ", url: " + url, ew);

代码示例来源:origin: remoting/dubbox

TMessage message;
if ( result.hasException() ) {
  Throwable throwable = result.getException();
  int index = 1;
  boolean found = false;
  Object realResult = result.getResult();

代码示例来源:origin: com.alibaba/dubbo-rpc-api

/**
 * @see com.alibaba.dubbo.rpc.RpcResult#setValue(Object)
 * @deprecated Replace to setValue()
 */
@Deprecated
public void setResult(Object result) {
  setValue(result);
}

代码示例来源:origin: com.alibaba/dubbo

/**
 * @see com.alibaba.dubbo.rpc.RpcResult#getValue()
 * @deprecated Replace to getValue()
 */
@Override
@Deprecated
public Object getResult() {
  return getValue();
}

代码示例来源:origin: QNJR-GROUP/EasyTransaction

@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
  DubboEasyTransRpcProviderImpl instance = DubboEasyTransRpcProviderImpl.getInstance();
  if(checkEasyTransRequest(invocation)){
    EasyTransRequest<?, ?> easyTransRequest = (EasyTransRequest<?, ?>) ((Object[])invocation.getArguments()[2])[0];
    @SuppressWarnings("unchecked")
    Map<String,Object> header = (Map<String,Object>) ((Object[])invocation.getArguments()[2])[1];
    BusinessIdentifer businessIdentifer = ReflectUtil.getBusinessIdentifer(easyTransRequest.getClass());
    EasyTransFilterChain filterChain = instance.getFilterChainFactory().getFilterChainByFilters(businessIdentifer.appId(), businessIdentifer.busCode(), (String)(invocation.getArguments()[0]),instance.getFilters());
    
    filterChain.addFilter(new EasyTransFilterAdapter(invoker, invocation));
    
    EasyTransResult result;
    try {
      result = filterChain.invokeFilterChain(header,easyTransRequest);
    } catch (Exception e) {
      LOG.error("RPC EasyTrans FilterChain execute Error!",e);
      throw e;
    }
    
    if(result.hasException()){
      return new RpcResult(result.getException());
    }else{
      return new RpcResult(result.getValue());
    }
  }else{
    return invoker.invoke(invocation);
  }
}

代码示例来源:origin: com.alibaba/dubbo-rpc-api

RpcResult result = new RpcResult();
  result.setValue(null);
  return result;
} else if (mock.startsWith(Constants.RETURN_PREFIX)) {
    Type[] returnTypes = RpcUtils.getReturnTypes(invocation);
    Object value = parseMockValue(mock, returnTypes);
    return new RpcResult(value);
  } catch (Exception ew) {
    throw new RpcException("mock return invoke error. method :" + invocation.getMethodName() + ", mock:" + mock + ", url: " + url, ew);

代码示例来源:origin: remoting/dubbox

TMessage message;
if ( result.hasException() ) {
  Throwable throwable = result.getException();
  int index = 1;
  boolean found = false;
  Object realResult = result.getResult();

代码示例来源:origin: net.jahhan/dubbo-rpc-api

/**
 * @deprecated Replace to setValue()
 * @see com.alibaba.dubbo.rpc.RpcResult#setValue()
 */
@Deprecated
public void setResult(Object result) {
  setValue(result);
}

代码示例来源:origin: com.alibaba/dubbo-rpc-api

/**
 * @see com.alibaba.dubbo.rpc.RpcResult#getValue()
 * @deprecated Replace to getValue()
 */
@Override
@Deprecated
public Object getResult() {
  return getValue();
}

代码示例来源:origin: liuyangming/ByteTCC

public Result providerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException {
  CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
  CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
  RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();
  String instanceId = StringUtils.trimToEmpty(invocation.getAttachment(RemoteCoordinator.class.getName()));
  this.registerRemoteParticipantIfNecessary(instanceId);
  RpcResult result = new RpcResult();
  CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult();
  wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());
  result.setException(null);
  result.setValue(wrapped);
  return result;
}

代码示例来源:origin: javahongxi/whatsmars

private static void registerFallback() {
    // Register fallback handler for consumer.
    // If you only want to handle degrading, you need to
    // check the type of BlockException.
    DubboFallbackRegistry.setConsumerFallback((a, b, ex) ->
      new RpcResult("Error: " + ex.getClass().getTypeName()));
  }
}

代码示例来源:origin: liuyangming/ByteTCC

public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException {
  CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
  CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
  RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant();
  Map<String, String> attachments = invocation.getAttachments();
  attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier());
  RpcResult result = (RpcResult) invoker.invoke(invocation);
  Object value = result.getValue();
  if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) {
    CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value;
    result.setValue(null);
    result.setException(null);
    if (wrapped.isFailure()) {
      result.setException(wrapped.getError());
    } else {
      result.setValue(wrapped.getValue());
    }
    // String propagatedBy = (String) wrapped.getVariable(RemoteCoordinator.class.getName());
    // String identifier = compensableCoordinator.getIdentifier();
  }
  return result;
}

代码示例来源:origin: remoting/dubbox

RpcResult result = new RpcResult();
  result.setValue(null);
  return result;
} else if (mock.startsWith(Constants.RETURN_PREFIX)) {
    Type[] returnTypes = RpcUtils.getReturnTypes(invocation);
    Object value = parseMockValue(mock, returnTypes);
    return new RpcResult(value);
  } catch (Exception ew) {
    throw new RpcException("mock return invoke error. method :" + invocation.getMethodName() + ", mock:" + mock + ", url: "+ url , ew);

代码示例来源:origin: com.alibaba/dubbo

TMessage message;
if (result.hasException()) {
  Throwable throwable = result.getException();
  int index = 1;
  boolean found = false;
  Object realResult = result.getResult();

代码示例来源:origin: liuyangming/ByteTCC

public Result wrapResultForProvider(Invoker<?> invoker, Invocation invocation, String propagatedBy,
    boolean attachRequired) {
  try {
    RpcResult result = (RpcResult) invoker.invoke(invocation);
    if (result.hasException()) {
      return this.createErrorResultForProvider(result.getException(), propagatedBy, attachRequired);
    } else {
      return this.convertResultForProvider(result, propagatedBy, attachRequired);
    }
  } catch (Throwable rex) {
    return this.createErrorResultForProvider(rex, propagatedBy, attachRequired);
  }
}

代码示例来源:origin: com.alibaba/dubbo

/**
 * @see com.alibaba.dubbo.rpc.RpcResult#setValue(Object)
 * @deprecated Replace to setValue()
 */
@Deprecated
public void setResult(Object result) {
  setValue(result);
}

相关文章