com.alipay.sofa.rpc.log.Logger.warnWithApp()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(264)

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

Logger.warnWithApp介绍

[英]Warn with app.
[中]使用应用程序发出警告。

代码示例

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 打印连不上日志
  3. *
  4. * @param interfaceId 接口名称
  5. * @param providerInfo 服务端
  6. * @param transport 连接
  7. * @param e 错误
  8. */
  9. protected void printDead(String interfaceId, ProviderInfo providerInfo, ClientTransport transport, Exception e) {
  10. Throwable cause = e.getCause();
  11. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  12. LOGGER.warnWithApp(consumerConfig.getAppName(),
  13. "Connect to {} provider:{} failure !! The exception is " + ExceptionUtils.toShortString(e, 1)
  14. + (cause != null ? ", cause by " + cause.getMessage() + "." : "."),
  15. interfaceId, providerInfo);
  16. }
  17. }

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 打印连不上日志
  3. *
  4. * @param interfaceId 接口名称
  5. * @param providerInfo 服务端
  6. * @param transport 连接
  7. * @param e 错误
  8. */
  9. protected void printDead(String interfaceId, ProviderInfo providerInfo, ClientTransport transport, Exception e) {
  10. Throwable cause = e.getCause();
  11. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  12. LOGGER.warnWithApp(consumerConfig.getAppName(),
  13. "Connect to {} provider:{} failure !! The exception is " + ExceptionUtils.toShortString(e, 1)
  14. + (cause != null ? ", cause by " + cause.getMessage() + "." : "."),
  15. interfaceId, providerInfo);
  16. }
  17. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public void run() {
  3. try {
  4. ClientTransportFactory.releaseTransport(transport, 0);
  5. } catch (Exception e) {
  6. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  7. LOGGER.warnWithApp(consumerConfig.getAppName(),
  8. "catch exception but ignore it when close alive client : {}", providerInfo);
  9. }
  10. } finally {
  11. latch.countDown();
  12. }
  13. }
  14. });

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public void run() {
  3. try {
  4. ClientTransportFactory.releaseTransport(transport, 0);
  5. } catch (Exception e) {
  6. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  7. LOGGER.warnWithApp(consumerConfig.getAppName(),
  8. "catch exception but ignore it when close alive client : {}", providerInfo);
  9. }
  10. } finally {
  11. latch.countDown();
  12. }
  13. }
  14. });

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 检查方法,例如方法名、多态(重载)方法
  3. *
  4. * @param itfClass 接口类
  5. */
  6. protected void checkMethods(Class<?> itfClass) {
  7. ConcurrentHashMap<String, Boolean> methodsLimit = new ConcurrentHashMap<String, Boolean>();
  8. for (Method method : itfClass.getMethods()) {
  9. String methodName = method.getName();
  10. if (methodsLimit.containsKey(methodName)) {
  11. // 重名的方法
  12. if (LOGGER.isWarnEnabled(providerConfig.getAppName())) {
  13. LOGGER.warnWithApp(providerConfig.getAppName(), "Method with same name \"" + itfClass.getName()
  14. + "." + methodName + "\" exists ! The usage of overloading method in rpc is deprecated.");
  15. }
  16. }
  17. // 判断服务下方法的黑白名单
  18. Boolean include = methodsLimit.get(methodName);
  19. if (include == null) {
  20. include = inList(providerConfig.getInclude(), providerConfig.getExclude(), methodName); // 检查是否在黑白名单中
  21. methodsLimit.putIfAbsent(methodName, include);
  22. }
  23. providerConfig.setMethodsLimit(methodsLimit);
  24. }
  25. }

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 客户端已经超时了(例如在队列里等待太久了),丢弃这个请求
  3. *
  4. * @param appName 应用
  5. * @param serviceName 服务
  6. * @param remoteAddress 远程地址
  7. * @return 丢弃的异常
  8. */
  9. private SofaRpcException clientTimeoutWhenReceiveRequest(String appName, String serviceName, String remoteAddress) {
  10. String errorMsg = LogCodes.getLog(
  11. LogCodes.ERROR_DISCARD_TIMEOUT_REQUEST, serviceName, remoteAddress);
  12. if (LOGGER.isWarnEnabled(appName)) {
  13. LOGGER.warnWithApp(appName, errorMsg);
  14. }
  15. return new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, errorMsg);
  16. }

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 客户端已经超时了(例如在队列里等待太久了),丢弃这个请求
  3. *
  4. * @param appName 应用
  5. * @param serviceName 服务
  6. * @param remoteAddress 远程地址
  7. * @return 丢弃的异常
  8. */
  9. private SofaRpcException clientTimeoutWhenReceiveRequest(String appName, String serviceName, String remoteAddress) {
  10. String errorMsg = LogCodes.getLog(
  11. LogCodes.ERROR_DISCARD_TIMEOUT_REQUEST, serviceName, remoteAddress);
  12. if (LOGGER.isWarnEnabled(appName)) {
  13. LOGGER.warnWithApp(appName, errorMsg);
  14. }
  15. return new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, errorMsg);
  16. }

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 客户端已经超时了(例如在业务执行时间太长),丢弃这个返回值
  3. *
  4. * @param appName 应用
  5. * @param serviceName 服务
  6. * @param remoteAddress 远程地址
  7. * @return 丢弃的异常
  8. */
  9. private SofaRpcException clientTimeoutWhenSendResponse(String appName, String serviceName, String remoteAddress) {
  10. String errorMsg = LogCodes.getLog(
  11. LogCodes.ERROR_DISCARD_TIMEOUT_RESPONSE, serviceName, remoteAddress);
  12. if (LOGGER.isWarnEnabled(appName)) {
  13. LOGGER.warnWithApp(appName, errorMsg);
  14. }
  15. return new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, errorMsg);
  16. }

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 客户端已经超时了(例如在业务执行时间太长),丢弃这个返回值
  3. *
  4. * @param appName 应用
  5. * @param serviceName 服务
  6. * @param remoteAddress 远程地址
  7. * @return 丢弃的异常
  8. */
  9. private SofaRpcException clientTimeoutWhenSendResponse(String appName, String serviceName, String remoteAddress) {
  10. String errorMsg = LogCodes.getLog(
  11. LogCodes.ERROR_DISCARD_TIMEOUT_RESPONSE, serviceName, remoteAddress);
  12. if (LOGGER.isWarnEnabled(appName)) {
  13. LOGGER.warnWithApp(appName, errorMsg);
  14. }
  15. return new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, errorMsg);
  16. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public void run() {
  3. // 状态变化通知监听器
  4. for (ConsumerStateListener listener : onAvailable) {
  5. try {
  6. listener.onAvailable(consumerConfig.getConsumerBootstrap().getProxyIns());
  7. } catch (Exception e) {
  8. LOGGER.warnWithApp(consumerConfig.getAppName(),
  9. "Failed to notify consumer state listener when state change to available");
  10. }
  11. }
  12. }
  13. });

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public void run() {
  3. // 状态变化通知监听器
  4. for (ConsumerStateListener listener : onAvailable) {
  5. try {
  6. listener.onAvailable(consumerConfig.getConsumerBootstrap().getProxyIns());
  7. } catch (Exception e) {
  8. LOGGER.warnWithApp(consumerConfig.getAppName(),
  9. "Failed to notify consumer state listener when state change to available");
  10. }
  11. }
  12. }
  13. });

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 检测服务节点的一些信息
  3. *
  4. * @param providerGroup 服务列表分组
  5. */
  6. protected void checkProviderInfo(ProviderGroup providerGroup) {
  7. List<ProviderInfo> providerInfos = providerGroup == null ? null : providerGroup.getProviderInfos();
  8. if (CommonUtils.isEmpty(providerInfos)) {
  9. return;
  10. }
  11. Iterator<ProviderInfo> iterator = providerInfos.iterator();
  12. while (iterator.hasNext()) {
  13. ProviderInfo providerInfo = iterator.next();
  14. if (!StringUtils.equals(providerInfo.getProtocolType(), consumerConfig.getProtocol())) {
  15. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  16. LOGGER.warnWithApp(consumerConfig.getAppName(),
  17. "Unmatched protocol between consumer [{}] and provider [{}].",
  18. consumerConfig.getProtocol(), providerInfo.getProtocolType());
  19. }
  20. }
  21. }
  22. }

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 检测服务节点的一些信息
  3. *
  4. * @param providerGroup 服务列表分组
  5. */
  6. protected void checkProviderInfo(ProviderGroup providerGroup) {
  7. List<ProviderInfo> providerInfos = providerGroup == null ? null : providerGroup.getProviderInfos();
  8. if (CommonUtils.isEmpty(providerInfos)) {
  9. return;
  10. }
  11. Iterator<ProviderInfo> iterator = providerInfos.iterator();
  12. while (iterator.hasNext()) {
  13. ProviderInfo providerInfo = iterator.next();
  14. if (!StringUtils.equals(providerInfo.getProtocolType(), consumerConfig.getProtocol())) {
  15. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  16. LOGGER.warnWithApp(consumerConfig.getAppName(),
  17. "Unmatched protocol between consumer [{}] and provider [{}].",
  18. consumerConfig.getProtocol(), providerInfo.getProtocolType());
  19. }
  20. }
  21. }
  22. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public SofaResponse invoke() {
  3. if (isCircuitBreakerOpen() && LOGGER.isWarnEnabled(invoker.getConfig().getAppName())) {
  4. LOGGER.warnWithApp(invoker.getConfig().getAppName(), "Circuit Breaker is opened, method: {}#{}",
  5. invoker.getConfig().getInterfaceId(), request.getMethodName());
  6. }
  7. return execute();
  8. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public SofaResponse invoke() {
  3. if (isCircuitBreakerOpen() && LOGGER.isWarnEnabled(invoker.getConfig().getAppName())) {
  4. LOGGER.warnWithApp(invoker.getConfig().getAppName(), "Circuit Breaker is opened, method: {}#{}",
  5. invoker.getConfig().getInterfaceId(), request.getMethodName());
  6. }
  7. return execute();
  8. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public SofaResponse invoke() {
  3. if (isCircuitBreakerOpen() && LOGGER.isWarnEnabled(invoker.getConfig().getAppName())) {
  4. LOGGER.warnWithApp(invoker.getConfig().getAppName(), "Circuit Breaker is opened, method: {}#{}",
  5. invoker.getConfig().getInterfaceId(), request.getMethodName());
  6. }
  7. Future delegate = this.toObservable().toBlocking().toFuture();
  8. RpcInternalContext.getContext().setFuture(new HystrixResponseFuture(delegate, this.responseFuture));
  9. if (this.sofaResponse == null && this.responseFuture == null) {
  10. // 没有执行 construct,熔断或是线程池拒绝
  11. return new SofaResponse();
  12. }
  13. return this.sofaResponse;
  14. }
  15. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public SofaResponse invoke() {
  3. if (isCircuitBreakerOpen() && LOGGER.isWarnEnabled(invoker.getConfig().getAppName())) {
  4. LOGGER.warnWithApp(invoker.getConfig().getAppName(), "Circuit Breaker is opened, method: {}#{}",
  5. invoker.getConfig().getInterfaceId(), request.getMethodName());
  6. }
  7. Future delegate = this.toObservable().toBlocking().toFuture();
  8. RpcInternalContext.getContext().setFuture(new HystrixResponseFuture(delegate, this.responseFuture));
  9. if (this.sofaResponse == null && this.responseFuture == null) {
  10. // 没有执行 construct,熔断或是线程池拒绝
  11. return new SofaResponse();
  12. }
  13. return this.sofaResponse;
  14. }
  15. }

代码示例来源:origin: alipay/sofa-rpc

  1. /**
  2. * 取消订阅服务列表
  3. */
  4. public void unSubscribe() {
  5. if (StringUtils.isEmpty(consumerConfig.getDirectUrl()) && consumerConfig.isSubscribe()) {
  6. List<RegistryConfig> registryConfigs = consumerConfig.getRegistry();
  7. if (registryConfigs != null) {
  8. for (RegistryConfig registryConfig : registryConfigs) {
  9. Registry registry = RegistryFactory.getRegistry(registryConfig);
  10. try {
  11. registry.unSubscribe(consumerConfig);
  12. } catch (Exception e) {
  13. String appName = consumerConfig.getAppName();
  14. if (LOGGER.isWarnEnabled(appName)) {
  15. LOGGER.warnWithApp(appName,
  16. "Catch exception when unSubscribe from registry: " + registryConfig.getId()
  17. + ", but you can ignore if it's called by JVM shutdown hook", e);
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public void updateProviders(ProviderGroup providerGroup) {
  3. checkProviderInfo(providerGroup);
  4. ProviderGroup oldProviderGroup = addressHolder.getProviderGroup(providerGroup.getName());
  5. if (ProviderHelper.isEmpty(providerGroup)) {
  6. addressHolder.updateProviders(providerGroup);
  7. if (!ProviderHelper.isEmpty(oldProviderGroup)) {
  8. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  9. LOGGER.warnWithApp(consumerConfig.getAppName(), "Provider list is emptied, may be all " +
  10. "providers has been closed, or this consumer has been add to blacklist");
  11. closeTransports();
  12. }
  13. }
  14. } else {
  15. addressHolder.updateProviders(providerGroup);
  16. connectionHolder.updateProviders(providerGroup);
  17. }
  18. if (EventBus.isEnable(ProviderInfoUpdateEvent.class)) {
  19. ProviderInfoUpdateEvent event = new ProviderInfoUpdateEvent(consumerConfig, oldProviderGroup, providerGroup);
  20. EventBus.post(event);
  21. }
  22. }

代码示例来源:origin: alipay/sofa-rpc

  1. @Override
  2. public void updateProviders(ProviderGroup providerGroup) {
  3. checkProviderInfo(providerGroup);
  4. ProviderGroup oldProviderGroup = addressHolder.getProviderGroup(providerGroup.getName());
  5. if (ProviderHelper.isEmpty(providerGroup)) {
  6. addressHolder.updateProviders(providerGroup);
  7. if (!ProviderHelper.isEmpty(oldProviderGroup)) {
  8. if (LOGGER.isWarnEnabled(consumerConfig.getAppName())) {
  9. LOGGER.warnWithApp(consumerConfig.getAppName(), "Provider list is emptied, may be all " +
  10. "providers has been closed, or this consumer has been add to blacklist");
  11. closeTransports();
  12. }
  13. }
  14. } else {
  15. addressHolder.updateProviders(providerGroup);
  16. connectionHolder.updateProviders(providerGroup);
  17. }
  18. if (EventBus.isEnable(ProviderInfoUpdateEvent.class)) {
  19. ProviderInfoUpdateEvent event = new ProviderInfoUpdateEvent(consumerConfig, oldProviderGroup, providerGroup);
  20. EventBus.post(event);
  21. }
  22. }

相关文章