Java Code Examples for scala.concurrent.Future#map()

The following examples show how to use scala.concurrent.Future#map() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserProfileReadActor.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
private void checkUserExistence(Request request) {
  Map<String, Object> searchMap = new WeakHashMap<>();
  String value = (String) request.get(JsonKey.VALUE);
  String encryptedValue = null;
  try {
    encryptedValue = encryptionService.encryptData(StringUtils.lowerCase(value));
  } catch (Exception var11) {
    throw new ProjectCommonException(
        ResponseCode.userDataEncryptionError.getErrorCode(),
        ResponseCode.userDataEncryptionError.getErrorMessage(),
        ResponseCode.SERVER_ERROR.getResponseCode());
  }
  searchMap.put((String) request.get(JsonKey.KEY), encryptedValue);
  ProjectLogger.log(
      "UserProfileReadActor:checkUserExistence: search map prepared " + searchMap,
      LoggerEnum.INFO.name());
  SearchDTO searchDTO = new SearchDTO();
  searchDTO.getAdditionalProperties().put(JsonKey.FILTERS, searchMap);
  Future<Map<String, Object>> esFuture = esUtil.search(searchDTO, EsType.user.getTypeName());
  Future<Response> userResponse =
      esFuture.map(
          new Mapper<Map<String, Object>, Response>() {
            @Override
            public Response apply(Map<String, Object> responseMap) {
              List<Map<String, Object>> respList = (List) responseMap.get(JsonKey.CONTENT);
              long size = respList.size();
              Response resp = new Response();
              resp.put(JsonKey.EXISTS, true);
              if (size <= 0) {
                resp.put(JsonKey.EXISTS, false);
              }
              return resp;
            }
          },
          getContext().dispatcher());

  Patterns.pipe(userResponse, getContext().dispatcher()).to(sender());
}
 
Example 2
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 5 votes vote down vote up
@Benchmark
public String mapConstN() throws Exception {
  Future<String> f = constFuture;
  for (int i = 0; i < N.n; i++)
    f = f.map(mapF, ec);
  return Await.result(f, inf);
}
 
Example 3
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 5 votes vote down vote up
@Benchmark
public String mapPromiseN() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future();
  for (int i = 0; i < N.n; i++)
    f = f.map(mapF, ec);
  p.success(string);
  return Await.result(f, inf);
}
 
Example 4
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 5 votes vote down vote up
@Benchmark
public String setValueN() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future();
  for (int i = 0; i < N.n; i++)
    f = f.map(mapF, ec);
  p.success(string);
  return Await.result(f, inf);
}
 
Example 5
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 5 votes vote down vote up
@Benchmark
public String mapConstN() throws Exception {
  Future<String> f = constFuture;
  for (int i = 0; i < N.n; i++)
    f = f.map(mapF, ec);
  return Await.result(f, inf);
}
 
Example 6
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 5 votes vote down vote up
@Benchmark
public String mapPromiseN() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future();
  for (int i = 0; i < N.n; i++)
    f = f.map(mapF, ec);
  p.success(string);
  return Await.result(f, inf);
}
 
Example 7
Source File: ScalaFutureBenchmark.java    From future with Apache License 2.0 5 votes vote down vote up
@Benchmark
public String setValueN() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future();
  for (int i = 0; i < N.n; i++)
    f = f.map(mapF, ec);
  p.success(string);
  return Await.result(f, inf);
}