ThreadPoolComponentWrapper.java

biz/hammurapi/util/ThreadPoolComponentWrapper.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 070-A Cyclomatic complexity is too high: 13, maximum allowed is 12 2 75:9
Java Inspector 089 Undocumented top level type 2 34:1
Java Inspector 089 Undocumented method 2 43:9
Java Inspector 089 Undocumented method 2 47:9
Java Inspector 089 Undocumented method 2 65:9
Java Inspector 089 Undocumented method 2 71:9
Java Inspector 089 Undocumented method 2 75:9
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 36:37
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 38:30
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 51:66
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 57:66
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 57:121
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 77:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 78:73
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 80:66
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 84:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 85:66
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 88:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 89:58
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 92:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 93:45
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 96:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 97:52
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 98:29
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 100:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 102:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 105:66

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.util;
24
25import org.w3c.dom.Element;
26import org.w3c.dom.Node;
27
28import biz.hammurapi.config.Component;
29import biz.hammurapi.config.ConfigurationException;
30import biz.hammurapi.config.Context;
31import biz.hammurapi.config.DomConfigurable;
32import biz.hammurapi.config.Wrapper;
33
34public class ThreadPoolComponentWrapper implements Wrapper, Component, DomConfigurable {
35 private ThreadPool master;
36 private int numberOfThreads=20;
37 private int priority=Thread.NORM_PRIORITY;
38 private int maxQueue=1000;
39 private String exceptionSinkName;
40 private Object owner;
41 private String name;
42
43 public Object getMaster() {
44 return master;
45 }
46
47 public void start() throws ConfigurationException {
48 ExceptionSink exceptionSink=null;
49 if (exceptionSinkName!=null) {
50 if (!(owner instanceof Context)) {
51 throw new ConfigurationException("Cannot lookup exception sink - owner doesn't implement Context");
52 }
53
54 exceptionSink=(ExceptionSink) ((Context) owner).get(exceptionSinkName);
55
56 if (exceptionSink==null) {
57 throw new ConfigurationException("Lookup failed for exception sink '"+exceptionSinkName+"'");
58 }
59 }
60
61 master=new ThreadPool(numberOfThreads, priority, maxQueue, exceptionSink, name);
62 master.start();
63 }
64
65 public void stop() throws ConfigurationException {
66 if (master!=null) {
67 master.stop();
68 }
69 }
70
71 public void setOwner(Object owner) {
72 this.owner=owner;
73 }
74
75 public void configure(Node configNode, Context context, ClassLoader classLoader) throws ConfigurationException {
76 Element e=(Element) configNode;
77 if (e.hasAttribute("threads")) {
78 numberOfThreads=Integer.parseInt(e.getAttribute("threads"));
79 if (numberOfThreads<1) {
80 throw new ConfigurationException("Number of threads shall be >=1");
81 }
82 }
83
84 if (e.hasAttribute("max-queue")) {
85 maxQueue=Integer.parseInt(e.getAttribute("max-queue"));
86 }
87
88 if (e.hasAttribute("exception-sink")) {
89 exceptionSinkName=e.getAttribute("exception-sink");
90 }
91
92 if (e.hasAttribute("pool-name")) {
93 name=e.getAttribute("pool-name");
94 }
95
96 if (e.hasAttribute("priority")) {
97 String pStr=e.getAttribute("priority");
98 if ("min".equalsIgnoreCase(pStr)) {
99 priority=Thread.MIN_PRIORITY;
100 } else if ("max".equalsIgnoreCase(pStr)) {
101 priority=Thread.MAX_PRIORITY;
102 } else if ("normal".equalsIgnoreCase(pStr)) {
103 priority=Thread.NORM_PRIORITY;
104 } else {
105 throw new ConfigurationException("Invalid priority value: "+pStr);
106 }
107 }
108 }
109
110}
111