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.util.Iterator;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.TreeMap;
26 import org.apache.hadoop.record.Buffer;
27
28 public class ChukwaRecord extends ChukwaRecordJT implements Record {
29 public ChukwaRecord() {
30 }
31
32 public void add(String key, String value) {
33 synchronized (this) {
34 if (this.mapFields == null) {
35 this.mapFields = new TreeMap<String, org.apache.hadoop.record.Buffer>();
36 }
37 }
38 this.mapFields.put(key, new Buffer(value.getBytes()));
39 }
40
41 public String[] getFields() {
42 return this.mapFields.keySet().toArray(new String[0]);
43 }
44
45 public String getValue(String field) {
46 if (this.mapFields.containsKey(field)) {
47 return new String(this.mapFields.get(field).get());
48 } else {
49 return null;
50 }
51 }
52
53 public boolean containsField(String field) {
54 return this.mapFields.containsKey(field);
55 }
56
57 public void removeValue(String field) {
58 if (this.mapFields.containsKey(field)) {
59 this.mapFields.remove(field);
60 }
61 }
62
63 @Override
64 public String toString() {
65 Set<Map.Entry<String, Buffer>> f = this.mapFields.entrySet();
66 Iterator<Map.Entry<String, Buffer>> it = f.iterator();
67
68 Map.Entry<String, Buffer> entry = null;
69 StringBuilder sb = new StringBuilder();
70 sb.append("<event ");
71 StringBuilder body = new StringBuilder();
72
73 String key = null;
74 String val = null;
75 boolean hasBody = false;
76 String bodyVal = null;
77 while (it.hasNext()) {
78 entry = it.next();
79 key = entry.getKey().intern();
80 val = new String(entry.getValue().get());
81 if (key.intern() == Record.bodyField.intern()) {
82 hasBody = true;
83 bodyVal = val;
84 } else {
85 sb.append(key).append("=\"").append(val).append("\" ");
86 body.append(key).append(" = ").append(val).append("<br>");
87 }
88
89 }
90 if (hasBody) {
91 sb.append(">").append(bodyVal);
92 } else {
93 sb.append(">").append(body);
94 }
95 sb.append("</event>");
96
97 return sb.toString();
98 }
99
100 }