Skip to content

Commit

Permalink
MVStore
Browse files Browse the repository at this point in the history
Finally a use for the ProtobufDatatype - lol
  • Loading branch information
Hellblazer committed Dec 10, 2023
1 parent 6d2ea93 commit 655f8f8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions leyden/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<groupId>com.salesforce.apollo</groupId>
<artifactId>memberships</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2-mvstore</artifactId>
</dependency>

<!-- Test Only Dependencies Below This Line -->
<dependency>
Expand Down
33 changes: 27 additions & 6 deletions leyden/src/main/java/com/salesforce/apollo/leyden/LeydenJar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.salesforce.apollo.leyden;

import com.google.protobuf.InvalidProtocolBufferException;
import com.salesforce.apollo.archipelago.Router;
import com.salesforce.apollo.archipelago.RouterImpl;
import com.salesforce.apollo.cryptography.Digest;
Expand All @@ -13,19 +14,26 @@
import com.salesforce.apollo.thoth.proto.Intervals;
import com.salesforce.apollo.thoth.proto.Update;
import com.salesforce.apollo.thoth.proto.Updating;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* @author hal.hildebrand
**/
public class LeydenJar {

private final Context<Member> context;
private final RouterImpl.CommonCommunications<ReconciliationClient, ReconciliationService> reconComms;
private final RouterImpl.CommonCommunications<BinderClient, BinderService> binderComms;
private final double fpr;
private final SigningMember member;
public static final String LEYDEN_JAR = "Leyden-Jar";
private final Context<Member> context;
private final RouterImpl.CommonCommunications<ReconciliationClient, ReconciliationService> reconComms;
private final RouterImpl.CommonCommunications<BinderClient, BinderService> binderComms;
private final double fpr;
private final SigningMember member;
private final MVMap<Key_, Binding> bottled;
private final AtomicBoolean started = new AtomicBoolean();

public LeydenJar(SigningMember member, Context<Member> context, Router communications, double fpr,
public LeydenJar(SigningMember member, Context<Member> context, Router communications, double fpr, MVStore store,
ReconciliationMetrics metrics, BinderMetrics binderMetrics) {
this.context = context;
this.member = member;
Expand All @@ -42,6 +50,19 @@ public LeydenJar(SigningMember member, Context<Member> context, Router communica
binderMetrics), c -> Bind.getCreate(c, binderMetrics),
Bind.getLocalLoopback(borders, member));
this.fpr = fpr;
bottled = store.openMap(LEYDEN_JAR, new MVMap.Builder<Key_, Binding>().keyType(new ProtobufDatatype<Key_>(b -> {
try {
return Key_.parseFrom(b);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
})).valueType(new ProtobufDatatype<Binding>(b -> {
try {
return Binding.parseFrom(b);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
})));
}

private class Reconciled implements ReconciliationService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
package com.salesforce.apollo.model;

import java.nio.ByteBuffer;
import java.util.function.Function;
package com.salesforce.apollo.leyden;

import com.google.protobuf.Message;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.WriteBuffer;
import org.h2.mvstore.type.BasicDataType;

import com.google.protobuf.Message;
import java.nio.ByteBuffer;
import java.util.function.Function;

/**
* @author hal.hildebrand
*
*/
public final class ProtobufDatatype<Type extends Message> extends BasicDataType<Type> {
private Function<byte[], Type> factory;

private ProtobufDatatype(Function<byte[], Type> factory) {
public ProtobufDatatype(Function<byte[], Type> factory) {
this.factory = factory;
}

Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@
<artifactId>cryptography</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.salesforce.apollo</groupId>
<artifactId>leyden</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.salesforce.apollo</groupId>
<artifactId>isolates</artifactId>
Expand Down

0 comments on commit 655f8f8

Please sign in to comment.