Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pvkv1799 committed May 29, 2020
1 parent 436abbd commit 9ec677d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
12 changes: 10 additions & 2 deletions QuickFIXn/AbstractInitiator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading;
using System.Collections.Generic;
using System;

namespace QuickFix
{
Expand All @@ -13,7 +14,6 @@ public abstract class AbstractInitiator : IInitiator
private IMessageFactory _msgFactory = null;

private object sync_ = new object();
private bool _disposed = false;
private Dictionary<SessionID, Session> sessions_ = new Dictionary<SessionID, Session>();
private HashSet<SessionID> sessionIDs_ = new HashSet<SessionID>();
private HashSet<SessionID> pending_ = new HashSet<SessionID>();
Expand Down Expand Up @@ -381,6 +381,7 @@ public HashSet<SessionID> GetSessionIDs()
return new HashSet<SessionID>(sessions_.Keys);
}

private bool _disposed = false;
/// <summary>
/// Any subclasses of AbstractInitiator should override this if they have resources to dispose
/// that aren't already covered in its OnStop() handler.
Expand All @@ -389,13 +390,20 @@ public HashSet<SessionID> GetSessionIDs()
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
this.Stop();
if (_disposed) return;
if (disposing)
{
this.Stop();
}
_disposed = true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~AbstractInitiator() => Dispose(false);
}
}
18 changes: 16 additions & 2 deletions QuickFIXn/CompositeLog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

using System;

namespace QuickFix
{
/// <summary>
Expand Down Expand Up @@ -45,15 +47,27 @@ public void OnEvent(string s)

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing)
{
foreach (var log in logs_)
log.Dispose();
}
_disposed = true;
foreach (var log in logs_)
log.Dispose();
}

private void DisposedCheck()
{
if (_disposed)
throw new System.ObjectDisposedException(this.GetType().Name);
}

~CompositeLog() => Dispose(false);
}
}
15 changes: 14 additions & 1 deletion QuickFIXn/FileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,22 @@ public void Refresh()

public void Dispose()
{
close();
Dispose(true);
GC.SuppressFinalize(this);

}
private bool _disposed = false;
protected virtual void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing)
{
close();
}
_disposed = true;
}

~FileStore() => Dispose(false);
#endregion
}
}
16 changes: 15 additions & 1 deletion QuickFIXn/MemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,22 @@ public void Refresh()
{ }

public void Dispose()
{ }
{
Dispose(true);
GC.SuppressFinalize(this);
}
private bool _disposed = false;
protected virtual void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing)
{
messages_ = null;
}
_disposed = true;
}

~MemoryStore() => Dispose(false);
#endregion
}
}
13 changes: 11 additions & 2 deletions QuickFIXn/ScreenLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,19 @@ public void OnEvent(string s)
System.Console.WriteLine("<event> " + s);
}
}
#endregion

#region IDisposable implementation
public void Dispose()
{ }

{
Dispose(true);
System.GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
// Nothing to dispose of...
}
~ScreenLog() => Dispose(false);
#endregion
}
}

0 comments on commit 9ec677d

Please sign in to comment.