Skip to content

Commit 0142594

Browse files
authored
Merge pull request #86 from Rdornier/cache-facility
Fix bug when connecting to multiple servers
2 parents 7b601e0 + ca83790 commit 0142594

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/main/java/omero/gateway/Gateway.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ public class Gateway implements AutoCloseable {
187187
/** Flag to indicate that executor threads should be shutdown on disconnect */
188188
private boolean executorShutdownOnDisconnect = false;
189189

190+
private String serverHost;
191+
190192
/**
191193
* Creates a new Gateway instance
192194
* @param log A {@link Logger}
@@ -408,6 +410,20 @@ public String getServerVersion() throws DSOutOfServiceException {
408410
return serverVersion;
409411
}
410412

413+
/**
414+
* Get the hostname of the server the Gateway is connected to
415+
*
416+
* @return See above
417+
* @throws DSOutOfServiceException
418+
* If the connection is broken, or not logged in
419+
*/
420+
public String getServerHost() throws DSOutOfServiceException{
421+
if (serverHost == null) {
422+
throw new DSOutOfServiceException("Not logged in.");
423+
}
424+
return serverHost;
425+
}
426+
411427
/**
412428
* Get a {@link Facility} to perform further operations with the server
413429
*
@@ -1221,6 +1237,7 @@ private ExperimenterData login(SessionWrapper session, LoginCredentials cred)
12211237
}
12221238
// Connector now controls the secureClient for closing.
12231239
String host = session.client.getProperty("omero.host");
1240+
this.serverHost = host;
12241241
cred.getServer().setHostname(host);
12251242
String port = session.client.getProperty("omero.port");
12261243
cred.getServer().setPort(Integer.parseInt(port));

src/main/java/omero/gateway/facility/Facility.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,14 @@ public static <T extends Facility> T getFacility(final Class<T> type,
115115
+ type.getSimpleName(), e);
116116
}
117117
}
118-
119-
return (T) cache.get(type.getSimpleName(), new Callable<Facility>() {
118+
String serverHost;
119+
try{
120+
serverHost = gateway.getServerHost();
121+
}catch (DSOutOfServiceException e){
122+
throw new ExecutionException("Not logged in; Can't instantiate "
123+
+ type.getSimpleName(), e);
124+
}
125+
return (T) cache.get(type.getSimpleName() + ":" +serverHost, new Callable<Facility>() {
120126

121127
@Override
122128
public Facility call() throws Exception {

0 commit comments

Comments
 (0)