1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.trace;
19 import java.io.IOException;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.conf.Configurable;
24 import org.apache.hadoop.conf.Configuration;
25 import org.cloudera.htrace.Span;
26 import org.cloudera.htrace.SpanReceiver;
27 import org.cloudera.htrace.Trace;
28 import org.cloudera.htrace.impl.LocalFileSpanReceiver;
29
30
31
32
33
34
35
36
37
38 public class HBaseLocalFileSpanReceiver implements SpanReceiver, Configurable {
39 public static final Log LOG = LogFactory
40 .getLog(HBaseLocalFileSpanReceiver.class);
41 public static final String FILE_NAME_CONF_KEY = "hbase.trace.spanreceiver.localfilespanreceiver.filename";
42 private Configuration conf;
43 private LocalFileSpanReceiver rcvr;
44
45 @Override
46 public Configuration getConf() {
47 return conf;
48 }
49
50 @Override
51 public void setConf(Configuration arg0) {
52 this.conf = arg0;
53
54 if (rcvr != null) {
55 try {
56 rcvr.close();
57 } catch (IOException e) {
58 LOG.warn("Error closing LocalFileSpanReceiver.", e);
59 }
60 }
61 try {
62 rcvr = new LocalFileSpanReceiver(conf.get(FILE_NAME_CONF_KEY));
63 } catch (IOException e) {
64 Trace.removeReceiver(this);
65 rcvr = null;
66 LOG.warn(
67 "Unable to initialize LocalFileSpanReceiver, removing owner (HBaseLocalFileSpanReceiver) from receiver list.",
68 e);
69 }
70 }
71
72 @Override
73 public void close() throws IOException {
74 try{
75 if (rcvr != null) {
76 rcvr.close();
77 }
78 } finally {
79 rcvr = null;
80 }
81 }
82
83 @Override
84 public void receiveSpan(Span span) {
85 if (rcvr != null) {
86 rcvr.receiveSpan(span);
87 }
88 }
89 }