import static java.util.Objects.requireNonNull;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
import io.netty.channel.Channel;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.HashedWheelTimer;
import javax.net.ssl.SSLPeerUnverifiedException;
import org.opendaylight.netconf.callhome.protocol.CallHomeNetconfSubsystemListener;
import org.opendaylight.netconf.callhome.protocol.CallHomeProtocolSessionContext;
-import org.opendaylight.netconf.callhome.protocol.TransportType;
import org.opendaylight.netconf.client.NetconfClientSession;
import org.opendaylight.netconf.client.NetconfClientSessionListener;
import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
import org.opendaylight.netconf.client.SslHandlerFactory;
import org.opendaylight.netconf.client.TlsClientChannelInitializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.parameters.Protocol.Name;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final CallHomeNetconfSubsystemListener subsystemListener) {
this.channel = requireNonNull(channel, "channel");
this.deviceId = deviceId;
- this.socketAddress = channel.remoteAddress();
- this.publicKey = createPublicKey(channel);
+ socketAddress = channel.remoteAddress();
+ publicKey = createPublicKey(channel);
this.sslHandlerFactory = requireNonNull(sslHandlerFactory, "sslHandlerFactory");
this.subsystemListener = subsystemListener;
}
channel.close();
}
- private Promise<NetconfClientSession> doActivate(final Channel ch, final NetconfClientSessionListener listener) {
+ private ListenableFuture<NetconfClientSession> doActivate(final Channel ch,
+ final NetconfClientSessionListener listener) {
final Promise<NetconfClientSession> activationPromise = newSessionPromise();
if (activated.compareAndExchange(false, true)) {
- return activationPromise.setFailure(new IllegalStateException("Session (channel) already activated."));
+ return Futures.immediateFailedFuture(new IllegalStateException("Session (channel) already activated."));
}
LOG.info("Activating Netconf channel for {} with {}", getRemoteAddress(), listener);
final TlsClientChannelInitializer tlsClientChannelInitializer = new TlsClientChannelInitializer(
sslHandlerFactory, negotiatorFactory, listener);
tlsClientChannelInitializer.initialize(ch, activationPromise);
- return activationPromise;
+ final SettableFuture<NetconfClientSession> future = SettableFuture.create();
+ activationPromise.addListener(ignored -> {
+ final var cause = activationPromise.cause();
+ if (cause != null) {
+ future.setException(cause);
+ } else {
+ future.set(activationPromise.getNow());
+ }
+ });
+ return future;
}
@Override
}
@Override
- public TransportType getTransportType() {
- return TransportType.TLS;
+ public Name getTransportType() {
+ return Name.TLS;
}
private static PublicKey createPublicKey(final Channel ch) {