Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix up

Fix typos and other issues
  • Loading branch information...
commit ab8791d3a7f33f1fba8869be20c87c838ba907b0 1 parent dbd54f9
@mr-miles mr-miles authored CoreyKaylor committed
View
176 Rhino.ServiceBus.Castle/CastleBootStrapper.cs
@@ -1,89 +1,89 @@
-using System.Reflection;
-using Castle.Core;
-using Castle.MicroKernel.Registration;
-using Castle.Windsor;
-using Rhino.ServiceBus.Actions;
-using Rhino.ServiceBus.Hosting;
-using Rhino.ServiceBus.Impl;
-using Rhino.ServiceBus.Internal;
-
-namespace Rhino.ServiceBus.Castle
-{
- public abstract class CastleBootStrapper : AbstractBootStrapper
- {
- private IWindsorContainer container;
-
- protected CastleBootStrapper()
- {
- }
-
- protected CastleBootStrapper(IWindsorContainer container)
- {
- this.container = container;
- }
-
- protected IWindsorContainer Container
- {
- get { return container; }
- }
-
- protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)
- {
- configuration.UseCastleWindsor(container);
- }
-
- public override void ExecuteDeploymentActions(string user)
- {
- foreach (var action in container.ResolveAll<IDeploymentAction>())
- action.Execute(user);
- }
-
- public override void ExecuteEnvironmentValidationActions()
- {
- foreach (var action in container.ResolveAll<IEnvironmentValidationAction>())
- action.Execute();
- }
-
- public override T GetInstance<T>()
- {
- return container.Resolve<T>();
- }
-
- public override void Dispose()
- {
- container.Dispose();
- }
-
- public override void CreateContainer()
- {
- if (container == null)
- container = new WindsorContainer();
-
- ConfigureContainer();
- }
-
- protected virtual void ConfigureContainer()
- {
- foreach (var assembly in Assemblies)
- {
- container.Register(
- AllTypes.FromAssembly(assembly)
- .BasedOn<IDeploymentAction>(),
- AllTypes.FromAssembly(assembly)
- .BasedOn<IEnvironmentValidationAction>()
- );
- RegisterConsumersFrom(assembly);
- }
- }
-
- protected virtual void RegisterConsumersFrom(Assembly assembly)
- {
- container.RegisterConsumersFrom(assembly, ConfigureConsumer);
- }
-
- protected virtual void ConfigureConsumer(ComponentRegistration registration)
- {
- registration.Named(registration.Implementation.FullName);
- }
- }
+using System.Reflection;
+using Castle.Core;
+using Castle.MicroKernel.Registration;
+using Castle.Windsor;
+using Rhino.ServiceBus.Actions;
+using Rhino.ServiceBus.Hosting;
+using Rhino.ServiceBus.Impl;
+using Rhino.ServiceBus.Internal;
+
+namespace Rhino.ServiceBus.Castle
+{
+ public abstract class CastleBootStrapper : AbstractBootStrapper
+ {
+ private IWindsorContainer container;
+
+ protected CastleBootStrapper()
+ {
+ }
+
+ protected CastleBootStrapper(IWindsorContainer container)
+ {
+ this.container = container;
+ }
+
+ protected IWindsorContainer Container
+ {
+ get { return container; }
+ }
+
+ protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)
+ {
+ configuration.UseCastleWindsor(container);
+ }
+
+ public override void ExecuteDeploymentActions(string user)
+ {
+ foreach (var action in container.ResolveAll<IDeploymentAction>())
+ action.Execute(user);
+ }
+
+ public override void ExecuteEnvironmentValidationActions()
+ {
+ foreach (var action in container.ResolveAll<IEnvironmentValidationAction>())
+ action.Execute();
+ }
+
+ public override T GetInstance<T>()
+ {
+ return container.Resolve<T>();
+ }
+
+ public override void Dispose()
+ {
+ container.Dispose();
+ }
+
+ public override void CreateContainer()
+ {
+ if (container == null)
+ container = new WindsorContainer();
+
+ ConfigureContainer();
+ }
+
+ protected virtual void ConfigureContainer()
+ {
+ foreach (var assembly in Assemblies)
+ {
+ container.Register(
+ AllTypes.FromAssembly(assembly)
+ .BasedOn<IDeploymentAction>(),
+ AllTypes.FromAssembly(assembly)
+ .BasedOn<IEnvironmentValidationAction>()
+ );
+ RegisterConsumersFrom(assembly);
+ }
+ }
+
+ protected virtual void RegisterConsumersFrom(Assembly assembly)
+ {
+ container.RegisterConsumersFrom(assembly, ConfigureConsumer, IsTypeAcceptableForThisBootStrapper);
+ }
+
+ protected virtual void ConfigureConsumer(ComponentRegistration registration)
+ {
+ registration.Named(registration.Implementation.FullName);
+ }
+ }
}
View
89 Rhino.ServiceBus.Castle/Extensions.cs
@@ -1,43 +1,48 @@
-using Castle.Windsor;
-using Rhino.ServiceBus.Castle;
-using Rhino.ServiceBus.Impl;
-
-namespace Rhino.ServiceBus
-{
- public static class Extensions
- {
- public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration)
- {
- return UseCastleWindsor(configuration, new WindsorContainer());
- }
-
- public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration, IWindsorContainer container)
- {
- new CastleBuilder(container, configuration);
- return configuration;
- }
-
- public static void RegisterConsumersFrom(this IWindsorContainer container, Assembly assembly)
- {
- RegisterConsumersFrom(container, assembly, x=>x.Named(x.Implementation.FullName));
- }
-
- public static void RegisterConsumersFrom(this IWindsorContainer container, Assembly assembly, Action<ComponentRegistration> configureConsumer)
- {
- container.Register(
- AllTypes
- .FromAssembly(assembly)
- .Where(type =>
- typeof(IMessageConsumer).IsAssignableFrom(type) &&
- !typeof(IOccasionalMessageConsumer).IsAssignableFrom(type) &&
- IsTypeAcceptableForThisBootStrapper(type)
- )
- .Configure(registration =>
- {
- registration.LifeStyle.Is(LifestyleType.Transient);
- configureConsumer(registration);
- })
- );
- }
- }
+using System;
+using System.Reflection;
+using Castle.Core;
+using Castle.MicroKernel.Registration;
+using Castle.Windsor;
+using Rhino.ServiceBus.Castle;
+using Rhino.ServiceBus.Impl;
+using Rhino.ServiceBus.Internal;
+
+namespace Rhino.ServiceBus
+{
+ public static class Extensions
+ {
+ public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration)
+ {
+ return UseCastleWindsor(configuration, new WindsorContainer());
+ }
+
+ public static AbstractRhinoServiceBusConfiguration UseCastleWindsor(this AbstractRhinoServiceBusConfiguration configuration, IWindsorContainer container)
+ {
+ new CastleBuilder(container, configuration);
+ return configuration;
+ }
+
+ public static void RegisterConsumersFrom(this IWindsorContainer container, Assembly assembly)
+ {
+ RegisterConsumersFrom(container, assembly, x=>x.Named(x.Implementation.FullName), x=>true);
+ }
+
+ public static void RegisterConsumersFrom(this IWindsorContainer container, Assembly assembly, Action<ComponentRegistration> configureConsumer, Func<Type, bool> isTypeAcceptable)
+ {
+ container.Register(
+ AllTypes
+ .FromAssembly(assembly)
+ .Where(type =>
+ typeof(IMessageConsumer).IsAssignableFrom(type) &&
+ !typeof(IOccasionalMessageConsumer).IsAssignableFrom(type) &&
+ isTypeAcceptable(type)
+ )
+ .Configure(registration =>
+ {
+ registration.LifeStyle.Is(LifestyleType.Transient);
+ configureConsumer(registration);
+ })
+ );
+ }
+ }
}
View
74 Rhino.ServiceBus.Tests/EndpointRouterTests.cs
@@ -1,38 +1,38 @@
-using System;
-using Rhino.ServiceBus.Impl;
-using Rhino.ServiceBus.Utils;
-using Xunit;
-
-namespace Rhino.ServiceBus.Tests
-{
- public class EndpointRouterTests
- {
-
- [Fact]
- public void can_handle_localhost_consistently()
- {
- var router = new EndpointRouter();
- var uri = new Uri("http://localhost/blahdee");
- var normalizedUri = uri.NormalizeLocalhost();
- var routeTo = new Uri("http://remotehost/zippee");
-
- router.RemapEndpoint(uri, routeTo);
-
- Assert.AreEqual(routeTo, router.GetRoutedEndpoint(normalizedUri).Uri);
- Assert.AreEqual(routeTo, router.GetRoutedEndpoint(uri).Uri);
- }
-
- [Fact]
- public void can_handle_localhost_consistently_2()
- {
- var router = new EndpointRouter();
- var uri = new Uri("http://localhost/blahdee");
- var normalizedUri = uri.NormalizeLocalhost();
- var routeFrom = new Uri("http://remotehost/zippee");
-
- router.RemapEndpoint(routeFrom, uri);
-
- Assert.AreEqual(normalizedUri, router.GetRoutedEndpoint(routeFrom).Uri);
- }
- }
+using System;
+using Rhino.ServiceBus.Impl;
+using Rhino.ServiceBus.Util;
+using Xunit;
+
+namespace Rhino.ServiceBus.Tests
+{
+ public class EndpointRouterTests
+ {
+
+ [Fact]
+ public void can_handle_localhost_consistently()
+ {
+ var router = new EndpointRouter();
+ var uri = new Uri("http://lOcAlHoSt/blahdee");
+ var normalizedUri = uri.NormalizeLocalhost();
+ var routeTo = new Uri("http://remotehost/zippee");
+
+ router.RemapEndpoint(uri, routeTo);
+
+ Assert.Equal(routeTo, router.GetRoutedEndpoint(normalizedUri).Uri);
+ Assert.Equal(routeTo, router.GetRoutedEndpoint(uri).Uri);
+ }
+
+ [Fact]
+ public void can_handle_localhost_consistently_2()
+ {
+ var router = new EndpointRouter();
+ var uri = new Uri("http://127.0.0.1/blahdee");
+ var normalizedUri = uri.NormalizeLocalhost();
+ var routeFrom = new Uri("http://remotehost/zippee");
+
+ router.RemapEndpoint(routeFrom, uri);
+
+ Assert.Equal(normalizedUri, router.GetRoutedEndpoint(routeFrom).Uri);
+ }
+ }
}
View
268 Rhino.ServiceBus.Tests/Hosting/Can_host_in_another_app_domain.cs
@@ -1,134 +1,136 @@
-using System;
-using System.IO;
-using System.Threading;
-using Castle.MicroKernel.Registration;
-using Castle.Windsor;
-using Castle.Windsor.Configuration.Interpreters;
-using Rhino.ServiceBus.Castle;
-using Rhino.ServiceBus.Hosting;
-using Rhino.ServiceBus.Impl;
-using Xunit;
-using System.Linq;
-
-namespace Rhino.ServiceBus.Tests.Hosting
-{
- public class Can_host_in_another_app_domain : MsmqTestBase, OccasionalConsumerOf<StringMsg>
- {
- readonly RemoteAppDomainHost host = new RemoteAppDomainHost(
- Path.Combine(Environment.CurrentDirectory, "Rhino.ServiceBus.Tests.dll"), typeof(TestBootStrapper));
- private string reply;
-
- private readonly ManualResetEvent resetEvent = new ManualResetEvent(false);
-
- private readonly IWindsorContainer container;
-
- public Can_host_in_another_app_domain()
- {
- container = new WindsorContainer();
- new RhinoServiceBusConfiguration()
- .UseCastleWindsor(container)
- .UseStandaloneConfigurationFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AnotherBus.config"))
- .Configure();
- }
-
- [Fact]
- public void Can_use_different_config_correctly()
- {
- var bootStrapper = new SimpleBootStrapper(windsorContainer);
- var differentConfig = new BusConfigurationSection();
- bootStrapper.UseConfiguration(differentConfig);
- bootStrapper.InitializeContainer();
- Assert.AreEqual(differentConfig, bootStrapper.ConfigurationSectionInUse);
- }
-
- [Fact]
- public void Components_are_registered_using_their_full_name()
- {
- var windsorContainer = new WindsorContainer(new XmlInterpreter());
- new SimpleBootStrapper(windsorContainer).InitializeContainer();
- var handler = windsorContainer.Kernel.GetHandler(typeof(TestRemoteHandler).FullName);
- Assert.NotNull(handler);
- }
-
- [Fact]
- public void And_accept_messages_from_there()
- {
- host.Start();
-
- using (var bus = container.Resolve<IStartableServiceBus>())
- {
- bus.Start();
-
- using (bus.AddInstanceSubscription(this))
- {
- bus.Send(new Uri("msmq://localhost/test_queue").ToEndpoint(), new StringMsg
- {
- Value = "hello"
- });
-
- Assert.True(resetEvent.WaitOne(TimeSpan.FromSeconds(10), false));
-
- Assert.Equal("olleh", reply);
- }
- }
- }
-
- public override void Dispose()
- {
- base.Dispose();
- host.Close();
- }
-
- public void Consume(StringMsg message)
- {
- reply = message.Value;
- resetEvent.Set();
- }
- }
-
- public class SimpleBootStrapper : CastleBootStrapper
- {
- public BusConfigurationSection ConfigurationSectionInUse {get ; private set;}
-
- public SimpleBootStrapper(IWindsorContainer container) : base(container)
- {
-
- }
-
- protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)
- {
- ConfigurationSectionInUse = configuration.ConfigurationSection;
- }
- }
-
- public class TestBootStrapper : CastleBootStrapper
- {
- protected override void ConfigureContainer()
- {
- Container.Register(Component.For<TestRemoteHandler>());
- }
- }
-
- public class TestRemoteHandler : ConsumerOf<StringMsg>
- {
- private readonly IServiceBus bus;
-
- public TestRemoteHandler(IServiceBus bus)
- {
- this.bus = bus;
- }
-
- public void Consume(StringMsg message)
- {
- bus.Reply(new StringMsg
- {
- Value = new String(message.Value.Reverse().ToArray())
- });
- }
- }
-
- public class StringMsg
- {
- public string Value { get; set; }
- }
+using System;
+using System.IO;
+using System.Threading;
+using Castle.MicroKernel.Registration;
+using Castle.Windsor;
+using Castle.Windsor.Configuration.Interpreters;
+using Rhino.ServiceBus.Config;
+using Rhino.ServiceBus.Castle;
+using Rhino.ServiceBus.Hosting;
+using Rhino.ServiceBus.Impl;
+using Xunit;
+using System.Linq;
+
+namespace Rhino.ServiceBus.Tests.Hosting
+{
+ public class Can_host_in_another_app_domain : MsmqTestBase, OccasionalConsumerOf<StringMsg>
+ {
+ readonly RemoteAppDomainHost host = new RemoteAppDomainHost(
+ Path.Combine(Environment.CurrentDirectory, "Rhino.ServiceBus.Tests.dll"), typeof(TestBootStrapper));
+ private string reply;
+
+ private readonly ManualResetEvent resetEvent = new ManualResetEvent(false);
+
+ private readonly IWindsorContainer container;
+
+ public Can_host_in_another_app_domain()
+ {
+ container = new WindsorContainer();
+ new RhinoServiceBusConfiguration()
+ .UseCastleWindsor(container)
+ .UseStandaloneConfigurationFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AnotherBus.config"))
+ .Configure();
+ }
+
+ [Fact]
+ public void Can_use_different_config_correctly()
+ {
+ var windsorContainer = new WindsorContainer();
+ var bootStrapper = new SimpleBootStrapper(windsorContainer);
+ var differentConfig = new BusConfigurationSection();
+ bootStrapper.UseConfiguration(differentConfig);
+ bootStrapper.InitializeContainer();
+ Assert.Equal(differentConfig, bootStrapper.ConfigurationSectionInUse);
+ }
+
+ [Fact]
+ public void Components_are_registered_using_their_full_name()
+ {
+ var windsorContainer = new WindsorContainer(new XmlInterpreter());
+ new SimpleBootStrapper(windsorContainer).InitializeContainer();
+ var handler = windsorContainer.Kernel.GetHandler(typeof(TestRemoteHandler).FullName);
+ Assert.NotNull(handler);
+ }
+
+ [Fact]
+ public void And_accept_messages_from_there()
+ {
+ host.Start();
+
+ using (var bus = container.Resolve<IStartableServiceBus>())
+ {
+ bus.Start();
+
+ using (bus.AddInstanceSubscription(this))
+ {
+ bus.Send(new Uri("msmq://localhost/test_queue").ToEndpoint(), new StringMsg
+ {
+ Value = "hello"
+ });
+
+ Assert.True(resetEvent.WaitOne(TimeSpan.FromSeconds(10), false));
+
+ Assert.Equal("olleh", reply);
+ }
+ }
+ }
+
+ public override void Dispose()
+ {
+ base.Dispose();
+ host.Close();
+ }
+
+ public void Consume(StringMsg message)
+ {
+ reply = message.Value;
+ resetEvent.Set();
+ }
+ }
+
+ public class SimpleBootStrapper : CastleBootStrapper
+ {
+ public BusConfigurationSection ConfigurationSectionInUse {get ; private set;}
+
+ public SimpleBootStrapper(IWindsorContainer container) : base(container)
+ {
+
+ }
+
+ protected override void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)
+ {
+ ConfigurationSectionInUse = configuration.ConfigurationSection;
+ }
+ }
+
+ public class TestBootStrapper : CastleBootStrapper
+ {
+ protected override void ConfigureContainer()
+ {
+ Container.Register(Component.For<TestRemoteHandler>());
+ }
+ }
+
+ public class TestRemoteHandler : ConsumerOf<StringMsg>
+ {
+ private readonly IServiceBus bus;
+
+ public TestRemoteHandler(IServiceBus bus)
+ {
+ this.bus = bus;
+ }
+
+ public void Consume(StringMsg message)
+ {
+ bus.Reply(new StringMsg
+ {
+ Value = new String(message.Value.Reverse().ToArray())
+ });
+ }
+ }
+
+ public class StringMsg
+ {
+ public string Value { get; set; }
+ }
}
View
52 Rhino.ServiceBus/Endpoint.cs
@@ -1,27 +1,27 @@
-using System;
-using Rhino.ServiceBus.Util;
-
-namespace Rhino.ServiceBus
-{
- public class Endpoint
- {
- private Uri uri;
-
- public bool? Transactional;
-
- public Uri Uri
- {
- get { return uri; }
- set
- {
- if (uri == null) throw new ArgumentNullException();
- uri = value.NormalizeLocalhost();
- }
- }
-
- public override string ToString()
- {
- return string.Format("Uri: {0}", Uri);
- }
- }
+using System;
+using Rhino.ServiceBus.Util;
+
+namespace Rhino.ServiceBus
+{
+ public class Endpoint
+ {
+ private Uri uri;
+
+ public bool? Transactional;
+
+ public Uri Uri
+ {
+ get { return uri; }
+ set
+ {
+ if (value == null) throw new ArgumentNullException();
+ uri = value.NormalizeLocalhost();
+ }
+ }
+
+ public override string ToString()
+ {
+ return string.Format("Uri: {0}", Uri);
+ }
+ }
}
View
150 Rhino.ServiceBus/Hosting/AbstractBootStrapper.cs
@@ -1,76 +1,76 @@
-using System;
-using System.Reflection;
-using Rhino.ServiceBus.Config;
-using Rhino.ServiceBus.Impl;
-using System.Collections.Generic;
-
-namespace Rhino.ServiceBus.Hosting
-{
- public abstract class AbstractBootStrapper : IDisposable
- {
- private AbstractRhinoServiceBusConfiguration config;
- private BusConfigurationSection busSection;
-
- public virtual IEnumerable<Assembly> Assemblies
- {
- get { yield return GetType().Assembly; }
- }
-
- public virtual void InitializeContainer()
- {
- config = CreateConfiguration();
- CreateContainer();
- ConfigureBusFacility(config);
- }
-
- public virtual void UseConfiguration(BusConfigurationSection configurationSection)
- {
- busSection = configurationSection;
- }
-
- public abstract void CreateContainer();
-
- public abstract void ExecuteDeploymentActions(string user);
-
- public abstract void ExecuteEnvironmentValidationActions();
-
- public abstract T GetInstance<T>();
-
- protected virtual bool IsTypeAcceptableForThisBootStrapper(Type t)
- {
- return true;
- }
-
- protected virtual AbstractRhinoServiceBusConfiguration CreateConfiguration()
- {
- var cfg = new RhinoServiceBusConfiguration();
- if (busSection!=null) config.UseConfiguration(configurationSection);
- return cfg;
- }
-
- protected virtual void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)
- {
- }
-
- protected virtual void OnBeginStart()
- {
- }
-
- public void BeginStart()
- {
- OnBeginStart();
- config.Configure();
- }
-
- public void EndStart()
- {
- OnEndStart();
- }
-
- protected virtual void OnEndStart()
- {
- }
-
- public abstract void Dispose();
- }
+using System;
+using System.Reflection;
+using Rhino.ServiceBus.Config;
+using Rhino.ServiceBus.Impl;
+using System.Collections.Generic;
+
+namespace Rhino.ServiceBus.Hosting
+{
+ public abstract class AbstractBootStrapper : IDisposable
+ {
+ private AbstractRhinoServiceBusConfiguration config;
+ private BusConfigurationSection busSection;
+
+ public virtual IEnumerable<Assembly> Assemblies
+ {
+ get { yield return GetType().Assembly; }
+ }
+
+ public virtual void InitializeContainer()
+ {
+ config = CreateConfiguration();
+ CreateContainer();
+ ConfigureBusFacility(config);
+ }
+
+ public virtual void UseConfiguration(BusConfigurationSection configurationSection)
+ {
+ busSection = configurationSection;
+ }
+
+ public abstract void CreateContainer();
+
+ public abstract void ExecuteDeploymentActions(string user);
+
+ public abstract void ExecuteEnvironmentValidationActions();
+
+ public abstract T GetInstance<T>();
+
+ protected virtual bool IsTypeAcceptableForThisBootStrapper(Type t)
+ {
+ return true;
+ }
+
+ protected virtual AbstractRhinoServiceBusConfiguration CreateConfiguration()
+ {
+ var cfg = new RhinoServiceBusConfiguration();
+ if (busSection!=null) cfg.UseConfiguration(busSection);
+ return cfg;
+ }
+
+ protected virtual void ConfigureBusFacility(AbstractRhinoServiceBusConfiguration configuration)
+ {
+ }
+
+ protected virtual void OnBeginStart()
+ {
+ }
+
+ public void BeginStart()
+ {
+ OnBeginStart();
+ config.Configure();
+ }
+
+ public void EndStart()
+ {
+ OnEndStart();
+ }
+
+ protected virtual void OnEndStart()
+ {
+ }
+
+ public abstract void Dispose();
+ }
}
View
59 Rhino.ServiceBus/Impl/EndpointRouter.cs
@@ -1,30 +1,31 @@
-using System;
-using Rhino.ServiceBus.DataStructures;
-using Rhino.ServiceBus.Internal;
-
-namespace Rhino.ServiceBus.Impl
-{
- public class EndpointRouter : IEndpointRouter
- {
- private readonly Hashtable<Uri, Uri> mapping = new Hashtable<Uri, Uri>();
-
- public void Init()
- {
- }
-
- public void RemapEndpoint(Uri originalEndpoint, Uri newEndpoint)
- {
- mapping.Write(writer => writer.Add(originalEndpoint.NormalizeLocalhost(), newEndpoint.NormalizeLocalhost()));
- }
-
- public Endpoint GetRoutedEndpoint(Uri endpoint)
- {
- Uri newEndpoint = null;
- mapping.Read(reader => reader.TryGetValue(endpoint.NormalizeLocalhost(), out newEndpoint));
- return new Endpoint
- {
- Uri = newEndpoint ?? endpoint
- };
- }
- }
+using System;
+using Rhino.ServiceBus.DataStructures;
+using Rhino.ServiceBus.Internal;
+using Rhino.ServiceBus.Util;
+
+namespace Rhino.ServiceBus.Impl
+{
+ public class EndpointRouter : IEndpointRouter
+ {
+ private readonly Hashtable<Uri, Uri> mapping = new Hashtable<Uri, Uri>();
+
+ public void Init()
+ {
+ }
+
+ public void RemapEndpoint(Uri originalEndpoint, Uri newEndpoint)
+ {
+ mapping.Write(writer => writer.Add(originalEndpoint.NormalizeLocalhost(), newEndpoint.NormalizeLocalhost()));
+ }
+
+ public Endpoint GetRoutedEndpoint(Uri endpoint)
+ {
+ Uri newEndpoint = null;
+ mapping.Read(reader => reader.TryGetValue(endpoint.NormalizeLocalhost(), out newEndpoint));
+ return new Endpoint
+ {
+ Uri = newEndpoint ?? endpoint
+ };
+ }
+ }
}
View
69 Rhino.ServiceBus/Util/UriExtensions.cs
@@ -1,35 +1,36 @@
-using System;
-using Rhino.ServiceBus.Transport;
-using System.Linq;
-
-namespace Rhino.ServiceBus.Util
-{
- public static class UriExtensions
- {
- public static Uri AddSubQueue(this Uri self, SubQueue subQueue)
- {
- Uri subQueueUrl;
- if (self.AbsolutePath.EndsWith("/"))
- subQueueUrl = new Uri(self + SubQueue.Discarded.ToString());
- else
- subQueueUrl = new Uri(self + "/" + SubQueue.Discarded);
- return subQueueUrl;
- }
-
- public static string GetQueueName(this Uri self)
- {
- return self.AbsolutePath.Substring(1).Split('/').First();
- }
-
- private static HashSet<string> localhosts = new HashSet<string>(new[]{"localhost","127.0.0.1"}, StringComparer.OrdinalIgnoreCase);
-
- public static Uri NormalizeLocalhost(this Uri uri)
- {
- if (localHosts.Contains(uri.Host))
- {
- return new UriBuilder(uri){ Host = Environment.MachineName }.Uri;
- }
- return uri;
- }
- }
+using System;
+using Rhino.ServiceBus.Transport;
+using System.Linq;
+using System.Collections.Generic;
+
+namespace Rhino.ServiceBus.Util
+{
+ public static class UriExtensions
+ {
+ public static Uri AddSubQueue(this Uri self, SubQueue subQueue)
+ {
+ Uri subQueueUrl;
+ if (self.AbsolutePath.EndsWith("/"))
+ subQueueUrl = new Uri(self + SubQueue.Discarded.ToString());
+ else
+ subQueueUrl = new Uri(self + "/" + SubQueue.Discarded);
+ return subQueueUrl;
+ }
+
+ public static string GetQueueName(this Uri self)
+ {
+ return self.AbsolutePath.Substring(1).Split('/').First();
+ }
+
+ private static HashSet<string> localhosts = new HashSet<string>(new[]{"localhost","127.0.0.1"}, StringComparer.OrdinalIgnoreCase);
+
+ public static Uri NormalizeLocalhost(this Uri uri)
+ {
+ if (localhosts.Contains(uri.Host))
+ {
+ return new UriBuilder(uri){ Host = Environment.MachineName }.Uri;
+ }
+ return uri;
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.