1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.datacollection.agent;
20
21
22 import org.apache.hadoop.chukwa.datacollection.adaptor.Adaptor;
23 import org.apache.log4j.Logger;
24
25
26
27
28
29
30
31 public class AdaptorFactory {
32 public static final String PREPENDED_PACKAGE = "org.apache.hadoop.chukwa.datacollection.adaptor.";
33 static Logger log = Logger.getLogger(ChukwaAgent.class);
34
35
36
37
38
39
40
41 static public Adaptor createAdaptor(String className) {
42 Object obj = null;
43 try {
44
45
46
47 obj = Class.forName(className).newInstance();
48 if (Adaptor.class.isInstance(obj)) {
49 return (Adaptor) obj;
50 } else
51 return null;
52 } catch (Exception e1) {
53 log.debug("Error instantiating new adaptor by class name, "
54 + "attempting again, but with default chukwa package prepended, i.e. "
55 + PREPENDED_PACKAGE + className
56 + ". " + e1);
57 try {
58
59 Object obj2 = Class.forName(
60 PREPENDED_PACKAGE + className)
61 .newInstance();
62 if (Adaptor.class.isInstance(obj2)) {
63 log.debug("Succeeded in finding class by adding default adaptor "
64 + "namespace prefix to class name profided");
65 return (Adaptor) obj2;
66 } else
67 return null;
68 } catch (Exception e2) {
69 log.warn("Error instantiating new adaptor "+ className + " by classname"
70 + " and also with \"o.a.h.c.datacollection.adaptor\" prefix added", e2);
71 return null;
72 }
73 }
74 }
75
76 }