Ejemplo n.º 1
0
  public void addClientRequest(InvokerContext context, boolean failed) {
    if (configManager.getBooleanValue(KEY_REQUEST_QUALITY_AUTO, false)
        && context.getClient() != null) {

      String address = context.getClient().getAddress();
      ConcurrentHashMap<String, ConcurrentHashMap<Integer, Quality>> requestSecondQuality =
          addrReqUrlSecondQualities.get(address);
      if (requestSecondQuality == null) {
        requestSecondQuality = new ConcurrentHashMap<String, ConcurrentHashMap<Integer, Quality>>();
        ConcurrentHashMap<String, ConcurrentHashMap<Integer, Quality>> last =
            addrReqUrlSecondQualities.putIfAbsent(address, requestSecondQuality);
        if (last != null) {
          requestSecondQuality = last;
        }
      }

      String requestUrl = getRequestUrl(context);
      ConcurrentHashMap<Integer, Quality> secondQuality = requestSecondQuality.get(requestUrl);
      if (secondQuality == null) {
        secondQuality = new ConcurrentHashMap<Integer, Quality>();
        ConcurrentHashMap<Integer, Quality> last =
            requestSecondQuality.putIfAbsent(requestUrl, secondQuality);
        if (last != null) {
          secondQuality = last;
        }
      }

      int currentSecond = Calendar.getInstance().get(Calendar.SECOND);
      Quality quality = secondQuality.get(currentSecond);
      if (quality == null) {
        quality = new Quality(0, 0);
        Quality last = secondQuality.putIfAbsent(currentSecond, quality);
        if (last != null) {
          quality = last;
        }
      }

      quality.total.incrementAndGet();
      if (failed) {
        quality.failed.incrementAndGet();
      }
    }
  }
Ejemplo n.º 2
0
 private void connectionException(Client client, Object attachment, Throwable e) {
   logger.info("exception while connecting to " + client, e);
   if (attachment == null) {
     return;
   }
   Object[] msg = (Object[]) attachment;
   if (msg[0] instanceof InvokerContext) {
     InvokerContext invokerContext = (InvokerContext) msg[0];
     InvocationRequest request = invokerContext.getRequest();
     if (request.getMessageType() == Constants.MESSAGE_TYPE_SERVICE && msg[1] != null) {
       try {
         Callback callback = (Callback) msg[1];
         if (client != null) {
           client.write(request, callback);
         } else {
           logger.error("no client found with service:" + request.getServiceName());
         }
       } catch (Throwable ex) {
         logger.error("", ex);
       }
       logger.error("", e);
     }
   }
 }
Ejemplo n.º 3
0
 private String getRequestUrl(InvokerContext context) {
   return context.getInvokerConfig().getUrl() + "#" + context.getMethodName();
 }