2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.netconf.transport.http;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.util.concurrent.FutureCallback;
13 import io.netty.channel.Channel;
14 import io.netty.channel.ChannelHandlerContext;
15 import io.netty.channel.SimpleChannelInboundHandler;
16 import io.netty.handler.codec.http.FullHttpRequest;
17 import io.netty.handler.codec.http.FullHttpResponse;
18 import org.eclipse.jdt.annotation.NonNull;
20 abstract class ClientRequestDispatcher extends SimpleChannelInboundHandler<FullHttpResponse>
21 implements RequestDispatcher {
22 private Channel channel = null;
25 public void handlerAdded(final ChannelHandlerContext ctx) throws Exception {
26 channel = ctx.channel();
27 super.handlerAdded(ctx);
31 public final void dispatch(final FullHttpRequest request, final FutureCallback<FullHttpResponse> callback) {
32 final var local = channel;
34 dispatch(local, requireNonNull(request), requireNonNull(callback));
36 throw new IllegalStateException("Connection is not established yet");
40 abstract void dispatch(@NonNull Channel channel, @NonNull FullHttpRequest request,
41 @NonNull FutureCallback<FullHttpResponse> callback);