01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal;
07:
08: import java.lang.reflect.Constructor;
09:
10: import org.jasig.portal.properties.PropertiesManager;
11: import org.apache.commons.logging.Log;
12: import org.apache.commons.logging.LogFactory;
13:
14: import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong;
15:
16: /**
17: * <p>The <code>ChannelRendererFactory</code> creates
18: * <code>IChannelRendererFactory</code> objects which are used to construct
19: * <code>IChannelRenderer</code> objects with implementation specific
20: * parameters.</p>
21: *
22: * <p>This factory design is motivated by the need for different kinds of
23: * <code>IChannelRenderer</code> implementations including single-threaded
24: * serial channel renderers, multi-threaded parallel channel renderers, and
25: * thread-pool serial/parallel channel renderers.</p>
26: *
27: * @author <a href="mailto:jnielsen@sct.com">Jan Nielsen</a>
28: *
29: * @version $Revision: 36731 $
30: **/
31: public final class ChannelRendererFactory {
32: /** <p> Class version identifier.</p> */
33: public final static String RCS_ID = "@(#) $Header$";
34:
35: private static final Log LOG = LogFactory
36: .getLog(ChannelRendererFactory.class);
37:
38: /**
39: * <p>Creates a new instance of a channel renderer factory object. This
40: * factory looks for the property <code>keyBase + ".factoryClassName"</code>
41: * in the configuration system and then reflectively constructs the
42: * factory class with a single string argument constructor, passing in
43: * the <code>keyBase</code> as the argument.</p>
44: *
45: * @param keyBase configuration base key
46: *
47: * @return new instance of a channel renderer for the specified channel,
48: * or <code>null</code>
49: **/
50: public static final IChannelRendererFactory newInstance(
51: String keyBase, final AtomicLong activeThreads,
52: final AtomicLong maxActiveThreads) {
53: IChannelRendererFactory factory = null;
54: String factoryClassName = null;
55:
56: try {
57: // Retrieve the factory class implementation from configuration.
58: factoryClassName = PropertiesManager.getProperty(keyBase
59: + ".ChannelRendererFactory.className");
60:
61: if (LOG.isDebugEnabled())
62: LOG
63: .debug("ChannelRendererFactory::newInstance("
64: + keyBase
65: + ") : about to construct channel renderer factory: "
66: + factoryClassName);
67:
68: // Get the string argument constructor for the class.
69: Constructor ctor = Class
70: .forName(factoryClassName)
71: .getConstructor(
72: new Class[] { String.class,
73: AtomicLong.class, AtomicLong.class });
74:
75: // Reflectively construct the factory with the key base argument.
76: factory = (IChannelRendererFactory) ctor
77: .newInstance(new Object[] { keyBase, activeThreads,
78: maxActiveThreads });
79:
80: if (LOG.isDebugEnabled())
81: LOG.debug("ChannelRendererFactory::newInstance("
82: + keyBase
83: + ") : constructed channel renderer factory: "
84: + factoryClassName);
85: } catch (Exception x) {
86: // Log the failure.
87: LOG.error("ChannelRendererFactory::newInstance(" + keyBase
88: + ") : failed to construct factory: "
89: + factoryClassName, x);
90: }
91:
92: return factory;
93: }
94: }
|