001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether; 020 021import java.util.function.Supplier; 022 023/** 024 * A container for data that is specific to a repository system session. Both components within the repository system 025 * and clients of the system may use this storage to associate arbitrary data with a session. 026 * <p> 027 * Unlike a cache, this session data is not subject to purging. For this same reason, session data should also not be 028 * abused as a cache (i.e. for storing values that can be re-calculated) to avoid memory exhaustion. 029 * <p> 030 * <strong>Note:</strong> Actual implementations must be thread-safe. 031 * 032 * @see RepositorySystemSession#getData() 033 * @noimplement This interface is not intended to be implemented by clients. 034 * @noextend This interface is not intended to be extended by clients. 035 */ 036public interface SessionData { 037 038 /** 039 * Associates the specified session data with the given key. 040 * 041 * @param key The key under which to store the session data, must not be {@code null}. 042 * @param value The data to associate with the key, may be {@code null} to remove the mapping. 043 */ 044 void set(Object key, Object value); 045 046 /** 047 * Associates the specified session data with the given key if the key is currently mapped to the given value. This 048 * method provides an atomic compare-and-update of some key's value. 049 * 050 * @param key The key under which to store the session data, must not be {@code null}. 051 * @param oldValue The expected data currently associated with the key, may be {@code null}. 052 * @param newValue The data to associate with the key, may be {@code null} to remove the mapping. 053 * @return {@code true} if the key mapping was successfully updated from the old value to the new value, 054 * {@code false} if the current key mapping didn't match the expected value and was not updated. 055 */ 056 boolean set(Object key, Object oldValue, Object newValue); 057 058 /** 059 * Gets the session data associated with the specified key. 060 * 061 * @param key The key for which to retrieve the session data, must not be {@code null}. 062 * @return The session data associated with the key or {@code null} if none. 063 */ 064 Object get(Object key); 065 066 /** 067 * Retrieve of compute the data associated with the specified key. 068 * 069 * @param key The key for which to retrieve the session data, must not be {@code null}. 070 * @param supplier The supplier will compute the new value. 071 * @return The session data associated with the key. 072 */ 073 Object computeIfAbsent(Object key, Supplier<Object> supplier); 074}