private Notification deserialize(final DOMNotification notification) { if(notification instanceof LazySerializedDOMNotification) { return ((LazySerializedDOMNotification) notification).getBindingData(); } return codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody()); } }
private String parsePayLoad(DOMNotification notification){ final AnyXmlNode encapData = (AnyXmlNode) notification.getBody().getChild(PAYLOAD_ARG).get(); final StringWriter writer = new StringWriter(); final StreamResult result = new StreamResult(writer); final TransformerFactory tf = TransformerFactory.newInstance(); try { final Transformer transformer = tf.newTransformer(); transformer.transform(encapData.getValue(), result); } catch (TransformerException e) { LOG.error("Can not parse PayLoad data", e); return null; } writer.flush(); return writer.toString(); }
public synchronized void publishNotification(final DOMNotification notification) { for (final DOMNotificationListener domNotificationListener : listeners.get(notification.getType())) { domNotificationListener.onNotification(notification); } }
private boolean isCapabilityChanged(final DOMNotification notification) { return notification.getBody().getNodeType().equals(NetconfCapabilityChange.QNAME); } };
@Override public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification) { final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers = listeners.get(notification.getType()); if (subscribers.isEmpty()) { return NO_LISTENERS; } return tryPublish(notification, subscribers); }
@Override public void onNotification(final DOMNotification notification) { final String nodeName = notification.getBody().getChild(EVENT_SOURCE_ARG).get().getValue().toString(); try { final AnyXmlNode encapData = (AnyXmlNode) notification.getBody().getChild(PAYLOAD_ARG).get(); final StringWriter writer = new StringWriter(); final StreamResult result = new StreamResult(writer); final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer transformer = tf.newTransformer(); transformer.transform(encapData.getValue(), result); writer.flush(); final String message = writer.toString(); synchronized (this) { for (final Map.Entry<ReceiverKey, AmqpReceiverContext> receiver : receivers.entrySet()) { receiver.getValue().sendMessage(message); } } LOG.info("Published notification for Agent {}: \nNotification {} ", nodeName, message); } catch (final Exception e) { throw new Messaging4TransportException(e); } }
@Override public ListenableFuture<? extends Object> offerNotification(final DOMNotification notification, final long timeout, final TimeUnit unit) throws InterruptedException { final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers = listeners.get(notification.getType()); if (subscribers.isEmpty()) { return NO_LISTENERS; } // Attempt to perform a non-blocking publish first final ListenableFuture<? extends Object> noBlock = tryPublish(notification, subscribers); if (!DOMNotificationPublishService.REJECTED.equals(noBlock)) { return noBlock; } /* * FIXME: we need a background thread, which will watch out for blocking too long. Here * we will arm a tasklet for it and synchronize delivery of interrupt properly. */ throw new UnsupportedOperationException("Not implemented yet"); }
/** * This method implements on Notification. * When there is a notification received by listener, that should be * parsed for the subscription-id and then processed. */ @Override public void onNotification(DOMNotification notification) { LOG.trace("Notification recieved {}", notification.getBody()); QName qname = PushUpdate.QNAME; SchemaPath schemaPath = SchemaPath.create(true, qname); if (notification.getType().equals(schemaPath)) { ContainerNode conNode = notification.getBody(); //If the subscription-id of notification same as // subscription-id set for this object then proceed. //if (conNode.getChild(subid).get().getValue().toString().equals(subscription_id)){ if (this.subscriptionList.contains(conNode.getChild(subid).get().getValue().toString())) { LOG.trace("Received push-udpate for subscription {}",conNode.getChild(subid).get().getValue().toString() ); try { pushUpdateHandlder(notification); } catch (Exception e) { LOG.warn(e.toString()); } } else { LOG.error("Received subscription-id {} is not valid. Skipping the notification processing", conNode.getChild(subid).get().getValue().toString()); } } }
@Override public void onNotification(DOMNotification notification) { LOG.debug("Notification arrived..."); String nodeName = null; TopicId topicId = null; // get the nodeName (identifier of event source) from notification if(notification.getBody().getChild(EVENT_SOURCE_ARG).isPresent()){ nodeName = notification.getBody().getChild(EVENT_SOURCE_ARG).get().getValue().toString(); } // get the TopicId from notification if(notification.getBody().getChild(TOPIC_ID_ARG).isPresent()){; topicId = (TopicId) notification.getBody().getChild(TOPIC_ID_ARG).get().getValue(); } if( nodeName != null && topicId != null ){ // if nodeName and TopicId are present and TopicId has been requested to process (TopicId is in registeredTopic) // then notification is parsed and written into the file. if(registeredTopic.contains(topicId.getValue())){ final String payLoadString = parsePayLoad(notification); if(payLoadString != null){ writeOutputLine(nodeName + " : " + payLoadString); LOG.debug("Notification write to FILE"); } } } }
@Override public void onNotification(@Nonnull final DOMNotification notification) { final Notification baNotification = deserialize(notification); final QName notificationQName = notification.getType().getLastComponent(); getInvoker(notification.getType()).invokeNotification(delegate, notificationQName, baNotification); }
private AnyXmlNode encapsulate(final DOMNotification body) { // FIXME: Introduce something like YangModeledAnyXmlNode in Yangtools final Document doc = XmlUtil.newDocument(); final Optional<String> namespace = Optional.of(PAYLOAD_ARG.getNodeType().getNamespace().toString()); final Element element = XmlUtil.createElement(doc, "payload", namespace); final DOMResult result = new DOMResult(element); final SchemaContext context = mount.getSchemaContext(); final SchemaPath schemaPath = body.getType(); try { NetconfUtil.writeNormalizedNode(body.getBody(), result, schemaPath, context); return Builders.anyXmlBuilder().withNodeIdentifier(PAYLOAD_ARG).withValue(new DOMSource(element)).build(); } catch (IOException | XMLStreamException e) { LOG.error("Unable to encapsulate notification.", e); throw Throwables.propagate(e); } }
/** * This method parse the pushUpdate notification received * for the subscription-id and stores the data to md-sal * using path /push-updates/push-update/[subscription-id=sub_id]/ * * @param notification * @return DOMSource for the notification */ private void pushUpdateHandlder(DOMNotification notification) { ContainerNode conNode = notification.getBody(); ChoiceNode valueNode = null; AnyXmlNode anyXmlValue = null; DOMSource domSource = null; String sub_id = ""; String timeofeventupdate = ""; try { sub_id = conNode.getChild(subid).get().getValue().toString(); timeofeventupdate = conNode.getChild(timeofevent).get().getValue().toString(); valueNode = (ChoiceNode) conNode.getChild(encoding).get(); anyXmlValue = (AnyXmlNode) valueNode.getChild(contents).get(); domSource = anyXmlValue.getValue(); } catch (Exception e) { LOG.warn(e.toString()); } //String notificationAsString = domSourceToString(domSource); String notificationAsString = valueNode.getChild(contents).get().getValue().toString(); LOG.trace("Notification recieved for sub_id :{} at : {}:\n {}", sub_id, timeofeventupdate, notificationAsString); storeToMdSal(sub_id, timeofeventupdate, domSource, notificationAsString); }
@Override public ListenableFuture<? extends Object> putNotification(final DOMNotification notification) throws InterruptedException { final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers = listeners.get(notification.getType()); if (subscribers.isEmpty()) { return NO_LISTENERS; } final long seq = disruptor.getRingBuffer().next(); return publish(seq, notification, subscribers); }
@Override public void onNotification(final DOMNotification notification) { SchemaPath notificationPath = notification.getType(); Date notificationEventTime = null; if (notification instanceof DOMEvent) { notificationEventTime = ((DOMEvent) notification).getEventTime(); } final String namespace = notification.getType().getLastComponent().getNamespace().toString(); for (NotificationTopicRegistration notifReg : notificationTopicRegistrations.get(namespace)) { notifReg.setLastEventTime(notificationEventTime); Set<TopicId> topicIdsForNotification = notifReg.getTopicsForNotification(notificationPath); for (TopicId topicId : topicIdsForNotification) { publishNotification(notification, topicId); LOG.debug("Notification {} has been published for TopicId {}", notification.getType(), topicId.getValue()); } } }