Skip to content

Commit

Permalink
feat: indy connections are opened on startup, not on the first resolu…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
peacekeeper committed Jan 5, 2024
1 parent 4a530be commit e03908a
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/main/java/uniresolver/driver/did/sov/DidSovDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,44 @@ public class DidSovDriver implements Driver {
private boolean openParallel;
private IndyConnector indyConnector;

public DidSovDriver(Map<String, Object> properties) {
public DidSovDriver(LibIndyInitializer libIndyInitializer, boolean openParallel, IndyConnector indyConnector) throws IndyConnectionException{

this.setLibIndyInitializer(libIndyInitializer);
this.setOpenParallel(openParallel);
this.setIndyConnector(indyConnector);

this.initializeIndy();
}

public DidSovDriver(Map<String, Object> properties) throws IndyConnectionException{

this.setProperties(properties);

this.initializeIndy();
}

public DidSovDriver() {
public DidSovDriver() throws IndyConnectionException {

this(getPropertiesFromEnvironment());
}

private void initializeIndy() throws IndyConnectionException {

// init libindy

if (this.getLibIndyInitializer() != null && ! this.getLibIndyInitializer().isInitialized()) {
this.getLibIndyInitializer().initializeLibIndy();
if (log.isInfoEnabled()) log.info("Successfully initialized libindy.");
}

// open indy connections

if (this.getIndyConnector() != null && ! this.getIndyConnector().isOpened()) {
this.getIndyConnector().openIndyConnections(true, false, this.getOpenParallel());
if (log.isInfoEnabled()) log.info("Successfully opened Indy connections.");
}
}

private static Map<String, Object> getPropertiesFromEnvironment() {

if (log.isDebugEnabled()) log.debug("Loading from environment: " + System.getenv());
Expand Down Expand Up @@ -109,22 +137,10 @@ private void configureFromProperties() {
@Override
public ResolveDataModelResult resolve(DID did, Map<String, Object> resolveOptions) throws ResolutionException {

// init

if (!this.getLibIndyInitializer().isInitialized()) {
this.getLibIndyInitializer().initializeLibIndy();
if (log.isInfoEnabled()) log.info("Successfully initialized libindy.");
}

// open indy connections
// check if Indy connections are open

if (! this.getIndyConnector().isOpened()) {
try {
this.getIndyConnector().openIndyConnections(true, false, this.getOpenParallel());
if (log.isInfoEnabled()) log.info("Successfully opened Indy connections.");
} catch (IndyConnectionException ex) {
throw new ResolutionException("Cannot open Indy connections: " + ex.getMessage(), ex);
}
throw new ResolutionException("Indy connections are not opened");
}

// parse identifier
Expand Down

0 comments on commit e03908a

Please sign in to comment.