01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1997-2004 Gerald Brose.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library 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: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: */
20:
21: package org.jacorb.orb.giop;
22:
23: import org.apache.avalon.framework.logger.Logger;
24: import org.apache.avalon.framework.configuration.Configuration;
25:
26: import org.jacorb.util.threadpool.*;
27:
28: /**
29: * @author Nicolas Noffke
30: * @version $Id: MessageReceptorPool.java,v 1.18 2006/07/27 13:50:35 nick.cross Exp $
31: */
32: public class MessageReceptorPool {
33: private static final int MAX_DEFAULT = 1000;
34: private static final int MAX_IDLE_DEFAULT = 5;
35:
36: private final ThreadPool pool;
37:
38: /**
39: * @param config must be client or server to specify which configurationsubset should be used
40: * @param threadNamePrefix prefix that's used to name all threads that are created by this pool
41: * @param myConfiguration current configuration
42: * TODO configuration of this class should be enhanced. config param does not feel right.
43: */
44: public MessageReceptorPool(String config, String threadNamePrefix,
45: Configuration myConfiguration) {
46: if (!"server".equals(config) && !"client".equals(config)) {
47: throw new IllegalArgumentException(
48: "must be client or server");
49: }
50:
51: final org.jacorb.config.Configuration configuration = (org.jacorb.config.Configuration) myConfiguration;
52:
53: final int maxConnectionThreads = configuration
54: .getAttributeAsInteger("jacorb.connection." + config
55: + ".max_receptor_threads", MAX_DEFAULT);
56:
57: final int maxIdleThreads = configuration.getAttributeAsInteger(
58: "jacorb.connection." + config
59: + ".max_idle_receptor_threads",
60: MAX_IDLE_DEFAULT);
61:
62: Logger logger = configuration.getNamedLogger("jacorb.orb.giop");
63:
64: if (logger.isDebugEnabled()) {
65: logger.debug("Maximum connection threads: "
66: + maxConnectionThreads);
67: logger.debug("Maximum idle threads: " + maxIdleThreads);
68: }
69:
70: pool = new ThreadPool(configuration, threadNamePrefix,
71: new ConsumerFactory() {
72: public Consumer create() {
73: return new MessageReceptor(configuration);
74: }
75: }, maxConnectionThreads, maxIdleThreads); //max idle threads
76: }
77:
78: public void connectionCreated(GIOPConnection conn) {
79: pool.putJob(conn);
80: }
81:
82: /**
83: * <code>shutdown</code> allows the ReceptorPool to be shutdown
84: * so that new ORB.init's will use fresh pools
85: */
86: public void shutdown() {
87: pool.shutdown();
88: }
89: }
|