protected <T> T execSsh(final Map<String, ?> props, final Function<ShellTool, T> task) { final LoadingCache<Map<String, ?>, Pool<SshTool>> sshPoolCache = getSshPoolCache(); Pool<SshTool> pool = sshPoolCache.getUnchecked(props); if (LOG.isTraceEnabled()) { LOG.trace("{} execSsh got pool: {}", this, pool); } if (groovyTruth(props.get(CLOSE_CONNECTION.getName()))) { Function<SshTool, T> close = new Function<SshTool, T>() { @Override public T apply(SshTool input) { T result = task.apply(input); if (LOG.isDebugEnabled()) { LOG.debug("{} invalidating all sshPoolCache entries: {}", SshMachineLocation.this, sshPoolCache.stats().toString()); } sshPoolCache.invalidateAll(); sshPoolCache.cleanUp(); return result; } }; return pool.exec(close); } else { return pool.exec(task); } }