This commit is contained in:
Looly 2022-06-10 09:00:30 +08:00
parent ea7716a517
commit 16dfcf3154
2 changed files with 3 additions and 3 deletions

View File

@ -96,7 +96,7 @@ public class SimpleCache<K, V> implements Iterable<Map.Entry<K, V>>, Serializabl
*/ */
public V get(K key, Predicate<V> validPredicate, Func0<V> supplier) { public V get(K key, Predicate<V> validPredicate, Func0<V> supplier) {
V v = get(key); V v = get(key);
if((null != validPredicate && false == validPredicate.test(v))){ if((null != validPredicate && null != v && false == validPredicate.test(v))){
v = null; v = null;
} }
if (null == v && null != supplier) { if (null == v && null != supplier) {

View File

@ -42,7 +42,7 @@ public enum JschSessionPool {
*/ */
public Session getSession(String sshHost, int sshPort, String sshUser, String sshPass) { public Session getSession(String sshHost, int sshPort, String sshUser, String sshPass) {
final String key = StrUtil.format("{}@{}:{}", sshUser, sshHost, sshPort); final String key = StrUtil.format("{}@{}:{}", sshUser, sshHost, sshPort);
return this.cache.get(key, (conn)->null != conn && conn.isConnected(), ()-> JschUtil.openSession(sshHost, sshPort, sshUser, sshPass)); return this.cache.get(key, Session::isConnected, ()-> JschUtil.openSession(sshHost, sshPort, sshUser, sshPass));
} }
/** /**
@ -57,7 +57,7 @@ public enum JschSessionPool {
*/ */
public Session getSession(String sshHost, int sshPort, String sshUser, String prvkey, byte[] passphrase) { public Session getSession(String sshHost, int sshPort, String sshUser, String prvkey, byte[] passphrase) {
final String key = StrUtil.format("{}@{}:{}", sshUser, sshHost, sshPort); final String key = StrUtil.format("{}@{}:{}", sshUser, sshHost, sshPort);
return this.cache.get(key, (conn)->null != conn && conn.isConnected(), ()->JschUtil.openSession(sshHost, sshPort, sshUser, prvkey, passphrase)); return this.cache.get(key, Session::isConnected, ()->JschUtil.openSession(sshHost, sshPort, sshUser, prvkey, passphrase));
} }
/** /**