001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.spi;
018
019import org.apache.camel.Service;
020
021/**
022 * This {@link StateRepository} holds a set of key/value pairs for defining a particular <em>state</em> of a component. For instance it can be a set of indexes.
023 * <p/>
024 * An {@link IdempotentRepository} behaves more or less like a {@code Set} whereas this {@link StateRepository} behaves like a {@code Map}.
025 *
026 * @param <K> Key type
027 * @param <V> Value type
028 */
029public interface StateRepository<K, V> extends Service {
030
031    /**
032     * Sets the state value for the given key.
033     *
034     * @param key State key
035     * @param value State value
036     */
037    void setState(K key, V value);
038
039    /**
040     * Gets the state value for the given key. It returns {@code null} if the key is unknown.
041     *
042     * @param key State key
043     * @return State value or null the key is unknown
044     */
045    V getState(K key);
046}
047