You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/08/07 15:52:13 UTC
[2/2] incubator-tamaya-sandbox git commit: TAMAYA-145: Added meta
logging feature.
TAMAYA-145: Added meta logging feature.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/31b9c0e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/31b9c0e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/31b9c0e1
Branch: refs/heads/java8
Commit: 31b9c0e1db95143e67dc945f25694f676d8cb00c
Parents: 1fec344
Author: anatole <an...@apache.org>
Authored: Mon Aug 7 17:33:38 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Aug 7 17:33:38 2017 +0200
----------------------------------------------------------------------
.../internal/resolver/LoggingReader.java | 79 ++++++++++++++++++++
...tamaya.metamodel.spi.MetaConfigurationReader | 19 +++++
2 files changed, 98 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/31b9c0e1/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java
----------------------------------------------------------------------
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java
new file mode 100644
index 0000000..c0d67bc
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/LoggingReader.java
@@ -0,0 +1,79 @@
+/*
+ * 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.tamaya.metamodel.internal.resolver;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.metamodel.MetaContext;
+import org.apache.tamaya.metamodel.spi.MetaConfigurationReader;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * Created by atsticks on 01.05.17.
+ */
+public class LoggingReader implements MetaConfigurationReader{
+
+ private static final JavaResolver resolver = new JavaResolver();
+
+ @Override
+ public void read(final Document document, ConfigurationContextBuilder contextBuilder) {
+ new Timer(true).schedule(new TimerTask() {
+ @Override
+ public void run() {
+ Map<String, Object> meta = new HashMap<>();
+ meta.put("context", ConfigurationProvider.getConfiguration().getContext());
+ meta.put("config", ConfigurationProvider.getConfiguration());
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("context");
+ for(int i=0;i<nodeList.getLength();i++){
+ Node node = nodeList.item(i);
+ if(node.getNodeName().equals("log")){
+ String expression = node.getTextContent();
+ BufferedReader reader = new BufferedReader(new StringReader(expression));
+ String line = null;
+ try {
+ line = reader.readLine();
+ while(line!=null){
+ Object res = resolver.evaluate(line);
+ if(res!=null) {
+ System.out.println(res);
+ }
+ line = reader.readLine();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }, 10000L);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/31b9c0e1/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
----------------------------------------------------------------------
diff --git a/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
new file mode 100644
index 0000000..ace072c
--- /dev/null
+++ b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.MetaConfigurationReader
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.tamaya.metamodel.internal.resolver.LoggingReader
\ No newline at end of file