Refactoring of web-sockets in RESTCONF RFC-8040
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / streams / listeners / BaseListenerInterface.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.listeners;
9
10 import io.netty.channel.Channel;
11 import java.util.Set;
12 import org.opendaylight.yangtools.concepts.ListenerRegistration;
13
14 /**
15  * Base interface for both listeners({@link ListenerAdapter}, {@link NotificationListenerAdapter}).
16  */
17 public interface BaseListenerInterface extends AutoCloseable {
18
19     /**
20      * Return all subscribers of listener.
21      *
22      * @return Set of all subscribers.
23      */
24     Set<Channel> getSubscribers();
25
26     /**
27      * Checks if exists at least one {@link Channel} subscriber.
28      *
29      * @return {@code true} if exist at least one {@link Channel} subscriber, {@code false} otherwise.
30      */
31     boolean hasSubscribers();
32
33     /**
34      * Get name of stream.
35      *
36      * @return Stream name.
37      */
38     String getStreamName();
39
40     /**
41      * Get output type.
42      *
43      * @return Output type (JSON or XML).
44      */
45     String getOutputType();
46
47     /**
48      * Creates event of type {@link EventType#REGISTER}, set {@link Channel}
49      * subscriber to the event and post event into event bus.
50      *
51      * @param subscriber Web-socket channel.
52      */
53     void addSubscriber(Channel subscriber);
54
55     /**
56      * Creates event of type {@link EventType#DEREGISTER}, sets {@link Channel}
57      * subscriber to the event and posts event into event bus.
58      *
59      * @param subscriber Subscriber channel.
60      */
61     void removeSubscriber(Channel subscriber);
62
63     /**
64      * Sets {@link ListenerRegistration} registration.
65      *
66      * @param registration DOMDataChangeListener registration.
67      */
68     void setRegistration(ListenerRegistration<?> registration);
69
70     /**
71      * Checks if {@link ListenerRegistration} registration exists.
72      *
73      * @return {@code true} if exists, {@code false} otherwise.
74      */
75     boolean isListening();
76 }