当前位置: 首页>>代码示例>>Java>>正文


Java ErrorCode类代码示例

本文整理汇总了Java中okhttp3.internal.http2.ErrorCode的典型用法代码示例。如果您正苦于以下问题:Java ErrorCode类的具体用法?Java ErrorCode怎么用?Java ErrorCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ErrorCode类属于okhttp3.internal.http2包,在下文中一共展示了ErrorCode类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: streamFailed

import okhttp3.internal.http2.ErrorCode; //导入依赖的package包/类
public void streamFailed(IOException e) {
  Socket socket;
  boolean noNewStreams = false;

  synchronized (connectionPool) {
    if (e instanceof StreamResetException) {
      StreamResetException streamResetException = (StreamResetException) e;
      if (streamResetException.errorCode == ErrorCode.REFUSED_STREAM) {
        refusedStreamCount++;
      }
      // On HTTP/2 stream errors, retry REFUSED_STREAM errors once on the same connection. All
      // other errors must be retried on a new connection.
      if (streamResetException.errorCode != ErrorCode.REFUSED_STREAM || refusedStreamCount > 1) {
        noNewStreams = true;
        route = null;
      }
    } else if (connection != null
        && (!connection.isMultiplexed() || e instanceof ConnectionShutdownException)) {
      noNewStreams = true;

      // If this route hasn't completed a call, avoid it for new connections.
      if (connection.successCount == 0) {
        if (route != null && e != null) {
          routeSelector.connectFailed(route, e);
        }
        route = null;
      }
    }
    socket = deallocate(noNewStreams, false, true);
  }

  closeQuietly(socket);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:StreamAllocation.java

示例2: writeResponse

import okhttp3.internal.http2.ErrorCode; //导入依赖的package包/类
private void writeResponse(Http2Stream stream, MockResponse response) throws IOException {
  Settings settings = response.getSettings();
  if (settings != null) {
    stream.getConnection().setSettings(settings);
  }

  if (response.getSocketPolicy() == NO_RESPONSE) {
    return;
  }
  List<Header> http2Headers = new ArrayList<>();
  String[] statusParts = response.getStatus().split(" ", 2);
  if (statusParts.length != 2) {
    throw new AssertionError("Unexpected status: " + response.getStatus());
  }
  // TODO: constants for well-known header names.
  http2Headers.add(new Header(Header.RESPONSE_STATUS, statusParts[1]));
  Headers headers = response.getHeaders();
  for (int i = 0, size = headers.size(); i < size; i++) {
    http2Headers.add(new Header(headers.name(i), headers.value(i)));
  }

  Buffer body = response.getBody();
  boolean closeStreamAfterHeaders = body != null || !response.getPushPromises().isEmpty();
  stream.sendResponseHeaders(http2Headers, closeStreamAfterHeaders);
  pushPromises(stream, response.getPushPromises());
  if (body != null) {
    BufferedSink sink = Okio.buffer(stream.getSink());
    sleepIfDelayed(response);
    throttledTransfer(response, socket, body, sink, bodyLimit, false);
    sink.close();
  } else if (closeStreamAfterHeaders) {
    stream.close(ErrorCode.NO_ERROR);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:MockWebServer.java

示例3: streamFailed

import okhttp3.internal.http2.ErrorCode; //导入依赖的package包/类
public void streamFailed(IOException e) {
  Socket socket;
  Connection releasedConnection;
  boolean noNewStreams = false;

  synchronized (connectionPool) {
    if (e instanceof StreamResetException) {
      StreamResetException streamResetException = (StreamResetException) e;
      if (streamResetException.errorCode == ErrorCode.REFUSED_STREAM) {
        refusedStreamCount++;
      }
      // On HTTP/2 stream errors, retry REFUSED_STREAM errors once on the same connection. All
      // other errors must be retried on a new connection.
      if (streamResetException.errorCode != ErrorCode.REFUSED_STREAM || refusedStreamCount > 1) {
        noNewStreams = true;
        route = null;
      }
    } else if (connection != null
        && (!connection.isMultiplexed() || e instanceof ConnectionShutdownException)) {
      noNewStreams = true;

      // If this route hasn't completed a call, avoid it for new connections.
      if (connection.successCount == 0) {
        if (route != null && e != null) {
          routeSelector.connectFailed(route, e);
        }
        route = null;
      }
    }
    releasedConnection = connection;
    socket = deallocate(noNewStreams, false, true);
    if (connection != null || !reportedAcquired) releasedConnection = null;
  }

  closeQuietly(socket);
  if (releasedConnection != null) {
    eventListener.connectionReleased(call, releasedConnection);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:StreamAllocation.java

示例4: writeResponse

import okhttp3.internal.http2.ErrorCode; //导入依赖的package包/类
private void writeResponse(Http2Stream stream, MockResponse response) throws IOException {
  Settings settings = response.getSettings();
  if (settings != null) {
    stream.getConnection().setSettings(settings);
  }

  if (response.getSocketPolicy() == NO_RESPONSE) {
    return;
  }
  List<Header> http2Headers = new ArrayList<>();
  String[] statusParts = response.getStatus().split(" ", 3);
  if (statusParts.length < 2) {
    throw new AssertionError("Unexpected status: " + response.getStatus());
  }
  // TODO: constants for well-known header names.
  http2Headers.add(new Header(Header.RESPONSE_STATUS, statusParts[1]));
  Headers headers = response.getHeaders();
  for (int i = 0, size = headers.size(); i < size; i++) {
    http2Headers.add(new Header(headers.name(i), headers.value(i)));
  }

  sleepIfDelayed(response.getHeadersDelay(TimeUnit.MILLISECONDS));

  Buffer body = response.getBody();
  boolean closeStreamAfterHeaders = body != null || !response.getPushPromises().isEmpty();
  stream.sendResponseHeaders(http2Headers, closeStreamAfterHeaders);
  pushPromises(stream, response.getPushPromises());
  if (body != null) {
    BufferedSink sink = Okio.buffer(stream.getSink());
    sleepIfDelayed(response.getBodyDelay(TimeUnit.MILLISECONDS));
    throttledTransfer(response, socket, body, sink, body.size(), false);
    sink.close();
  } else if (closeStreamAfterHeaders) {
    stream.close(ErrorCode.NO_ERROR);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:MockWebServer.java

示例5: streamFailed

import okhttp3.internal.http2.ErrorCode; //导入依赖的package包/类
public void streamFailed(IOException e) {
    boolean noNewStreams = false;

    synchronized (connectionPool) {
        if (e instanceof StreamResetException) {
            StreamResetException streamResetException = (StreamResetException) e;
            if (streamResetException.errorCode == ErrorCode.REFUSED_STREAM) {
                refusedStreamCount++;
            }
            // On HTTP/2 stream errors, retry REFUSED_STREAM errors once on the same connection. All
            // other errors must be retried on a new connection.
            if (streamResetException.errorCode != ErrorCode.REFUSED_STREAM || refusedStreamCount > 1) {
                noNewStreams = true;
                route = null;
            }
        } else if (connection != null && !connection.isMultiplexed()) {
            noNewStreams = true;

            // If this route hasn't completed a call, avoid it for new connections.
            if (connection.successCount == 0) {
                if (route != null && e != null) {
                    routeSelector.connectFailed(route, e);
                }
                route = null;
            }
        }
    }

    deallocate(noNewStreams, false, true);
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:31,代码来源:StreamAllocation.java

示例6: writeResponse

import okhttp3.internal.http2.ErrorCode; //导入依赖的package包/类
private void writeResponse(Http2Stream stream, MockResponse response) throws IOException {
  Settings settings = response.getSettings();
  if (settings != null) {
    stream.getConnection().setSettings(settings);
  }

  if (response.getSocketPolicy() == NO_RESPONSE) {
    return;
  }
  List<Header> http2Headers = new ArrayList<>();
  String[] statusParts = response.getStatus().split(" ", 2);
  if (statusParts.length != 2) {
    throw new AssertionError("Unexpected status: " + response.getStatus());
  }
  // TODO: constants for well-known header names.
  http2Headers.add(new Header(Header.RESPONSE_STATUS, statusParts[1]));
  Headers headers = response.getHeaders();
  for (int i = 0, size = headers.size(); i < size; i++) {
    http2Headers.add(new Header(headers.name(i), headers.value(i)));
  }

  Buffer body = response.getBody();
  boolean closeStreamAfterHeaders = body != null || !response.getPushPromises().isEmpty();
  stream.reply(http2Headers, closeStreamAfterHeaders);
  pushPromises(stream, response.getPushPromises());
  if (body != null) {
    BufferedSink sink = Okio.buffer(stream.getSink());
    sleepIfDelayed(response);
    throttledTransfer(response, socket, body, sink, bodyLimit, false);
    sink.close();
  } else if (closeStreamAfterHeaders) {
    stream.close(ErrorCode.NO_ERROR);
  }
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:35,代码来源:MockWebServer.java

示例7: onStream

import okhttp3.internal.http2.ErrorCode; //导入依赖的package包/类
/** Refuse incoming streams. */
@Override public void onStream(Http2Stream stream) throws IOException {
  stream.close(ErrorCode.REFUSED_STREAM);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:RealConnection.java


注:本文中的okhttp3.internal.http2.ErrorCode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。