-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging factory #267
Logging factory #267
Changes from 2 commits
2199012
f63a88e
cf5830e
6579f6f
819d411
79c1ae2
3f29879
7b8b1cf
9425300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,14 @@ | |
package net.schmizz.concurrent; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.locks.Condition; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
import net.schmizz.sshj.common.LoggerFactory; | ||
|
||
/** | ||
* Represents promised data of the parameterized type {@code V} and allows waiting on it. An exception may also be | ||
* delivered to a waiter, and will be of the parameterized type {@code T}. | ||
|
@@ -32,8 +33,7 @@ | |
*/ | ||
public class Promise<V, T extends Throwable> { | ||
|
||
private final Logger log = LoggerFactory.getLogger(getClass()); | ||
|
||
private final Logger log; | ||
private final String name; | ||
private final ExceptionChainer<T> chainer; | ||
private final ReentrantLock lock; | ||
|
@@ -49,8 +49,8 @@ public class Promise<V, T extends Throwable> { | |
* @param name name of this promise | ||
* @param chainer {@link ExceptionChainer} that will be used for chaining exceptions | ||
*/ | ||
public Promise(String name, ExceptionChainer<T> chainer) { | ||
this(name, chainer, null); | ||
public Promise(String name, ExceptionChainer<T> chainer, LoggerFactory loggerFactory) { | ||
this(name, chainer, null, loggerFactory); | ||
} | ||
|
||
/** | ||
|
@@ -60,10 +60,11 @@ public Promise(String name, ExceptionChainer<T> chainer) { | |
* @param chainer {@link ExceptionChainer} that will be used for chaining exceptions | ||
* @param lock lock to use | ||
*/ | ||
public Promise(String name, ExceptionChainer<T> chainer, ReentrantLock lock) { | ||
public Promise(String name, ExceptionChainer<T> chainer, ReentrantLock lock, LoggerFactory loggerFactory) { | ||
this.name = name; | ||
this.chainer = chainer; | ||
this.lock = lock == null ? new ReentrantLock() : lock; | ||
this.log = loggerFactory.getLogger(getClass()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation |
||
this.cond = this.lock.newCondition(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import com.hierynomus.sshj.transport.cipher.StreamCiphers; | ||
import net.schmizz.keepalive.KeepAliveProvider; | ||
import net.schmizz.sshj.common.Factory; | ||
import net.schmizz.sshj.common.LoggerFactory; | ||
import net.schmizz.sshj.common.SecurityUtils; | ||
import net.schmizz.sshj.signature.SignatureDSA; | ||
import net.schmizz.sshj.signature.SignatureECDSA; | ||
|
@@ -35,7 +36,6 @@ | |
import net.schmizz.sshj.userauth.keyprovider.PKCS8KeyFile; | ||
import net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
|
@@ -67,11 +67,12 @@ | |
public class DefaultConfig | ||
extends ConfigImpl { | ||
|
||
private final Logger log = LoggerFactory.getLogger(getClass()); | ||
|
||
private static final String VERSION = "SSHJ_0_17_2"; | ||
|
||
private Logger log; | ||
|
||
public DefaultConfig() { | ||
setLoggerFactory(LoggerFactory.DEFAULT); | ||
setVersion(VERSION); | ||
final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered(); | ||
initKeyExchangeFactories(bouncyCastleRegistered); | ||
|
@@ -84,6 +85,30 @@ public DefaultConfig() { | |
setKeepAliveProvider(KeepAliveProvider.HEARTBEAT); | ||
} | ||
|
||
/** | ||
* Default SLF4J-based implementation of the SSHJ LoggerFactory. | ||
*/ | ||
public static class DefaultLoggerFactory implements LoggerFactory { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this one still needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, no, I forgot to remove that.
|
||
private DefaultLoggerFactory() { | ||
} | ||
|
||
@Override | ||
public Logger getLogger(String name) { | ||
return org.slf4j.LoggerFactory.getLogger(name); | ||
} | ||
|
||
@Override | ||
public Logger getLogger(Class<?> clazz) { | ||
return org.slf4j.LoggerFactory.getLogger(clazz); | ||
} | ||
} | ||
|
||
@Override | ||
public void setLoggerFactory(LoggerFactory loggerFactory) { | ||
super.setLoggerFactory(loggerFactory); | ||
log = loggerFactory.getLogger(getClass()); | ||
} | ||
|
||
protected void initKeyExchangeFactories(boolean bouncyCastleRegistered) { | ||
if (bouncyCastleRegistered) | ||
setKeyExchangeFactories(new Curve25519SHA256.Factory(), | ||
|
@@ -141,7 +166,8 @@ protected void initCipherFactories() { | |
BlockCiphers.TwofishCBC(), | ||
StreamCiphers.Arcfour(), | ||
StreamCiphers.Arcfour128(), | ||
StreamCiphers.Arcfour256())); | ||
StreamCiphers.Arcfour256()) | ||
); | ||
|
||
boolean warn = false; | ||
// Ref. https://issues.apache.org/jira/browse/SSHD-24 | ||
|
@@ -167,17 +193,26 @@ protected void initCipherFactories() { | |
} | ||
|
||
protected void initSignatureFactories() { | ||
setSignatureFactories(new SignatureECDSA.Factory(), new SignatureRSA.Factory(), new SignatureDSA.Factory(), new SignatureEdDSA.Factory()); | ||
setSignatureFactories( | ||
new SignatureECDSA.Factory(), | ||
new SignatureRSA.Factory(), | ||
new SignatureDSA.Factory(), | ||
new SignatureEdDSA.Factory() | ||
); | ||
} | ||
|
||
protected void initMACFactories() { | ||
setMACFactories(new HMACSHA1.Factory(), new HMACSHA196.Factory(), new HMACMD5.Factory(), | ||
new HMACMD596.Factory(), new HMACSHA2256.Factory(), new HMACSHA2512.Factory()); | ||
setMACFactories( | ||
new HMACSHA1.Factory(), | ||
new HMACSHA196.Factory(), | ||
new HMACMD5.Factory(), | ||
new HMACMD596.Factory(), | ||
new HMACSHA2256.Factory(), | ||
new HMACSHA2512.Factory() | ||
); | ||
} | ||
|
||
protected void initCompressionFactories() { | ||
setCompressionFactories(new NoneCompression.Factory()); | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the indentation (sorry I use tabs for 8 spaces reflexively). What’s up with the “license” issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add new classes, easiest is to run
gradle licenseFormat
. This will fix the license headers.