Skip to content

Commit de429e7

Browse files
author
Hubert Plociniczak
committed
Moved the code responsible for checking the type of the command that is about to be sent in the quiescing state to the version-specific ProtocolBase classes.
1 parent cee1311 commit de429e7

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

src/client/impl/AbstractProtocolBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public abstract void CreateChannelClose(ushort reasonCode,
8989
out Command request,
9090
out int replyClassId,
9191
out int replyMethodId);
92+
93+
///<summary>Used in the quiescing session to determine if the command
94+
///is allowed to be sent.</summary>
95+
public abstract bool CanSendWhileClosed(Command cmd);
9296

9397
public AmqpVersion Version {
9498
get {

src/client/impl/SessionBase.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ public abstract class SessionBase: ISession
7272

7373
public readonly ConnectionBase m_connection;
7474
public readonly int m_channelNumber;
75-
76-
public int m_channelCloseOkClassId;
77-
public int m_channelCloseOkMethodId;
7875

7976
public SessionBase(ConnectionBase connection, int channelNumber)
8077
{
@@ -83,12 +80,6 @@ public SessionBase(ConnectionBase connection, int channelNumber)
8380
if (channelNumber != 0)
8481
connection.ConnectionShutdown +=
8582
new ConnectionShutdownEventHandler(this.OnConnectionShutdown);
86-
87-
Command request;
88-
connection.Protocol.CreateChannelClose(0,"",
89-
out request,
90-
out m_channelCloseOkClassId,
91-
out m_channelCloseOkMethodId);
9283
}
9384

9485
public virtual void OnCommandReceived(Command cmd)
@@ -180,10 +171,7 @@ public virtual void Transmit(Command cmd)
180171
{
181172
if (m_closeReason != null)
182173
{
183-
// Allow always for sending close ok
184-
MethodBase method = cmd.m_method;
185-
if ( (method.ProtocolClassId != m_channelCloseOkClassId)
186-
|| (method.ProtocolMethodId != m_channelCloseOkMethodId))
174+
if (!m_connection.Protocol.CanSendWhileClosed(cmd))
187175
throw new AlreadyClosedException(m_closeReason);
188176
}
189177
// We transmit *inside* the lock to avoid interleaving

src/client/impl/v0_8/ProtocolBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,13 @@ public override void CreateChannelClose(ushort reasonCode,
101101
replyClassId = RabbitMQ.Client.Framing.Impl.v0_8.ChannelCloseOk.ClassId;
102102
replyMethodId = RabbitMQ.Client.Framing.Impl.v0_8.ChannelCloseOk.MethodId;
103103
}
104+
105+
public override bool CanSendWhileClosed(Command cmd)
106+
{
107+
return (cmd.m_method.ProtocolClassId
108+
== RabbitMQ.Client.Framing.Impl.v0_8.ChannelCloseOk.ClassId)
109+
&& (cmd.m_method.ProtocolMethodId
110+
== RabbitMQ.Client.Framing.Impl.v0_8.ChannelCloseOk.MethodId);
111+
}
104112
}
105113
}

src/client/impl/v0_8qpid/ProtocolBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,13 @@ public override void CreateChannelClose(ushort reasonCode,
101101
replyClassId = RabbitMQ.Client.Framing.Impl.v0_8qpid.ChannelCloseOk.ClassId;
102102
replyMethodId = RabbitMQ.Client.Framing.Impl.v0_8qpid.ChannelCloseOk.MethodId;
103103
}
104+
105+
public override bool CanSendWhileClosed(Command cmd)
106+
{
107+
return (cmd.m_method.ProtocolClassId
108+
== RabbitMQ.Client.Framing.Impl.v0_8qpid.ChannelCloseOk.ClassId)
109+
&& (cmd.m_method.ProtocolMethodId
110+
== RabbitMQ.Client.Framing.Impl.v0_8qpid.ChannelCloseOk.MethodId);
111+
}
104112
}
105113
}

src/client/impl/v0_9/ProtocolBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,13 @@ public override void CreateChannelClose(ushort reasonCode,
101101
replyClassId = RabbitMQ.Client.Framing.Impl.v0_9.ChannelCloseOk.ClassId;
102102
replyMethodId = RabbitMQ.Client.Framing.Impl.v0_9.ChannelCloseOk.MethodId;
103103
}
104+
105+
public override bool CanSendWhileClosed(Command cmd)
106+
{
107+
return (cmd.m_method.ProtocolClassId
108+
== RabbitMQ.Client.Framing.Impl.v0_9.ChannelCloseOk.ClassId)
109+
&& (cmd.m_method.ProtocolMethodId
110+
== RabbitMQ.Client.Framing.Impl.v0_9.ChannelCloseOk.MethodId);
111+
}
104112
}
105113
}

0 commit comments

Comments
 (0)