List of usage examples for java.util.concurrent CompletableFuture thenApply
public <U> CompletableFuture<U> thenApply(Function<? super T, ? extends U> fn)
From source file:org.mascherl.example.page.MailComposePage.java
@POST @Path("/mail/compose") public CompletableFuture<MascherlAction> composeNew() { String mailUuid = composeMailService.composeNewMail(user); Observable<MascherlPage> composeObservable = compose(mailUuid); CompletableFuture<MascherlPage> completableFuture = new CompletableFuture<>(); composeObservable.subscribe(completableFuture::complete, completableFuture::completeExceptionally); return completableFuture.thenApply( (pageDef) -> Mascherl.navigate(UriBuilder.fromMethod(getClass(), "compose").build(mailUuid)) .renderContainer("content").withPageDef(pageDef)); }
From source file:com.devicehive.service.DeviceCommandService.java
public CompletableFuture<Optional<DeviceCommand>> findOne(Long id, String guid) { CommandSearchRequest searchRequest = new CommandSearchRequest(); searchRequest.setId(id);//from w ww . j av a 2s. c o m searchRequest.setGuid(guid); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder().withBody(searchRequest).build(), new ResponseConsumer(future)); return future .thenApply(r -> r.getBody().cast(CommandSearchResponse.class).getCommands().stream().findFirst()); }
From source file:com.devicehive.service.NetworkService.java
public CompletableFuture<List<NetworkVO>> list(String name, String namePattern, String sortField, boolean sortOrderAsc, Integer take, Integer skip, HivePrincipal principal) { Optional<HivePrincipal> principalOpt = ofNullable(principal); ListNetworkRequest request = new ListNetworkRequest(); request.setName(name);/* w ww . j a v a 2 s. co m*/ request.setNamePattern(namePattern); request.setSortField(sortField); request.setSortOrderAsc(sortOrderAsc); request.setTake(take); request.setSkip(skip); request.setPrincipal(principalOpt); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder().withBody(request).build(), new ResponseConsumer(future)); return future.thenApply(r -> ((ListNetworkResponse) r.getBody()).getNetworks()); }
From source file:com.devicehive.service.DeviceNotificationService.java
public CompletableFuture<Optional<DeviceNotification>> findOne(Long id, String guid) { NotificationSearchRequest searchRequest = new NotificationSearchRequest(); searchRequest.setId(id);// w w w . j a va 2 s.c o m searchRequest.setGuid(guid); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call( Request.newBuilder().withBody(searchRequest).withPartitionKey(searchRequest.getGuid()).build(), new ResponseConsumer(future)); return future .thenApply(r -> ((NotificationSearchResponse) r.getBody()).getNotifications().stream().findFirst()); }
From source file:com.devicehive.service.DeviceCommandService.java
public CompletableFuture<Void> update(DeviceCommand cmd, DeviceCommandWrapper commandWrapper) { if (cmd == null) { throw new NoSuchElementException("Command not found"); }/*from w w w.ja v a 2s .com*/ cmd.setIsUpdated(true); if (commandWrapper.getCommand() != null) { cmd.setCommand(commandWrapper.getCommand().orElse(null)); } if (commandWrapper.getTimestamp() != null && commandWrapper.getTimestamp().isPresent()) { cmd.setTimestamp(commandWrapper.getTimestamp().get()); } if (commandWrapper.getParameters() != null) { cmd.setParameters(commandWrapper.getParameters().orElse(null)); } if (commandWrapper.getLifetime() != null) { cmd.setLifetime(commandWrapper.getLifetime().orElse(null)); } if (commandWrapper.getStatus() != null) { cmd.setStatus(commandWrapper.getStatus().orElse(null)); } if (commandWrapper.getResult() != null) { cmd.setResult(commandWrapper.getResult().orElse(null)); } hiveValidator.validate(cmd); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder().withBody(new CommandUpdateRequest(cmd)).build(), new ResponseConsumer(future)); return future.thenApply(response -> null); }
From source file:com.devicehive.service.DeviceCommandService.java
public CompletableFuture<DeviceCommand> insert(DeviceCommandWrapper commandWrapper, DeviceVO device, UserVO user) {/* www .java2 s. c o m*/ DeviceCommand command = convertWrapperToCommand(commandWrapper, device, user); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder().withBody(new CommandInsertRequest(command)) .withPartitionKey(device.getGuid()).build(), new ResponseConsumer(future)); return future.thenApply(r -> ((CommandInsertResponse) r.getBody()).getDeviceCommand()); }
From source file:com.devicehive.service.DeviceClassService.java
public CompletableFuture<List<DeviceClassWithEquipmentVO>> list(String name, String namePattern, String sortField, Boolean sortOrderAsc, Integer take, Integer skip) { ListDeviceClassRequest request = new ListDeviceClassRequest(); request.setName(name);//from w ww. j a v a 2 s . c om request.setNamePattern(namePattern); request.setSortField(sortField); request.setSortOrderAsc(sortOrderAsc); request.setTake(take); request.setSkip(skip); CompletableFuture<com.devicehive.shim.api.Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder().withBody(request).build(), new ResponseConsumer(future)); return future.thenApply(r -> ((ListDeviceClassResponse) r.getBody()).getDeviceClasses()); }
From source file:com.devicehive.service.DeviceService.java
public CompletableFuture<List<DeviceVO>> list(String name, String namePattern, Long networkId, String networkName, Long deviceClassId, String deviceClassName, String sortField, @NotNull Boolean sortOrderAsc, Integer take, Integer skip, HivePrincipal principal) { ListDeviceRequest request = new ListDeviceRequest(); request.setName(name);//w w w. ja va 2 s. c om request.setNamePattern(namePattern); request.setNetworkId(networkId); request.setNetworkName(networkName); request.setDeviceClassId(deviceClassId); request.setDeviceClassName(deviceClassName); request.setSortField(sortField); request.setSortOrderAsc(sortOrderAsc); request.setTake(take); request.setSkip(skip); request.setPrincipal(principal); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder().withBody(request).build(), new ResponseConsumer(future)); return future.thenApply(r -> ((ListDeviceResponse) r.getBody()).getDevices()); }
From source file:com.devicehive.service.UserService.java
public CompletableFuture<List<UserVO>> list(String login, String loginPattern, Integer role, Integer status, String sortField, Boolean sortOrderAsc, Integer take, Integer skip) { ListUserRequest request = new ListUserRequest(); request.setLogin(login);/*from w w w. ja v a 2s. c om*/ request.setLoginPattern(loginPattern); request.setRole(role); request.setStatus(status); request.setSortField(sortField); request.setSortOrderAsc(sortOrderAsc); request.setTake(take); request.setSkip(skip); CompletableFuture<Response> future = new CompletableFuture<>(); rpcClient.call(Request.newBuilder().withBody(request).build(), new ResponseConsumer(future)); return future.thenApply(r -> ((ListUserResponse) r.getBody()).getUsers()); }
From source file:io.pravega.controller.store.stream.AbstractStreamMetadataStore.java
@Override public CompletableFuture<TxnStatus> abortTransaction(final String scope, final String streamName, final int epoch, final UUID txId, final OperationContext context, final Executor executor) { Stream stream = getStream(scope, streamName, context); CompletableFuture<TxnStatus> future = withCompletion(stream.abortTransaction(epoch, txId), executor); future.thenApply(result -> { stream.getNumberOfOngoingTransactions().thenAccept(count -> { DYNAMIC_LOGGER.incCounterValue(nameFromStream(ABORT_TRANSACTION, scope, streamName), 1); DYNAMIC_LOGGER.reportGaugeValue(nameFromStream(OPEN_TRANSACTIONS, scope, streamName), count); });/* w w w .j a v a2 s.c o m*/ return result; }); return future; }