Skip to content

Commit

Permalink
The databus now has a Start method that gets called when the main bus…
Browse files Browse the repository at this point in the history
… starts. This will allow implementers to perform any actions related to startup in a controlled fashion
  • Loading branch information
andreasohlund committed Jan 31, 2011
1 parent ae03e80 commit 17646dc
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ nuget
CommonAssemblyInfo.cs
lib/sqlite/System.Data.SQLite.dll
*.orig
Samples/DataBus/storage
Binary file modified Samples/DataBus/DataBus.suo
Binary file not shown.
10 changes: 10 additions & 0 deletions src/databus/NServiceBus.Databus.Tests/InMemoryDataBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@ public string Put(Stream stream, TimeSpan timeToBeReceived)
storage.Add(key,data);
return key;
}

public void Start()
{
//no-op
}

public void Dispose()
{
//no-op
}
}
}
48 changes: 29 additions & 19 deletions src/databus/NServiceBus.Databus/Config/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,41 @@ namespace NServiceBus.DataBus.Config
{
using System;
using System.Configuration;
using Unicast;

public class Bootstrapper:INeedInitialization
{
public void Init()
{
bool dataBusPropertyFound = Configure.TypesToScan
.Where(t => typeof (IMessage).IsAssignableFrom(t))
.SelectMany(messageType => messageType.GetProperties())
public class Bootstrapper : INeedInitialization
{
public void Init()
{
bool dataBusPropertyFound = Configure.TypesToScan
.Where(t => typeof(IMessage).IsAssignableFrom(t))
.SelectMany(messageType => messageType.GetProperties())
.Any(t => typeof(IDataBusProperty).IsAssignableFrom(t.PropertyType));

if (dataBusPropertyFound)
{
if(!Configure.Instance.Configurer.HasComponent<IDataBus>())
throw new InvalidOperationException("Messages containing databus properties found, please configure a databus!");
if (!dataBusPropertyFound)
return;

Configure.Instance.Configurer.ConfigureComponent<DataBusMessageMutator>(
DependencyLifecycle.InstancePerCall);
if (!Configure.Instance.Configurer.HasComponent<IDataBus>())
throw new InvalidOperationException("Messages containing databus properties found, please configure a databus!");

Configure.Instance.Configurer.ConfigureComponent<DefaultDatabusSerializer>(
DependencyLifecycle.SingleInstance);
Configure.Instance.Configurer.ConfigureComponent<DataBusMessageMutator>(
DependencyLifecycle.InstancePerCall);

Configure.Instance.Configurer.ConfigureComponent<DefaultDatabusSerializer>(
DependencyLifecycle.SingleInstance);


}

HookupDataBusStartMethod();
}
}

static void HookupDataBusStartMethod()
{
Configure.ConfigurationComplete +=
(o,a) =>
{
Configure.Instance.Builder.Build<IStartableBus>()
.Started += (sender, eventargs) => Configure.Instance.Builder.Build<IDataBus>().Start();

};
}
}
}
7 changes: 6 additions & 1 deletion src/databus/NServiceBus.Databus/IDataBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NServiceBus.DataBus
/// <summary>
/// The main interface for interactions with the databus
/// </summary>
public interface IDataBus
public interface IDataBus:IDisposable
{
/// <summary>
/// Gets a data item from the bus
Expand All @@ -22,5 +22,10 @@ public interface IDataBus
/// <param name="stream">A create containing the data to be sent on the databus</param>
/// <param name="timeToBeReceived">The time to be received specified on the message type. TimeSpan.MaxValue is the default</param>
string Put(Stream stream, TimeSpan timeToBeReceived);

/// <summary>
/// Called when the bus starts up to allow the data bus to active background tasks
/// </summary>
void Start();
}
}
3 changes: 3 additions & 0 deletions src/databus/NServiceBus.Databus/NServiceBus.DataBus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.ObjectBuilder.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.Unicast">
<HintPath>..\..\..\build\nservicebus.core\NServiceBus.Unicast.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
</Reference>
Expand Down
13 changes: 13 additions & 0 deletions src/impl/databus/NServiceBus.Databus.FileShare/FileShareDataBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
{
using System;
using System.IO;
using Common.Logging;
using DataBus;

public class FileShareDataBus : IDataBus
{
readonly string basePath;
private readonly ILog logger = LogManager.GetLogger(typeof(IDataBus));

public FileShareDataBus(string basePath)
{
Expand Down Expand Up @@ -41,6 +43,13 @@ public string Put(Stream stream, TimeSpan timeToBeReceived)
return key;
}

public void Start()
{
logger.Info("File share data bus started. Location: " + basePath);

//TODO: Implement a clean up thread
}

string GenerateKey(TimeSpan timeToBeReceived)
{
if (timeToBeReceived > MaxMessageTimeToLive)
Expand All @@ -54,5 +63,9 @@ string GenerateKey(TimeSpan timeToBeReceived)
return Path.Combine(keepMessageUntil.ToString("yyyy-MM-dd_hh"), Guid.NewGuid().ToString());
}

public void Dispose()
{
logger.Info("File share data bus started. Location: " + basePath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Common.Logging">
<HintPath>..\..\..\..\lib\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="NServiceBus">
<HintPath>..\..\..\..\build\output\NServiceBus.dll</HintPath>
</Reference>
Expand Down

0 comments on commit 17646dc

Please sign in to comment.