當前位置: 首頁>>代碼示例>>Java>>正文


Java Completable類代碼示例

本文整理匯總了Java中io.reactivex.Completable的典型用法代碼示例。如果您正苦於以下問題:Java Completable類的具體用法?Java Completable怎麽用?Java Completable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Completable類屬於io.reactivex包,在下文中一共展示了Completable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: remove

import io.reactivex.Completable; //導入依賴的package包/類
@Override
public Completable remove(K... keys) {
    return Completable.fromAction(() -> {
        try (Jedis jedis = pool.getResource()) {
            String[] fullKeys = new String[keys.length];

            for (int i = 0; i < keys.length; i++) {
                fullKeys[i] = buildKey(keys[i]);
            }

            jedis.del(fullKeys);
        } catch (Exception e) {
            LOG.error("Could not write to Redis", e);

            throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e);
        }
    });
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:19,代碼來源:RedisDaoImpl.java

示例2: storeComminities

import io.reactivex.Completable; //導入依賴的package包/類
@Override
public Completable storeComminities(int accountId, List<CommunityEntity> communities, int userId, boolean invalidateBefore) {
    return Completable.create(emitter -> {
        Uri uri = MessengerContentProvider.getRelativeshipContentUriFor(accountId);
        ArrayList<ContentProviderOperation> operations = new ArrayList<>(communities.size() * 2 + 1);

        if (invalidateBefore) {
            operations.add(clearOperationFor(accountId, userId, RelationshipColumns.TYPE_MEMBER));
        }

        for (CommunityEntity dbo : communities) {
            operations.add(ContentProviderOperation.newInsert(uri)
                    .withValues(RelationshipColumns.getCV(userId, -dbo.getId(), RelationshipColumns.TYPE_MEMBER))
                    .build());
        }

        OwnersRepositiry.appendCommunitiesInsertOperation(operations, accountId, communities);
        getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
        emitter.onComplete();
    });
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:22,代碼來源:RelativeshipStore.java

示例3: resetPassword

import io.reactivex.Completable; //導入依賴的package包/類
@Override
public Completable resetPassword(Long userId, PasswordCredentials credentials) {
    AuthenticatedEntity.authenticatedAsAdmin(RequestContextAccessor.get().getAuthenticated());

    User user = new User();
    user.setId(userId);

    return FacadePolicies.singleOrException(
                authenticationFacade.getCredentialsForAuthenticatable(user)
                    .filter((userCredentials) -> PasswordCredentials.class.isAssignableFrom(userCredentials.getClass())),
                HttpStatus.SC_INTERNAL_SERVER_ERROR,
                "Could not determine user's login credentials")

            // Update the password to the new value
            .flatMap((passwordCredentials) -> {
                    // Invalidate the salt caches
                    cacheManager.evictForGroup(passwordSaltCacheGroup, ((PasswordCredentials) passwordCredentials).getEmailAddress());

                    credentials.setEmailAddress(((PasswordCredentials) passwordCredentials).getEmailAddress()); // Copy over the email address
                    user.setCredentials(credentials);

                    return authenticationFacade.revokeCredentials(user) // Revoke all existing credentials
                            .andThen(generateEmailCredentials(user)); // Create the new credentials

            }).toCompletable();
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:27,代碼來源:PasswordCredentialsFacadeImpl.java

示例4: setValue

import io.reactivex.Completable; //導入依賴的package包/類
/**
 * Set the given value on the specified {@link DatabaseReference}.
 *
 * @param ref reference represents a particular location in your database.
 * @param value value to update.
 * @return a {@link Completable} which is complete when the set value call finish successfully.
 */
@NonNull
public static Completable setValue(@NonNull final DatabaseReference ref,
                                   final Object value) {
   return Completable.create(new CompletableOnSubscribe() {
      @Override
      public void subscribe(@io.reactivex.annotations.NonNull final CompletableEmitter e) throws Exception {
         ref.setValue(value).addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override public void onSuccess(Void aVoid) {
               e.onComplete();
            }
         }).addOnFailureListener(new OnFailureListener() {
            @Override public void onFailure(@NonNull Exception exception) {
               e.onError(exception);
            }
         });
      }
   });
}
 
開發者ID:DVT,項目名稱:showcase-android,代碼行數:26,代碼來源:RxFirebaseDatabase.java

示例5: insertPeerDbos

