إعادة دخول Reliable Actors

يسمح وقت تشغيل Reliable Actors، افتراضياً، بإعادة الدخول المنطقية المستندة إلى سياق الاستدعاء. يسمح هذا للمستخدمين بإعادة الدخول إذا كانوا في نفس سلسلة سياق الاستدعاء. على سبيل المثال، يرسل المستخدم "أ" رسالة إلى المستخدم "ب"، الذي يرسل رسالة إلى المستخدم "ج". وإذا اتصل المستخدم "ج" بالمستخدم "أ" كجزء من معالجة الرسالة، تتم إعادة إرسال الرسالة، لذلك سيتم السماح بها. سيتم منع أي رسائل أخرى تكون جزءاً من سياق استدعاء مختلف على المستخدم "أ" حتى تنتهي المعالجة.

يوجد خياران متاحان لإعادة دخول المستخدمين المحددين في قائمة تعداد ActorReentrancyMode:

  • LogicalCallContext (السلوك الافتراضي)
  • Disallowed - تعطيل إعادة الدخول
public enum ActorReentrancyMode
{
    LogicalCallContext = 1,
    Disallowed = 2
}
public enum ActorReentrancyMode
{
    LogicalCallContext(1),
    Disallowed(2)
}

يمكن تكوين إعادة الدخول في إعدادات ActorService أثناء التسجيل. ينطبق الإعداد على جميع مثيلات المستخدم التي تم إنشاؤها في خدمة المستخدم.

يوضح المثال التالي خدمة المستخدم التي تعين وضع إعادة الدخول إلى ActorReentrancyMode.Disallowed. في هذه الحالة، إذا أرسل أحد المستخدمين رسالة إعادة دخول إلى مستخدم آخر، فسيتم طرح استثناء من النوع FabricException.

static class Program
{
    static void Main()
    {
        try
        {
            ActorRuntime.RegisterActorAsync<Actor1>(
                (context, actorType) => new ActorService(
                    context,
                    actorType, () => new Actor1(),
                    settings: new ActorServiceSettings()
                    {
                        ActorConcurrencySettings = new ActorConcurrencySettings()
                        {
                            ReentrancyMode = ActorReentrancyMode.Disallowed
                        }
                    }))
                .GetAwaiter().GetResult();

            Thread.Sleep(Timeout.Infinite);
        }
        catch (Exception e)
        {
            ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
            throw;
        }
    }
}
static class Program
{
    static void Main()
    {
        try
        {
            ActorConcurrencySettings actorConcurrencySettings = new ActorConcurrencySettings();
            actorConcurrencySettings.setReentrancyMode(ActorReentrancyMode.Disallowed);

            ActorServiceSettings actorServiceSettings = new ActorServiceSettings();
            actorServiceSettings.setActorConcurrencySettings(actorConcurrencySettings);

            ActorRuntime.registerActorAsync(
                Actor1.getClass(),
                (context, actorType) -> new FabricActorService(
                    context,
                    actorType, () -> new Actor1(),
                    null,
                    stateProvider,
                    actorServiceSettings, timeout);

            Thread.sleep(Long.MAX_VALUE);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
}

الخطوات التالية