KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aspects > asynchronous > concurrent > ThreadManagerFactory


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22
23 package org.jboss.aspects.asynchronous.concurrent;
24
25 import org.jboss.aspects.asynchronous.AsynchronousParameters;
26 import org.jboss.aspects.asynchronous.AsynchronousUserTask;
27 import org.jboss.aspects.asynchronous.ThreadManager;
28 import org.jboss.aspects.asynchronous.ThreadManagerRequest;
29 import org.jboss.aspects.asynchronous.common.ThreadManagerRequestImpl;
30
31 import java.util.ResourceBundle JavaDoc;
32
33 /**
34  * @author <a HREF="mailto:chussenet@yahoo.com">{Claude Hussenet Independent Consultant}</a>.
35  * @version <tt>$Revision: 37406 $</tt>
36  */

37
38 public class ThreadManagerFactory
39 {
40
41    protected ThreadManager threadManager;
42
43    protected String JavaDoc DEFAULT_MIN_THREAD = "10";
44
45    protected String JavaDoc DEFAULT_MAX_THREAD = "100";
46
47    protected String JavaDoc DEFAULT_KEEP_ALIVE = "5000";
48
49    protected String JavaDoc DEFAULT_IS_WAITING_WHEN_POOLSIZE_FULL = "FALSE";
50
51    protected String JavaDoc DEFAULT_IS_POOLING = "TRUE";
52
53    static protected String JavaDoc MIN_POOL_SIZE = "threadManager.minimumPoolsize";
54
55    static protected String JavaDoc MAX_POOL_SIZE = "threadManager.maximumPoolsize";
56
57    static protected String JavaDoc KEEP_ALIVE = "threadManager.keepAlive";
58
59    static protected String JavaDoc IS_WAITING_WHEN_POOLSIZE_FULL =
60
61    "threadManager.isWaitingWhenPoolSize";
62
63    static protected String JavaDoc IS_POOLING =
64
65    "threadManager.isPooling";
66
67    static protected String JavaDoc PROPERTY_FILE =
68
69    "org.jboss.aspects.asynchronous.threadManager";
70
71    protected static final ThreadManagerFactory threadManagerFactory =
72
73    new ThreadManagerFactory();
74
75    static protected ResourceBundle JavaDoc rb;
76
77    static void initResourceBundle()
78    {
79
80       try
81       {
82
83          rb = ResourceBundle.getBundle(PROPERTY_FILE);
84
85       }
86       catch (Exception JavaDoc e)
87       {
88
89          //System.err.println(e.getMessage());
90

91       }
92
93    }
94
95    private static String JavaDoc getString(String JavaDoc key, String JavaDoc defaultValue)
96    {
97
98       try
99       {
100
101          if (rb == null)
102
103             return defaultValue;
104
105          String JavaDoc value = rb.getString(key);
106
107          if (value == null)
108
109             return defaultValue;
110
111          else
112
113             return value;
114
115       }
116       catch (Exception JavaDoc e)
117       {}
118
119       return defaultValue;
120
121    }
122
123    protected ThreadManagerFactory()
124    {
125
126       initResourceBundle();
127
128       threadManager = new ThreadManagerImpl();
129
130       threadManager.setMinimumPoolSize(Integer.parseInt(getString(MIN_POOL_SIZE, DEFAULT_MIN_THREAD)));
131
132       threadManager.setMaximumPoolSize(Integer.parseInt(getString(MAX_POOL_SIZE, DEFAULT_MAX_THREAD)));
133
134       threadManager.setKeepAliveTime(Integer.parseInt(getString(KEEP_ALIVE, DEFAULT_KEEP_ALIVE)));
135
136       threadManager.setWaitWhenPoolSizeIsFull(Boolean
137
138       .valueOf(getString(IS_WAITING_WHEN_POOLSIZE_FULL,
139
140       DEFAULT_IS_WAITING_WHEN_POOLSIZE_FULL))
141
142       .booleanValue());
143
144
145       threadManager.setPooling(Boolean
146
147       .valueOf(getString(IS_POOLING,
148
149       DEFAULT_IS_POOLING))
150
151       .booleanValue());
152
153    }
154
155    static public ThreadManager getThreadManager()
156    {
157
158       return threadManagerFactory.threadManager;
159
160    }
161
162    static public ThreadManagerRequest createNewThreadManagerRequest(String JavaDoc id,
163
164                                                                     AsynchronousParameters inputParameters,
165
166                                                                     AsynchronousUserTask taskClassNameImpl,
167
168                                                                     long timeout)
169    {
170
171       return new ThreadManagerRequestImpl(id,
172
173       inputParameters,
174
175       taskClassNameImpl,
176
177       timeout);
178
179    }
180
181 }
182
Popular Tags