1 package org.apache.helix.healthcheck;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.StringTokenizer;
23
24 import org.apache.log4j.Logger;
25
26 public class AggregationTypeFactory
27 {
28 private static final Logger logger = Logger
29 .getLogger(AggregationTypeFactory.class);
30
31 public AggregationTypeFactory()
32 {
33 }
34
35
36
37 public static AggregationType getAggregationType(String input)
38 {
39 if (input == null)
40 {
41 logger.error("AggregationType name is null");
42 return null;
43 }
44 StringTokenizer tok = new StringTokenizer(input, AggregationType.DELIM);
45 String type = tok.nextToken();
46 int numParams = tok.countTokens();
47 String[] params = new String[numParams];
48 for (int i = 0; i < numParams; i++)
49 {
50 if (!tok.hasMoreTokens())
51 {
52 logger.error("Trying to parse non-existent params");
53 return null;
54 }
55 params[i] = tok.nextToken();
56 }
57
58 if (type.equals(AccumulateAggregationType.TYPE_NAME))
59 {
60 return new AccumulateAggregationType();
61 }
62 else if (type.equals(DecayAggregationType.TYPE_NAME))
63 {
64 if (params.length < 1)
65 {
66 logger
67 .error("DecayAggregationType must contain <decay weight> parameter");
68 return null;
69 }
70 return new DecayAggregationType(Double.parseDouble(params[0]));
71 }
72 else if (type.equals(WindowAggregationType.TYPE_NAME))
73 {
74 if (params.length < 1)
75 {
76 logger
77 .error("WindowAggregationType must contain <window size> parameter");
78 }
79 return new WindowAggregationType(Integer.parseInt(params[0]));
80 }
81 else
82 {
83 logger.error("Unknown AggregationType " + type);
84 return null;
85 }
86 }
87 }