SlicingMeasurementCategoryFactory.java

biz/hammurapi/metrics/SlicingMeasurementCategoryFactory.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 089 Type is not documented 2 48:1
Java Inspector 089 Undocumented method 2 51:5
Java Inspector 089 Javadoc contains tag for non-existent parameter cxpa 2 83:9
Java Inspector 089 Javadoc contains tag for non-existent parameter factory 2 83:9
Java Inspector 089 Javadoc contains tag for exception which method doesn't throw TransformerException 2 83:9
Java Inspector 089 Method return value is not properly documented 2 83:9
Java Inspector 089 Parameter tick is not documented 2 100:9
Java Inspector 089 Parameter keepMeasurements is not documented 2 100:9
Java Inspector 089 Parameter maxQueue is not documented 2 100:9
Java Inspector 089 Javadoc contains tag for non-existent parameter sliceConsumer 2 100:9
Java Inspector 089 Method return value is not properly documented 2 100:9
Java Inspector 089 Undocumented method 2 104:9
Java Inspector 089 Undocumented field 2 111:9
Java Inspector 089 Undocumented method 2 113:9
Java Inspector 089 Undocumented method 2 117:9
Java Inspector 089 Undocumented method 2 132:9
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 60:43
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 66:50
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 53:66
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 59:78
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 62:76
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 63:64
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 65:82
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 85:146
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 124:55

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.metrics;
24
25import java.util.ArrayList;
26import java.util.Iterator;
27import java.util.List;
28
29import javax.xml.transform.TransformerException;
30
31import org.w3c.dom.Element;
32import org.w3c.dom.Node;
33import org.w3c.dom.NodeList;
34
35import biz.hammurapi.config.Component;
36import biz.hammurapi.config.ConfigurationException;
37import biz.hammurapi.config.Context;
38import biz.hammurapi.config.DomConfigFactory;
39import biz.hammurapi.config.DomConfigurable;
40import biz.hammurapi.xml.dom.AbstractDomObject;
41import biz.hammurapi.xml.dom.DOMUtils;
42
43
44/**
45 * @author Pavel Vlasov
46 * @revision $Revision$
47 */
48public class SlicingMeasurementCategoryFactory extends MeasurementCategoryFactory implements Component, DomConfigurable {
49 private SlicingMeasurementConsumer consumer;
50
51 public void start() throws ConfigurationException {
52 try {
53 NodeList nl = DOMUtils.selectNodeList(configElement, "category");
54 for (int i=0, l=nl.getLength(); i<l; ++i) {
55 Element ce = (Element) nl.item(i);
56 categories.add(DOMUtils.getElementText(ce));
57 }
58
59 String tickValue=AbstractDomObject.getElementText(configElement, "tick");
60 long tick = tickValue==null ? 60000 : Long.parseLong(tickValue);
61
62 String kmValue=AbstractDomObject.getElementText(configElement, "keep-measurements");
63 boolean keepMeasurements = kmValue==null ? false : "yes".equalsIgnoreCase(kmValue);
64
65 String maxQueueValue=AbstractDomObject.getElementText(configElement, "max-queue");
66 int maxQueue = maxQueueValue==null ? 1000 : Integer.parseInt(maxQueueValue);
67
68 consumer=createMeasurementConsumer(tick, keepMeasurements, maxQueue);
69 consumer.start();
70 } catch (Exception e) {
71 throw new ConfigurationException(e);
72 }
73 }
74
75 /**
76 * Creates a consumer using DomConfigFactory
77 * @param cxpa
78 * @param factory
79 * @return
80 * @throws ConfigurationException
81 * @throws TransformerException
82 */
83 protected SliceConsumer createSliceConsumer() throws ConfigurationException {
84 try {
85 return (SliceConsumer) new DomConfigFactory(getClass().getClassLoader()).create(DOMUtils.selectSingleNode(configElement, "slice-consumer"));
86 } catch (Exception e) {
87 throw new ConfigurationException(e);
88 }
89 }
90
91 /**
92 * Override this method to create a custom consumer.
93 * @param tick
94 * @param keepMeasurements
95 * @param maxQueue
96 * @param sliceConsumer
97 * @return
98 * @throws ConfigurationException
99 */
100 protected SlicingMeasurementConsumer createMeasurementConsumer(long tick, boolean keepMeasurements, int maxQueue) throws ConfigurationException {
101 return new SlicingMeasurementConsumer (tick, keepMeasurements, maxQueue, createSliceConsumer());
102 }
103
104 public void stop() throws ConfigurationException {
105 if (consumer!=null) {
106 consumer.shutdown();
107 }
108 }
109
110 private List categories=new ArrayList();
111 protected Element configElement;
112
113 public void configure(Node configNode, Context context, ClassLoader classLoader) throws ConfigurationException {
114 configElement=(Element) configNode;
115 }
116
117 public MeasurementConsumer getMeasurementConsumer(String categoryName) {
118 if (categories.isEmpty() || categories.contains(categoryName)) {
119 return consumer.getCategoryInstance(categoryName);
120 }
121
122 Iterator it=categories.iterator();
123 while (it.hasNext()) {
124 if (categoryName.startsWith(it.next()+".")) {
125 return consumer.getCategoryInstance(categoryName);
126 }
127 }
128
129 return null;
130 }
131
132 public void setOwner(Object owner) {
133 // Ignore
134 }
135}
136