List of usage examples for java.util.concurrent CompletableFuture completedFuture
public static <U> CompletableFuture<U> completedFuture(U value)
From source file:io.pravega.controller.store.stream.InMemoryStream.java
@Override CompletableFuture<Void> createHistoryTableIfAbsent(Data<Integer> data) { Preconditions.checkNotNull(data);/*from ww w . j a v a2 s .c o m*/ Preconditions.checkNotNull(data.getData()); CompletableFuture<Void> result = new CompletableFuture<>(); synchronized (lock) { if (historyTable == null) { historyTable = new Data<>(Arrays.copyOf(data.getData(), data.getData().length), 0); } } return CompletableFuture.completedFuture(null); }
From source file:com.ikanow.aleph2.data_model.interfaces.shared_services.MockManagementCrudService.java
@Override public ManagementFuture<Boolean> deleteObjectBySpec(QueryComponent<T> spec) { if (!_mutable_values.isEmpty()) { _mutable_values.remove(0);//from www . j a v a 2 s . co m return FutureUtils.createManagementFuture(CompletableFuture.completedFuture(true)); } else { return FutureUtils.createManagementFuture(CompletableFuture.completedFuture(false)); } }
From source file:com.yahoo.pulsar.broker.namespace.NamespaceServiceTest.java
@SuppressWarnings("unchecked") private Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles(NamespaceBundleFactory utilityFactory, NamespaceName nsname, NamespaceBundles bundles, NamespaceBundle targetBundle) throws Exception { Field bCacheField = NamespaceBundleFactory.class.getDeclaredField("bundlesCache"); bCacheField.setAccessible(true);//from ww w .ja v a 2s .c om ((AsyncLoadingCache<NamespaceName, NamespaceBundles>) bCacheField.get(utilityFactory)).put(nsname, CompletableFuture.completedFuture(bundles)); return utilityFactory.splitBundles(targetBundle, 2); }
From source file:com.ikanow.aleph2.harvest.logstash.services.LogstashHarvestService.java
@Override public CompletableFuture<BasicMessageBean> onHarvestComplete(DataBucketBean completed_bucket, IHarvestContext context) {/*ww w. j a va2 s . c o m*/ return CompletableFuture.completedFuture( ErrorUtils.buildMessage(true, this.getClass().getSimpleName(), "onHarvestComplete", "NYI")); }
From source file:com.ikanow.aleph2.graph.titan.services.TitanGraphService.java
@Override public CompletableFuture<BasicMessageBean> switchCrudServiceToPrimaryBuffer(DataBucketBean bucket, Optional<String> secondary_buffer, Optional<String> new_name_for_ex_primary, Optional<String> intermediate_step) { return CompletableFuture.completedFuture(ErrorUtils.buildErrorMessage(this.getClass().getSimpleName(), "switchCrudServiceToPrimaryBuffer", ErrorUtils.BUFFERS_NOT_SUPPORTED, bucket.full_name())); }
From source file:com.ikanow.aleph2.data_model.interfaces.shared_services.MockManagementCrudService.java
@Override public ManagementFuture<Long> deleteObjectsBySpec(QueryComponent<T> spec) { final int curr_size = _mutable_values.size(); _mutable_values.clear();/*from w w w . j av a2 s . c om*/ return FutureUtils.createManagementFuture(CompletableFuture.completedFuture((long) curr_size)); }
From source file:io.pravega.controller.server.eventProcessor.ControllerEventProcessors.java
private CompletableFuture<Void> handleOrphanedReaders( final EventProcessorGroup<? extends ControllerEvent> group, final Supplier<Set<String>> processes) { return withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> { try {//from ww w . j a v a2 s. com return group.getProcesses(); } catch (CheckpointStoreException e) { if (e.getType().equals(CheckpointStoreException.Type.NoNode)) { return Collections.<String>emptySet(); } throw new CompletionException(e); } }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor) .thenComposeAsync(groupProcesses -> withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> { try { return new ImmutablePair<>(processes.get(), groupProcesses); } catch (Exception e) { log.error(String.format("Error fetching current processes%s", group.toString()), e); throw new CompletionException(e); } }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor)).thenComposeAsync(pair -> { Set<String> activeProcesses = pair.getLeft(); Set<String> registeredProcesses = pair.getRight(); if (registeredProcesses == null || registeredProcesses.isEmpty()) { return CompletableFuture.completedFuture(null); } if (activeProcesses != null) { registeredProcesses.removeAll(activeProcesses); } List<CompletableFuture<Void>> futureList = new ArrayList<>(); for (String process : registeredProcesses) { futureList.add(withRetriesAsync(() -> CompletableFuture.runAsync(() -> { try { group.notifyProcessFailure(process); } catch (CheckpointStoreException e) { log.error(String.format( "Error notifying failure of process=%s in event processor group %s", process, group.toString()), e); throw new CompletionException(e); } }, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor)); } return FutureHelpers.allOf(futureList); }); }
From source file:com.ikanow.aleph2.data_model.interfaces.shared_services.MockManagementCrudService.java
@Override public ManagementFuture<Boolean> deleteDatastore() { _mutable_values.clear(); return FutureUtils.createManagementFuture(CompletableFuture.completedFuture(true)); }
From source file:com.ikanow.aleph2.aleph2_rest_utils.SharedLibraryCrudServiceWrapper.java
@Override public CompletableFuture<Boolean> deleteObjectById(Object id) { //delete from shared lib, then delete from filesys //have to get shared lib entry, so we know where the file is on filesys final Optional<SharedLibraryBean> shared_library_bean = shared_library_crud.getObjectById(id).join(); return shared_library_bean.map(slb -> { return shared_library_crud.deleteObjectById(id).<Boolean>thenCompose(f -> { if (f) { final Tuple2<ICrudService<FileDescriptor>, FileDescriptor> storage = getSharedLibraryDataStore( service_context, slb.path_name(), new FileDescriptor(null, null)); return storage._1.deleteObjectById(storage._2.file_name()); } else { return CompletableFuture.completedFuture(f); //false, shared object delete must have failed }/*from ww w .j a v a2s.c o m*/ }); }).orElseGet(() -> CompletableFuture.completedFuture(false)); }
From source file:com.ikanow.aleph2.example.flume_harvester.services.FlumeHarvestTechnology.java
@Override public CompletableFuture<BasicMessageBean> onPurge(DataBucketBean to_purge, IHarvestContext context) { // Do nothing: this isn't like logstash where the files persist, you have to copy new files in anyway return CompletableFuture.completedFuture( new BasicMessageBean(new Date(), true, "onPurge", "onPurge", null, "No action taken", null)); }