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 import java.util.function.Supplier; 23 24 /** 25 * A container for data that is specific to a repository system session. Both components within the repository system 26 * and clients of the system may use this storage to associate arbitrary data with a session. 27 * <p> 28 * Unlike a cache, this session data is not subject to purging. For this same reason, session data should also not be 29 * abused as a cache (i.e. for storing values that can be re-calculated) to avoid memory exhaustion. 30 * <p> 31 * <strong>Note:</strong> Actual implementations must be thread-safe. 32 * 33 * @see RepositorySystemSession#getData() 34 * @noimplement This interface is not intended to be implemented by clients. 35 * @noextend This interface is not intended to be extended by clients. 36 */ 37 public interface SessionData 38 { 39 40 /** 41 * Associates the specified session data with the given key. 42 * 43 * @param key The key under which to store the session data, must not be {@code null}. 44 * @param value The data to associate with the key, may be {@code null} to remove the mapping. 45 */ 46 void set( Object key, Object value ); 47 48 /** 49 * Associates the specified session data with the given key if the key is currently mapped to the given value. This 50 * method provides an atomic compare-and-update of some key's value. 51 * 52 * @param key The key under which to store the session data, must not be {@code null}. 53 * @param oldValue The expected data currently associated with the key, may be {@code null}. 54 * @param newValue The data to associate with the key, may be {@code null} to remove the mapping. 55 * @return {@code true} if the key mapping was successfully updated from the old value to the new value, 56 * {@code false} if the current key mapping didn't match the expected value and was not updated. 57 */ 58 boolean set( Object key, Object oldValue, Object newValue ); 59 60 /** 61 * Gets the session data associated with the specified key. 62 * 63 * @param key The key for which to retrieve the session data, must not be {@code null}. 64 * @return The session data associated with the key or {@code null} if none. 65 */ 66 Object get( Object key ); 67 68 /** 69 * Retrieve of compute the data associated with the specified key. 70 * 71 * @param key The key for which to retrieve the session data, must not be {@code null}. 72 * @param supplier The supplier will compute the new value. 73 * @return The session data associated with the key. 74 */ 75 Object computeIfAbsent( Object key, Supplier<Object> supplier ); 76 77 }