Skip to content

Commit 2b09bdd

Browse files
author
David R. MacIver
committed
complete the apparently half completed process of ripping out Protocol from AmqpTcpEndpoint
1 parent 58eb2d1 commit 2b09bdd

File tree

8 files changed

+57
-93
lines changed

8 files changed

+57
-93
lines changed

projects/client/RabbitMQ.Client/src/client/api/AmqpTcpEndpoint.cs

Lines changed: 25 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ namespace RabbitMQ.Client
7373
///</para>
7474
public class AmqpTcpEndpoint
7575
{
76-
private IProtocol m_protocol;
77-
///<summary>Retrieve or set the IProtocol of this AmqpTcpEndpoint.</summary>
78-
public IProtocol Protocol
79-
{
80-
get { return m_protocol; }
81-
set { m_protocol = value; }
82-
}
83-
8476
private string m_hostName;
8577
///<summary>Retrieve or set the hostname of this AmqpTcpEndpoint.</summary>
8678
public string HostName
@@ -91,11 +83,11 @@ public string HostName
9183

9284
private int m_port;
9385
///<summary>Retrieve or set the port number of this
94-
///AmqpTcpEndpoint. A port number of -1 causes the default
95-
///port number for the IProtocol to be used.</summary>
86+
///AmqpTcpEndpoint. -1 indicates the default value should be used.
87+
///</summary>
9688
public int Port
9789
{
98-
get { return (m_port == -1) ? m_protocol.DefaultPort : m_port; }
90+
get { return m_port; }
9991
set { m_port = value; }
10092
}
10193

@@ -110,67 +102,37 @@ public SslOption Ssl
110102
}
111103

112104
///<summary>Construct an AmqpTcpEndpoint with the given
113-
///IProtocol, hostname, port number and ssl option. If the port
105+
///hostname, port number and ssl option. If the port
114106
///number is -1, the default port number for the IProtocol
115107
///will be used.</summary>
116-
public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne, SslOption ssl)
108+
public AmqpTcpEndpoint(string hostName, int portOrMinusOne, SslOption ssl)
117109
{
118-
m_protocol = protocol;
119110
m_hostName = hostName;
120111
m_port = portOrMinusOne;
121112
m_ssl = ssl;
122113
}
123114

124115
///<summary>Construct an AmqpTcpEndpoint with the given
125-
///IProtocol, hostname, and port number. If the port number is
126-
///-1, the default port number for the IProtocol will be
127-
///used.</summary>
128-
public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne) :
129-
this(protocol, hostName, portOrMinusOne, new SslOption())
130-
{
131-
}
132-
133-
///<summary>Construct an AmqpTcpEndpoint with the given
134-
///IProtocol and hostname, using the default port for the
135-
///IProtocol.</summary>
136-
public AmqpTcpEndpoint(IProtocol protocol, string hostName) :
137-
this(protocol, hostName, -1)
138-
{
139-
}
140-
141-
///<summary>Construct an AmqpTcpEndpoint with the given
142-
///IProtocol, "localhost" as the hostname, and using the
143-
///default port for the IProtocol.</summary>
144-
public AmqpTcpEndpoint(IProtocol protocol) :
145-
this(protocol, "localhost", -1)
146-
{
147-
}
148-
149-
///<summary>Construct an AmqpTcpEndpoint with the given
150-
///hostname and port number, using the IProtocol from
151-
///Protocols.FromEnvironment(). If the port number is
116+
/// hostname, and port number. If the port number is
152117
///-1, the default port number for the IProtocol will be
153118
///used.</summary>
154119
public AmqpTcpEndpoint(string hostName, int portOrMinusOne) :
155-
this(Protocols.FromEnvironment(), hostName, portOrMinusOne)
120+
this(hostName, portOrMinusOne, new SslOption())
156121
{
157122
}
158123

