This project has retired. For details please refer to its
Attic page.
ChukwaRecord xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.extraction.engine;
20
21
22 import java.nio.charset.Charset;
23 import java.util.Iterator;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.TreeMap;
27
28 import org.apache.hadoop.record.Buffer;
29
30 public class ChukwaRecord extends ChukwaRecordJT implements Record {
31 public ChukwaRecord() {
32 }
33
34 public void add(String key, String value) {
35 synchronized (this) {
36 if (this.mapFields == null) {
37 this.mapFields = new TreeMap<String, Buffer>();
38 }
39 }
40 this.mapFields.put(key, new Buffer(value.getBytes(Charset.forName("UTF-8"))));
41 }
42
43 public String[] getFields() {
44 return this.mapFields.keySet().toArray(new String[0]);
45 }
46
47 public String getValue(String field) {
48 if (this.mapFields.containsKey(field)) {
49 return new String(this.mapFields.get(field).get(), Charset.forName("UTF-8"));
50 } else {
51 return null;
52 }
53 }
54
55 public boolean containsField(String field) {
56 return this.mapFields.containsKey(field);
57 }
58
59 public void removeValue(String field) {
60 if (this.mapFields.containsKey(field)) {
61 this.mapFields.remove(field);
62 }
63 }
64
65 @Override
66 public String toString() {
67 Set<Map.Entry<String, Buffer>> f = this.mapFields.entrySet();
68 Iterator<Map.Entry<String, Buffer>> it = f.iterator();
69
70 Map.Entry<String, Buffer> entry = null;
71 StringBuilder sb = new StringBuilder();
72 sb.append("<event ");
73 StringBuilder body = new StringBuilder();
74
75 String key = null;
76 String val = null;
77 boolean hasBody = false;
78 String bodyVal = null;
79 while (it.hasNext()) {
80 entry = it.next();
81 key = entry.getKey().intern();
82 val = new String(entry.getValue().get(), Charset.forName("UTF-8"));
83 if (key.intern() == Record.bodyField.intern()) {
84 hasBody = true;
85 bodyVal = val;
86 } else {
87 sb.append(key).append("=\"").append(val).append("\" ");
88 body.append(key).append(" = ").append(val).append("<br>");
89 }
90
91 }
92 if (hasBody) {
93 sb.append(">").append(bodyVal);
94 } else {
95 sb.append(">").append(body);
96 }
97 sb.append("</event>");
98
99 return sb.toString();
100 }
101
102 }