Skip to content

Commit

Permalink
remove commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
Christine Zhou committed Aug 14, 2024
1 parent 1d95c31 commit f67b723
Show file tree
Hide file tree
Showing 16 changed files with 887 additions and 1,411 deletions.
993 changes: 0 additions & 993 deletions Src/PChecker/CheckerCore/Actors/Actor.cs

This file was deleted.

12 changes: 6 additions & 6 deletions Src/PChecker/CheckerCore/Actors/ActorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ internal static class ActorFactory
/// <summary>
/// Cache storing actors constructors.
/// </summary>
private static readonly Dictionary<Type, Func<Actor>> ActorConstructorCache =
new Dictionary<Type, Func<Actor>>();
private static readonly Dictionary<Type, Func<StateMachine>> ActorConstructorCache =
new Dictionary<Type, Func<StateMachine>>();

/// <summary>
/// Creates a new <see cref="Actor"/> instance of the specified type.
/// Creates a new <see cref="StateMachine"/> instance of the specified type.
/// </summary>
/// <param name="type">The type of the actors.</param>
/// <returns>The created actor instance.</returns>
public static Actor Create(Type type)
public static StateMachine Create(Type type)
{
Func<Actor> constructor = null;
Func<StateMachine> constructor = null;
lock (ActorConstructorCache)
{
if (!ActorConstructorCache.TryGetValue(type, out constructor))
Expand All @@ -36,7 +36,7 @@ public static Actor Create(Type type)
throw new Exception("Could not find empty constructor for type " + type.FullName);
}

constructor = Expression.Lambda<Func<Actor>>(
constructor = Expression.Lambda<Func<StateMachine>>(
Expression.New(constructorInfo)).Compile();
ActorConstructorCache.Add(type, constructor);
}
Expand Down
99 changes: 39 additions & 60 deletions Src/PChecker/CheckerCore/Actors/ActorRuntime.cs

Large diffs are not rendered by default.

40 changes: 19 additions & 21 deletions Src/PChecker/CheckerCore/Actors/EventQueues/EventQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ internal sealed class EventQueue : IEventQueue
/// <summary>
/// Manages the actor that owns this queue.
/// </summary>
private readonly IActorManager ActorManager;
private readonly IStateMachineManager StateMachineManager;

/// <summary>
/// The actor that owns this queue.
/// </summary>
private readonly Actor Actor;
private readonly StateMachine Actor;

/// <summary>
/// The internal queue that contains events with their metadata.
Expand Down Expand Up @@ -66,9 +66,9 @@ internal sealed class EventQueue : IEventQueue
/// <summary>
/// Initializes a new instance of the <see cref="EventQueue"/> class.
/// </summary>
internal EventQueue(IActorManager actorManager, Actor actor)
internal EventQueue(IStateMachineManager stateMachineManager, StateMachine actor)
{
ActorManager = actorManager;
StateMachineManager = stateMachineManager;
Actor = actor;
Queue = new LinkedList<(Event, Guid, EventInfo)>();
EventWaitTypes = new Dictionary<Type, Func<Event, bool>>();
Expand All @@ -87,23 +87,23 @@ public EnqueueStatus Enqueue(Event e, Guid opGroupId, EventInfo info)
(predicate is null || predicate(e)))
{
EventWaitTypes.Clear();
ActorManager.OnReceiveEvent(e, opGroupId, info);
StateMachineManager.OnReceiveEvent(e, opGroupId, info);
ReceiveCompletionSource.SetResult(e);
return EnqueueStatus.EventHandlerRunning;
}

ActorManager.OnEnqueueEvent(e, opGroupId, info);
StateMachineManager.OnEnqueueEvent(e, opGroupId, info);
Queue.AddLast((e, opGroupId, info));

if (!ActorManager.IsEventHandlerRunning)
if (!StateMachineManager.IsEventHandlerRunning)
{
if (TryDequeueEvent(true).e is null)
{
return EnqueueStatus.NextEventUnavailable;
}
else
{
ActorManager.IsEventHandlerRunning = true;
StateMachineManager.IsEventHandlerRunning = true;
return EnqueueStatus.EventHandlerNotRunning;
}
}
Expand All @@ -118,7 +118,7 @@ public EnqueueStatus Enqueue(Event e, Guid opGroupId, EventInfo info)
// have priority over the events in the inbox.
if (RaisedEvent != default)
{
if (ActorManager.IsEventIgnored(RaisedEvent.e, RaisedEvent.opGroupId, RaisedEvent.info))
if (StateMachineManager.IsEventIgnored(RaisedEvent.e, RaisedEvent.opGroupId, RaisedEvent.info))
{
// TODO: should the user be able to raise an ignored event?
// The raised event is ignored in the current state.
Expand All @@ -132,7 +132,7 @@ public EnqueueStatus Enqueue(Event e, Guid opGroupId, EventInfo info)
}
}

var hasDefaultHandler = ActorManager.IsDefaultHandlerAvailable();
var hasDefaultHandler = StateMachineManager.IsDefaultHandlerAvailable();
if (hasDefaultHandler)
{
Actor.Runtime.NotifyDefaultEventHandlerCheck(Actor);
Expand All @@ -150,14 +150,13 @@ public EnqueueStatus Enqueue(Event e, Guid opGroupId, EventInfo info)
if (!hasDefaultHandler)
{
// There is no default event handler installed, so do not return an event.
ActorManager.IsEventHandlerRunning = false;
StateMachineManager.IsEventHandlerRunning = false;
return (DequeueStatus.NotAvailable, null, Guid.Empty, null);
}

// TODO: check op-id of default event.
// A default event handler exists.
var stateName = Actor is StateMachine stateMachine ?
NameResolver.GetStateNameForLogging(stateMachine.CurrentState.GetType()) : string.Empty;
var stateName = NameResolver.GetStateNameForLogging(Actor.CurrentState.GetType());
var eventOrigin = new EventOriginInfo(Actor.Id, Actor.GetType().FullName, stateName);
return (DequeueStatus.Default, DefaultEvent.Instance, Guid.Empty, new EventInfo(DefaultEvent.Instance, eventOrigin));
}
Expand All @@ -176,7 +175,7 @@ public EnqueueStatus Enqueue(Event e, Guid opGroupId, EventInfo info)
var nextNode = node.Next;
var currentEvent = node.Value;

if (ActorManager.IsEventIgnored(currentEvent.e, currentEvent.opGroupId, currentEvent.info))
if (StateMachineManager.IsEventIgnored(currentEvent.e, currentEvent.opGroupId, currentEvent.info))
{
if (!checkOnly)
{
Expand All @@ -189,7 +188,7 @@ public EnqueueStatus Enqueue(Event e, Guid opGroupId, EventInfo info)
}

// Skips a deferred event.
if (!ActorManager.IsEventDeferred(currentEvent.e, currentEvent.opGroupId, currentEvent.info))
if (!StateMachineManager.IsEventDeferred(currentEvent.e, currentEvent.opGroupId, currentEvent.info))
{
nextAvailableEvent = currentEvent;
if (!checkOnly)
Expand All @@ -209,12 +208,11 @@ public EnqueueStatus Enqueue(Event e, Guid opGroupId, EventInfo info)
/// <inheritdoc/>
public void RaiseEvent(Event e, Guid opGroupId)
{
var stateName = Actor is StateMachine stateMachine ?
NameResolver.GetStateNameForLogging(stateMachine.CurrentState.GetType()) : string.Empty;
var stateName = NameResolver.GetStateNameForLogging(Actor.CurrentState.GetType());
var eventOrigin = new EventOriginInfo(Actor.Id, Actor.GetType().FullName, stateName);
var info = new EventInfo(e, eventOrigin);
RaisedEvent = (e, opGroupId, info);
ActorManager.OnRaiseEvent(e, opGroupId, info);
StateMachineManager.OnRaiseEvent(e, opGroupId, info);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -279,11 +277,11 @@ private Task<Event> ReceiveEventAsync(Dictionary<Type, Func<Event, bool>> eventW
{
ReceiveCompletionSource = new TaskCompletionSource<Event>();
EventWaitTypes = eventWaitTypes;
ActorManager.OnWaitEvent(EventWaitTypes.Keys);
StateMachineManager.OnWaitEvent(EventWaitTypes.Keys);
return ReceiveCompletionSource.Task;
}

ActorManager.OnReceiveEventWithoutWaiting(receivedEvent.e, receivedEvent.opGroupId, receivedEvent.info);
StateMachineManager.OnReceiveEventWithoutWaiting(receivedEvent.e, receivedEvent.opGroupId, receivedEvent.info);
return Task.FromResult(receivedEvent.e);
}

Expand Down Expand Up @@ -320,7 +318,7 @@ private void Dispose(bool disposing)

foreach (var (e, opGroupId, info) in Queue)
{
ActorManager.OnDropEvent(e, opGroupId, info);
StateMachineManager.OnDropEvent(e, opGroupId, info);
}

Queue.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace PChecker.Actors.Exceptions
{
/// <summary>
/// Exception that is thrown by the runtime upon an <see cref="Actor"/> action failure.
/// Exception that is thrown by the runtime upon an <see cref="StateMachine"/> action failure.
/// </summary>
internal sealed class ActionExceptionFilterException : RuntimeException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace PChecker.Actors.Exceptions
{
/// <summary>
/// The outcome when an <see cref="Actor"/> throws an exception.
/// The outcome when an <see cref="StateMachine"/> throws an exception.
/// </summary>
public enum OnExceptionOutcome
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace PChecker.Actors.Exceptions
{
/// <summary>
/// Signals that an <see cref="Actor"/> received an unhandled event.
/// Signals that an <see cref="StateMachine"/> received an unhandled event.
/// </summary>
public sealed class UnhandledEventException : RuntimeException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public virtual void OnPopState(ActorId id, string currentStateName, string resto
/// <inheritdoc/>
public virtual void OnPopStateUnhandledEvent(ActorId id, string stateName, Event e)
{
var eventName = e.GetType().FullName;
var eventName = e.GetType().Name;
var text = $"<PopLog> {id} popped state {stateName} due to unhandled event '{eventName}'.";
Logger.WriteLine(text);
}
Expand Down
2 changes: 1 addition & 1 deletion Src/PChecker/CheckerCore/Actors/Logging/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class VectorClockGenerator
{
/// <summary>
/// Nested class for handling FIFO send receive requests.
/// NOTE: In the case of sending to a the same machine with the same event and same payload.
/// NOTE: In the case of sending to the same machine with the same event and same payload.
/// </summary>
private class FifoSendReceiveMapping
{
Expand Down
151 changes: 0 additions & 151 deletions Src/PChecker/CheckerCore/Actors/Managers/ActorManager.cs

This file was deleted.

Loading

0 comments on commit f67b723

Please sign in to comment.