import io.netty.util.Timeout;
import io.netty.util.Timer;
import io.netty.util.TimerTask;
-import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.Promise;
import java.util.concurrent.TimeUnit;
@Override
protected final void startNegotiation() {
- final Optional<SslHandler> sslHandler = getSslHandler(channel);
- if (sslHandler.isPresent()) {
- Future<Channel> future = sslHandler.get().handshakeFuture();
- future.addListener(new GenericFutureListener<Future<? super Channel>>() {
- @Override
- public void operationComplete(final Future<? super Channel> future) {
+ if (ifNegotiatedAlready()) {
+ LOG.debug("Negotiation on channel {} already started", channel);
+ } else {
+ final Optional<SslHandler> sslHandler = getSslHandler(channel);
+ if (sslHandler.isPresent()) {
+ sslHandler.get().handshakeFuture().addListener(future -> {
Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful");
LOG.debug("Ssl handshake complete");
start();
- }
- });
- } else {
- start();
+ });
+ } else {
+ start();
+ }
}
}
+ protected final synchronized boolean ifNegotiatedAlready() {
+ // Indicates whether negotiation already started
+ return this.state != State.IDLE;
+ }
+
private static Optional<SslHandler> getSslHandler(final Channel channel) {
final SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
- return sslHandler == null ? Optional.<SslHandler>absent() : Optional.of(sslHandler);
+ return sslHandler == null ? Optional.absent() : Optional.of(sslHandler);
}
public P getSessionPreferences() {
timeout = this.timer.newTimeout(new TimerTask() {
@Override
+ @SuppressWarnings("checkstyle:hiddenField")
public void run(final Timeout timeout) {
synchronized (this) {
if (state != State.ESTABLISHED) {
// Do not fail negotiation if promise is done or canceled
// It would result in setting result of the promise second time and that throws exception
- if (isPromiseFinished() == false) {
+ if (!isPromiseFinished()) {
LOG.warn("Netconf session was not established after {}", connectionTimeoutMillis);
changeState(State.FAILED);
- channel.close().addListener(new GenericFutureListener<ChannelFuture>() {
- @Override
- public void operationComplete(final ChannelFuture future) throws Exception {
- if (future.isSuccess()) {
- LOG.debug("Channel {} closed: success", future.channel());
- } else {
- LOG.warn("Channel {} closed: fail", future.channel());
- }
+ channel.close().addListener((GenericFutureListener<ChannelFuture>) future -> {
+ if (future.isSuccess()) {
+ LOG.debug("Channel {} closed: success", future.channel());
+ } else {
+ LOG.warn("Channel {} closed: fail", future.channel());
}
});
}
return channel.pipeline().replace(handlerKey, handlerKey, decoder);
}
+ @SuppressWarnings("checkstyle:hiddenField")
protected abstract S getSession(L sessionListener, Channel channel, NetconfHelloMessage message)
throws NetconfDocumentedException;
}
private static boolean containsBase11Capability(final Document doc) {
- final NodeList nList = doc.getElementsByTagName(XmlNetconfConstants.CAPABILITY);
+ final NodeList nList = doc.getElementsByTagNameNS(
+ XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
+ XmlNetconfConstants.CAPABILITY);
for (int i = 0; i < nList.getLength(); i++) {
if (nList.item(i).getTextContent().contains(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1)) {
return true;