* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.test.tool.rpc;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlRootElement;
-import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.messages.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.impl.NetconfServerSession;
-import org.opendaylight.netconf.impl.mapping.operations.DefaultNetconfOperation;
-import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation;
+import org.opendaylight.netconf.server.NetconfServerSession;
+import org.opendaylight.netconf.server.api.operations.AbstractLastNetconfOperation;
+import org.opendaylight.netconf.server.mapping.operations.DefaultNetconfOperation;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
public class SimulatedCreateSubscription extends AbstractLastNetconfOperation implements DefaultNetconfOperation {
-
private final Map<Notification, NetconfMessage> notifications;
+
private NetconfServerSession session;
private ScheduledExecutorService scheduledExecutorService;
- public SimulatedCreateSubscription(final String id, final Optional<File> notificationsFile) {
- super(id);
+ public SimulatedCreateSubscription(final SessionIdType sessionId, final Optional<File> notificationsFile) {
+ super(sessionId);
final Optional<Notifications> notifs;
-
if (notificationsFile.isPresent()) {
- notifs = Optional.of(loadNotifications(notificationsFile.get()));
+ notifs = Optional.of(loadNotifications(notificationsFile.orElseThrow()));
scheduledExecutorService = Executors.newScheduledThreadPool(1);
} else {
- notifs = Optional.absent();
+ notifs = Optional.empty();
}
if (notifs.isPresent()) {
- final Collection<Notification> toCopy = notifs.get().getNotificationList();
+ final List<Notification> toCopy = notifs.orElseThrow().getNotificationList();
final Map<Notification, NetconfMessage> preparedMessages = Maps.newHashMapWithExpectedSize(toCopy.size());
for (final Notification notification : toCopy) {
final NetconfMessage parsedNotification = parseNetconfNotification(notification.getContent());
preparedMessages.put(notification, parsedNotification);
}
- this.notifications = preparedMessages;
+ notifications = preparedMessages;
} else {
- this.notifications = Collections.emptyMap();
+ notifications = Map.of();
}
}
}, delayAggregator, TimeUnit.SECONDS);
}
}
- return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent());
+ return document.createElement(XmlNetconfConstants.OK);
}
private static NetconfMessage parseNetconfNotification(String content) {
@Override
public void setNetconfSession(final NetconfServerSession newSession) {
- this.session = newSession;
+ session = newSession;
}
@XmlRootElement(name = "notifications")
@Override
public String toString() {
- final StringBuffer sb = new StringBuffer("Notifications{");
+ final StringBuilder sb = new StringBuilder("Notifications{");
sb.append("notificationList=").append(notificationList);
sb.append('}');
return sb.toString();
@Override
public String toString() {
- final StringBuffer sb = new StringBuffer("Notification{");
+ final StringBuilder sb = new StringBuilder("Notification{");
sb.append("delayInSeconds=").append(delayInSeconds);
sb.append(", times=").append(times);
sb.append(", content='").append(content).append('\'');