7
7
*/
8
8
package io .lighty .modules .northbound .restconf .community .impl ;
9
9
10
+ import static org .opendaylight .restconf .nb .rfc8040 .rests .utils .RestconfStreamsConstants .DATA_SUBSCRIPTION ;
11
+ import static org .opendaylight .restconf .nb .rfc8040 .rests .utils .RestconfStreamsConstants .NOTIFICATION_STREAM ;
12
+ import static org .opendaylight .restconf .nb .rfc8040 .utils .RestconfConstants .NOTIF ;
13
+
10
14
import com .google .common .base .Stopwatch ;
11
15
import com .google .common .base .Throwables ;
12
16
import io .lighty .core .controller .api .AbstractLightyModule ;
15
19
import io .lighty .server .LightyServerBuilder ;
16
20
import java .net .InetAddress ;
17
21
import java .net .InetSocketAddress ;
22
+ import javax .servlet .ServletContext ;
18
23
import org .eclipse .jetty .server .Server ;
19
24
import org .eclipse .jetty .server .handler .ContextHandlerCollection ;
20
25
import org .eclipse .jetty .servlet .ServletContextHandler ;
21
26
import org .eclipse .jetty .servlet .ServletHolder ;
27
+ import org .eclipse .jetty .websocket .server .WebSocketServerFactory ;
28
+ import org .eclipse .jetty .websocket .servlet .WebSocketServletFactory ;
22
29
import org .glassfish .jersey .server .ResourceConfig ;
23
30
import org .glassfish .jersey .servlet .ServletContainer ;
31
+ import org .opendaylight .controller .config .threadpool .ScheduledThreadPool ;
24
32
import org .opendaylight .mdsal .dom .api .DOMActionService ;
25
33
import org .opendaylight .mdsal .dom .api .DOMDataBroker ;
26
34
import org .opendaylight .mdsal .dom .api .DOMMountPointService ;
27
35
import org .opendaylight .mdsal .dom .api .DOMNotificationService ;
28
36
import org .opendaylight .mdsal .dom .api .DOMRpcService ;
29
37
import org .opendaylight .mdsal .dom .api .DOMSchemaService ;
38
+ import org .opendaylight .restconf .nb .rfc8040 .DataStreamApplication ;
30
39
import org .opendaylight .restconf .nb .rfc8040 .RestconfApplication ;
31
40
import org .opendaylight .restconf .nb .rfc8040 .databind .DatabindProvider ;
32
41
import org .opendaylight .restconf .nb .rfc8040 .databind .mdsal .DOMDatabindProvider ;
33
42
import org .opendaylight .restconf .nb .rfc8040 .handlers .SchemaContextHandler ;
43
+ import org .opendaylight .restconf .nb .rfc8040 .rests .services .impl .RestconfDataStreamServiceImpl ;
34
44
import org .opendaylight .restconf .nb .rfc8040 .streams .StreamsConfiguration ;
45
+ import org .opendaylight .restconf .nb .rfc8040 .streams .WebSocketInitializer ;
35
46
import org .slf4j .Logger ;
36
47
import org .slf4j .LoggerFactory ;
37
48
@@ -51,13 +62,14 @@ public class CommunityRestConf extends AbstractLightyModule {
51
62
private Server jettyServer ;
52
63
private LightyServerBuilder lightyServerBuilder ;
53
64
private SchemaContextHandler schemaCtxHandler ;
65
+ private final ScheduledThreadPool scheduledThreadPool ;
54
66
55
67
public CommunityRestConf (final DOMDataBroker domDataBroker , final DOMRpcService domRpcService ,
56
68
final DOMActionService domActionService , final DOMNotificationService domNotificationService ,
57
69
final DOMMountPointService domMountPointService ,
58
70
final DOMSchemaService domSchemaService , final InetAddress inetAddress ,
59
71
final int httpPort , final String restconfServletContextPath ,
60
- final LightyServerBuilder serverBuilder ) {
72
+ final LightyServerBuilder serverBuilder , final ScheduledThreadPool threadPool ) {
61
73
this .domDataBroker = domDataBroker ;
62
74
this .domRpcService = domRpcService ;
63
75
this .domActionService = domActionService ;
@@ -68,16 +80,17 @@ public CommunityRestConf(final DOMDataBroker domDataBroker, final DOMRpcService
68
80
this .httpPort = httpPort ;
69
81
this .inetAddress = inetAddress ;
70
82
this .restconfServletContextPath = restconfServletContextPath ;
83
+ this .scheduledThreadPool = threadPool ;
71
84
}
72
85
73
86
public CommunityRestConf (final DOMDataBroker domDataBroker ,
74
87
final DOMRpcService domRpcService , final DOMActionService domActionService ,
75
88
final DOMNotificationService domNotificationService , final DOMMountPointService domMountPointService ,
76
89
final DOMSchemaService domSchemaService , final InetAddress inetAddress , final int httpPort ,
77
- final String restconfServletContextPath ) {
90
+ final String restconfServletContextPath , final ScheduledThreadPool threadPool ) {
78
91
this (domDataBroker , domRpcService , domActionService , domNotificationService ,
79
92
domMountPointService , domSchemaService , inetAddress , httpPort ,
80
- restconfServletContextPath , null );
93
+ restconfServletContextPath , null , threadPool );
81
94
}
82
95
83
96
@ Override
@@ -93,10 +106,15 @@ protected boolean initProcedure() {
93
106
final RestconfApplication restconfApplication = new RestconfApplication (databindProvider ,
94
107
this .domMountPointService , this .domDataBroker , this .domRpcService , this .domActionService ,
95
108
this .domNotificationService , this .domSchemaService , streamsConfiguration );
109
+ final DataStreamApplication dataStreamApplication = new DataStreamApplication (databindProvider , this .domMountPointService ,
110
+ new RestconfDataStreamServiceImpl (scheduledThreadPool , streamsConfiguration ));
96
111
final ServletContainer servletContainer8040 = new ServletContainer (ResourceConfig
97
112
.forApplication (restconfApplication ));
98
113
final ServletHolder jaxrs = new ServletHolder (servletContainer8040 );
99
114
115
+ final ServletContainer dataStreamServletContainer = new ServletContainer (ResourceConfig .forApplication (dataStreamApplication ));
116
+ final ServletHolder dataStreamHolder = new ServletHolder (dataStreamServletContainer );
117
+
100
118
LOG .info ("RestConf init complete, starting Jetty" );
101
119
LOG .info ("http address:port {}:{}, url prefix: {}" , this .inetAddress .toString (), this .httpPort ,
102
120
this .restconfServletContextPath );
@@ -108,6 +126,19 @@ protected boolean initProcedure() {
108
126
new ServletContextHandler (contexts , this .restconfServletContextPath , true , false );
109
127
mainHandler .addServlet (jaxrs , "/*" );
110
128
129
+ final ServletContextHandler notifHandler =
130
+ new ServletContextHandler (contexts , "/" + NOTIF , true , false );
131
+ notifHandler .addServlet (dataStreamHolder , "/*" );
132
+
133
+ final ServletContextHandler wsHandler = new ServletContextHandler (contexts , "/" + DATA_SUBSCRIPTION , true , false );
134
+ final ServletContextHandler wsHandler1 = new ServletContextHandler (contexts , "/" + NOTIFICATION_STREAM , true , false );
135
+ final WebSocketInitializer webSocketInitializer = new WebSocketInitializer (scheduledThreadPool , streamsConfiguration );
136
+ ServletContext context = wsHandler1 .getServletContext ();
137
+ WebSocketServletFactory factory = new WebSocketServerFactory (context );
138
+ webSocketInitializer .configure (factory );
139
+ wsHandler .addServlet (new ServletHolder (webSocketInitializer ), "/*" );
140
+ wsHandler1 .addServlet (new ServletHolder (webSocketInitializer ), "/*" );
141
+
111
142
final ServletContextHandler rrdHandler =
112
143
new ServletContextHandler (contexts , "/.well-known" , true , false );
113
144
final RootFoundApplication rootDiscoveryApp = new RootFoundApplication (restconfServletContextPath );
0 commit comments