You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:26:18 UTC
[sling-org-apache-sling-nosql-generic] 09/38: SLING-4381 enable
metrics logging for nosql adapter and disable event distribution
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-nosql-generic.git
commit 122f37e63307a18308dbf2ea4eeb95983ba12271
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu May 21 14:09:21 2015 +0000
SLING-4381 enable metrics logging for nosql adapter and disable event distribution
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1680879 13f79535-47bb-0310-9956-ffa450edef68
---
.../adapter/MetricsNoSqlAdapterWrapper.java | 111 +++++++++++++++++++++
.../resource/impl/NoSqlResourceProvider.java | 3 -
2 files changed, 111 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/nosql/generic/adapter/MetricsNoSqlAdapterWrapper.java b/src/main/java/org/apache/sling/nosql/generic/adapter/MetricsNoSqlAdapterWrapper.java
new file mode 100644
index 0000000..eaebf1d
--- /dev/null
+++ b/src/main/java/org/apache/sling/nosql/generic/adapter/MetricsNoSqlAdapterWrapper.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.nosql.generic.adapter;
+
+import java.util.Iterator;
+
+import org.slf4j.Logger;
+
+/**
+ * Wrapper for {@link NoSqlAdapter} that enables logging and time counting for each call.
+ */
+public final class MetricsNoSqlAdapterWrapper implements NoSqlAdapter {
+
+ private final NoSqlAdapter delegate;
+ private final Logger logger;
+
+ public MetricsNoSqlAdapterWrapper(NoSqlAdapter delegate, Logger logger) {
+ this.delegate = delegate;
+ this.logger = logger;
+ }
+
+ public boolean validPath(String path) {
+ return delegate.validPath(path);
+ }
+
+ public NoSqlData get(String path) {
+ Metrics metrics = new Metrics();
+ try {
+ return delegate.get(path);
+ }
+ finally {
+ metrics.finish("get({})", path);
+ }
+ }
+
+ public Iterator<NoSqlData> getChildren(String parentPath) {
+ Metrics metrics = new Metrics();
+ try {
+ return delegate.getChildren(parentPath);
+ }
+ finally {
+ metrics.finish("getChildren({})", parentPath);
+ }
+ }
+
+ public boolean store(NoSqlData data) {
+ Metrics metrics = new Metrics();
+ try {
+ return delegate.store(data);
+ }
+ finally {
+ metrics.finish("store({})", data.getPath());
+ }
+ }
+
+ public boolean deleteRecursive(String path) {
+ Metrics metrics = new Metrics();
+ try {
+ return delegate.deleteRecursive(path);
+ }
+ finally {
+ metrics.finish("deleteRecursive({})", path);
+ }
+ }
+
+ public Iterator<NoSqlData> query(String query, String language) {
+ Metrics metrics = new Metrics();
+ try {
+ return delegate.query(query, language);
+ }
+ finally {
+ metrics.finish("query({})", query);
+ }
+ }
+
+ private class Metrics {
+
+ private long startTime;
+
+ public Metrics() {
+ if (logger.isDebugEnabled()) {
+ startTime = System.currentTimeMillis();
+ }
+ }
+
+ public void finish(String message, Object... data) {
+ if (logger.isDebugEnabled()) {
+ long duration = System.currentTimeMillis() - startTime;
+ logger.debug(message + " (" + duration + "ms)", data);
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java b/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
index 1df45cb..acad8b4 100644
--- a/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
+++ b/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
@@ -223,7 +223,6 @@ public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourc
private void notifyAdded(String path) {
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(SlingConstants.PROPERTY_PATH, path);
- props.put("event.distribute", "");
final Event event = new Event(SlingConstants.TOPIC_RESOURCE_ADDED, props);
this.eventAdmin.postEvent(event);
}
@@ -231,7 +230,6 @@ public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourc
private void notifyUpdated(String path) {
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(SlingConstants.PROPERTY_PATH, path);
- props.put("event.distribute", "");
final Event event = new Event(SlingConstants.TOPIC_RESOURCE_CHANGED, props);
this.eventAdmin.postEvent(event);
}
@@ -239,7 +237,6 @@ public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourc
private void notifyRemoved(String path) {
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(SlingConstants.PROPERTY_PATH, path);
- props.put("event.distribute", "");
final Event event = new Event(SlingConstants.TOPIC_RESOURCE_REMOVED, props);
this.eventAdmin.postEvent(event);
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.