play.libs.F.Function - java examples

Here are the examples of the java api play.libs.F.Function taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

15 View Complete Implementation : BaseController.java
Copyright MIT License
Author : project-sunbird
/**
 * This method will make a call to Akka actor and return promise.
 *
 * @param actorRef ActorSelection
 * @param request Request
 * @param timeout Timeout
 * @param responseKey String
 * @param httpReq play.mvc.Http.Request
 * @return Promise<Result>
 */
public Promise<Result> actorResponseHandler(Object actorRef, org.sunbird.common.request.Request request, Timeout timeout, String responseKey, Request httpReq) {
    String operation = request.getOperation();
    // set header to request object , setting actor type and channel headers value
    // ...
    setChannelAndActorInfo(ctx(), request);
    Function<Object, Result> function = new Function<Object, Result>() {

        @Override
        public Result apply(Object result) {
            if (ActorOperations.HEALTH_CHECK.getValue().equals(request.getOperation())) {
                setGlobalHealthFlag(result);
            }
            if (result instanceof Response) {
                Response response = (Response) result;
                return createCommonResponse(response, responseKey, httpReq);
            } else if (result instanceof ProjectCommonException) {
                return createCommonExceptionResponse((ProjectCommonException) result, request());
            } else if (result instanceof File) {
                return createFileDownloadResponse((File) result);
            } else {
                return createCommonExceptionResponse(new Exception(), httpReq);
            }
        }
    };
    if (actorRef instanceof ActorRef) {
        return Promise.wrap(Patterns.ask((ActorRef) actorRef, request, timeout)).map(function);
    } else {
        return Promise.wrap(Patterns.ask((ActorSelection) actorRef, request, timeout)).map(function);
    }
}