import io.reactivex.Completable; //導入依賴的package包/類
@Override
public Completable insertPeerDbos(int accountId, int peerId, @NonNull List<MessageEntity> dbos, boolean clearHistory) {
    return Completable.create(emitter -> {
        ArrayList<ContentProviderOperation> operations = new ArrayList<>();

        if (clearHistory) {
            Uri uri = MessengerContentProvider.getMessageContentUriFor(accountId);
            String where = MessageColumns.PEER_ID + " = ? AND " + MessageColumns.ATTACH_TO + " = ? AND " + MessageColumns.STATUS + " = ?";
            String[] args = new String[]{String.valueOf(peerId), String.valueOf(MessageColumns.DONT_ATTACH), String.valueOf(MessageStatus.SENT)};

            operations.add(ContentProviderOperation.newDelete(uri).withSelection(where, args).build());
        }

        for (MessageEntity dbo : dbos) {
            appendDboOperation(accountId, dbo, operations, null, null);
        }

        getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
        emitter.onComplete();
    });
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:22,代碼來源:MessagesStore.java

示例6: testBackPressure

import io.reactivex.Completable; //導入依賴的package包/類
@Test
public void testBackPressure() {
  AtomicInteger counter = new AtomicInteger();
  Publisher<Integer> publisher = Flowable.range(0, 5000);

  Sink<Integer> slow = data -> Completable.fromAction(() -> {
    Thread.sleep(10);
    counter.incrementAndGet();
  });

  Source.fromPayloads(publisher)
    .transformFlow(f -> f
      .observeOn(Schedulers.computation()))
    .to(slow);

  await()
    .atMost(1, TimeUnit.MINUTES)
    .untilAtomic(counter, is(greaterThan(4000)));

  assertThat(counter.doubleValue()).isGreaterThan(4000.0);
}
 
開發者ID:cescoffier,項目名稱:fluid,代碼行數:22,代碼來源:SinkTest.java

示例7: testForEachAsync

import io.reactivex.Completable; //導入依賴的package包/類
@Test
public void testForEachAsync() {
  List<Data<Integer>> list = new ArrayList<>();
  Sink<Integer> sink = Sink.forEachAsync(i -> {
    list.add(i);
    return Completable.complete();
  });
  assertThat(sink.name()).isNull();
  Completable c1 = sink.dispatch(1);
  Completable c2 = sink.dispatch(2);
  Completable c3 = sink.dispatch(3);

  assertThat(c1.blockingGet()).isNull();
  assertThat(c2.blockingGet()).isNull();
  assertThat(c3.blockingGet()).isNull();

  assertThat(list.stream().map(Data::payload).collect(Collectors.toList()))
    .containsExactly(1, 2, 3);
}
 
開發者ID:cescoffier,項目名稱:fluid,代碼行數:20,代碼來源:SinkTest.java

示例8: loadImageInto

import io.reactivex.Completable; //導入依賴的package包/類
private Completable loadImageInto(ImageView im, Pokemon pk) {
    return Completable.create(e -> picasso.load(PokeQuestApp.BASE_URL + pk.getImageUrl())
            .placeholder(R.drawable.pokeball_padding)
            .error(R.drawable.pokeball)
            .into(im, new Callback() {
                @Override
                public void onSuccess() {
                    e.onComplete();
                }

                @Override
                public void onError() {
                    e.onError(new Throwable("Error when loading poke image at id=" + pk.getId()));
                }
            }));

}
 
開發者ID:datdescartes,項目名稱:pokequest,代碼行數:18,代碼來源:PokeQuizPickImage.java

示例9: dismissAlarm

import io.reactivex.Completable; //導入依賴的package包/類
@Override
public Completable dismissAlarm() {
    if (mediaPlayer != null) {
        mediaPlayer.stop();
        mediaPlayer.release();
        mediaPlayer = null;
    }

    if (vibe != null) {
        vibe.cancel();
    }

    if (wakeLock != null && wakeLock.isHeld()) {
        wakeLock.release();
    }

    return Completable.complete();
}
 
開發者ID:BracketCove,項目名稱:PosTrainer,代碼行數:19,代碼來源:AlarmService.java

示例10: leave

import io.reactivex.Completable; //導入依賴的package包/類
public static Completable leave(final View view, final int xOffset, final int yOffset) {
    final float startingX = view.getX();
    final float startingY = view.getY();
    return animate(view, new AccelerateInterpolator())
            .fadeOut()
            .translateBy(xOffset, yOffset)
            .onAnimationCancel(aView -> set(aView, startingX, startingY, TRANSPARENT))
            .schedule(false);
}
 
開發者ID:0ximDigital,項目名稱:Rx2Animations,代碼行數:10,代碼來源:RxAnimations.java

示例11: remove

import io.reactivex.Completable; //導入依賴的package包/類
@Override
public Completable remove(int accountId, @AttachToType int attachToType, int attachToDbid, int generatedAttachmentId) {
    return Completable.create(e -> {
        Uri uri = uriForType(attachToType, accountId);

        String selection = idColumnFor(attachToType) + " = ?";
        String[] args = {String.valueOf(generatedAttachmentId)};

        int count = getContext().getContentResolver().delete(uri, selection, args);

        if (count > 0) {
            e.onComplete();
        } else {
            e.onError(new NotFoundException());
        }
    });
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:18,代碼來源:AttachmentsStore.java

示例12: deleteLocation

import io.reactivex.Completable; //導入依賴的package包/類
public Completable deleteLocation(Location location) {
    return Completable.fromAction(() -> {
        try (BriteDatabase.Transaction transaction =
                     dbHelper.getBriteDatabase().newTransaction()) {
            dbHelper.blockingDeleteByValue(entityRegistry.location.getTableName(),
                    entityRegistry.location.getIdColumn(), location.getId());
            dbHelper.blockingDeleteByValue(entityRegistry.concert.getTableName(),
                    Contract.ConcertsTable.COLUMN_LOCATION_ID, location.getId());
            dbHelper.blockingDeleteByValue(entityRegistry.syncState.getTableName(),
                    Contract.SyncStatesTable.COLUMN_LOCATION_ID, location.getId());

            transaction.markSuccessful();
        }
    })
            .subscribeOn(schedulerProvider.io());
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:17,代碼來源:LocationRepository.java

示例13: commitMinorUpdate

import io.reactivex.Completable; //導入依賴的package包/類
@Override
public Completable commitMinorUpdate(CommentUpdate update) {
    return Completable.fromAction(() -> {
        ContentValues cv = new ContentValues();

        if (update.hasLikesUpdate()) {
            cv.put(CommentsColumns.USER_LIKES, update.getLikeUpdate().isUserLikes());
            cv.put(CommentsColumns.LIKES, update.getLikeUpdate().getCount());
        }

        if (update.hasDeleteUpdate()) {
            cv.put(CommentsColumns.DELETED, update.getDeleteUpdate().isDeleted());
        }

        Uri uri = MessengerContentProvider.getCommentsContentUriFor(update.getAccountId());

        String where = CommentsColumns.SOURCE_OWNER_ID + " = ? AND " + CommentsColumns.COMMENT_ID + " = ?";
        String[] args = {String.valueOf(update.getCommented().getSourceOwnerId()), String.valueOf(update.getCommentId())};

        getContentResolver().update(uri, cv, where, args);

        minorUpdatesPublisher.onNext(update);
    });
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:25,代碼來源:CommentsStore.java

示例14: demo5

import io.reactivex.Completable; //導入依賴的package包/類
private void demo5() {
    Completable completable = Completable.fromAction(() -> {
        log("Let's do something");
    });

    completable.subscribe(() -> {
        log("Finished");
    }, throwable -> {
        log(throwable);
    });


    Single.just("One item")
            .subscribe((item) -> {
                log(item);
            }, (throwable) -> {
                log(throwable);
            });

    Maybe.empty();
    Maybe.just("Item")
            .subscribe(s -> {
                log("On Success: " + s);
            });

    Maybe.just("Item")
            .subscribe(s -> {
                log("On Success: " + s);
            }, throwable -> log("error"));

    Maybe.just("Item")
            .subscribe(
                    s -> log("success: " + s),
                    throwable -> log("error"),
                    () -> log("onComplete")
            );
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Android-Programming,代碼行數:38,代碼來源:MainActivity.java

示例15: addProduct

import io.reactivex.Completable; //導入依賴的package包/類
/**
 * Adds a product to the shopping cart
 */
public Completable addProduct(Product product) {
  List<Product> updatedShoppingCart = new ArrayList<>();
  updatedShoppingCart.addAll(itemsInShoppingCart.getValue());
  updatedShoppingCart.add(product);
  itemsInShoppingCart.onNext(updatedShoppingCart);
  return Completable.complete();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:ShoppingCart.java


注:本文中的io.reactivex.Completable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。