Java 类org.apache.http.nio.protocol.BasicAsyncRequestProducer 实例源码

项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<BanResponse> getActiveBan(UUID serverUuid, String playerIdentifier) {
    HttpGet httpRequest = new HttpGet(buildSafe(createUri("/server/" + serverUuid + "/check/" + escape(playerIdentifier))));
    initHeaders(httpRequest);

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), BanResponse.class),
            DeafFutureCallback.<BanResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<BanResponse> createBan(BanRequest request) {
    HttpPost httpRequest = new HttpPost(buildSafe(createUri("/bans")));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), BanResponse.class),
            DeafFutureCallback.<BanResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<BanResponse> updateBan(BanRequest request) {
    HttpPut httpRequest = new HttpPut(buildSafe(createUri("/ban/" + request.getId())));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), BanResponse.class),
            DeafFutureCallback.<BanResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<BanResponse> deleteBan(UUID banId) {
    HttpDelete httpRequest = new HttpDelete(buildSafe(createUri("/ban/" + banId)));
    initHeaders(httpRequest);

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), BanResponse.class),
            DeafFutureCallback.<BanResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<NoticeResponse> createNotice(NoticeRequest request) {
    HttpPost httpRequest = new HttpPost(buildSafe(createUri("/notices")));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), NoticeResponse.class),
            DeafFutureCallback.<NoticeResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<NoticeResponse> updateNotice(NoticeRequest request) {
    HttpPut httpRequest = new HttpPut(buildSafe(createUri("/notice/" + request.getId())));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), NoticeResponse.class),
            DeafFutureCallback.<NoticeResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<NoticeResponse> deleteNotice(UUID noticeId) {
    HttpDelete httpRequest = new HttpDelete(buildSafe(createUri("/notice/" + noticeId)));
    initHeaders(httpRequest);

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), NoticeResponse.class),
            DeafFutureCallback.<NoticeResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<KickResponse> kick(KickRequest request) {
    HttpPost httpRequest = new HttpPost(buildSafe(createUri("/kick")));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), KickResponse.class),
            DeafFutureCallback.<KickResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<ServerHeartbeatResponse> doHeartbeat(ServerHeartbeatRequest request) {
    HttpPost httpRequest = new HttpPost(buildSafe(createUri("/server/heartbeat")));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), ServerHeartbeatResponse.class),
            DeafFutureCallback.<ServerHeartbeatResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<ServerPlayerJoinResponse> propagateJoin(ServerPlayerJoinRequest request) {
    HttpPost httpRequest = new HttpPost(buildSafe(createUri("/server/join")));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), ServerPlayerJoinResponse.class),
            DeafFutureCallback.<ServerPlayerJoinResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public Future<ServerPlayerLeaveResponse> propagateLeave(ServerPlayerLeaveRequest request) {
    HttpPost httpRequest = new HttpPost(buildSafe(createUri("/server/leave")));
    initHeaders(httpRequest);
    httpRequest.setEntity(createEntity(request));

    return client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), ServerPlayerLeaveResponse.class),
            DeafFutureCallback.<ServerPlayerLeaveResponse>instance()
    );
}
项目:java-api-client    文件:DefaultClient.java   
@Override
public void registerOneTimeListener(EventListener listener, EventType... types) {
    URIBuilder uriBuilder = createUri("/listen")
            .addParameter("types", StringUtils.join(",", (Object[]) types));

    HttpGet httpRequest = new HttpGet(buildSafe(uriBuilder));
    initHeaders(httpRequest);

    client.execute(
            new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), Event.class),
            new EventCallback(listener)
    );
}
项目:algorithmia-java    文件:HttpClient.java   
private <T> Future<T> executeAsync(HttpUriRequest request, HttpAsyncResponseConsumer<T> consumer) {
    if(this.auth != null) {
        this.auth.authenticateRequest(request);
    }
    request.addHeader("User-Agent", HttpClient.userAgent);
    HttpHost target = new HttpHost(request.getURI().getHost(), request.getURI().getPort());
    return client.execute(new BasicAsyncRequestProducer(target, request), consumer, null);
}
项目:jsonrpc4j    文件:JsonRpcHttpAsyncClient.java   
/**
 * Invokes the given method with the given arguments and invokes the
 * {@code JsonRpcCallback} with the result cast to the given
 * {@code returnType}, or null if void. The {@code extraHeaders} are added
 * to the request.
 *
 * @param methodName   the name of the method to invoke
 * @param argument     the arguments to the method
 * @param extraHeaders extra headers to add to the request
 * @param returnType   the return type
 * @param callback     the {@code JsonRpcCallback}
 */
