Skip to content

Commit

Permalink
Merge pull request #14 from qupath/ice-connection-logs
Browse files Browse the repository at this point in the history
Clearer log messages when Ice connects
  • Loading branch information
Rylern authored Feb 21, 2024
2 parents 6401afd + e61b704 commit cdf858f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
33 changes: 9 additions & 24 deletions src/main/java/qupath/ext/omero/core/pixelapis/ice/IceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import qupath.lib.images.servers.PixelType;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -131,30 +132,14 @@ public PixelAPIReader createReader(long id, ImageServerMetadata metadata) throws
throw new IllegalArgumentException("The provided image cannot be read by this API");
}

return new IceReader(
List.of(
new LoginCredentials(
sessionUuid,
sessionUuid,
apisHandler.getWebServerURI().getHost(),
apisHandler.getServerPort()
),
new LoginCredentials(
sessionUuid,
sessionUuid,
apisHandler.getServerURI(),
apisHandler.getServerPort()
),
new LoginCredentials(
sessionUuid,
sessionUuid,
serverAddress.get(),
serverPort.get()
)
),
id,
metadata.getChannels()
);
List<LoginCredentials> credentials = new ArrayList<>();
credentials.add(new LoginCredentials(sessionUuid, sessionUuid, apisHandler.getWebServerURI().getHost(), apisHandler.getServerPort()));
credentials.add(new LoginCredentials(sessionUuid, sessionUuid, apisHandler.getServerURI(), apisHandler.getServerPort()));
if (serverAddress.get() != null) {
credentials.add(new LoginCredentials(sessionUuid, sessionUuid, serverAddress.get(), serverPort.get()));
}

return new IceReader(credentials, id, metadata.getChannels());
}

@Override
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/qupath/ext/omero/core/pixelapis/ice/IceReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,25 @@ public String toString() {
}

private Optional<ExperimenterData> connect(List<LoginCredentials> loginCredentials) {
for (LoginCredentials loginCredential: loginCredentials) {
for (int i=0; i<loginCredentials.size(); i++) {
try {
return Optional.ofNullable(gateway.connect(loginCredential));
return Optional.ofNullable(gateway.connect(loginCredentials.get(i)));
} catch (Exception e) {
logger.info(String.format(
"Can't connect to %s:%d",
loginCredential.getServer().getHost(),
loginCredential.getServer().getPort()
), e);
if (i < loginCredentials.size()-1) {
logger.warn(String.format(
"Ice can't connect to %s:%d. Trying %s:%d...",
loginCredentials.get(i).getServer().getHost(),
loginCredentials.get(i).getServer().getPort(),
loginCredentials.get(i+1).getServer().getHost(),
loginCredentials.get(i+1).getServer().getPort()
), e);
} else {
logger.warn(String.format(
"Ice can't connect to %s:%d. No more credentials available",
loginCredentials.get(i).getServer().getHost(),
loginCredentials.get(i).getServer().getPort()
), e);
}
}
}
return Optional.empty();
Expand Down

0 comments on commit cdf858f

Please sign in to comment.