*/
package org.opendaylight.netconf.sal.connect.netconf;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import java.util.LinkedList;
import java.util.List;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
+import java.util.Optional;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
private MessageTransformer<NetconfMessage> messageTransformer;
NotificationHandler(final RemoteDeviceHandler<?> salFacade, final RemoteDeviceId id) {
- this.salFacade = Preconditions.checkNotNull(salFacade);
- this.id = Preconditions.checkNotNull(id);
+ this.salFacade = requireNonNull(salFacade);
+ this.id = requireNonNull(id);
}
synchronized void handleNotification(final NetconfMessage notification) {
- if(passNotifications) {
+ if (passNotifications) {
passNotification(transformNotification(notification));
} else {
queueNotification(notification);
/**
* Forward all cached notifications and pass all notifications from this point directly to sal facade.
- * @param messageTransformer
+ * @param transformer Message transformer
*/
- synchronized void onRemoteSchemaUp(final MessageTransformer<NetconfMessage> messageTransformer) {
- this.messageTransformer = Preconditions.checkNotNull(messageTransformer);
+ synchronized void onRemoteSchemaUp(final MessageTransformer<NetconfMessage> transformer) {
+ this.messageTransformer = requireNonNull(transformer);
passNotifications = true;
}
private DOMNotification transformNotification(final NetconfMessage cachedNotification) {
- final DOMNotification parsedNotification = messageTransformer.toNotification(cachedNotification);
- Preconditions.checkNotNull(parsedNotification, "%s: Unable to parse received notification: %s", id, cachedNotification);
- return parsedNotification;
+ return checkNotNull(messageTransformer.toNotification(cachedNotification),
+ "%s: Unable to parse received notification: %s", id, cachedNotification);
}
private void queueNotification(final NetconfMessage notification) {
- Preconditions.checkState(passNotifications == false);
+ checkState(!passNotifications);
LOG.debug("{}: Caching notification {}, remote schema not yet fully built", id, notification);
- if(LOG.isTraceEnabled()) {
+ if (LOG.isTraceEnabled()) {
LOG.trace("{}: Caching notification {}", id, XmlUtil.toString(notification.getDocument()));
}
private synchronized void passNotification(final DOMNotification parsedNotification) {
LOG.debug("{}: Forwarding notification {}", id, parsedNotification);
- if(filter == null || filter.filterNotification(parsedNotification).isPresent()) {
+ if (filter == null || filter.filterNotification(parsedNotification).isPresent()) {
salFacade.onNotification(parsedNotification);
}
}
- synchronized void addNotificationFilter(final NotificationFilter filter) {
- this.filter = filter;
+ synchronized void addNotificationFilter(final NotificationFilter newFilter) {
+ this.filter = newFilter;
}
synchronized void onRemoteSchemaDown() {
messageTransformer = null;
}
- static interface NotificationFilter {
+ interface NotificationFilter {
Optional<DOMNotification> filterNotification(DOMNotification notification);
}