Rework SslHandlerFactory
[netconf.git] / apps / callhome-provider / src / main / java / org / opendaylight / netconf / callhome / server / ssh / CallHomeSshSessionContext.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.callhome.server.ssh;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import com.google.common.util.concurrent.SettableFuture;
14 import java.net.SocketAddress;
15 import org.opendaylight.netconf.callhome.server.CallHomeSessionContext;
16 import org.opendaylight.netconf.client.NetconfClientSession;
17 import org.opendaylight.netconf.client.NetconfClientSessionListener;
18 import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
19
20 public record CallHomeSshSessionContext(String id, SocketAddress remoteAddress, ClientSession sshSession,
21         NetconfClientSessionListener netconfSessionListener, SettableFuture<NetconfClientSession> settableFuture)
22         implements CallHomeSessionContext {
23
24     public CallHomeSshSessionContext {
25         requireNonNull(id);
26         requireNonNull(remoteAddress);
27         requireNonNull(sshSession);
28         requireNonNull(netconfSessionListener);
29         requireNonNull(settableFuture);
30     }
31
32     @Override
33     public void close() {
34         if (sshSession.isOpen()) {
35             sshSession.close(true);
36         }
37     }
38
39     @Override
40     public String toString() {
41         return MoreObjects.toStringHelper(this)
42             .add("protocol", "SSH")
43             .add("id", id)
44             .add("address", remoteAddress)
45             .toString();
46     }
47 }