[
https://issues.apache.org/jira/browse/KARAF-5915?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16614973#comment-16614973
]
ASF GitHub Bot commented on KARAF-5915:
---------------------------------------
jbonofre closed pull request #53: [KARAF-5915] Improve the API Parser adding
key data as parameter
URL: https://github.com/apache/karaf-decanter/pull/53
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/api/src/main/java/org/apache/karaf/decanter/api/parser/Parser.java
b/api/src/main/java/org/apache/karaf/decanter/api/parser/Parser.java
index c5567c3..dc24ddc 100644
--- a/api/src/main/java/org/apache/karaf/decanter/api/parser/Parser.java
+++ b/api/src/main/java/org/apache/karaf/decanter/api/parser/Parser.java
@@ -22,5 +22,5 @@
String SERVICE_KEY_ID = "parserId";
- Map<String, Object> parse(String line);
+ Map<String, Object> parse(String key, String line);
}
diff --git
a/api/src/main/java/org/apache/karaf/decanter/impl/parser/IdentityParser.java
b/api/src/main/java/org/apache/karaf/decanter/impl/parser/IdentityParser.java
index f088d9a..2abef04 100644
---
a/api/src/main/java/org/apache/karaf/decanter/impl/parser/IdentityParser.java
+++
b/api/src/main/java/org/apache/karaf/decanter/impl/parser/IdentityParser.java
@@ -26,24 +26,29 @@
public class IdentityParser implements Parser {
@Override
- public Map<String, Object> parse(String line) {
+ public Map<String, Object> parse(String key, String line) {
Map<String, Object> data = new HashMap<>();
+ String datakey = "line";
+ if (key != null) {
+ datakey = key.trim();
+ }
+
try {
- data.put("line", Integer.parseInt(line));
+ data.put(datakey, Integer.parseInt(line));
return data;
} catch (Exception e) {
// nothing to do
}
try {
- data.put("line", Long.parseLong(line));
+ data.put(datakey, Long.parseLong(line));
return data;
} catch (Exception e) {
// nothing to do
}
- data.put("line", line);
+ data.put(datakey, line);
return data;
}
}
diff --git
a/api/src/test/java/org/apache/karaf/decanter/impl/parser/TestIdentityParser.java
b/api/src/test/java/org/apache/karaf/decanter/impl/parser/TestIdentityParser.java
index fae39ed..a3d05a1 100644
---
a/api/src/test/java/org/apache/karaf/decanter/impl/parser/TestIdentityParser.java
+++
b/api/src/test/java/org/apache/karaf/decanter/impl/parser/TestIdentityParser.java
@@ -38,30 +38,30 @@ public void testParse() {
"uuid=e75146c3-f73c-46e3-878b-1b88e58d76cf] for service with
service.id [16]";
System.out.println("line String :: " + lineString);
- data = parser.parse(lineString);
+ data = parser.parse("line_string", lineString);
Assert.assertNotNull("parser result is null", data);
Assert.assertEquals("parser size result is incorrect",1, data.size());
- Assert.assertTrue("parser value is not a string",data.get("line")
instanceof String);
+ Assert.assertTrue("parser value is not a
string",data.get("line_string") instanceof String);
// Integer type test
String lineInteger = "512";
System.out.println("line Integer :: " + lineInteger);
- data = parser.parse(lineInteger);
+ data = parser.parse("line_integer", lineInteger);
Assert.assertNotNull("parser result is null", data);
Assert.assertEquals("parser size result is incorrect", 1, data.size());
- Assert.assertTrue("parser value is not an integer",data.get("line")
instanceof Integer);
+ Assert.assertTrue("parser value is not an
integer",data.get("line_integer") instanceof Integer);
// Long type test
String lineLong = "9223372036854775806";
System.out.println("line Long :: " + lineLong);
- data = parser.parse(lineLong);
+ data = parser.parse("line_long", lineLong);
Assert.assertNotNull("parser result is null", data);
Assert.assertEquals("parser size result is incorrect", 1, data.size());
- Assert.assertTrue("parser value is not a long",data.get("line")
instanceof Long);
+ Assert.assertTrue("parser value is not a long",data.get("line_long")
instanceof Long);
}
}
diff --git
a/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
b/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
index 040953d..f07bce1 100644
---
a/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
+++
b/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
@@ -103,12 +103,12 @@ public void handle(String line) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
- data.putAll(this.parser.parse(line));
+ data.putAll(this.parser.parse("line_" + type, line));
} else {
return;
}
} else {
- data.putAll(this.parser.parse(line));
+ data.putAll(this.parser.parse("line_" + type, line));
}
try {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Improve the API Parser adding key data as parameter
> ---------------------------------------------------
>
> Key: KARAF-5915
> URL: https://issues.apache.org/jira/browse/KARAF-5915
> Project: Karaf
> Issue Type: Improvement
> Components: decanter
> Reporter: Francois Papon
> Assignee: Francois Papon
> Priority: Major
> Fix For: decanter-2.2.0
>
>
> Today we have the data key line defined in the parser. It would be
> interesting to add the key as parameter in the API that we could have a
> different key for each collector instance.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)