View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether;
20  
21  import java.util.function.Supplier;
22  
23  /**
24   * A container for data that is specific to a repository system session. Both components within the repository system
25   * and clients of the system may use this storage to associate arbitrary data with a session.
26   * <p>
27   * Unlike a cache, this session data is not subject to purging. For this same reason, session data should also not be
28   * abused as a cache (i.e. for storing values that can be re-calculated) to avoid memory exhaustion.
29   * <p>
30   * <strong>Note:</strong> Actual implementations must be thread-safe.
31   *
32   * @see RepositorySystemSession#getData()
33   * @noimplement This interface is not intended to be implemented by clients.
34   * @noextend This interface is not intended to be extended by clients.
35   */
36  public interface SessionData {
37  
38      /**
39       * Associates the specified session data with the given key.
40       *
41       * @param key The key under which to store the session data, must not be {@code null}.
42       * @param value The data to associate with the key, may be {@code null} to remove the mapping.
43       */
44      void set(Object key, Object value);
45  
46      /**
47       * Associates the specified session data with the given key if the key is currently mapped to the given value. This
48       * method provides an atomic compare-and-update of some key's value.
49       *
50       * @param key The key under which to store the session data, must not be {@code null}.
51       * @param oldValue The expected data currently associated with the key, may be {@code null}.
52       * @param newValue The data to associate with the key, may be {@code null} to remove the mapping.
53       * @return {@code true} if the key mapping was successfully updated from the old value to the new value,
54       *         {@code false} if the current key mapping didn't match the expected value and was not updated.
55       */
56      boolean set(Object key, Object oldValue, Object newValue);
57  
58      /**
59       * Gets the session data associated with the specified key.
60       *
61       * @param key The key for which to retrieve the session data, must not be {@code null}.
62       * @return The session data associated with the key or {@code null} if none.
63       */
64      Object get(Object key);
65  
66      /**
67       * Retrieve of compute the data associated with the specified key.
68       *
69       * @param key The key for which to retrieve the session data, must not be {@code null}.
70       * @param supplier The supplier will compute the new value.
71       * @return The session data associated with the key.
72       */
73      Object computeIfAbsent(Object key, Supplier<Object> supplier);
74  }