2  * Copyright 2015 Open Networking Laboratory
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  17 package org.onosproject.store.consistent.impl;
 
  19 import java.util.Collection;
 
  21 import java.util.Map.Entry;
 
  24 import org.onosproject.store.service.Transaction;
 
  25 import org.onosproject.store.service.Versioned;
 
  27 import net.kuujo.copycat.state.Command;
 
  28 import net.kuujo.copycat.state.Initializer;
 
  29 import net.kuujo.copycat.state.Query;
 
  30 import net.kuujo.copycat.state.StateContext;
 
  36 public interface DatabaseState<K, V> {
 
  39    * Initializes the database state.
 
  41    * @param context The map state context.
 
  44   void init(StateContext<DatabaseState<K, V>> context);
 
  50   Map<String, Long> counters();
 
  53   int mapSize(String mapName);
 
  56   boolean mapIsEmpty(String mapName);
 
  59   boolean mapContainsKey(String mapName, K key);
 
  62   boolean mapContainsValue(String mapName, V value);
 
  65   Versioned<V> mapGet(String mapName, K key);
 
  68   Result<UpdateResult<K, V>> mapUpdate(String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);
 
  71   Result<Void> mapClear(String mapName);
 
  74   Set<K> mapKeySet(String mapName);
 
  77   Collection<Versioned<V>> mapValues(String mapName);
 
  80   Set<Entry<K, Versioned<V>>> mapEntrySet(String mapName);
 
  83   Long counterAddAndGet(String counterName, long delta);
 
  86   Long counterGetAndAdd(String counterName, long delta);
 
  89   Long queueSize(String queueName);
 
  92   byte[] queuePeek(String queueName);
 
  95   byte[] queuePop(String queueName);
 
  98   void queuePush(String queueName, byte[] entry);
 
 101   Long counterGet(String counterName);
 
 104   CommitResponse prepareAndCommit(Transaction transaction);
 
 107   boolean prepare(Transaction transaction);
 
 110   CommitResponse commit(Transaction transaction);
 
 113   boolean rollback(Transaction transaction);