Skip to content

Commit

Permalink
Added isOpen to OddsFeed (extended with IOddsFeedV6)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrovat committed Jun 2, 2022
1 parent c1a0e72 commit 537fef9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/Sportradar.OddsFeed.SDK.API/Extended/IOddsFeedExt.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* Copyright (C) Sportradar AG. See LICENSE for full license governing this code
*/
using System;
using Sportradar.OddsFeed.SDK.Messages.EventArguments;
using System;

namespace Sportradar.OddsFeed.SDK.API.Extended
{
/// <summary>
/// Represent an extended unified odds feed
/// </summary>
public interface IOddsFeedExt : IOddsFeedV5
public interface IOddsFeedExt : IOddsFeedV6
{
/// <summary>
/// Occurs when any feed message arrives
Expand Down
118 changes: 62 additions & 56 deletions src/Sportradar.OddsFeed.SDK.API/Feed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Sportradar.OddsFeed.SDK.API
/// <summary>
/// A <see cref="IOddsFeed"/> implementation acting as an entry point to the odds feed SDK
/// </summary>
public class Feed : EntityDispatcherBase, IOddsFeedV5, IGlobalEventDispatcher
public class Feed : EntityDispatcherBase, IOddsFeedV6, IGlobalEventDispatcher
{
/// <summary>
/// A <see cref="ILog"/> instance used for execution logging
Expand Down Expand Up @@ -534,61 +534,6 @@ public IOddsFeedSessionBuilder CreateBuilder()
return new OddsFeedSessionBuilder(this);
}

/// <summary>
/// Closes the current <see cref="Feed"/> instance and disposes resources used by it
/// </summary>
public void Close()
{
Dispose();
}

/// <summary>
/// Disposes the current instance and resources associated with it
/// </summary>
/// <param name="disposing">Value indicating whether the managed resources should also be disposed</param>
protected virtual void Dispose(bool disposing)
{
if (_isDisposed)
{
return;
}

if (_connectionFactory != null)
{
DetachFromConnectionEvents();
}

if (_feedRecoveryManager != null)
{
_feedRecoveryManager.ProducerDown -= MarkProducerAsDown;
_feedRecoveryManager.ProducerUp -= MarkProducerAsUp;
_feedRecoveryManager.CloseFeed -= OnCloseFeed;
_feedRecoveryManager.EventRecoveryCompleted -= OnEventRecoveryCompleted;
_feedRecoveryManager.Close();
}

foreach (var session in Sessions)
{
session.Close();
}

EventChangeManager.Stop();

if (disposing)
{
try
{
UnityContainer.Dispose();
}
catch (Exception ex)
{
_log.Warn("An exception has occurred while disposing the feed instance.", ex);
}
}

_isDisposed = true;
}

/// <summary>
/// Opens the current feed by opening all created sessions
/// </summary>
Expand Down Expand Up @@ -696,6 +641,67 @@ public void Open()
}
}

/// <inheritdoc />
public bool IsOpen()
{
return _opened == 1;
}

/// <summary>
/// Closes the current <see cref="Feed"/> instance and disposes resources used by it
/// </summary>
public void Close()
{
Dispose();
}

/// <summary>
/// Disposes the current instance and resources associated with it
/// </summary>
/// <param name="disposing">Value indicating whether the managed resources should also be disposed</param>
protected virtual void Dispose(bool disposing)
{
if (_isDisposed)
{
return;
}

if (_connectionFactory != null)
{
DetachFromConnectionEvents();
}

if (_feedRecoveryManager != null)
{
_feedRecoveryManager.ProducerDown -= MarkProducerAsDown;
_feedRecoveryManager.ProducerUp -= MarkProducerAsUp;
_feedRecoveryManager.CloseFeed -= OnCloseFeed;
_feedRecoveryManager.EventRecoveryCompleted -= OnEventRecoveryCompleted;
_feedRecoveryManager.Close();
}

foreach (var session in Sessions)
{
session.Close();
}

EventChangeManager.Stop();

if (disposing)
{
try
{
UnityContainer.Dispose();
}
catch (Exception ex)
{
_log.Warn("An exception has occurred while disposing the feed instance.", ex);
}
}

_isDisposed = true;
}

private void AttachToConnectionEvents()
{
if (_connectionFactory != null)
Expand Down
17 changes: 17 additions & 0 deletions src/Sportradar.OddsFeed.SDK.API/IOddsFeedV6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) Sportradar AG. See LICENSE for full license governing this code
*/

namespace Sportradar.OddsFeed.SDK.API
{
/// <summary>
/// Represent a root object of the unified odds feed
/// </summary>
public interface IOddsFeedV6 : IOddsFeedV5
{
/// <summary>
/// Returns an indicator if the feed instance is opened or not
/// </summary>
bool IsOpen();
}
}
4 changes: 2 additions & 2 deletions src/Sportradar.OddsFeed.SDK.API/ReplayFeed.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (C) Sportradar AG. See LICENSE for full license governing this code
*/
using Sportradar.OddsFeed.SDK.API.Internal;
using Microsoft.Practices.Unity;
using Sportradar.OddsFeed.SDK.API.Internal;

namespace Sportradar.OddsFeed.SDK.API
{
Expand Down Expand Up @@ -40,7 +40,7 @@ protected override void InitFeed()
return;
}
base.InitFeed();
((ProducerManager) ProducerManager).SetIgnoreRecovery(0);
((ProducerManager)ProducerManager).SetIgnoreRecovery(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<Compile Include="Internal\Replay\ReplayEvent.cs" />
<Compile Include="Internal\TimestampTracker.cs" />
<Compile Include="Extended\IOddsFeedExt.cs" />
<Compile Include="IOddsFeedV6.cs" />
<Compile Include="IOddsFeedV5.cs" />
<Compile Include="IOddsFeedV4.cs" />
<Compile Include="IOddsFeedV3.cs" />
Expand Down

0 comments on commit 537fef9

Please sign in to comment.