use of org.opendaylight.netconf.sal.streams.websockets.WebSocketServer in project netconf by opendaylight.
the class RestconfImpl method notifStream.
/**
* Register notification listener by stream name.
*
* @param identifier
* stream name
* @param uriInfo
* uriInfo
* @param stop
* stop-time of getting notification
* @param start
* start-time of getting notification
* @param filter
* indicate which subset of all possible events are of interest
* @return {@link URI} of location
*/
private URI notifStream(final String identifier, final UriInfo uriInfo, final Instant start, final Instant stop, final String filter) {
final String streamName = Notificator.createStreamNameFromUri(identifier);
if (Strings.isNullOrEmpty(streamName)) {
throw new RestconfDocumentedException("Stream name is empty.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final List<NotificationListenerAdapter> listeners = Notificator.getNotificationListenerFor(streamName);
if (listeners == null || listeners.isEmpty()) {
throw new RestconfDocumentedException("Stream was not found.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
}
for (final NotificationListenerAdapter listener : listeners) {
broker.registerToListenNotification(listener);
listener.setQueryParams(start, Optional.ofNullable(stop), Optional.ofNullable(filter), false, false);
}
final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
final WebSocketServer webSocketServerInstance = WebSocketServer.getInstance(NOTIFICATION_PORT);
final int notificationPort = webSocketServerInstance.getPort();
final UriBuilder uriToWebsocketServerBuilder = uriBuilder.port(notificationPort).scheme(getWsScheme(uriInfo));
return uriToWebsocketServerBuilder.replacePath(streamName).build();
}
use of org.opendaylight.netconf.sal.streams.websockets.WebSocketServer in project netconf by opendaylight.
the class RestconfImpl method dataSubs.
/**
* Register data change listener by stream name.
*
* @param identifier
* stream name
* @param uriInfo
* uri info
* @param stop
* start-time of getting notification
* @param start
* stop-time of getting notification
* @param filter
* indicate which subset of all possible events are of interest
* @return {@link URI} of location
*/
private URI dataSubs(final String identifier, final UriInfo uriInfo, final Instant start, final Instant stop, final String filter, final boolean leafNodesOnly, final boolean skipNotificationData) {
final String streamName = Notificator.createStreamNameFromUri(identifier);
if (Strings.isNullOrEmpty(streamName)) {
throw new RestconfDocumentedException("Stream name is empty.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final ListenerAdapter listener = Notificator.getListenerFor(streamName);
if (listener == null) {
throw new RestconfDocumentedException("Stream was not found.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
}
listener.setQueryParams(start, Optional.ofNullable(stop), Optional.ofNullable(filter), leafNodesOnly, skipNotificationData);
final Map<String, String> paramToValues = resolveValuesFromUri(identifier);
final LogicalDatastoreType datastore = parserURIEnumParameter(LogicalDatastoreType.class, paramToValues.get(DATASTORE_PARAM_NAME));
if (datastore == null) {
throw new RestconfDocumentedException("Stream name doesn't contains datastore value (pattern /datastore=)", ErrorType.APPLICATION, ErrorTag.MISSING_ATTRIBUTE);
}
final Scope scope = parserURIEnumParameter(Scope.class, paramToValues.get(SCOPE_PARAM_NAME));
if (scope == null) {
throw new RestconfDocumentedException("Stream name doesn't contains datastore value (pattern /scope=)", ErrorType.APPLICATION, ErrorTag.MISSING_ATTRIBUTE);
}
broker.registerToListenDataChanges(datastore, scope, listener);
final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
final WebSocketServer webSocketServerInstance = WebSocketServer.getInstance(NOTIFICATION_PORT);
final int notificationPort = webSocketServerInstance.getPort();
final UriBuilder uriToWebsocketServerBuilder = uriBuilder.port(notificationPort).scheme(getWsScheme(uriInfo));
return uriToWebsocketServerBuilder.replacePath(streamName).build();
}
Aggregations