Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Commit

Permalink
Move classes using coroutines out of experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
cleishm committed Nov 1, 2018
1 parent 8f2cbc3 commit 05a6d12
Show file tree
Hide file tree
Showing 38 changed files with 328 additions and 703 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
import net.consensys.cava.bytes.Bytes;
import net.consensys.cava.io.Resources;
import net.consensys.cava.junit.BouncyCastleExtension;
import net.consensys.cava.trie.experimental.MerklePatriciaTrie;
import net.consensys.cava.trie.MerklePatriciaTrie;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -50,7 +49,7 @@ private Bytes readFromString(String value) {
@MethodSource("readAnyOrderTrieTests")
@SuppressWarnings({"unchecked", "rawtypes"})
void testAnyOrderTrieTrees(String name, Map input, String root) throws Exception {
MerklePatriciaTrie<String> trie = new MerklePatriciaTrie<>((Function<String, Bytes>) this::readFromString);
MerklePatriciaTrie<String> trie = MerklePatriciaTrie.create(this::readFromString);
for (Object entry : input.entrySet()) {
Map.Entry keyValue = (Map.Entry) entry;
trie.putAsync(readFromString((String) keyValue.getKey()), (String) keyValue.getValue()).join();
Expand All @@ -62,7 +61,7 @@ void testAnyOrderTrieTrees(String name, Map input, String root) throws Exception
@MethodSource("readTrieTests")
@SuppressWarnings({"unchecked", "rawtypes"})
void testTrieTrees(String name, List input, String root) throws Exception {
MerklePatriciaTrie<String> trie = new MerklePatriciaTrie<>((Function<String, Bytes>) this::readFromString);
MerklePatriciaTrie<String> trie = MerklePatriciaTrie.create(this::readFromString);
for (Object entry : input) {
List keyValue = (List) entry;
trie.putAsync(readFromString((String) keyValue.get(0)), (String) keyValue.get(1)).join();
Expand Down
46 changes: 0 additions & 46 deletions kv/src/main/java/net/consensys/cava/kv/KeyValueStore.java

This file was deleted.

47 changes: 0 additions & 47 deletions kv/src/main/java/net/consensys/cava/kv/LevelDBKeyValueStore.java

This file was deleted.

33 changes: 0 additions & 33 deletions kv/src/main/java/net/consensys/cava/kv/MapDBKeyValueStore.java

This file was deleted.

44 changes: 0 additions & 44 deletions kv/src/main/java/net/consensys/cava/kv/MapKeyValueStore.java

This file was deleted.

75 changes: 0 additions & 75 deletions kv/src/main/java/net/consensys/cava/kv/RedisKeyValueStore.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package net.consensys.cava.kv.experimental
package net.consensys.cava.kv

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
Expand All @@ -20,13 +20,12 @@ import net.consensys.cava.concurrent.AsyncCompletion
import net.consensys.cava.concurrent.AsyncResult
import net.consensys.cava.concurrent.coroutines.asyncCompletion
import net.consensys.cava.concurrent.coroutines.asyncResult
import java.io.Closeable

/**
* A key-value store.
*
* This interface extends [net.consensys.cava.kv.KeyValueStore], exposing co-routine based access methods.
*/
interface KeyValueStore : net.consensys.cava.kv.KeyValueStore {
interface KeyValueStore : Closeable {

/**
* Retrieves data from the store.
Expand All @@ -43,7 +42,7 @@ interface KeyValueStore : net.consensys.cava.kv.KeyValueStore {
* @return An [AsyncResult] that will complete with the stored content,
* or an empty optional if no content was available.
*/
override fun getAsync(key: Bytes): AsyncResult<Bytes?> = getAsync(Dispatchers.Default, key)
fun getAsync(key: Bytes): AsyncResult<Bytes?> = getAsync(Dispatchers.Default, key)

/**
* Retrieves data from the store.
Expand Down Expand Up @@ -74,7 +73,7 @@ interface KeyValueStore : net.consensys.cava.kv.KeyValueStore {
* @param value The data to store.
* @return An [AsyncCompletion] that will complete when the content is stored.
*/
override fun putAsync(key: Bytes, value: Bytes): AsyncCompletion = putAsync(Dispatchers.Default, key, value)
fun putAsync(key: Bytes, value: Bytes): AsyncCompletion = putAsync(Dispatchers.Default, key, value)

/**
* Puts data into the store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package net.consensys.cava.kv.experimental
package net.consensys.cava.kv

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
Expand All @@ -34,13 +34,37 @@ import java.nio.file.Path
* @constructor Open a LevelDB-backed key-value store.
*/
class LevelDBKeyValueStore
@JvmOverloads
@Throws(IOException::class)
constructor(
dbPath: Path,
options: Options = Options().createIfMissing(true).cacheSize((100 * 1048576).toLong()),
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
) : KeyValueStore, net.consensys.cava.kv.LevelDBKeyValueStore {
) : KeyValueStore {

companion object {
/**
* Open a LevelDB-backed key-value store.
*
* @param dbPath The path to the levelDB database.
* @return A key-value store.
* @throws IOException If an I/O error occurs.
*/
@JvmStatic
@Throws(IOException::class)
fun open(dbPath: Path) = LevelDBKeyValueStore(dbPath)

/**
* Open a LevelDB-backed key-value store.
*
* @param dbPath The path to the levelDB database.
* @param options Options for the levelDB database.
* @return A key-value store.
* @throws IOException If an I/O error occurs.
*/
@JvmStatic
@Throws(IOException::class)
fun open(dbPath: Path, options: Options) = LevelDBKeyValueStore(dbPath, options)
}

private val db: DB

Expand Down

0 comments on commit 05a6d12

Please sign in to comment.