/** * Convenience method that simply calls {@link #weakLockManager(Function)} * with the identity function. So all inputs map directly to an individual * lock. * * @param <T> the type of the thing used to look up locks * @deprecated use {@link ManagedLocks#weakManagedLockFactory()} instead. */ @Deprecated public static <T> LockManager<T> weakLockManager() { return weakLockManager(Functions.<T> identity()); }
public <T> Function<Supplier<T>, Supplier<T>> handler() { return Functions.<T> ignoreExceptions(); } },
private <T, R> Function<T, R> toGoogleFunction(final com.atlassian.util.concurrent.Function<T, R> inputStreamProcessor) { return com.atlassian.util.concurrent.Functions.toGoogleFunction(inputStreamProcessor); }
/** * Implementation for the invokeAll methods, needs to be passed an accessor * function that is responsible for getting things from the CompletionService. */ <T> Iterable<T> invokeAllTasks(final Iterable<? extends Callable<T>> callables, final Accessor<T> accessor) { final CompletionService<T> apply = completionServiceDecorator.apply(completionServiceFactory.<T> create().apply(executor)); // we must copy the resulting Iterable<Supplier> so // each iteration doesn't resubmit the jobs final Iterable<Supplier<T>> lazyAsyncSuppliers = copyOf(transform(callables, new AsyncCompletionFunction<T>(apply, accessor))); final Iterable<Supplier<T>> handled = transform(lazyAsyncSuppliers, policy.<T> handler()); return filter(transform(handled, Functions.<T> fromSupplier()), notNull()); }
final Function<D, ManagedLock> lockFactory = fromSupplier(managedLockFactory(lockFactory())); return createManager(stripeFunction, weakMemoizer(lockFactory));
/** * Create a {@link Function} for resolving {@link ManagedLock managed locks} . * The particular lock is resolved using a striping {@link Function} that is * used look up a lock instance. This allows for a finite set of locks to be * used even if the set of T is essentially unbounded. The locks are stored * using weak references so infrequently accessed locks should not use excess * memory. * * @param <T> the type of the thing used to look up locks * @param <D> the type used to map lock instances, should be a good map key * @param stripeFunction to convert the input to the thing used to look up the * individual locks * @param lockFactory the factory for creating the individual locks * @return a new {@link Function} that provides {@link ManagedLock} instances * that stores created instances with weak references. */ public static @NotNull <T, D> com.atlassian.util.concurrent.Function<T, ManagedLock> weakManagedLockFactory( final @NotNull Function<T, D> stripeFunction, final @NotNull Supplier<Lock> lockFactory) { final Function<D, ManagedLock> lockFunction = fromSupplier(managedLockFactory(lockFactory)); return managedFactory(weakMemoizer(lockFunction), stripeFunction); }
/** * Convenience method that calls * {@link ManagedLocks#weakManagedLockFactory(Function)} using the * {@link Functions#identity() identity function} for striping, essentially * meaning that unique input will have its own lock. * * @param <T> the type of the thing used to look up locks * @see #weakManagedLockFactory(Function, Supplier) */ public static @NotNull <T> com.atlassian.util.concurrent.Function<T, ManagedLock> weakManagedLockFactory() { return weakManagedLockFactory(Functions.<T> identity()); }
@Override public Promise<? extends StoreAttachmentResult> get(final TemporaryAttachmentId temporaryAttachmentId) { return moveTemporaryToAttachment(temporaryAttachmentId, attachmentKey).flatMap(Functions.toGoogleFunction(new Function<Unit, Promise<? extends StoreAttachmentResult>>() { @Override public Promise<? extends StoreAttachmentResult> get(final Unit input) { return Promises.promise(StoreAttachmentResult.created()); } })); } }));
/** * Create a {@link Function} for resolving {@link ManagedLock.ReadWrite * managed read-write locks}. The particular lock is resolved using a striping * {@link Function} that is used look up a lock instance. This allows for a * finite set of locks to be used even if the set of T is essentially * unbounded. The locks are stored using weak references so infrequently * accessed locks should not use excess memory. * * @param <T> the type of the thing used to look up locks * @param <D> the type used to map lock instances, should be a good map key * @param stripeFunction to convert the input to the thing used to look up the * individual locks * @param lockFactory the factory for creating the individual locks * @return a new {@link Function} that provides {@link ManagedLock.ReadWrite} * instances that stores created instances with weak references. */ public static @NotNull <T, D> com.atlassian.util.concurrent.Function<T, ManagedLock.ReadWrite> weakReadWriteManagedLockFactory( final @NotNull Function<T, D> stripeFunction, final @NotNull Supplier<ReadWriteLock> lockFactory) { notNull("stripeFunction", stripeFunction); final Function<D, ReadWrite> readWriteManagedLockFactory = fromSupplier(managedReadWriteLockFactory(lockFactory)); final WeakMemoizer<D, ManagedLock.ReadWrite> locks = weakMemoizer(readWriteManagedLockFactory); return new Function<T, ManagedLock.ReadWrite>() { public ManagedLock.ReadWrite get(final T input) { return locks.get(stripeFunction.get(input)); }; }; }
/** * A convenience method for calling * {@link #weakReadWriteManagedLockFactory(Function)} that uses the * {@link Functions#identity() identity function} for striping, essentially * meaning that unique input will have its own lock. * * @param <T> the type of the thing used to look up locks * @return a new {@link Function} that provides the appropriate * {@link ReadWrite} for the argument {@link ManagedLock.ReadWrite} instances * that stores created instances with weak references. */ public static @NotNull <T> com.atlassian.util.concurrent.Function<T, ManagedLock.ReadWrite> weakReadWriteManagedLockFactory() { return weakReadWriteManagedLockFactory(Functions.<T> identity()); }
private Promise<StoreAttachmentResult> putAttachment(final InputStream inputStream, final Long size, final AttachmentKey attachmentKey) { return putTemporaryAttachment(inputStream, size).flatMap(Functions.toGoogleFunction(new Function<TemporaryAttachmentId, Promise<? extends StoreAttachmentResult>>() { @Override public Promise<? extends StoreAttachmentResult> get(final TemporaryAttachmentId temporaryAttachmentId) { return moveTemporaryToAttachment(temporaryAttachmentId, attachmentKey).flatMap(Functions.toGoogleFunction(new Function<Unit, Promise<? extends StoreAttachmentResult>>() { @Override public Promise<? extends StoreAttachmentResult> get(final Unit input) { return Promises.promise(StoreAttachmentResult.created()); } })); } })); }