001/* 002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.storage.kv; 020 021/** 022 * Key/Value Store. 023 * <p> 024 * This is the interface for a Key/Value store, which stores simple values associated to keys. 025 * <p> 026 * A Key/Value store is thread-safe. 027 * 028 * @since 9.1 029 */ 030public interface KeyValueStore { 031 032 /** 033 * Sets the value associated to the key. 034 * 035 * @param key the key 036 * @param value the value, which may be {@code null} 037 */ 038 void put(String key, byte[] value); 039 040 /** 041 * Retrieves the value associated to the key. 042 * 043 * @param key the key 044 * @return the value, or {@code null} if there is no value 045 */ 046 byte[] get(String key); 047 048 /** 049 * Atomically sets the value associated to the key to the given value if the current value is the expected value. 050 * <p> 051 * Note value comparison is done by value and not by reference. 052 * 053 * @param key the key 054 * @param expected the expected value, which may be {@code null} 055 * @param value the updated value, which may be {@code null} 056 * @return {@code true} if the value was updated, or {@code false} if not (the expected value was not found) 057 */ 058 boolean compareAndSet(String key, byte[] expected, byte[] value); 059 060}