Flatten callhome-provider
[netconf.git] / apps / callhome-provider / src / main / java / org / opendaylight / netconf / topology / callhome / 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.topology.callhome;
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.client.NetconfClientSession;
16 import org.opendaylight.netconf.client.NetconfClientSessionListener;
17 import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
18
19 public record CallHomeSshSessionContext(String id, SocketAddress remoteAddress, ClientSession sshSession,
20         NetconfClientSessionListener netconfSessionListener, SettableFuture<NetconfClientSession> settableFuture)
21         implements CallHomeSessionContext {
22
23     public CallHomeSshSessionContext {
24         requireNonNull(id);
25         requireNonNull(remoteAddress);
26         requireNonNull(sshSession);
27         requireNonNull(netconfSessionListener);
28         requireNonNull(settableFuture);
29     }
30
31     @Override
32     public void close() {
33         if (sshSession.isOpen()) {
34             sshSession.close(true);
35         }
36     }
37
38     @Override
39     public String toString() {
40         return MoreObjects.toStringHelper(this)
41             .add("protocol", "SSH")
42             .add("id", id)
43             .add("address", remoteAddress)
44             .toString();
45     }
46 }