/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2023 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,
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.MessageToByteEncoder;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.netconf.api.messages.FramingMechanism;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class FramingMechanismHandlerFactory {
- private static final Logger LOG = LoggerFactory.getLogger(FramingMechanismHandlerFactory.class);
+/**
+ * An channel handler framing outbound messages into specified framing.
+ */
+public abstract sealed class FramingMechanismEncoder extends MessageToByteEncoder<ByteBuf>
+ permits ChunkedFramingMechanismEncoder, EOMFramingMechanismEncoder {
+ private static final Logger LOG = LoggerFactory.getLogger(FramingMechanismEncoder.class);
- private FramingMechanismHandlerFactory() {
- // not called - private constructor for utility class
+ FramingMechanismEncoder() {
+ // Hidden on purpose
}
- public static MessageToByteEncoder<ByteBuf> createHandler(final FramingMechanism framingMechanism) {
+ /**
+ * Return a {@link FramingMechanismEncoder} for specified {@link FramingMechanism}.
+ *
+ * @param framingMechanism Desired {@link FramingMechanism}
+ * @return A {@link FramingMechanismEncoder}
+ */
+ public static final @NonNull FramingMechanismEncoder of(final FramingMechanism framingMechanism) {
LOG.debug("{} framing mechanism was selected.", framingMechanism);
return switch (framingMechanism) {
case CHUNK -> new ChunkedFramingMechanismEncoder();