X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Ftools%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Ftest%2Ftool%2Frpc%2FSimulatedCreateSubscription.java;h=fc7e99a31d3cf0b72cb56b05e872a3b20f79b882;hb=c1868b25648677e5834bc6823a7a4aa8ce1dd2c8;hp=9ec5795de21f0b87d6d7d727ed4d03a4a56916f1;hpb=dffe3d87e10e92d53c8fa175266eff388d5d88d7;p=netconf.git diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpc/SimulatedCreateSubscription.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpc/SimulatedCreateSubscription.java index 9ec5795de2..fc7e99a31d 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpc/SimulatedCreateSubscription.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpc/SimulatedCreateSubscription.java @@ -14,6 +14,7 @@ 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; @@ -25,11 +26,10 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlRootElement; -import org.opendaylight.controller.config.util.xml.DocumentedException; -import org.opendaylight.controller.config.util.xml.XmlElement; -import org.opendaylight.controller.config.util.xml.XmlUtil; import org.opendaylight.netconf.api.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; @@ -46,19 +46,19 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im public SimulatedCreateSubscription(final String id, final Optional notificationsFile) { super(id); - Optional notifications; + final Optional notifs; if (notificationsFile.isPresent()) { - notifications = Optional.of(loadNotifications(notificationsFile.get())); + notifs = Optional.of(loadNotifications(notificationsFile.get())); scheduledExecutorService = Executors.newScheduledThreadPool(1); } else { - notifications = Optional.absent(); + notifs = Optional.absent(); } - if (notifications.isPresent()) { - Map preparedMessages = Maps.newHashMapWithExpectedSize( - notifications.get().getNotificationList().size()); - for (final Notification notification : notifications.get().getNotificationList()) { + if (notifs.isPresent()) { + final Collection toCopy = notifs.get().getNotificationList(); + final Map preparedMessages = Maps.newHashMapWithExpectedSize(toCopy.size()); + for (final Notification notification : toCopy) { final NetconfMessage parsedNotification = parseNetconfNotification(notification.getContent()); preparedMessages.put(notification, parsedNotification); } @@ -66,10 +66,9 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im } else { this.notifications = Collections.emptyMap(); } - } - private Notifications loadNotifications(final File file) { + private static Notifications loadNotifications(final File file) { try { final JAXBContext jaxbContext = JAXBContext.newInstance(Notifications.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); @@ -90,8 +89,7 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im } @Override - protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) - throws DocumentedException { + protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) { long delayAggregator = 0; for (final Map.Entry notification : notifications.entrySet()) { @@ -99,16 +97,13 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im delayAggregator += notification.getKey().getDelayInSeconds(); - scheduledExecutorService.schedule(new Runnable() { - @Override - public void run() { - Preconditions.checkState(session != null, "Session is not set, cannot process notifications"); - session.sendMessage(notification.getValue()); - } + scheduledExecutorService.schedule(() -> { + Preconditions.checkState(session != null, "Session is not set, cannot process notifications"); + session.sendMessage(notification.getValue()); }, delayAggregator, TimeUnit.SECONDS); } } - return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); } private static NetconfMessage parseNetconfNotification(String content) { @@ -127,8 +122,8 @@ public class SimulatedCreateSubscription extends AbstractLastNetconfOperation im } @Override - public void setNetconfSession(final NetconfServerSession session) { - this.session = session; + public void setNetconfSession(final NetconfServerSession newSession) { + this.session = newSession; } @XmlRootElement(name = "notifications")