If the listener is not started yet, or it has stopped, we should
not try to format the document. This splits the checking into two
phases, improving things and laying the foundation for a complete
factoring out the common bits.
Change-Id: Ibff73a4979a5d67385f10647ca7c9ab64a35f42a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
- /**
- * Checking query parameters on specific notification.
- *
- * @param xml data of notification
- * @param listener listener of notification
- * @return true if notification meets the requirements of query parameters,
- * false otherwise
- */
@SuppressWarnings("checkstyle:IllegalCatch")
@SuppressWarnings("checkstyle:IllegalCatch")
- protected <T extends BaseListenerInterface> boolean checkQueryParams(final String xml, final T listener) {
- final Instant now = Instant.now();
+ <T extends BaseListenerInterface> boolean checkStartStop(final Instant now, final T listener) {
- if ((this.start.compareTo(now) < 0) && (this.stop.compareTo(now) > 0)) {
- return checkFilter(xml);
+ if (this.start.compareTo(now) < 0 && this.stop.compareTo(now) > 0) {
+ return true;
}
if (this.stop.compareTo(now) < 0) {
try {
}
if (this.stop.compareTo(now) < 0) {
try {
} else if (this.start != null) {
if (this.start.compareTo(now) < 0) {
this.start = null;
} else if (this.start != null) {
if (this.start.compareTo(now) < 0) {
this.start = null;
- return checkFilter(xml);
- return checkFilter(xml);
* @param xml data of notification
*/
@SuppressWarnings("checkstyle:IllegalCatch")
* @param xml data of notification
*/
@SuppressWarnings("checkstyle:IllegalCatch")
- private boolean checkFilter(final String xml) {
+ boolean checkFilter(final String xml) {
if (this.filter == null) {
return true;
}
if (this.filter == null) {
return true;
}
import com.google.common.base.Preconditions;
import java.io.IOException;
import com.google.common.base.Preconditions;
import java.io.IOException;
+import java.time.Instant;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
@Override
public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> dataTreeCandidates) {
@Override
public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> dataTreeCandidates) {
+ final Instant now = Instant.now();
+ if (!checkStartStop(now, this)) {
+ return;
+ }
+
final String xml = prepareXml(dataTreeCandidates);
final String xml = prepareXml(dataTreeCandidates);
- if (checkQueryParams(xml, this)) {
+ if (checkFilter(xml)) {
prepareAndPostData(xml);
}
}
prepareAndPostData(xml);
}
}
@Override
public void onNotification(final DOMNotification notification) {
@Override
public void onNotification(final DOMNotification notification) {
+ final Instant now = Instant.now();
+ if (!checkStartStop(now, this)) {
+ return;
+ }
+
final SchemaContext schemaContext = controllerContext.getGlobalSchema();
final String xml = prepareXml(schemaContext, notification);
final SchemaContext schemaContext = controllerContext.getGlobalSchema();
final String xml = prepareXml(schemaContext, notification);
- if (checkQueryParams(xml, this)) {
+ if (checkFilter(xml)) {
prepareAndPostData(outputType.equals("JSON") ? prepareJson(schemaContext, notification) : xml);
}
}
prepareAndPostData(outputType.equals("JSON") ? prepareJson(schemaContext, notification) : xml);
}
}
- /**
- * Checking query parameters on specific notification.
- *
- * @param xml data of notification
- * @param listener listener of notification
- * @return true if notification meets the requirements of query parameters,
- * false otherwise
- */
@SuppressWarnings("checkstyle:IllegalCatch")
@SuppressWarnings("checkstyle:IllegalCatch")
- protected <T extends BaseListenerInterface> boolean checkQueryParams(final String xml, final T listener) {
- final Instant now = Instant.now();
+ <T extends BaseListenerInterface> boolean checkStartStop(final Instant now, final T listener) {
- if ((this.start.compareTo(now) < 0) && (this.stop.compareTo(now) > 0)) {
- return checkFilter(xml);
+ if (this.start.compareTo(now) < 0 && this.stop.compareTo(now) > 0) {
+ return true;
}
if (this.stop.compareTo(now) < 0) {
try {
}
if (this.stop.compareTo(now) < 0) {
try {
} else if (this.start != null) {
if (this.start.compareTo(now) < 0) {
this.start = null;
} else if (this.start != null) {
if (this.start.compareTo(now) < 0) {
this.start = null;
- return checkFilter(xml);
- return checkFilter(xml);
* @param xml data of notification
*/
@SuppressWarnings("checkstyle:IllegalCatch")
* @param xml data of notification
*/
@SuppressWarnings("checkstyle:IllegalCatch")
- private boolean checkFilter(final String xml) {
+ boolean checkFilter(final String xml) {
if (this.filter == null) {
return true;
}
if (this.filter == null) {
return true;
}
import com.google.common.base.Preconditions;
import java.io.IOException;
import com.google.common.base.Preconditions;
import java.io.IOException;
+import java.time.Instant;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
@Override
public void onDataTreeChanged(final Collection<DataTreeCandidate> dataTreeCandidates) {
@Override
public void onDataTreeChanged(final Collection<DataTreeCandidate> dataTreeCandidates) {
+ final Instant now = Instant.now();
+ if (!checkStartStop(now, this)) {
+ return;
+ }
+
final String xml = prepareXml(dataTreeCandidates);
final String xml = prepareXml(dataTreeCandidates);
- if (checkQueryParams(xml, this)) {
+ if (checkFilter(xml)) {
prepareAndPostData(xml);
}
}
prepareAndPostData(xml);
}
}
@Override
public void onNotification(final DOMNotification notification) {
@Override
public void onNotification(final DOMNotification notification) {
+ final Instant now = Instant.now();
+ if (!checkStartStop(now, this)) {
+ return;
+ }
+
final SchemaContext schemaContext = schemaHandler.get();
final String xml = prepareXml(schemaContext, notification);
final SchemaContext schemaContext = schemaHandler.get();
final String xml = prepareXml(schemaContext, notification);
- if (checkQueryParams(xml, this)) {
+ if (checkFilter(xml)) {
prepareAndPostData(outputType.equals("JSON") ? prepareJson(schemaContext, notification) : xml);
}
}
prepareAndPostData(outputType.equals("JSON") ? prepareJson(schemaContext, notification) : xml);
}
}