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


Java Response.CompleteListener方法代码示例

本文整理汇总了Java中org.eclipse.jetty.client.api.Response.CompleteListener方法的典型用法代码示例。如果您正苦于以下问题:Java Response.CompleteListener方法的具体用法?Java Response.CompleteListener怎么用?Java Response.CompleteListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.client.api.Response的用法示例。


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

示例1: fireResponse

import org.eclipse.jetty.client.api.Response; //导入方法依赖的package包/类
private void fireResponse(CapturingRequest request, int errorCode, String responseText, int resultSize, ObservableObserver observer, boolean successfulResponse) throws InterruptedException {
    Response.CompleteListener listener = request.awaitSend(1000, TimeUnit.MILLISECONDS);
    assertNotNull(listener);
    InputStreamResponseListener responseListener = (InputStreamResponseListener) listener;

    Result result = mock(Result.class);
    Response response = mock(Response.class);
    when(result.getResponse()).thenReturn(response);
    when(result.isSucceeded()).thenReturn(successfulResponse);
    when(result.isFailed()).thenReturn(!successfulResponse);
    HttpFields headers = mock(HttpFields.class);
    when(response.getHeaders()).thenReturn(headers);
    when(headers.get(HttpHeader.CONTENT_LENGTH)).thenReturn(String.valueOf(resultSize));
    when(response.getStatus()).thenReturn(errorCode);
    when(response.getVersion()).thenReturn(HttpVersion.HTTP_1_1);

    // fire that event
    responseListener.onHeaders(response);
    responseListener.onContent(response, ByteBuffer.allocate(0));
    responseListener.onComplete(result);

    assertTrue(observer.getLatch().await(1000, TimeUnit.MILLISECONDS));
}
 
开发者ID:betfair,项目名称:cougar,代码行数:24,代码来源:AsyncHttpExecutableTest.java

示例2: newProxyResponseListener

import org.eclipse.jetty.client.api.Response; //导入方法依赖的package包/类
@Override
protected Response.CompleteListener newProxyResponseListener(HttpServletRequest clientRequest, HttpServletResponse proxyResponse) {
    throw new UnsupportedOperationException("This is just used for adding proxy headers, not stuff like this");
}
 
开发者ID:danielflower,项目名称:app-runner-router,代码行数:5,代码来源:ForwardedHeadersAdder.java

示例3: sendRequests

import org.eclipse.jetty.client.api.Response; //导入方法依赖的package包/类
static void sendRequests(Requests requests) throws Exception {
    org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient();
    client.setConnectTimeout(requests.getTimeout());
    client.setMaxRequestsQueuedPerDestination(requests.size());
    client.setMaxConnectionsPerDestination(256);

    final CountDownLatch completed = new CountDownLatch(requests.size());

    final AtomicInteger failed = new AtomicInteger();
    final List<Throwable> failures = new ArrayList<>();

    Response.CompleteListener listener = new Response.CompleteListener() {
        public void onComplete(Result result) {
            if (result.isFailed()) {
                failed.incrementAndGet();
                if (failures.size() < 3) failures.add(result.getFailure());
            }
            completed.countDown();
        }
    };

    long start = System.currentTimeMillis();
    client.start();

    out.println("Sending " + requests.size() + " requests ...");
    for (Requests.Request request : requests) {
        Request r = client.newRequest(request.url);
        r.method(HttpMethod.valueOf(request.method));

        for (Map.Entry<String, String> entry: request.headers.entrySet())
            r.header(entry.getKey(), entry.getValue());

        if (request.body != null) r.content(new BytesContentProvider(request.body));
        r.send(listener);
    }

    completed.await();
    client.stop();
    long time = System.currentTimeMillis() - start;
    double rps = Math.floor(requests.size() * 10d * 1000 / time) / 10;

    out.println("Failed:" + failed.get() + "/" + requests.size() + ", speed:" + rps + "rps");

    if (!failures.isEmpty()) {
        out.println("Failures (" + failures.size() + "/" + failed.get() + "):");
        for (Throwable failure : failures)
            failure.printStackTrace(out);
    }
}
 
开发者ID:stealthly,项目名称:punxsutawney,代码行数:50,代码来源:HttpClient.java

示例4: onComplete

import org.eclipse.jetty.client.api.Response; //导入方法依赖的package包/类
@Override
public Request onComplete(Response.CompleteListener listener) {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
}
 
开发者ID:betfair,项目名称:cougar,代码行数:5,代码来源:CapturingRequest.java

示例5: send

import org.eclipse.jetty.client.api.Response; //导入方法依赖的package包/类
@Override
public void send(Response.CompleteListener listener) {
    completeListener.set(listener);
    sendLatch.countDown();

}
 
开发者ID:betfair,项目名称:cougar,代码行数:7,代码来源:CapturingRequest.java

示例6: awaitSend

import org.eclipse.jetty.client.api.Response; //导入方法依赖的package包/类
public Response.CompleteListener awaitSend(long time, TimeUnit unit) throws InterruptedException {
    if (sendLatch.await(time, unit)) {
        return completeListener.get();
    }
    return null;
}
 
开发者ID:betfair,项目名称:cougar,代码行数:7,代码来源:CapturingRequest.java


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