Skip to content

Commit

Permalink
Merge pull request #45 from datalust/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
nblumhardt authored Feb 13, 2019
2 parents 2bee59e + b986316 commit b604114
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Seq.Forwarder/Cli/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static void WriteBanner()
Console.WriteLine();
Write(" Seq Forwarder", ConsoleColor.White);
Write(" ──", ConsoleColor.DarkGray);
Write(" © 2017 Datalust Pty Ltd", ConsoleColor.Gray);
Write(" © 2019 Datalust Pty Ltd", ConsoleColor.Gray);
Console.WriteLine();
Write("─", ConsoleColor.DarkGray, 47);
Console.WriteLine();
Expand Down
14 changes: 14 additions & 0 deletions src/Seq.Forwarder/Multiplexing/ActiveLogBufferMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using Nancy;
using Seq.Forwarder.Config;
using Seq.Forwarder.Storage;
using Seq.Forwarder.Util;
using Seq.Forwarder.Web;
using Serilog;

namespace Seq.Forwarder.Multiplexing
Expand All @@ -33,6 +35,7 @@ class ActiveLogBufferMap : IDisposable
readonly ILogger _log = Log.ForContext<ActiveLogBufferMap>();

readonly object _sync = new object();
bool _loaded;
ActiveLogBuffer _noApiKeyLogBuffer;
readonly Dictionary<string, ActiveLogBuffer> _buffersByApiKey = new Dictionary<string, ActiveLogBuffer>();

Expand All @@ -55,6 +58,8 @@ public void Load()

lock (_sync)
{
if (_loaded) throw new InvalidOperationException("The log buffer map is already loaded.");

Directory.CreateDirectory(_bufferPath);

var defaultDataFilePath = Path.Combine(_bufferPath, DataFileName);
Expand Down Expand Up @@ -102,13 +107,17 @@ public void Load()
_buffersByApiKey.Add(apiKey, activeBuffer);
}
}

_loaded = true;
}
}

public void Start()
{
lock (_sync)
{
if (!_loaded) throw new InvalidOperationException("The log buffer map is not loaded.");

foreach (var buffer in OpenBuffers)
{
buffer.Shipper.Start();
Expand All @@ -120,6 +129,9 @@ public void Stop()
{
lock (_sync)
{
// Hard to ensure _loaded is set in all cases, better here to be forgiving and
// permit a clean shut-down.

foreach (var buffer in OpenBuffers)
{
buffer.Shipper.Stop();
Expand All @@ -131,6 +143,8 @@ public LogBuffer GetLogBuffer(string apiKey)
{
lock (_sync)
{
if (!_loaded) throw new BadRequestException("The forwarder service is starting up.", HttpStatusCode.ServiceUnavailable);

if (apiKey == null)
{
if (_noApiKeyLogBuffer == null)
Expand Down
2 changes: 1 addition & 1 deletion src/Seq.Forwarder/ServiceProcess/ServerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ServerService
{
readonly Lazy<ActiveLogBufferMap> _logBufferMap;
readonly NancyHost _nancyHost;
string _listenUri;
readonly string _listenUri;

public ServerService(NancyBootstrapper bootstrapper, Lazy<ActiveLogBufferMap> logBufferMap, string listenUri)
{
Expand Down

0 comments on commit b604114

Please sign in to comment.