Skip to content

Commit

Permalink
use open() method because getOpenFuture() method was removed from cod…
Browse files Browse the repository at this point in the history
…e in version 2.9.0 (without prior deprecation);

Signed-off-by: Stefan <stefan.maute@bosch.io>
  • Loading branch information
Stefan authored and thjaeckle committed Aug 24, 2022
1 parent de52ec6 commit ccc7bc6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.connectivity.service.messaging.tunnel;

import java.io.IOException;

import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelListener;
Expand All @@ -37,7 +39,8 @@ final class TunnelChannelListener implements ChannelListener {
* @param initialSshChannelWindowSize the initial window size to use for the RemoteWindow of the SSH channel
* @param logger the logger
*/
TunnelChannelListener(final ActorRef sshTunnelActor, final String initialSshChannelWindowSize, final LoggingAdapter logger) {
TunnelChannelListener(final ActorRef sshTunnelActor, final String initialSshChannelWindowSize,
final LoggingAdapter logger) {
this.sshTunnelActor = sshTunnelActor;
this.logger = logger;
try {
Expand Down Expand Up @@ -95,18 +98,28 @@ public void channelClosed(final Channel channel, final Throwable reason) {
// attach a listener to the open future, otherwise we have no access to the exception that caused the opening
// to fail (e.g. channelOpenFailure is not called with an exception)
if (channel instanceof TcpipClientChannel tcpipClientChannel) {
final OpenFuture openFuture = tcpipClientChannel.getOpenFuture();
if (openFuture != null) {
tcpipClientChannel.getOpenFuture()
.addListener(future -> {
final Throwable exception = future.getException();
if (exception != null) {
final SshTunnelActor.TunnelClosed tunnelClosed =
new SshTunnelActor.TunnelClosed(TUNNEL_EXCEPTION_MESSAGE, exception);
sshTunnelActor.tell(tunnelClosed, ActorRef.noSender());
}
});
final OpenFuture openFuture;
try {
openFuture = tcpipClientChannel.open();
if (openFuture != null) {
tcpipClientChannel.open()
.addListener(future -> {
final Throwable exception = future.getException();
if (exception != null) {
tellExceptionToTunnelActor(exception);
}
});
}
} catch (IOException e) {
tellExceptionToTunnelActor(e);
}
}
}

private void tellExceptionToTunnelActor(final Throwable exception) {
final SshTunnelActor.TunnelClosed tunnelClosed =
new SshTunnelActor.TunnelClosed(TUNNEL_EXCEPTION_MESSAGE, exception);
sshTunnelActor.tell(tunnelClosed, ActorRef.noSender());
}

}
Expand Up @@ -68,4 +68,5 @@ public void sessionDisconnect(final Session session, final int reason, final Str
logger.debug("SSH session disconnected: {}, reason: {}, msg: {}, initiator: {}",
session, reason, msg, initiator ? "local" : "remote");
}

}

0 comments on commit ccc7bc6

Please sign in to comment.