Skip to content

Commit

Permalink
[improve] Allow to construct Oxia metadata-store directly from a clie…
Browse files Browse the repository at this point in the history
…nt instance (apache#22756)
  • Loading branch information
merlimat authored May 22, 2024
1 parent 949260f commit ce99986
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ public class OxiaMetadataStore extends AbstractMetadataStore {
private final String identity;
private Optional<MetadataEventSynchronizer> synchronizer;

OxiaMetadataStore(
public OxiaMetadataStore(AsyncOxiaClient oxia, String identity) {
super("oxia-metadata");
this.client = oxia;
this.identity = identity;
this.synchronizer = Optional.empty();
init();
}

public OxiaMetadataStore(
@NonNull String serviceAddress,
@NonNull String namespace,
@NonNull MetadataStoreConfig metadataStoreConfig,
Expand All @@ -69,7 +77,7 @@ public class OxiaMetadataStore extends AbstractMetadataStore {
if (!metadataStoreConfig.isBatchingEnabled()) {
linger = 0;
}
updateMetadataEventSynchronizer(metadataStoreConfig.getSynchronizer());
synchronizer = Optional.ofNullable(metadataStoreConfig.getSynchronizer());
identity = UUID.randomUUID().toString();
client =
OxiaClientBuilder.create(serviceAddress)
Expand All @@ -80,8 +88,14 @@ public class OxiaMetadataStore extends AbstractMetadataStore {
.maxRequestsPerBatch(metadataStoreConfig.getBatchingMaxOperations())
.asyncClient()
.get();
init();
}

private void init() {
updateMetadataEventSynchronizer(synchronizer.orElse(null));

client.notifications(this::notificationCallback);
super.registerSyncListener(Optional.ofNullable(metadataStoreConfig.getSynchronizer()));
super.registerSyncListener(synchronizer);
}

private void notificationCallback(Notification notification) {
Expand Down

0 comments on commit ce99986

Please sign in to comment.