Rework SslHandlerFactory
[netconf.git] / apps / callhome-provider / src / main / java / org / opendaylight / netconf / callhome / server / tls / CallHomeTlsSessionContext.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.tls;
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 io.netty.channel.Channel;
15 import org.opendaylight.netconf.callhome.server.CallHomeSessionContext;
16 import org.opendaylight.netconf.client.NetconfClientSession;
17 import org.opendaylight.netconf.client.NetconfClientSessionListener;
18
19 public record CallHomeTlsSessionContext(String id, Channel nettyChannel,
20         NetconfClientSessionListener netconfSessionListener, SettableFuture<NetconfClientSession> settableFuture)
21         implements CallHomeSessionContext {
22
23     public CallHomeTlsSessionContext {
24         requireNonNull(id);
25         requireNonNull(nettyChannel);
26         requireNonNull(netconfSessionListener);
27         requireNonNull(settableFuture);
28     }
29
30     @Override
31     public void close() {
32         if (nettyChannel.isOpen()) {
33             nettyChannel.close();
34         }
35     }
36
37     @Override
38     public String toString() {
39         return MoreObjects.toStringHelper(this)
40             .add("protocol", "TLS")
41             .add("id", id)
42             .add("address", nettyChannel.remoteAddress())
43             .toString();
44     }
45 }