congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
RequestContext.tryDone
Code IndexAdd Tabnine to your IDE (free)

How to use
tryDone
method
in
com.mpush.netty.http.RequestContext

Best Java code snippets using com.mpush.netty.http.RequestContext.tryDone (Showing top 5 results out of 315)

origin: mpusher/mpush

@Override
public void run(Timeout timeout) throws Exception {
  if (tryDone()) {
    if (callback != null) {
      callback.onTimeout();
    }
  }
}
origin: mpusher/mpush

private void writeRequest(Channel channel, RequestContext context) {
  channel.attr(requestKey).set(context);
  pool.attachHost(context.host, channel);
  channel.writeAndFlush(context.request).addListener((ChannelFutureListener) future -> {
    if (!future.isSuccess()) {
      RequestContext info = future.channel().attr(requestKey).getAndSet(null);
      info.tryDone();
      info.onFailure(503, "Service Unavailable");
      LOGGER.debug("request failure request={}", info);
      pool.tryRelease(future.channel());
    }
  });
}
origin: mpusher/mpush

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  RequestContext context = ctx.channel().attr(client.requestKey).getAndSet(null);
  try {
    if (context != null && context.tryDone()) {
      context.onException(cause);
    }
  } finally {
    client.pool.tryRelease(ctx.channel());
  }
  LOGGER.error("http client caught an ex, info={}", context, cause);
}
origin: mpusher/mpush

  writeRequest(future.channel(), context);
} else {//3.2如果链接创建失败,直接返回客户端网关超时
  context.tryDone();
  context.onFailure(504, "Gateway Timeout");
  LOGGER.warn("create new channel failure, request={}", context);
origin: mpusher/mpush

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  RequestContext context = ctx.channel().attr(client.requestKey).getAndSet(null);
  try {
    if (context != null && context.tryDone()) {
      LOGGER.debug("receive server response, request={}, response={}", context, msg);
      HttpResponse response = (HttpResponse) msg;
      if (isRedirect(response)) {
        if (context.onRedirect(response)) {
          String location = getRedirectLocation(context.request, response);
          if (location != null && location.length() > 0) {
            context.cancelled.set(false);
            context.request.setUri(location);
            client.request(context);
            return;
          }
        }
      }
      context.onResponse(response);
    } else {
      LOGGER.warn("receive server response but timeout, request={}, response={}", context, msg);
    }
  } finally {
    client.pool.tryRelease(ctx.channel());
    ReferenceCountUtil.release(msg);
  }
}
com.mpush.netty.httpRequestContexttryDone

Javadoc

由于检测请求超时的任务存在,为了防止多线程下重复处理

Popular methods of RequestContext

  • <init>
  • destroy
  • onException
  • onFailure
  • onRedirect
  • onResponse
  • parseTimeout

Popular in Java

  • Updating database using SQL prepared statement
  • compareTo (BigDecimal)
  • getSystemService (Context)
  • onCreateOptionsMenu (Activity)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • JButton (javax.swing)
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now