001 /* 002 * Copyright 2009 Red Hat, Inc. 003 * Red Hat licenses this file to you under the Apache License, version 004 * 2.0 (the "License"); you may not use this file except in compliance 005 * with the License. You may obtain a copy of the License at 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * Unless required by applicable law or agreed to in writing, software 008 * distributed under the License is distributed on an "AS IS" BASIS, 009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 010 * implied. See the License for the specific language governing 011 * permissions and limitations under the License. 012 */ 013 package org.hornetq.api.jms; 014 015 import java.util.List; 016 017 import javax.jms.Queue; 018 import javax.jms.Topic; 019 020 import org.hornetq.api.core.Pair; 021 import org.hornetq.api.core.TransportConfiguration; 022 import org.hornetq.api.core.client.ClientSessionFactory; 023 import org.hornetq.core.logging.Logger; 024 import org.hornetq.jms.client.HornetQConnectionFactory; 025 import org.hornetq.jms.client.HornetQDestination; 026 027 /** 028 * A utility class for creating HornetQ client-side JMS managed resources. 029 * 030 * @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a> 031 */ 032 public class HornetQJMSClient 033 { 034 private static final Logger log = Logger.getLogger(HornetQJMSClient.class); 035 036 /** 037 * Creates a HornetQConnectionFactory using all the defaults. 038 * 039 * @return The HornetQConnectionFactory. 040 */ 041 public static HornetQConnectionFactory createConnectionFactory() 042 { 043 return new HornetQConnectionFactory(); 044 } 045 046 /** 047 * Creates a HornetQConnectionFactory using the ClientSessionFactory for its underlying connection. 048 * 049 * @param sessionFactory The underlying ClientSessionFactory to use. 050 * @return The HornetQConnectionFactory. 051 */ 052 public static HornetQConnectionFactory createConnectionFactory(final ClientSessionFactory sessionFactory) 053 { 054 return new HornetQConnectionFactory(sessionFactory); 055 } 056 057 /** 058 * Creates a HornetQConnectionFactory that will use discovery to connect to the server. 059 * 060 * @param discoveryAddress The address to use for discovery. 061 * @param discoveryPort The port to use for discovery. 062 * @return The HornetQConnectionFactory. 063 */ 064 public static HornetQConnectionFactory createConnectionFactory(final String discoveryAddress, final int discoveryPort) 065 { 066 return new HornetQConnectionFactory(discoveryAddress, discoveryPort); 067 } 068 069 /** 070 * Creates a HornetQConnectionFactory using a List of TransportConfigurations and backups. 071 * 072 * @param staticConnectors The list of TransportConfiguration to use. 073 * @return The HornetQConnectionFactory. 074 */ 075 public static HornetQConnectionFactory createConnectionFactory(final List<Pair<TransportConfiguration, TransportConfiguration>> staticConnectors) 076 { 077 return new HornetQConnectionFactory(staticConnectors); 078 } 079 080 /** 081 * Creates a HornetQConnectionFactory using a single pair of live-backup TransportConfiguration. 082 * 083 * @param connectorConfig The TransportConfiguration of the server to connect to. 084 * @param backupConnectorConfig The TransportConfiguration of the backup server to connect to. can be null. 085 * @return The HornetQConnectionFactory. 086 */ 087 public static HornetQConnectionFactory createConnectionFactory(final TransportConfiguration connectorConfig, 088 final TransportConfiguration backupConnectorConfig) 089 { 090 return new HornetQConnectionFactory(connectorConfig, backupConnectorConfig); 091 } 092 093 /** 094 * Creates a HornetQConnectionFactory to connect to a single live server. 095 * 096 * @param connectorConfig The TransportConfiguration of the server. 097 * @return The HornetQConnectionFactory. 098 */ 099 public static HornetQConnectionFactory createConnectionFactory(final TransportConfiguration connectorConfig) 100 { 101 return new HornetQConnectionFactory(connectorConfig); 102 } 103 104 /** 105 * Creates a client-side representation of a JMS Topic. 106 * 107 * @param name the name of the topic 108 * @return The Topic 109 */ 110 public static Topic createTopic(final String name) 111 { 112 return HornetQDestination.createTopic(name); 113 } 114 115 /** 116 * Creates a client-side representation of a JMS Queue. 117 * 118 * @param name the name of the queue 119 * @return The Queue 120 */ 121 public static Queue createQueue(final String name) 122 { 123 return HornetQDestination.createQueue(name); 124 } 125 126 private HornetQJMSClient() 127 { 128 } 129 }