1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: DestinationCacheFactory.java,v 1.2 2005/11/12 12:27:40 tanderson Exp $
44 */
45 package org.exolab.jms.messagemgr;
46
47 import javax.jms.JMSException;
48
49 import org.apache.commons.logging.LogFactory;
50 import org.apache.commons.logging.Log;
51
52 import org.exolab.jms.client.JmsDestination;
53 import org.exolab.jms.client.JmsQueue;
54 import org.exolab.jms.client.JmsTopic;
55 import org.exolab.jms.lease.LeaseManager;
56 import org.exolab.jms.server.ServerConnectionManager;
57 import org.exolab.jms.persistence.DatabaseService;
58
59
60 /***
61 * Factory for {@link DestinationCache} instances.
62 *
63 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
64 * @version $Revision: 1.2 $ $Date: 2005/11/12 12:27:40 $
65 */
66 public class DestinationCacheFactory {
67
68 /***
69 * The lease manager.
70 */
71 private final LeaseManager _leases;
72
73 /***
74 * The server connection manager.
75 */
76 private final ServerConnectionManager _connections;
77
78 /***
79 * The database service.
80 */
81 private final DatabaseService _database;
82
83 /***
84 * The logger.
85 */
86 private static final Log _log
87 = LogFactory.getLog(DestinationCacheFactory.class);
88
89
90 /***
91 * Construct a new <code>DestinationCacheFactory</code>.
92 *
93 * @param leases the lease mananger
94 * @param connections the connection manager
95 */
96 public DestinationCacheFactory(LeaseManager leases,
97 DatabaseService database,
98 ServerConnectionManager connections) {
99
100 if (leases == null) {
101 throw new IllegalArgumentException("Argument 'leases' is null");
102 }
103 if (database == null) {
104 throw new IllegalArgumentException("Argument 'database' is null");
105 }
106 if (connections == null) {
107 throw new IllegalArgumentException(
108 "Argument 'connections' is null");
109 }
110 _leases = leases;
111 _database = database;
112 _connections = connections;
113 }
114
115 /***
116 * Create a new destination cache.
117 *
118 * @param destination the destination to create the cache for
119 * @return a new cache
120 * @throws JMSException if the cache can't be created
121 */
122 public DestinationCache createDestinationCache(
123 JmsDestination destination) throws JMSException {
124 DestinationCache result;
125 if (destination instanceof JmsTopic) {
126 result = new TopicDestinationCache((JmsTopic) destination,
127 _database, _leases);
128 } else {
129 result = new QueueDestinationCache((JmsQueue) destination,
130 _database, _leases,
131 _connections);
132 }
133 return result;
134 }
135
136 }