KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > client > JmsConnectionFactory


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright (c) 2001, 2002 Dan Greff
20  */

21 package com.presumo.jms.client;
22
23 import com.presumo.jms.router.Router;
24 import com.presumo.jms.persistence.PersistentQueue;
25 import com.presumo.jms.plugin.MessageQueue;
26 import com.presumo.jms.plugin.implementation.MemoryMessageQueue;
27
28 import java.io.File JavaDoc;
29
30 import javax.jms.ConnectionFactory JavaDoc;
31 import javax.jms.JMSException JavaDoc;
32
33 /**
34  * @see javax.jms.ConnectionFactory
35  * @author Dan Greff
36  */

37 public class JmsConnectionFactory
38   implements ConnectionFactory JavaDoc, java.io.Serializable JavaDoc
39 {
40   /** Host to connect to. **/
41   protected String JavaDoc host;
42
43   /** Port server process is running on. **/
44   protected int port;
45   
46   /** Storage directory **/
47   protected File JavaDoc persistentDir;
48   
49   /** Storage directory prefix **/
50   protected String JavaDoc persistentFilePrefix = "presumo";
51
52   /** Maximum size for the storage files **/
53   protected int persistentLogSize = 100000;
54
55     /////////////////////////////////////////////////////////////////////////
56
// Constructors //
57
/////////////////////////////////////////////////////////////////////////
58

59   public JmsConnectionFactory()
60   {
61   }
62
63     /////////////////////////////////////////////////////////////////////////
64
// Public Methods //
65
/////////////////////////////////////////////////////////////////////////
66

67
68   public void setHost(String JavaDoc host)
69   {
70     this.host = host;
71   }
72   
73   public void setPort(int port)
74   {
75     this.port = port;
76   }
77         
78   public void setPersistentDir(String JavaDoc directory) throws JMSException JavaDoc
79   {
80     File JavaDoc temp = new File JavaDoc(directory);
81
82     if (! temp.isDirectory()) {
83       throw new JMSException JavaDoc("Specified directory for persistent messages"+
84                              " either is not a directory or does not exist: "+
85                              directory);
86     }
87     this.persistentDir = temp;
88   }
89
90   public void setPersistentPrefix(String JavaDoc prefix)
91   {
92     this.persistentFilePrefix = prefix;
93   }
94
95   public void setPersistentLogSize(int bytes)
96   {
97     this.persistentLogSize = bytes;
98   }
99
100
101
102     /////////////////////////////////////////////////////////////////////////
103
// Protected Methods //
104
/////////////////////////////////////////////////////////////////////////
105

106   protected Router getRouter() throws JMSException JavaDoc
107   {
108     return new Router(createQueue());
109   }
110
111
112
113     /////////////////////////////////////////////////////////////////////////
114
// Private Methods //
115
/////////////////////////////////////////////////////////////////////////
116

117   private MessageQueue createQueue() throws JMSException JavaDoc
118   {
119     if (persistentDir == null) {
120       return new MemoryMessageQueue();
121     }
122     else {
123       return new PersistentQueue(persistentDir,
124                                  persistentFilePrefix,
125                                  persistentLogSize);
126     }
127   }
128 }
129
130
Popular Tags