@SuppressWarnings("unchecked")
private <T> Future<T> doInvoke(String methodName, Object argument, Class<T> returnType, Map<String, String> extraHeaders, JsonRpcCallback<T> callback) {

    String path = serviceUrl.getPath() + (serviceUrl.getQuery() != null ? "?" + serviceUrl.getQuery() : "");
    int port = serviceUrl.getPort() != -1 ? serviceUrl.getPort() : serviceUrl.getDefaultPort();
    HttpRequest request = new BasicHttpEntityEnclosingRequest("POST", path);

    addHeaders(request, headers);
    addHeaders(request, extraHeaders);

    try {
        writeRequest(methodName, argument, request);
    } catch (IOException e) {
        callback.onError(e);
    }

    HttpHost target = new HttpHost(serviceUrl.getHost(), port, serviceUrl.getProtocol());
    BasicAsyncRequestProducer asyncRequestProducer = new BasicAsyncRequestProducer(target, request);
    BasicAsyncResponseConsumer asyncResponseConsumer = new BasicAsyncResponseConsumer();

    RequestAsyncFuture<T> futureCallback = new RequestAsyncFuture<>(returnType, callback);

    BasicHttpContext httpContext = new BasicHttpContext();
    requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback);

    return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}
项目:jsonrpc    文件:JsonRpcHttpAsyncClient.java   
/**
 * Invokes the given method with the given arguments and invokes the
 * {@code JsonRpcCallback} with the result cast to the given
 * {@code returnType}, or null if void. The {@code extraHeaders} are added
 * to the request.
 * 
 * @param methodName
 *            the name of the method to invoke
 * @param arguments
 *            the arguments to the method
 * @param extraHeaders
 *            extra headers to add to the request
 * @param returnType
 *            the return type
 * @param callback
 *            the {@code JsonRpcCallback}
 */
@SuppressWarnings("unchecked")
private <T> Future<T> doInvoke(String methodName, Object argument,
        Class<T> returnType, Map<String, String> extraHeaders,
        JsonRpcCallback<T> callback) {

    String path = serviceUrl.getPath()
            + (serviceUrl.getQuery() != null ? "?" + serviceUrl.getQuery()
                    : "");
    int port = serviceUrl.getPort() != -1 ? serviceUrl.getPort()
            : serviceUrl.getDefaultPort();

    // create the HttpRequest
    HttpRequest request = new BasicHttpEntityEnclosingRequest("POST", path);

    addHeaders(request, headers);
    addHeaders(request, extraHeaders);

    // create the JSON payload
    try {
        writeRequest(methodName, argument, request);
    } catch (IOException e) {
        callback.onError(e);
    }

    HttpHost target = new HttpHost(serviceUrl.getHost(), port,
            serviceUrl.getProtocol());
    BasicAsyncRequestProducer asyncRequestProducer = new BasicAsyncRequestProducer(
            target, request);
    BasicAsyncResponseConsumer asyncResponseConsumer = new BasicAsyncResponseConsumer();

    RequestAsyncFuture<T> futureCallback = new RequestAsyncFuture<T>(
            returnType, callback);

    BasicHttpContext httpContext = new BasicHttpContext();
    requester.execute(asyncRequestProducer, asyncResponseConsumer, pool,
            httpContext, futureCallback);

    return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}