Clean up SSH server subsystem handling
[netconf.git] / protocol / netconf-server / src / main / java / org / opendaylight / netconf / server / ServerTransportInitializer.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.server;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.netconf.transport.api.TransportChannel;
13 import org.opendaylight.netconf.transport.api.TransportChannelListener;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * A {@link TransportChannelListener} which initializes NETCONF server implementations working on top
19  * of a {@link TransportChannel}.
20  */
21 public final class ServerTransportInitializer implements TransportChannelListener {
22     private static final Logger LOG = LoggerFactory.getLogger(ServerTransportInitializer.class);
23
24     private final ServerChannelInitializer initializer;
25
26     public ServerTransportInitializer(final ServerChannelInitializer initializer) {
27         this.initializer = requireNonNull(initializer);
28     }
29
30     @Override
31     public void onTransportChannelEstablished(final TransportChannel channel) {
32         LOG.debug("Transport channel {} established", channel);
33         final var nettyChannel = channel.channel();
34         initializer.initialize(nettyChannel, nettyChannel.eventLoop().newPromise());
35     }
36
37     @Override
38     public void onTransportChannelFailed(final Throwable cause) {
39         LOG.error("Transport channel failed", cause);
40     }
41 }