159124
///<summary>Construct an AmqpTcpEndpoint with the given
160-
///hostname, using the IProtocol from
161-
///Protocols.FromEnvironment(), and the default port number of
162-
///that IProtocol.</summary>
125+
///hostname, using the default port for the
126+
///IProtocol.</summary>
163127
public AmqpTcpEndpoint(string hostName) :
164-
this(Protocols.FromEnvironment(), hostName)
128+
this(hostName, -1)
165129
{
166130
}
167131

168-
///<summary>Construct an AmqpTcpEndpoint with a hostname of
169-
///"localhost", using the IProtocol from
170-
///Protocols.FromEnvironment(), and the default port number of
171-
///that IProtocol.</summary>
132+
///<summary>Construct an AmqpTcpEndpoint with the given
133+
///localhost" as the hostname, and the default port </summary>
172134
public AmqpTcpEndpoint() :
173-
this(Protocols.FromEnvironment())
135+
this("localhost", -1)
174136
{
175137
}
176138

@@ -180,31 +142,19 @@ public AmqpTcpEndpoint() :
180142
/// Please see the class overview documentation for
181143
/// information about the Uri format in use.
182144
///</remarks>
183-
public AmqpTcpEndpoint(IProtocol protocol, Uri uri, SslOption ssl) :
184-
this(protocol, uri.Host, uri.Port, ssl)
185-
{
186-
}
187-
188-
///<summary>Construct an AmqpTcpEndpoint with the given
189-
///IProtocol and Uri.</summary>
190-
///<remarks>
191-
/// Please see the class overview documentation for
192-
/// information about the Uri format in use.
193-
///</remarks>
194-
public AmqpTcpEndpoint(IProtocol protocol, Uri uri) :
195-
this(protocol, uri.Host, uri.Port)
145+
public AmqpTcpEndpoint(Uri uri, SslOption ssl) :
146+
this(uri.Host, uri.Port, ssl)
196147
{
197148
}
198149

199150
///<summary>Construct an AmqpTcpEndpoint with the given
200-
///Uri, using the IProtocol from
201-
///Protocols.FromEnvironment().</summary>
151+
///Uri.</summary>
202152
///<remarks>
203153
/// Please see the class overview documentation for
204154
/// information about the Uri format in use.
205155
///</remarks>
206156
public AmqpTcpEndpoint(Uri uri) :
207-
this(Protocols.FromEnvironment(), uri)
157+
this(uri.Host, uri.Port)
208158
{
209159
}
210160

@@ -215,7 +165,7 @@ public AmqpTcpEndpoint(Uri uri) :
215165
///</remarks>
216166
public override string ToString()
217167
{
218-
return "amqp-" + Protocol + "://" + HostName + ":" + Port;
168+
return "amqp://" + HostName + ":" + Port;
219169
}
220170

221171
///<summary>Compares this instance by value (protocol,
@@ -224,24 +174,22 @@ public override bool Equals(object obj)
224174
{
225175
AmqpTcpEndpoint other = obj as AmqpTcpEndpoint;
226176
if (other == null) return false;
227-
if (other.Protocol != Protocol) return false;
228177
if (other.HostName != HostName) return false;
229178
if (other.Port != Port) return false;
230179
return true;
231180
}
232181

233-
///<summary>Implementation of hash code depending on protocol,
182+
///<summary>Implementation of hash code depending on
234183
///hostname and port, to line up with the implementation of
235184
///Equals()</summary>
236185
public override int GetHashCode()
237186
{
238187
return
239-
Protocol.GetHashCode() ^
240188
HostName.GetHashCode() ^
241189
Port;
242190
}
243191

