Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for POCO grains #7360

Merged
merged 1 commit into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Orleans.Analyzers/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
Rule ID | Category | Severity | Notes
--------|----------|----------|--------------------
ORLEANS0001 | Usage | Error | [AlwaysInterleave] must only be used on the grain interface method and not the grain class method
ORLEANS0002 | Usage | Error | Reference parameter modifiers are not allowed
ORLEANS0003 | Usage | Warning | Non-abstract classes that implement IGrain should derive from the base class Orleans.Grain
ORLEANS0002 | Usage | Error | Reference parameter modifiers are not allowed
75 changes: 0 additions & 75 deletions src/Orleans.Analyzers/InheritFromGrainBaseAnalyzer.cs

This file was deleted.

70 changes: 0 additions & 70 deletions src/Orleans.Analyzers/InheritFromGrainBaseCodeFixProvider.cs

This file was deleted.

7 changes: 1 addition & 6 deletions src/Orleans.Core.Abstractions/Activation/IGrainContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IGrainContext : ITargetHolder, IEquatable<IGrainContext>

/// <summary>Gets the instance of the grain associated with this activation context.
/// The value will be <see langword="null"/> if the grain is being created.</summary>
IAddressable GrainInstance { get; }
object GrainInstance { get; }

/// <summary>
/// Gets the activation id.
Expand Down Expand Up @@ -101,11 +101,6 @@ internal interface ICollectibleGrainContext : IGrainContext
void DelayDeactivation(TimeSpan timeSpan);
}

internal interface IActivationData : ICollectibleGrainContext
{
IGrainRuntime GrainRuntime { get; }
}

internal interface IGrainTimerRegistry
{
void OnTimerCreated(IGrainTimer timer);
Expand Down
37 changes: 0 additions & 37 deletions src/Orleans.Core.Abstractions/CodeGeneration/GrainFactoryBase.cs

This file was deleted.

22 changes: 10 additions & 12 deletions src/Orleans.Core.Abstractions/Core/Grain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ namespace Orleans
/// </summary>
public abstract class Grain : IGrainBase, IAddressable
{
private readonly IGrainContext _grainContext;

// Do not use this directly because we currently don't provide a way to inject it;
// any interaction with it will result in non unit-testable code. Any behaviour that can be accessed
// from within client code (including subclasses of this class), should be exposed through IGrainRuntime.
// The better solution is to refactor this interface and make it injectable through the constructor.
internal IActivationData Data => _grainContext as IActivationData;
internal IGrainContext GrainContext { get; private set; }

IGrainContext IGrainBase.GrainContext => _grainContext;
IGrainContext IGrainBase.GrainContext => GrainContext;

public GrainReference GrainReference { get { return _grainContext.GrainReference; } }
public GrainReference GrainReference { get { return GrainContext.GrainReference; } }

internal IGrainRuntime Runtime { get; }

Expand All @@ -41,10 +39,10 @@ protected IGrainFactory GrainFactory
/// </summary>
protected internal IServiceProvider ServiceProvider
{
get { return _grainContext?.ActivationServices ?? Runtime?.ServiceProvider; }
get { return GrainContext?.ActivationServices ?? Runtime?.ServiceProvider; }
}

internal GrainId GrainId => _grainContext.GrainId;
internal GrainId GrainId => GrainContext.GrainId;

/// <summary>
/// This constructor should never be invoked. We expose it so that client code (subclasses of Grain) do not have to add a constructor.
Expand All @@ -61,7 +59,7 @@ protected Grain() : this(RuntimeContext.Current, grainRuntime: null)
/// </summary>
protected Grain(IGrainContext grainContext, IGrainRuntime grainRuntime = null)
{
_grainContext = grainContext;
GrainContext = grainContext;
Runtime = grainRuntime ?? grainContext?.ActivationServices.GetRequiredService<IGrainRuntime>();
}

Expand Down Expand Up @@ -113,7 +111,7 @@ protected IDisposable RegisterTimer(Func<object, Task> asyncCallback, object sta
throw new ArgumentNullException(nameof(asyncCallback));

EnsureRuntime();
return Runtime.TimerRegistry.RegisterTimer(_grainContext ?? RuntimeContext.Current, asyncCallback, state, dueTime, period);
return Runtime.TimerRegistry.RegisterTimer(GrainContext ?? RuntimeContext.Current, asyncCallback, state, dueTime, period);
}

/// <summary>
Expand Down Expand Up @@ -184,7 +182,7 @@ protected Task<List<IGrainReminder>> GetReminders()
protected void DeactivateOnIdle()
{
EnsureRuntime();
Runtime.DeactivateOnIdle(_grainContext ?? RuntimeContext.Current);
Runtime.DeactivateOnIdle(GrainContext ?? RuntimeContext.Current);
}

/// <summary>
Expand All @@ -197,7 +195,7 @@ protected void DeactivateOnIdle()
protected void DelayDeactivation(TimeSpan timeSpan)
{
EnsureRuntime();
Runtime.DelayDeactivation(_grainContext ?? RuntimeContext.Current, timeSpan);
Runtime.DelayDeactivation(GrainContext ?? RuntimeContext.Current, timeSpan);
}

/// <summary>
Expand Down Expand Up @@ -287,7 +285,7 @@ private Task OnSetupState(CancellationToken ct)
{
if (ct.IsCancellationRequested)
return Task.CompletedTask;
this.storage = this.Runtime.GetStorage<TGrainState>(Data);
this.storage = this.Runtime.GetStorage<TGrainState>(GrainContext);
return this.ReadStateAsync();
}
}
Expand Down
Loading