Skip to content

Commit

Permalink
added some cross-thread locks
Browse files Browse the repository at this point in the history
  • Loading branch information
beneidel committed May 3, 2013
1 parent a510bf8 commit e745aeb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.16.0")]
[assembly: AssemblyFileVersion("1.0.16.0")]
[assembly: AssemblyVersion("1.0.18.0")]
[assembly: AssemblyFileVersion("1.0.18.0")]
19 changes: 13 additions & 6 deletions Roque.Core/EventProxyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class EventInterceptor : IInterceptor
{
public IDictionary<string, IList<Delegate>> EventDelegates = new Dictionary<string, IList<Delegate>>();
public IDictionary<string, int> EventDelegatesCounts = new Dictionary<string, int>();
private object _syncRoot = new object();

public void Intercept(IInvocation invocation)
{
Expand Down Expand Up @@ -97,10 +98,13 @@ public void Intercept(IInvocation invocation)
if (evenInfo != null)
{
IList<Delegate> delegates;
if (!EventDelegates.TryGetValue(eventName, out delegates))
lock (_syncRoot)
{
delegates = new List<Delegate>();
EventDelegates[eventName] = delegates;
if (!EventDelegates.TryGetValue(eventName, out delegates))
{
delegates = new List<Delegate>();
EventDelegates[eventName] = delegates;
}
}
delegates.Add((Delegate)invocation.Arguments[0]);
return;
Expand All @@ -113,10 +117,13 @@ public void Intercept(IInvocation invocation)
if (evenInfo != null)
{
IList<Delegate> delegates;
if (!EventDelegates.TryGetValue(eventName, out delegates))
lock (_syncRoot)
{
delegates = new List<Delegate>();
EventDelegates[eventName] = delegates;
if (!EventDelegates.TryGetValue(eventName, out delegates))
{
delegates = new List<Delegate>();
EventDelegates[eventName] = delegates;
}
}
delegates.Remove((Delegate)invocation.Arguments[0]);
return;
Expand Down
24 changes: 15 additions & 9 deletions Roque.Core/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ public void Raise(string eventName, params string[] parameters)
}
}

private IDictionary<string, Target> _Targets = new Dictionary<string, Target>();
private object _syncRoot = new object();

private readonly IDictionary<string, Target> _Targets = new Dictionary<string, Target>();

private static Executor _Instance;

Expand Down Expand Up @@ -311,17 +313,19 @@ private void InvokeTarget(Job job)
private Target GetTarget(string targetTypeName, bool ifNotFoundUseEventProxy = false)
{
Target target;
string fullName = targetTypeName.Split(new[] { ',', ' ' }).First();
if (!_Targets.TryGetValue(fullName, out target))
var fullName = targetTypeName.Split(new[] { ',', ' ' }).First();
lock (_syncRoot)
{
Type type = null;
type = Type.GetType(targetTypeName);
if (type == null)
if (!_Targets.TryGetValue(fullName, out target))
{
throw new ShouldRetryException(TimeSpan.FromSeconds(10), 0, new Exception("Type not found: " + targetTypeName));
var type = Type.GetType(targetTypeName);
if (type == null)
{
throw new ShouldRetryException(TimeSpan.FromSeconds(10), 0, new Exception("Type not found: " + targetTypeName));
}
target = new Target(type, ifNotFoundUseEventProxy);
_Targets[fullName] = target;
}
target = new Target(type, ifNotFoundUseEventProxy);
_Targets[fullName] = target;
}
return target;
}
Expand All @@ -348,6 +352,7 @@ public void RegisterSubscriber(object subscriber, string sourceQueue = null, str
{
RoqueTrace.Source.Trace(TraceEventType.Error, "Error injecting subscriber parameter: {0}. Method: {1}, Parameter: {2}, Expected Type: {3}",
ex.Message, suscribeMethod.Name, paramInfo.Name, paramInfo.ParameterType.FullName, ex);
RoqueTrace.Source.Trace(TraceEventType.Error, "Error details: {0}", ex.ToString());
throw;
}
}
Expand Down Expand Up @@ -400,6 +405,7 @@ public void RegisterSubscribersForWorker(Worker worker)
{
RoqueTrace.Source.Trace(TraceEventType.Error, "Error registering subscriber: {0}. Type: {1}",
ex.Message, subscriberConfig.SubscriberType, ex);
RoqueTrace.Source.Trace(TraceEventType.Error, "Error details: {0}", ex.ToString());
throw;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Roque.Worker.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Roque.Worker</id>
<version>1.0.16</version>
<version>1.0.18</version>
<authors>benjamineidelman@blogtalkradio.com</authors>
<owners>benjamineidelman@blogtalkradio.com</owners>
<licenseUrl>https://raw.github.com/benjamine/Roque/master/MIT-LICENSE.txt</licenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion Roque.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Roque</id>
<version>1.0.16</version>
<version>1.0.18</version>
<authors>benjamineidelman@blogtalkradio.com</authors>
<owners>benjamineidelman@blogtalkradio.com</owners>
<licenseUrl>https://raw.github.com/benjamine/Roque/master/MIT-LICENSE.txt</licenseUrl>
Expand Down

0 comments on commit e745aeb

Please sign in to comment.