本文整理汇总了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));
}
示例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");
}
示例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);
}
}
示例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.
}
示例5: send
import org.eclipse.jetty.client.api.Response; //导入方法依赖的package包/类
@Override
public void send(Response.CompleteListener listener) {
completeListener.set(listener);
sendLatch.countDown();
}
示例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;
}