View Javadoc
1   package org.eclipse.aether;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * A container for data that is specific to a repository system session. Both components within the repository system
24   * and clients of the system may use this storage to associate arbitrary data with a session.
25   * <p>
26   * Unlike a cache, this session data is not subject to purging. For this same reason, session data should also not be
27   * abused as a cache (i.e. for storing values that can be re-calculated) to avoid memory exhaustion.
28   * <p>
29   * <strong>Note:</strong> Actual implementations must be thread-safe.
30   * 
31   * @see RepositorySystemSession#getData()
32   * @noimplement This interface is not intended to be implemented by clients.
33   * @noextend This interface is not intended to be extended by clients.
34   */
35  public interface SessionData
36  {
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  }