Skip to content

Commit

Permalink
Merge pull request #17 from garyschulte/bugfix/trielogobserver-init
Browse files Browse the repository at this point in the history
delay ZkTrieLogObserver construction until after cli param parsing
  • Loading branch information
garyschulte authored May 19, 2023
2 parents 26aec54 + c25e60f commit c558c2c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
releaseVersion=0.1.0-SNAPSHOT
releaseVersion=0.2.0-SNAPSHOT
besuVersion=23.4.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class ZkTrieLogObserver

private static final Logger LOG = LoggerFactory.getLogger(ZkTrieLogObserver.class);
// todo: get from config
private String shomeiHttpHost = "localhost";
private int shomeiHttpPort = 8888;
private final String shomeiHttpHost;
private final int shomeiHttpPort;
private boolean isSyncing;
private static long timeSinceLastLog = System.currentTimeMillis();

Expand All @@ -50,6 +50,7 @@ public ZkTrieLogObserver(final String shomeiHttpHost, final int shomeiHttpPort)
this.webClient = WebClient.create(vertx, options);
this.shomeiHttpHost = shomeiHttpHost;
this.shomeiHttpPort = shomeiHttpPort;
LOG.info("shomei http host:port {}:{}", this.shomeiHttpHost, this.shomeiHttpPort);

// TODO: wire up the SyncStatusListener via plugin, until then hack:

Expand Down
22 changes: 12 additions & 10 deletions src/main/java/net/consensys/shomei/trielog/ZkTrieLogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@
import org.hyperledger.besu.plugin.services.trielogs.TrieLogProvider;

public class ZkTrieLogService implements TrieLogService {
private static AtomicReference<ZkTrieLogService> singleton = new AtomicReference<>();
private static ZkTrieLogService singleton = new ZkTrieLogService();

ZkTrieLogService() {
observer =
new ZkTrieLogObserver(
ShomeiCliOptions.INSTANCE.shomeiHttpHost, ShomeiCliOptions.INSTANCE.shomeiHttpPort);
}
ZkTrieLogService() {}

public static ZkTrieLogService getInstance() {
singleton.compareAndSet(null, new ZkTrieLogService());
return singleton.get();
return singleton;
}

// TODO: configure:
private final ZkTrieLogObserver observer;
private final AtomicReference<ZkTrieLogObserver> observer = new AtomicReference<>();
private TrieLogProvider trieLogProvider = null;

@Override
public List<TrieLogEvent.TrieLogObserver> getObservers() {
return List.of(observer);
// initialize observer late so we are assured we have gotten pico cli params from besu
if (observer.get() == null) {
observer.compareAndSet(
null,
new ZkTrieLogObserver(
ShomeiCliOptions.INSTANCE.shomeiHttpHost, ShomeiCliOptions.INSTANCE.shomeiHttpPort));
}
return List.of(observer.get());
}

@Override
Expand Down

0 comments on commit c558c2c

Please sign in to comment.