/** creates an instance wrapping a {@link SoftReference}, so it might go absent later on. * if null is supplied the result is a present null. */ public static <T> Maybe<T> soft(@Nonnull T value) { return softThen(value, null); } /** creates an instance wrapping a {@link SoftReference}, using the second item given
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void setSubmittedByTask(Task<?> task) { submittedByTask = Maybe.softThen((Task)task, (Maybe)Maybe.of(BasicTask.newGoneTaskFor(task))); }
/** creates a tag suitable for marking a stream available on a task, but which might be GC'd */ public static WrappedStream tagForStreamSoft(String streamType, ByteArrayOutputStream stream) { MemoryUsageTracker.SOFT_REFERENCES.track(stream, stream.size()); Maybe<ByteArrayOutputStream> weakStream = Maybe.softThen(stream, STREAM_GARBAGE_COLLECTED_MAYBE); return new WrappedStream(streamType, Suppliers.compose(Functions.toStringFunction(), weakStream), Suppliers.compose(Streams.sizeFunction(), weakStream)); }