Skip to content

Commit 52668d1

Browse files
author
Hubert Plociniczak
committed
Added Abort methods to the model and simpler
Close method without close code and message.
1 parent 34e37e2 commit 52668d1

File tree

2 files changed

+83
-14
lines changed

2 files changed

+83
-14
lines changed

src/client/api/IModel.cs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,55 @@ BasicGetResult BasicGet(ushort ticket,
403403

404404
///<summary>Close this session.</summary>
405405
///<remarks>
406-
/// If the session is already closed (or closing), then this
407-
/// method does nothing but wait for the in-progress close
408-
/// operation to complete. This method will not return to the
409-
/// caller until the shutdown is complete.
406+
///If the session is already closed (or closing), then this
407+
///method does nothing but wait for the in-progress close
408+
///operation to complete. This method will not return to the
409+
///caller until the shutdown is complete.
410+
///</remarks>
411+
[AmqpMethodDoNotImplement(null)]
412+
void Close();
413+
414+
///<summary>Close this session.</summary>
415+
///<remarks>
416+
///The method behaves in the same way as Close(), with the only
417+
///difference that the model is closed with the given model
418+
///close code and message.
419+
///<para>
420+
///The close code (See under "Reply Codes" in the AMQP specification)
421+
///</para>
422+
///<para>
423+
///A message indicating the reason for closing the model
424+
///</para>
410425
///</remarks>
411426
[AmqpMethodDoNotImplement(null)]
412427
void Close(ushort replyCode, string replyText);
428+
429+
///<summary>Abort this session.</summary>
430+
///<remarks>
431+
///If the session is already closed (or closing), then this
432+
///method does nothing but wait for the in-progress close
433+
///operation to complete. This method will not return to the
434+
///caller until the shutdown is complete.
435+
///In comparison to normal Close() method, Abort() will not throw
436+
///AlreadyClosedException or IOException during closing model.
437+
///</remarks>
438+
[AmqpMethodDoNotImplement(null)]
439+
void Abort();
440+
441+
///<summary>Abort this session.</summary>
442+
///<remarks>
443+
///The method behaves in the same way as Abort(), with the only
444+
///difference that the model is closed with the given model
445+
///close code and message.
446+
///<para>
447+
///The close code (See under "Reply Codes" in the AMQP specification)
448+
///</para>
449+
///<para>
450+
///A message indicating the reason for closing the model
451+
///</para>
452+
///</remarks>
453+
[AmqpMethodDoNotImplement(null)]
454+
void Abort(ushort replyCode, string replyText);
413455
}
414456

415457
///<summary>Represents Basic.GetOk responses from the server.</summary>

src/client/impl/ModelBase.cs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -873,22 +873,49 @@ public abstract void BasicReject(ulong deliveryTag,
873873

874874
void IDisposable.Dispose()
875875
{
876-
Close(200, "");
876+
Close();
877+
}
878+
879+
public void Close()
880+
{
881+
Close(200, "Goodbye");
877882
}
878883

879-
public void Close(ushort replyCode, string replyText)
884+
public void Close(ushort replyCode, string replyText)
885+
{
886+
Close(replyCode, replyText, false);
887+
}
888+
889+
public void Abort()
890+
{
891+
Abort(200, "Goodbye");
892+
}
893+
894+
public void Abort(ushort replyCode, string replyText)
895+
{
896+
Close(replyCode, replyText, true);
897+
}
898+
899+
public void Close(ushort replyCode, string replyText, bool abort)
880900
{
881901
ShutdownContinuation k = new ShutdownContinuation();
882902
ModelShutdown += new ModelShutdownEventHandler(k.OnShutdown);
883-
884-
if (SetCloseReason(new ShutdownEventArgs(ShutdownInitiator.Application,
885-
replyCode,
886-
replyText)))
887-
{
888-
_Private_ChannelClose(replyCode, replyText, 0, 0);
903+
904+
try {
905+
if (SetCloseReason(new ShutdownEventArgs(ShutdownInitiator.Application,
906+
replyCode,
907+
replyText)))
908+
{
909+
_Private_ChannelClose(replyCode, replyText, 0, 0);
910+
}
911+
k.Wait();
912+
} catch (AlreadyClosedException ace) {
913+
if (!abort)
914+
throw ace;
915+
} catch (IOException ioe) {
916+
if (!abort)
917+
throw ioe;
889918
}
890-
891-
k.Wait();
892919
}
893920

894921
public void HandleChannelCloseOk()

0 commit comments

Comments
 (0)