Line | Hits | Source |
---|---|---|
1 | package umich.cac.data; | |
2 | ||
3 | import java.util.logging.Level; | |
4 | import java.util.logging.Logger; | |
5 | import java.util.regex.Matcher; | |
6 | import java.util.regex.Pattern; | |
7 | ||
8 | import umich.cac.pbs.FieldFactory; | |
9 | ||
10 | /** | |
11 | * This class encapsulates memory field data. Memory in PBS is encoded as | |
12 | * "1234kb" where the data AND the unites are in the same field. It is nice to | |
13 | * have the units seperate from the data. Thus two children are created MEMORY | |
14 | * and UNITS, so the results XML looks like | |
15 | * | |
16 | * <pre> | |
17 | * <mem> <memory>15848</memory> <units>kb</units> </mem> | |
18 | * </pre> | |
19 | * | |
20 | * @author rmach@umich.edu | |
21 | * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/data/MemField.java,v 1.3 2003/10/21 19:08:00 rodmach Exp $ | |
22 | */ | |
23 | public class MemField extends Field { | |
24 | ||
25 | ||
26 | 18 | private Logger logger = Logger.getLogger(MemField.class.getName()); |
27 | ||
28 | /** | |
29 | * Constructor for MemField field | |
30 | * | |
31 | * @param fieldName | |
32 | * FieldName describing this field, like MEM or VMEM | |
33 | * @param rawValue | |
34 | * The raw value of this field from accounting data | |
35 | */ | |
36 | public MemField(FieldName fieldName, String rawValue) { | |
37 | 15 | super(fieldName, rawValue, fieldName.getFieldType()); |
38 | 15 | setupChildren(rawValue); |
39 | 15 | } |
40 | ||
41 | /** | |
42 | * Contains children of type node. | |
43 | * | |
44 | * @param rawValue | |
45 | * The raw value of this field from accounting data | |
46 | */ | |
47 | private void setupChildren(String rawValue) { | |
48 | ||
49 | //The pattern matchines 1234kb for example | |
50 | 15 | String patternStr = "(\\d+)(\\S+)"; |
51 | 15 | Pattern pattern = Pattern.compile(patternStr); |
52 | 15 | Matcher matcher = pattern.matcher(rawValue); |
53 | 15 | boolean matchFound = matcher.find(); |
54 | ||
55 | //Look for a match, we should always find one if data is in correct | |
56 | // format | |
57 | 15 | if (matchFound) { |
58 | 15 | if (matcher.groupCount() == 2) { |
59 | ||
60 | //The memory is the match from group 1, the (\\d+) | |
61 | 15 | String memory = matcher.group(1); |
62 | //The units is the match from group 2, the (\\S+) | |
63 | 15 | String units = matcher.group(2); |
64 | ||
65 | //Add the child nodes | |
66 | 15 | Field memoryNode = |
67 | FieldFactory.getInstance().getField( | |
68 | FieldName.MEMORY, | |
69 | memory); | |
70 | 15 | addChild(memoryNode); |
71 | ||
72 | 15 | Field unitsNode = |
73 | FieldFactory.getInstance().getField(FieldName.UNITS, units); | |
74 | 15 | addChild(unitsNode); |
75 | ||
76 | } else { | |
77 | 0 | if (logger.isLoggable(Level.WARNING)) { |
78 | 0 | logger.warning( |
79 | "The group count for " | |
80 | + rawValue | |
81 | + " is not correct, it should be 2"); | |
82 | } | |
83 | } | |
84 | } else { | |
85 | 0 | if (logger.isLoggable(Level.WARNING)) { |
86 | 0 | logger.warning( |
87 | "The regex of " | |
88 | + patternStr | |
89 | + " did not match " | |
90 | + rawValue | |
91 | + " so discarding"); | |
92 | } | |
93 | } | |
94 | ||
95 | 15 | } |
96 | ||
97 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |