HTTP transport implementation
[netconf.git] / transport / transport-http / src / main / java / org / opendaylight / netconf / transport / http / HTTPTransportStack.java
diff --git a/transport/transport-http/src/main/java/org/opendaylight/netconf/transport/http/HTTPTransportStack.java b/transport/transport-http/src/main/java/org/opendaylight/netconf/transport/http/HTTPTransportStack.java
new file mode 100644 (file)
index 0000000..482a4af
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2024 PANTHEON.tech s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.transport.http;
+
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.netconf.transport.api.AbstractOverlayTransportStack;
+import org.opendaylight.netconf.transport.api.TransportChannel;
+import org.opendaylight.netconf.transport.api.TransportChannelListener;
+
+public abstract sealed class HTTPTransportStack extends AbstractOverlayTransportStack<HTTPTransportChannel>
+        permits HTTPClient, HTTPServer {
+    final HttpChannelInitializer channelInitializer;
+
+    public HTTPTransportStack(final TransportChannelListener listener, final HttpChannelInitializer handler) {
+        super(listener);
+        this.channelInitializer = handler;
+    }
+
+    @Override
+    protected void onUnderlayChannelEstablished(final @NonNull TransportChannel underlayChannel) {
+        underlayChannel.channel().pipeline().addLast(channelInitializer);
+        Futures.addCallback(channelInitializer.completeFuture(), new FutureCallback<>() {
+            @Override
+            public void onSuccess(final Void result) {
+                addTransportChannel(new HTTPTransportChannel(underlayChannel));
+            }
+
+            @Override
+            public void onFailure(Throwable cause) {
+                notifyTransportChannelFailed(cause);
+            }
+        }, MoreExecutors.directExecutor());
+    }
+}