@Override public Promise<Boolean> exists(final AttachmentKey attachmentKey) { return Promises.promise(false); }
@Override public Promise<Void> deleteThumbnailDirectory(@Nonnull final Issue issue) { final File thumbnailDirectory = attachmentDirectoryAccessor.getThumbnailDirectory(issue, false); try { FileUtils.deleteDirectory(thumbnailDirectory); return Promises.promise(null); } catch (IOException e) { return Promises.rejected(new AttachmentCleanupException(e)); } }
/** * Returns a new {@link Promise} representing the status of a list of other * promises. More generally this is known as {code}sequence{code} as both List * and Promise are traversable monads. * * @param promises The promises that the new promise should track * @return The new, aggregate promise */ public static <A> Promise<List<A>> when(Iterable<? extends Promise<? extends A>> promises) { return forListenableFuture(Futures.<A> allAsList(promises)); }
if (defaultLinkOption.isEmpty()) { logger.debug("The link has been removed since triggering the upgrade - could be due to work in another node of a cluster."); return Promises.rejected(new LinkNotFoundException(), null); } else { HipChatLink hipChatLink = defaultLinkOption.get(); Promises.when(lastSynchronisedConnectDescriptorPromise, currentCapabilitiesConnectDescriptorPromise) .done(new Effect<List<ConnectDescriptor>>() { @Override return Promises.forListenableFuture(complete);
/** * Creates a new, rejected promise from the given Throwable and result type. * <p> * Synonym for {@link #rejected(Throwable, Class)} * * @param t The throwable * @return The new promise */ public static <A> Promise<A> toRejectedPromise(Throwable t) { return rejected(t); }
/** * Returns a new {@link Promise} representing the status of a list of other * promises. * * @param promises The promises that the new promise should track * @return The new, aggregate promise */ public static <A> Promise<List<A>> when(Promise<? extends A>... promises) { return when(asList(promises)); }
/** * Create a {@link FutureCallback} from an Effect to be run if there is a * success. * * @param effect To be passed the produced value if it happens * @return The FutureCallback with a no-op onFailure */ public static <A> FutureCallback<A> onSuccessDo(final Effect<? super A> effect) { return futureCallback(effect, Effects.<Throwable> noop()); }
/** * Creates a new, rejected promise from the given {@link Throwable} and result * type. * * @param throwable The throwable * @param resultType The result type * @return The new promise * @deprecated Use {@link #rejected(Throwable)} * @since 2.5.0 */ public static <A> Promise<A> rejected(Throwable throwable, Class<A> resultType) { return rejected(throwable); }
private Promise<Result<List<CollapsedRoom>>> getRooms(final HipChatAPI hipChatAPI, final int startIndex, final ImmutableList.Builder<CollapsedRoom> currentRooms, final boolean includePrivate) { final ImmutableList.Builder<Promise<Result<AllRoomsResult>>> builder = ImmutableList.builder(); for (int i = 0; i < BATCH_SIZE; i++) { builder.add(hipChatAPI.rooms() .getAllRooms() .startIndex(startIndex + i * PAGE_SIZE) .maxResults(PAGE_SIZE) .includePrivate(includePrivate) .build()); } return Promises.when(builder.build()) .flatMap(toRoomList(hipChatAPI, startIndex, currentRooms, includePrivate)); }
/** * Create a {@link FutureCallback} from an Effect to be run if there is a * failure. * * @param effect To be passed an exception if it happens * @return The FutureCallback with a no-op onSuccess */ public static <A> FutureCallback<A> onFailureDo(final Effect<Throwable> effect) { return futureCallback(Effects.<A> noop(), effect); }
/** * Creates a new, resolved promise for the specified concrete value. * <p> * Synonym for {@link #promise(Object)}. * * @param value The value for which a promise should be created * @return The new promise */ public static <A> Promise<A> toResolvedPromise(A value) { return promise(value); }
@Override public Promise<Unit> deleteAttachmentContainerForIssue(final Issue issue) { Preconditions.checkNotNull(issue); final File attachmentDir = directoryAccessor.getAttachmentDirectory(issue); try { FileUtils.deleteDirectory(attachmentDir); eventPublisher.publish(new JiraHomeChangeEvent(JiraHomeChangeEvent.Action.FILE_DELETED, JiraHomeChangeEvent.FileType.ATTACHMENT, attachmentDir)); return Promises.promise(Unit.VALUE); } catch (final IOException e) { return Promises.rejected(new AttachmentCleanupException(e)); } }
/** * Creates a new, rejected promise from the given Throwable and result type. * <p> * Synonym for {@link #rejected(Throwable, Class)} * * @param t The throwable * @param resultType The result type * @return The new promise * @deprecated Use {@link #toRejectedPromise(Throwable)} * @since 2.5.0 */ public static <A> Promise<A> toRejectedPromise(Throwable t, Class<A> resultType) { return rejected(t); }
FutureOperation(final Callable<T> operation) { this.operation = operation; this.future = SettableFuture.create(); this.promise = Promises.forListenableFuture(future); }
private Promise<Map<String, Result<ExpandedRoom>>> expandRoomsForIds(final HipChatAPI hipChatAPI, final Iterable<String> roomIds, final ImmutableMap.Builder<String, Result<ExpandedRoom>> results) { final ImmutableList.Builder<Promise<RoomResult>> builder = ImmutableList .builder(); final boolean usingPersonalToken = hipChatAPI.getTokenType() instanceof HipChatAPI.TokenType.PersonalToken; //Only schedule at most BATCH_SIZE requests for (final String roomId : Iterables.take(BATCH_SIZE, roomIds)) { Promise<Result<ExpandedRoom>> roomPromise = hipChatAPI.rooms() .getRoom(roomId); if (!usingPersonalToken) { roomPromise = roomPromise.map(FILTER_PRIVATE_ROOM); } builder.add(roomPromise.map(toRoomResult(roomId))); } return Promises.when(builder.build()).flatMap(expandRoomBatch(hipChatAPI, roomIds, results)); }
private Promise<Unit> getUnitPromise() {return Promises.promise(Unit.VALUE);} }
@Override public Promise<Unit> deleteAttachment(final AttachmentKey attachmentKey) { try { final File attachmentFile = getAttachmentFile(attachmentKey); if (attachmentFile.exists()) { if (!attachmentFile.delete()) { log.warn("Failed to delete attachmentFile: " + attachmentFile.getAbsolutePath()); } eventPublisher.publish(new JiraHomeChangeEvent(JiraHomeChangeEvent.Action.FILE_DELETED, JiraHomeChangeEvent.FileType.ATTACHMENT, attachmentFile)); } else { log.warn("Trying to delete non-existent attachment: [" + attachmentFile.getAbsolutePath() + "] ..ignoring"); } } catch (final DataAccessException e) { Promises.rejected(new AttachmentCleanupException(e)); } return Promises.promise(Unit.VALUE); }
private <A> Promise<A> fail() { return Promises.rejected(new UnsupportedOperationException(MESSAGE)); }
@Override public <B> Promise<B> map(Function<? super A, ? extends B> function) { return forListenableFuture(Futures.transform(this, function)); }
Promises.when(ImmutableList.copyOf(Iterables.transform(attachments, move))).claim(); deleteThumbnailsDirectoryForIssue(oldIssue);