Search in sources :

Example 1 with Request

use of com.github.ambry.network.Request in project ambry by linkedin.

the class RequestHandlerPool method run.

public void run() {
    while (true) {
        try {
            Request req = requestChannel.receiveRequest();
            if (req.equals(EmptyRequest.getInstance())) {
                logger.debug("Request handler {} received shut down command", id);
                return;
            }
            requests.handleRequests(req);
            logger.trace("Request handler {} handling request {}", id, req);
        } catch (Throwable e) {
            // TODO add metric to track background threads
            logger.error("Exception when handling request", e);
            // this is bad and we need to shutdown the app
            Runtime.getRuntime().halt(1);
        }
    }
}
Also used : Request(com.github.ambry.network.Request)

Example 2 with Request

use of com.github.ambry.network.Request in project ambry by linkedin.

the class AmbryRequestsTest method sendRequestGetResponse.

// helpers
// general
/**
 * Calls {@link AmbryRequests#handleRequests(Request)} with {@code request} and returns the {@link Response} received.
 * @param request the {@link Request} to process
 * @param expectedServerErrorCode the expected {@link ServerErrorCode} in the server response.
 * @return the {@link Response} received.
 * @throws InterruptedException
 * @throws IOException
 */
private Response sendRequestGetResponse(RequestOrResponse request, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
    Request mockRequest = MockRequest.fromRequest(request);
    ambryRequests.handleRequests(mockRequest);
    assertEquals("Request accompanying response does not match original request", mockRequest, requestResponseChannel.lastOriginalRequest);
    assertNotNull("Response not sent", requestResponseChannel.lastResponse);
    Response response = (Response) requestResponseChannel.lastResponse;
    assertNotNull("Response is not of type Response", response);
    assertEquals("Correlation id in response does match the one in the request", request.getCorrelationId(), response.getCorrelationId());
    assertEquals("Client id in response does match the one in the request", request.getClientId(), response.getClientId());
    assertEquals("Error code does not match expected", expectedServerErrorCode, response.getError());
    return response;
}
Also used : CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) ReplicaMetadataRequest(com.github.ambry.protocol.ReplicaMetadataRequest) GetRequest(com.github.ambry.protocol.GetRequest) Request(com.github.ambry.network.Request) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) PutRequest(com.github.ambry.protocol.PutRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) DeleteRequest(com.github.ambry.protocol.DeleteRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest)

Aggregations

Request (com.github.ambry.network.Request)2 AdminRequest (com.github.ambry.protocol.AdminRequest)1 AdminResponse (com.github.ambry.protocol.AdminResponse)1 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)1 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)1 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)1 DeleteRequest (com.github.ambry.protocol.DeleteRequest)1 GetRequest (com.github.ambry.protocol.GetRequest)1 GetResponse (com.github.ambry.protocol.GetResponse)1 PutRequest (com.github.ambry.protocol.PutRequest)1 ReplicaMetadataRequest (com.github.ambry.protocol.ReplicaMetadataRequest)1 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)1 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)1 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)1 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)1 Response (com.github.ambry.protocol.Response)1