1 package com.atlassian.vcache.internal;
2
3 import java.util.Optional;
4 import java.util.function.Supplier;
5
6 /**
7 * Represents the context for a request. Implementations must be thread-safe.
8 *
9 * @since 1.0.0
10 */
11 public interface RequestContext {
12 /**
13 * Returns the partition identifier
14 *
15 * @return the partition identifier
16 */
17 String partitionIdentifier();
18
19 /**
20 * Returns the value associated with the specified key, or computes it atomically using the provided
21 * supplier. The provided supplier <b>must not</b> attempt to perform any other mutations on the
22 * request context.
23 *
24 * @param key the key to retrieve the value under.
25 * @param supplier the supplier to create the missing value. Should be short and sweet and not mutate the
26 * request context.
27 * @param <T> the return type
28 * @return the current value associated with the key, or a new value created with the provided supplier.
29 */
30 <T> T computeIfAbsent(Object key, Supplier<T> supplier);
31
32 /**
33 * Returns the value associated with the specified key, or {@link java.util.Optional#empty()}.
34 */
35 <T> Optional<T> get(Object key);
36 }