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.core.client;
014
015 import org.hornetq.api.core.DiscoveryGroupConfiguration;
016 import org.hornetq.api.core.TransportConfiguration;
017 import org.hornetq.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy;
018 import org.hornetq.core.client.impl.ServerLocatorImpl;
019
020 /**
021 * Utility class for creating HornetQ {@link ClientSessionFactory} objects.
022 *
023 * Once a {@link ClientSessionFactory} has been created, it can be further configured
024 * using its setter methods before creating the sessions. Once a session is created,
025 * the factory can no longer be modified (its setter methods will throw a {@link IllegalStateException}.
026 *
027 * @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
028 */
029 public class HornetQClient
030 {
031 public static final String DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME = RoundRobinConnectionLoadBalancingPolicy.class.getCanonicalName();
032
033 public static final long DEFAULT_CLIENT_FAILURE_CHECK_PERIOD = 30000;
034
035 // 1 minute - this should be higher than ping period
036
037 public static final long DEFAULT_CONNECTION_TTL = 1 * 60 * 1000;
038
039 // Any message beyond this size is considered a large message (to be sent in chunks)
040
041 public static final int DEFAULT_MIN_LARGE_MESSAGE_SIZE = 100 * 1024;
042
043 public static final boolean DEFAULT_COMPRESS_LARGE_MESSAGES = false;
044
045 public static final int DEFAULT_CONSUMER_WINDOW_SIZE = 1024 * 1024;
046
047 public static final int DEFAULT_CONSUMER_MAX_RATE = -1;
048
049 public static final int DEFAULT_CONFIRMATION_WINDOW_SIZE = -1;
050
051 public static final int DEFAULT_PRODUCER_WINDOW_SIZE = 64 * 1024;
052
053 public static final int DEFAULT_PRODUCER_MAX_RATE = -1;
054
055 public static final boolean DEFAULT_BLOCK_ON_ACKNOWLEDGE = false;
056
057 public static final boolean DEFAULT_BLOCK_ON_DURABLE_SEND = true;
058
059 public static final boolean DEFAULT_BLOCK_ON_NON_DURABLE_SEND = false;
060
061 public static final boolean DEFAULT_AUTO_GROUP = false;
062
063 public static final long DEFAULT_CALL_TIMEOUT = 30000;
064
065 public static final int DEFAULT_ACK_BATCH_SIZE = 1024 * 1024;
066
067 public static final boolean DEFAULT_PRE_ACKNOWLEDGE = false;
068
069 public static final long DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT = 10000;
070
071 public static final long DEFAULT_DISCOVERY_REFRESH_TIMEOUT = 10000;
072
073 public static final int DEFAULT_DISCOVERY_PORT = 9876;
074
075 public static final long DEFAULT_RETRY_INTERVAL = 2000;
076
077 public static final double DEFAULT_RETRY_INTERVAL_MULTIPLIER = 1d;
078
079 public static final long DEFAULT_MAX_RETRY_INTERVAL = 2000;
080
081 public static final int DEFAULT_RECONNECT_ATTEMPTS = 0;
082
083 public static final int INITIAL_CONNECT_ATTEMPTS = 1;
084
085 public static final boolean DEFAULT_FAILOVER_ON_INITIAL_CONNECTION = false;
086
087 public static final boolean DEFAULT_IS_HA = false;
088
089 public static final boolean DEFAULT_USE_GLOBAL_POOLS = true;
090
091 public static final int DEFAULT_THREAD_POOL_MAX_SIZE = -1;
092
093 public static final int DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE = 5;
094
095 public static final boolean DEFAULT_CACHE_LARGE_MESSAGE_CLIENT = false;
096
097 public static final int DEFAULT_INITIAL_MESSAGE_PACKET_SIZE = 1500;
098
099 public static final boolean DEFAULT_XA = false;
100
101 public static final boolean DEFAULT_HA = false;
102
103 /**
104 * Create a ServerLocator which creates session factories using a static list of transportConfigurations, the ServerLocator is not updated automatically
105 * as the cluster topology changes, and no HA backup information is propagated to the client
106 *
107 * @param transportConfigurations
108 * @return the ServerLocator
109 */
110 public static ServerLocator createServerLocatorWithoutHA(TransportConfiguration... transportConfigurations)
111 {
112 return new ServerLocatorImpl(false, transportConfigurations);
113 }
114
115 /**
116 * Create a ServerLocator which creates session factories from a set of live servers, no HA backup information is propagated to the client
117 *
118 * The UDP address and port are used to listen for live servers in the cluster
119 *
120 * @param discoveryAddress The UDP group address to listen for updates
121 * @param discoveryPort the UDP port to listen for updates
122 * @return the ServerLocator
123 */
124 public static ServerLocator createServerLocatorWithoutHA(final DiscoveryGroupConfiguration groupConfiguration)
125 {
126 return new ServerLocatorImpl(false, groupConfiguration);
127 }
128
129 /**
130 * Create a ServerLocator which will receive cluster topology updates from the cluster as servers leave or join and new backups are appointed or removed.
131 * The initial list of servers supplied in this method is simply to make an initial connection to the cluster, once that connection is made, up to date
132 * cluster topology information is downloaded and automatically updated whenever the cluster topology changes. If the topology includes backup servers
133 * that information is also propagated to the client so that it can know which server to failover onto in case of live server failure.
134 * @param initialServers The initial set of servers used to make a connection to the cluster. Each one is tried in turn until a successful connection is made. Once
135 * a connection is made, the cluster topology is downloaded and the rest of the list is ignored.
136 * @return the ServerLocator
137 */
138 public static ServerLocator createServerLocatorWithHA(TransportConfiguration... initialServers)
139 {
140 return new ServerLocatorImpl(true, initialServers);
141 }
142
143 /**
144 * Create a ServerLocator which will receive cluster topology updates from the cluster as servers leave or join and new backups are appointed or removed.
145 * The discoveryAddress and discoveryPort parameters in this method are used to listen for UDP broadcasts which contain connection information for members of the cluster.
146 * The broadcasted connection information is simply used to make an initial connection to the cluster, once that connection is made, up to date
147 * cluster topology information is downloaded and automatically updated whenever the cluster topology changes. If the topology includes backup servers
148 * that information is also propagated to the client so that it can know which server to failover onto in case of live server failure.
149 * @param discoveryAddress The UDP group address to listen for updates
150 * @param discoveryPort the UDP port to listen for updates
151 * @return the ServerLocator
152 */
153 public static ServerLocator createServerLocatorWithHA(final DiscoveryGroupConfiguration groupConfiguration)
154 {
155 return new ServerLocatorImpl(true, groupConfiguration);
156 }
157
158
159 private HornetQClient()
160 {
161 }
162 }