244-
///<summary>Construct an instance from a protocol and an
192+
///<summary>Construct an instance from an
245193
///address in "hostname:port" format.</summary>
246194
///<remarks>
247195
/// If the address string passed in contains ":", it is split
@@ -250,15 +198,14 @@ public override int GetHashCode()
250198
/// is set to -1 (meaning the default number for the protocol
251199
/// variant specified).
252200
///</remarks>
253-
public static AmqpTcpEndpoint Parse(IProtocol protocol, string address) {
201+
public static AmqpTcpEndpoint Parse(string address) {
254202
int index = address.IndexOf(':');
255203
if (index == -1) {
256-
return new AmqpTcpEndpoint(protocol, address, -1);
204+
return new AmqpTcpEndpoint(address, -1);
257205
} else {
258206
string portStr = address.Substring(index + 1).Trim();
259207
int portNum = (portStr.Length == 0) ? -1 : int.Parse(portStr);
260-
return new AmqpTcpEndpoint(protocol,
261-
address.Substring(0, index),
208+
return new AmqpTcpEndpoint(address.Substring(0, index),
262209
portNum);
263210
}
264211
}
@@ -271,13 +218,13 @@ public static AmqpTcpEndpoint Parse(IProtocol protocol, string address) {
271218
/// optional, and returns a corresponding array of
272219
/// AmqpTcpEndpoints.
273220
///</remarks>
274-
public static AmqpTcpEndpoint[] ParseMultiple(IProtocol protocol, string addresses) {
221+
public static AmqpTcpEndpoint[] ParseMultiple(string addresses) {
275222
string[] partsArr = addresses.Split(new char[] { ',' });
276223
ArrayList results = new ArrayList();
277224
foreach (string partRaw in partsArr) {
278225
string part = partRaw.Trim();
279226
if (part.Length > 0) {
280-
results.Add(Parse(protocol, part));
227+
results.Add(Parse(part));
281228
}
282229
}
283230
return (AmqpTcpEndpoint[]) results.ToArray(typeof(AmqpTcpEndpoint));

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,28 @@ namespace RabbitMQ.Client
103103
///</remarks>
104104
public class ConnectionFactory
105105
{
106-
public ConnectionParameters[] ConnectionParameters = { new ConnectionParameters() };
106+
public ConnectionParameters[] ConnectionParameters;
107107

108108
///<summary>Constructs a ConnectionFactory with default values
109109
///for Parameters.</summary>
110-
public ConnectionFactory()
110+
public ConnectionFactory(params ConnectionParameters[] parameters)
111111
{
112+
this.ConnectionParameters = parameters;
112113
}
113114

115+
public ConnectionFactory(AMQPParameters amqpParameters, AmqpTcpEndpoint endpoint) : this(new ConnectionParameters(amqpParameters, endpoint))
116+
{
117+
}
118+
119+
public ConnectionFactory(AMQPParameters amqpParameters) : this(amqpParameters, new AmqpTcpEndpoint())
120+
{
121+
}
122+
123+
public ConnectionFactory(AmqpTcpEndpoint endpoint) : this(new AMQPParameters(), endpoint)
124+
{
125+
}
126+
127+
114128
protected virtual IConnection FollowRedirectChain
115129
(int maxRedirects,
116130
IDictionary connectionAttempts,

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ IProtocol IConnection.Protocol
194194
{
195195
get
196196
{
197-
return Endpoint.Protocol;
197+
return Parameters.Protocol;
198198
}
199199
}
200200

@@ -204,7 +204,7 @@ public AbstractProtocolBase Protocol
204204
{
205205
get
206206
{
207-
return (AbstractProtocolBase)Endpoint.Protocol;
207+
return (AbstractProtocolBase)Parameters.Protocol;
208208
}
209209
}
210210

@@ -982,7 +982,7 @@ public void Open(bool insist)
982982
string knownHosts = m_model0.ConnectionOpen(m_parameters.VirtualHost,
983983
"", // FIXME: make configurable?
984984
insist);
985-
KnownHosts = AmqpTcpEndpoint.ParseMultiple(Protocol, knownHosts);
985+
KnownHosts = AmqpTcpEndpoint.ParseMultiple(knownHosts);
986986
}
987987

988988
public override string ToString()

projects/client/RabbitMQ.Client/src/client/impl/RedirectException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public RedirectException(IProtocol protocol,
8585
string host,
8686
string knownHosts)
8787
: this(ParseHost(protocol, host),
88-
AmqpTcpEndpoint.ParseMultiple(protocol, knownHosts))
88+
AmqpTcpEndpoint.ParseMultiple(knownHosts))
8989
{}
9090

9191
public RedirectException(AmqpTcpEndpoint host, AmqpTcpEndpoint[] knownHosts)
@@ -108,9 +108,9 @@ public RedirectException(AmqpTcpEndpoint host, AmqpTcpEndpoint[] knownHosts)
108108
/// array.
109109
///</remarks>
110110
public static AmqpTcpEndpoint ParseHost(IProtocol protocol, string host) {
111-
AmqpTcpEndpoint[] addresses = AmqpTcpEndpoint.ParseMultiple(protocol, host);
111+
AmqpTcpEndpoint[] addresses = AmqpTcpEndpoint.ParseMultiple(host);
112112
if (addresses.Length == 0) {
113-
return AmqpTcpEndpoint.Parse(protocol, "");
113+
return AmqpTcpEndpoint.Parse("");
114114
// ^^ effectively, a (kind of useless) default or null result
115115
} else {
116116
return addresses[0];

projects/client/RabbitMQ.Client/src/client/impl/SocketFrameHandler_0_9.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ public class SocketFrameHandler_0_9 : IFrameHandler
6969
// ^^ System.Net.Sockets.SocketError doesn't exist in .NET 1.1
7070

7171
public AmqpTcpEndpoint m_endpoint;
72+
public IProtocol Protocol;
7273
public TcpClient m_socket;
7374
public NetworkBinaryReader m_reader;
74-
public NetworkBinaryWriter m_writer;
75+
public NetworkBinaryWriter m_writer;
7576

76-
public SocketFrameHandler_0_9(AmqpTcpEndpoint endpoint)
77+
public SocketFrameHandler_0_9(IProtocol protocol, AmqpTcpEndpoint endpoint)
7778
{
79+
Protocol = protocol;
7880
m_endpoint = endpoint;
7981
m_socket = new TcpClient();
8082
m_socket.Connect(endpoint.HostName, endpoint.Port);
@@ -121,8 +123,8 @@ public void SendHeader()
121123
m_writer.Write(Encoding.ASCII.GetBytes("AMQP"));
122124
m_writer.Write((byte)1);
123125
m_writer.Write((byte)1);
124-
m_writer.Write((byte)m_endpoint.Protocol.MajorVersion);
125-
m_writer.Write((byte)m_endpoint.Protocol.MinorVersion);
126+
m_writer.Write((byte)Protocol.MajorVersion);
127+
m_writer.Write((byte)Protocol.MinorVersion);
126128
m_writer.Flush();
127129
}
128130
}

projects/client/RabbitMQ.Client/src/client/impl/v0_8/ProtocolBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace RabbitMQ.Client.Framing.Impl.v0_8 {
6262
public abstract class ProtocolBase: AbstractProtocolBase {
6363

6464
public override IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint) {
65-
return new SocketFrameHandler_0_9(endpoint);
65+
return new SocketFrameHandler_0_9(this, endpoint);
6666
}
6767

6868
public override IModel CreateModel(ISession session) {

projects/client/RabbitMQ.Client/src/client/impl/v0_8qpid/ProtocolBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ namespace RabbitMQ.Client.Framing.Impl.v0_8qpid {
6262
public abstract class ProtocolBase: AbstractProtocolBase {
6363

6464
public override IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint) {
65-
return new SocketFrameHandler_0_9(endpoint);
65+
//TODO: Query why we are creating a 0.9 frame handler for a 0.8 protocol
66+
return new SocketFrameHandler_0_9(this, endpoint);
6667
}
6768

6869
public override IModel CreateModel(ISession session) {

projects/client/RabbitMQ.Client/src/client/impl/v0_9/ProtocolBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace RabbitMQ.Client.Framing.Impl.v0_9 {
6262
public abstract class ProtocolBase: AbstractProtocolBase {
6363

6464
public override IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint) {
65-
return new SocketFrameHandler_0_9(endpoint);
65+
return new SocketFrameHandler_0_9(this, endpoint);
6666
}
6767

6868
public override IModel CreateModel(ISession session) {

0 commit comments

Comments
 (0)