Expose streams with all supported encodings
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / streams / Subscriber.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.restconf.nb.rfc8040.streams;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.concepts.AbstractRegistration;
14
15 /**
16  * A single subscriber to an {@link AbstractStream}.
17  */
18 final class Subscriber<T> extends AbstractRegistration {
19     private final @NonNull RestconfStream<T> stream;
20     private final @NonNull StreamSessionHandler handler;
21     private final @NonNull EventFormatter<T> formatter;
22
23     Subscriber(final RestconfStream<T> stream, final StreamSessionHandler handler, final EventFormatter<T> formatter) {
24         this.stream = requireNonNull(stream);
25         this.handler = requireNonNull(handler);
26         this.formatter = requireNonNull(formatter);
27     }
28
29     @NonNull EventFormatter<T> formatter() {
30         return formatter;
31     }
32
33     @NonNull StreamSessionHandler handler() {
34         return handler;
35     }
36
37     @Override
38     protected void removeRegistration() {
39         stream.removeSubscriber(this);
40     }
41 }