KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > tcp > TcpConnectionFactory


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - Bull SA
4  * Copyright (C) 2004 - ScalAgent Distributed Technologies
5  * Copyright (C) 1996 - Dyade
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or any later version.
11  *
12  * This library 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 library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA.
21  *
22  * Initial developer(s): Frederic Maistre (INRIA)
23  * Contributor(s): Nicolas Tachker (ScalAgent)
24  */

25 package org.objectweb.joram.client.jms.tcp;
26
27 import org.objectweb.joram.client.jms.Connection;
28 import org.objectweb.joram.client.jms.FactoryParameters;
29 import org.objectweb.joram.client.jms.admin.AdminModule;
30
31 import java.util.Vector JavaDoc;
32
33 import javax.naming.NamingException JavaDoc;
34
35 import org.objectweb.joram.shared.JoramTracing;
36 import org.objectweb.util.monolog.api.BasicLevel;
37
38 /**
39  * A <code>TcpConnectionFactory</code> instance is a factory of
40  * TCP connections.
41  */

42 public class TcpConnectionFactory extends org.objectweb.joram.client.jms.ConnectionFactory {
43   /**
44    * Constructs a <code>TcpConnectionFactory</code> instance.
45    *
46    * @param host Name or IP address of the server's host.
47    * @param port Server's listening port.
48    */

49   public TcpConnectionFactory(String JavaDoc host, int port) {
50     super(host, port);
51   }
52
53   /**
54    * Constructs an empty <code>TcpConnectionFactory</code> instance.
55    */

56   public TcpConnectionFactory() {}
57
58   /**
59    * Method inherited from the <code>ConnectionFactory</code> class.
60    *
61    * @exception JMSSecurityException If the user identification is incorrect.
62    * @exception IllegalStateException If the server is not listening.
63    */

64   public javax.jms.Connection JavaDoc createConnection(String JavaDoc name, String JavaDoc password)
65     throws javax.jms.JMSException JavaDoc {
66     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
67       JoramTracing.dbgClient.log(BasicLevel.DEBUG,
68                                  "TcpConnectionFactory.createConnection(" +
69                                  name + ',' + password + ") reliableClass=" + reliableClass);
70
71     return new Connection(params,
72                           new TcpConnection(params,
73                                             name,
74                                             password,
75                                             reliableClass));
76   }
77
78   /**
79    * Admin method creating a <code>javax.jms.ConnectionFactory</code>
80    * instance for creating TCP connections with a given server.
81    *
82    * @param host Name or IP address of the server's host.
83    * @param port Server's listening port.
84    */

85   public static javax.jms.ConnectionFactory JavaDoc create(String JavaDoc host, int port) {
86     return create(host,
87                   port,
88                   "org.objectweb.joram.client.jms.tcp.ReliableTcpClient");
89   }
90
91   /**
92    * Admin method creating a <code>javax.jms.ConnectionFactory</code>
93    * instance for creating TCP connections with a given server.
94    *
95    * @param host Name or IP address of the server's host.
96    * @param port Server's listening port.
97    * @param reliableClass Reliable class name.
98    */

99   public static javax.jms.ConnectionFactory JavaDoc
100       create(String JavaDoc host,
101              int port,
102              String JavaDoc reliableClass) {
103     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
104       JoramTracing.dbgClient.log(
105         BasicLevel.DEBUG,
106         "TcpConnectionFactory.create(" +
107         host + ',' + port + ',' + reliableClass +')');
108     TcpConnectionFactory cf = new TcpConnectionFactory(host, port);
109     cf.setReliableClass(reliableClass);
110     return cf;
111   }
112
113   /**
114    * Admin method creating a <code>javax.jms.ConnectionFactory</code>
115    * instance for creating TCP connections with the local server.
116    *
117    * @exception ConnectException If the admin connection is closed or broken.
118    */

119   public static javax.jms.ConnectionFactory JavaDoc create()
120                 throws java.net.ConnectException JavaDoc
121   {
122     return create(AdminModule.getLocalHost(), AdminModule.getLocalPort());
123   }
124 }
125
Popular Tags