Skip to content

Commit

Permalink
Merge pull request #1 from dennisn00/open_connections_improve_perform…
Browse files Browse the repository at this point in the history
…ance

parallelize creation of indy connections
  • Loading branch information
peacekeeper authored Jan 3, 2024
2 parents 6b8f7bb + e455433 commit bbb94d5
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/main/java/com/danubetech/libindy/IndyConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class IndyConnector {
Expand Down Expand Up @@ -146,9 +148,8 @@ public synchronized void openIndyConnections(boolean createSubmitterDid, boolean
// create indy connections

Map<String, IndyConnection> indyConnections = new LinkedHashMap<>();

for (String network : poolConfigFiles.keySet()) {

List<IndyConnectionException> exceptions = new ArrayList<>();
poolConfigFiles.keySet().parallelStream().forEach(network -> {
String poolConfigName = poolConfigNames.get(network);
String poolConfigFile = poolConfigFiles.get(network);
Integer poolVersion = poolVersions.get(network);
Expand All @@ -161,21 +162,34 @@ public synchronized void openIndyConnections(boolean createSubmitterDid, boolean
String submitterDidSeed = submitterDidSeeds.get(network);
Long genesisTimestamp = genesisTimestamps.get(network);

if (poolConfigName == null) throw new IndyConnectionException("No 'poolConfigName' for network: " + network);
if (poolConfigFile == null) throw new IndyConnectionException("No 'poolConfigFile' for network: " + network);
if (poolVersion == null) throw new IndyConnectionException("No 'poolVersion' for network: " + network);
if (nativeDidIndy == null) throw new IndyConnectionException("No 'nativeDidIndy' for network: " + network);
if (nymAddSignMulti == null) throw new IndyConnectionException("No 'nymAddSignMulti' for network: " + network);
if (nymEditSignMulti == null) throw new IndyConnectionException("No 'nymEditSignMulti' for network: " + network);
if (attribAddSignMulti == null) throw new IndyConnectionException("No 'attribAddSignMulti' for network: " + network);
if (attribEditSignMulti == null) throw new IndyConnectionException("No 'attribEditSignMulti' for network: " + network);
if (walletName == null) throw new IndyConnectionException("No 'walletName' for network: " + network);
if (submitterDidSeed == null) throw new IndyConnectionException("No 'submitterDidSeed' for network: " + network);

if (poolConfigName == null) exceptions.add(new IndyConnectionException("No 'poolConfigName' for network: " + network));
if (poolConfigFile == null) exceptions.add(new IndyConnectionException("No 'poolConfigFile' for network: " + network));
if (poolVersion == null) exceptions.add(new IndyConnectionException("No 'poolVersion' for network: " + network));
if (nativeDidIndy == null) exceptions.add(new IndyConnectionException("No 'nativeDidIndy' for network: " + network));
if (nymAddSignMulti == null) exceptions.add(new IndyConnectionException("No 'nymAddSignMulti' for network: " + network));
if (nymEditSignMulti == null) exceptions.add(new IndyConnectionException("No 'nymEditSignMulti' for network: " + network));
if (attribAddSignMulti == null) exceptions.add(new IndyConnectionException("No 'attribAddSignMulti' for network: " + network));
if (attribEditSignMulti == null) exceptions.add(new IndyConnectionException("No 'attribEditSignMulti' for network: " + network));
if (walletName == null) exceptions.add(new IndyConnectionException("No 'walletName' for network: " + network));
if (submitterDidSeed == null) exceptions.add(new IndyConnectionException("No 'submitterDidSeed' for network: " + network));
if (poolVersion == null || nativeDidIndy == null || nymAddSignMulti == null || nymEditSignMulti == null
|| attribAddSignMulti == null || attribEditSignMulti == null || walletName == null || submitterDidSeed == null)
return;
IndyConnection indyConnection = new IndyConnection(network, poolConfigName, poolConfigFile, poolVersion, nativeDidIndy, nymAddSignMulti, nymEditSignMulti, attribAddSignMulti, attribEditSignMulti, walletName, submitterDidSeed, genesisTimestamp);
indyConnection.open(createSubmitterDid, retrieveTaa);
try {
indyConnection.open(createSubmitterDid, retrieveTaa);
} catch (IndyConnectionException e) {
exceptions.add(e);
}

indyConnections.put(network, indyConnection);
});
if (!exceptions.isEmpty()) {
StringBuilder errorMessage = new StringBuilder();
for (IndyConnectionException e: exceptions){
errorMessage.append(e.getMessage()).append("; ");
}
throw new IndyConnectionException(errorMessage.toString());
}

if (log.isInfoEnabled()) log.info("Opened " + indyConnections.size() + " Indy connections: " + indyConnections.keySet());
Expand Down

0 comments on commit bbb94d5

Please sign in to comment.