Пример #1
0
        async Task Activate(ActorPath path)
        {
            var system = ClusterActorSystem.Current;

            var runtime = new ActorRuntime(system, this);
            var prototype = ActorPrototype.Of(path.Type);

            actor = Activator.Activate(path.Type, path.Id, runtime);
            actor.Initialize(path.Id, runtime, prototype);

            await actor.OnActivate();
        }
Пример #2
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                //Creating a new event listener to redirect the traces to a file
                ActorEventListener listener = new ActorEventListener("CounterActorApplication");
                listener.EnableEvents(ActorEventSource.Current, EventLevel.LogAlways, EventKeywords.All);

                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                ActorRuntime.RegisterActorAsync <CounterActorService>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(ex.ToString());
                throw;
            }
        }
Пример #3
0
        public async Task NoActivateMessageFromRuntime()
        {
            var actorType = typeof(MyActor);

            var options = new ActorRuntimeOptions();

            options.Actors.RegisterActor <MyActor>();
            var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory);

            Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture);

            var output = new MemoryStream();
            await runtime.DispatchWithoutRemotingAsync(actorType.Name, "abc", nameof(MyActor.MyMethod), new MemoryStream(), output);

            var text = Encoding.UTF8.GetString(output.ToArray());

            Assert.Equal("\"hi\"", text);
            Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture);
        }
        /// <summary>
        /// Add an actor implementation to the fabric container
        /// </summary>
        /// <typeparam name="TActor"></typeparam>
        /// <typeparam name="TActorService"></typeparam>
        /// <param name="container"></param>
        /// <param name="ActorServiceFactory"></param>
        /// <returns></returns>
        public static IUnityContainer WithActor <TActor, TActorService>(
            this IUnityContainer container,
            Func <IUnityContainer, StatefulServiceContext, ActorTypeInformation, Func <ActorService, ActorId, TActor>, TActorService> ActorServiceFactory)
            where TActor : ActorBase
            where TActorService : ActorService
        {
            //var logger = container.Resolve<ILoggerFactory>().CreateLogger<TActor>();
            //logger.LogInformation("Registering Actor {ActorName}", typeof(TActor).Name);

            //  container = container.IntializeScope();


            if (!container.IsRegistered <IActorDeactivationInterception>())
            {
                container.RegisterType <IActorDeactivationInterception, OnActorDeactivateInterceptor>(new HierarchicalLifetimeManager());
            }

            container.RegisterType(typeof(TActor), ActorProxyTypeFactory.CreateType <TActor>(), new HierarchicalLifetimeManager());
            ActorRuntime.RegisterActorAsync <TActor>((context, actorType) =>
            {
                try
                {
                    var serviceContainer = container.IntializeScope();

                    return(ActorServiceFactory(serviceContainer, context, actorType, (service, id) =>
                                               serviceContainer
                                               .IntializeScope()
                                               .RegisterInstance(service.Context.CodePackageActivationContext, new ExternallyControlledLifetimeManager())
                                               .RegisterInstance(service, new ExternallyControlledLifetimeManager())
                                               // .RegisterInstance(service as TActorService, new ExternallyControlledLifetimeManager())
                                               .RegisterInstance(id, new ContainerControlledLifetimeManager()).Resolve <TActor>()));
                }
                catch (Exception ex)
                {
                    // logger.LogCritical(new EventId(100, "FailedToCreateActorService"), ex, "Failed to create ActorService for {ActorName}", typeof(TActor).Name);
                    throw;
                }
            }).GetAwaiter().GetResult();



            return(container);
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see http://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <VisualObjectActor>().GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #6
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <TestActor>(
                    (context, actorType) => new TestActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #7
0
        public static void AddActorMethodRoute(this IRouteBuilder routeBuilder)
        {
            routeBuilder.MapPut("actors/{actorTypeName}/{actorId}/method/{methodName}", async context =>
            {
                var routeValues   = context.Request.RouteValues;
                var actorTypeName = (string)routeValues["actorTypeName"];
                var actorId       = (string)routeValues["actorId"];
                var methodName    = (string)routeValues["methodName"];

                // If Header is present, call is made using Remoting, use Remoting dispatcher.
                if (context.Request.Headers.ContainsKey(Constants.RequestHeaderName))
                {
                    var daprActorheader = context.Request.Headers[Constants.RequestHeaderName];
                    var(header, body)   = await ActorRuntime.DispatchWithRemotingAsync(actorTypeName, actorId, methodName, daprActorheader, context.Request.Body);

                    // Item 1 is header , Item 2 is body
                    if (header != string.Empty)
                    {
                        // exception case
                        context.Response.Headers.Add(Constants.ErrorResponseHeaderName, header); // add error header
                    }

                    await context.Response.Body.WriteAsync(body, 0, body.Length); // add response message body
                }
                else
                {
                    // write exception info in response.
                    try
                    {
                        await ActorRuntime.DispatchWithoutRemotingAsync(actorTypeName, actorId, methodName, context.Request.Body, context.Response.Body);
                    }
                    catch (Exception e)
                    {
                        context.Response.Headers.Add("Connection: close", default(string));
                        context.Response.ContentType = "application/json";
                        context.Response.StatusCode  = StatusCodes.Status500InternalServerError;
                        await context.Response.WriteAsync(e.ToString());
                        await context.Response.CompleteAsync();
                    }
                }
            });
        }
Пример #8
0
        /// <summary>
        /// Dies ist der Einstiegspunkt des Diensthostprozesses.
        /// </summary>
        private static void Main()
        {
            try
            {
                // Diese Zeile registriert einen Actordienst zum Hosten Ihrer Akteurklasse bei der Service Fabric-Laufzeit.
                // Der Inhalt der Dateien "ServiceManifest.xml" und "ApplicationManifest.xml"
                // wird automatisch aufgefüllt, wenn Sie dieses Projekt erstellen.
                // Weitere Informationen finden Sie unter https://aka.ms/servicefabricactorsplatform.

                ActorRuntime.RegisterActorAsync <NewWorkPiece>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #9
0
        /// <summary>
        /// Este é o ponto de entrada do processo de host de serviço.
        /// </summary>
        private static void Main()
        {
            try
            {
                // Esta linha registra um Serviço de Ator para hospedar sua classe de ator com o tempo de execução do Service Fabric.
                // Os conteúdos dos seus arquivos ServiceManifest.xml e ApplicationManifest.xml
                // são populados automaticamente ao compilar este projeto.
                // Para obter mais informações, consulte https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <HelloWorld> (
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// これは、サービス ホスト プロセスのエントリ ポイントです。
        /// </summary>
        private static void Main()
        {
            try
            {
                // この行は、Service Fabric ランタイムにアクター クラスをホストするアクター サービスを登録します。
                // ServiceManifest.xml ファイルと ApplicationManifest.xml ファイルのコンテンツ
                // は、このプロジェクトをビルドするときに自動的に設定されます。
                //詳細については、https://aka.ms/servicefabricactorsplatform を参照してください

                ActorRuntime.RegisterActorAsync <Shape>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #11
0
        /// <summary>
        /// 这是服务主机进程的入口点。
        /// </summary>
        private static void Main()
        {
            try
            {
                // 此行注册了一个角色服务,以使用 Service Fabric 运行时来托管角色类。
                // ServiceManifest.xml 和 ApplicationManifest.xml 文件的内容
                // 在生成此项目时自动填充。
                //有关详细信息,请参阅 https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <ActorBackendService>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #12
0
        /// <summary>
        /// Este es el punto de entrada del proceso de host del servicio.
        /// </summary>
        private static void Main()
        {
            try
            {
                // Esta línea registra un servicio de actor para hospedar la clase de actor en el runtime de Service Fabric.
                // El contenido de los archivos ServiceManifest.xml y ApplicationManifest.xml
                // se rellena automáticamente cuando se compila el proyecto.
                // Para obtener más información, vea https://aka.ms/servicefabricactorsplatform.

                ActorRuntime.RegisterActorAsync <GameManagerActor>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #13
0
        /// <summary>
        /// Questo è il punto di ingresso del processo host del servizio.
        /// </summary>
        private static void Main()
        {
            try
            {
                // Questa riga consente di registrare un Servizio Actor per ospitare la classe actor con il runtime di Service Fabric.
                // Il contenuto dei file ServiceManifest.xml e ApplicationManifest.xml
                // viene popolato automaticamente quando si compila questo progetto.
                // Per altre informazioni, vedere http://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <Game>(
                    (context, actorType) => new ActorService(context, actorType, (a, b) => new Game(a, b))).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #14
0
        public static Task RegisterActorAsync <TActor>(TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
            where TActor : RawStatePersistentActor
        {
            return(ActorRuntime.RegisterActorAsync <TActor>((context, actorTypeInfo) =>
            {
                return new ActorService(context, actorTypeInfo, null, (actor, provider) =>
                {
                    var persistent = provider as KvsActorStateProvider;
                    if (persistent != null)
                    {
                        var replica = (KeyValueStoreReplica)ReplicaField.GetValue(provider);
                        ((RawStatePersistentActor)actor).SetReplica(replica);

                        return new ThrowingActorStateManager();
                    }

                    throw new ArgumentException("Event sourced actor must be persistent and use KvsActorStateProvider");
                });
            }, timeout, cancellationToken));
        }
Пример #15
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static async Task Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                await ActorRuntime.RegisterActorAsync <PlayerSessionActor> (
                    (context, actorType) => new ActorService(context, actorType));

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
 public override Task RegisterAsync(IKernel kernel)
 {
     return(ActorRuntime.RegisterActorAsync <TActor>((ctx, info) =>
                                                     new ActorService(ctx, info, (actorService, actorId) =>
     {
         try
         {
             return kernel.Resolve <TActor>(new
             {
                 actorService,
                 actorId
             });
         }
         catch (Exception e)
         {
             ActorEventSource.Current.Message("Failed to resolve Actor type {0}.\n{1}", typeof(TActor), e);
             throw;
         }
     })));
 }
Пример #17
0
        static void Main()
        {
            try
            {
                ActorRuntime.RegisterActorAsync <FriendlyActor>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                ActorRuntime.RegisterActorAsync <PetActor>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                ActorRuntime.RegisterActorAsync <CalculatorActor>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #18
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                //Creating a new event listener to redirect the traces to a file
                ActorEventListener listener = new ActorEventListener("VisualObjects.ActorService");
                listener.EnableEvents(ActorEventSource.Current, EventLevel.LogAlways, EventKeywords.All);

                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // For more information, see http://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <VisualObjectActor>().GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform
                ActorRuntime.RegisterActorAsync <KittyService>(
                    (context, actorType) => new ActorService(context, actorType,
                                                             // Create new kitty service while injecting needed services
                                                             (s, i) => new KittyService(s, i, new EtherscanApiClient(new HttpClientRequestFactory()))
                                                             )).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #20
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            new ArgumentException();
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <HelloWorld> (
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #21
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <GameActor>(
                    (context, actorType) => new ActorService(context, actorType, (service, id) =>
                                                             new GameActor(service, id, ServiceProxy.Create <IGameManager>(new Uri("fabric:/c4_v3/GameManager"), new ServicePartitionKey(1)))
                                                             )).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #22
0
 /// <summary>
 /// This is the entry point of the service host process.
 /// </summary>
 private static void Main()
 {
     try
     {
         ActorRuntime.RegisterActorAsync <Gate>(
             (context, actorType) => new ActorService(context, actorType, null, null, null, new ActorServiceSettings
         {
             ActorGarbageCollectionSettings = new ActorGarbageCollectionSettings(120, 60),
             ActorConcurrencySettings       = new ActorConcurrencySettings
             {
                 LockTimeout = TimeSpan.FromSeconds(10)
             }
         })).GetAwaiter().GetResult();
         Thread.Sleep(Timeout.Infinite);
     }
     catch (Exception e)
     {
         ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
         e.Log();
         throw;
     }
 }
Пример #23
0
        private static void Main()
        {
            try
            {
                ActorRuntime.RegisterActorAsync <DictionaryService>(
                    (context, actorType) =>
                    new ActorService(context, actorType,
                                     () =>
                                     new DictionaryService(new AssetPairRepository(), new CountryRepository(),
                                                           new MarginalAssetPairRepository(), new MarginalIssuerRepository(),
                                                           new MarginalAssetRepository())))
                .GetAwaiter()
                .GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                TelemetryClient = new TelemetryClient();
            }
            catch (Exception)
            {
                // ignored
            }
            try
            {
                // Create default garbage collection settings for all the actor types
                var actorGarbageCollectionSettings = new ActorGarbageCollectionSettings(300, 60);

                // This line registers your actor class with the Fabric Runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see http://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <DeviceActor>(
                    (context, actorType) => new DeviceActorService(context, actorType, () => new DeviceActor(), null, new ActorServiceSettings
                {
                    ActorGarbageCollectionSettings = actorGarbageCollectionSettings
                })).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                TelemetryClient.TrackException(e);
                ActorEventSource.Current.ActorHostInitializationFailed(e);
                throw;
            }
            finally
            {
                TelemetryClient.Flush();
            }
        }
Пример #25
0
        public async Task TestActorSettingsWithReentrancy()
        {
            var actorType = typeof(TestActor);

            var options = new ActorRuntimeOptions();

            options.Actors.RegisterActor <TestActor>();
            options.ActorIdleTimeout               = TimeSpan.FromSeconds(33);
            options.ActorScanInterval              = TimeSpan.FromSeconds(44);
            options.DrainOngoingCallTimeout        = TimeSpan.FromSeconds(55);
            options.DrainRebalancedActors          = true;
            options.ReentrancyConfig.Enabled       = true;
            options.ReentrancyConfig.MaxStackDepth = 64;

            var runtime = new ActorRuntime(options, loggerFactory, activatorFactory, proxyFactory);

            Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture);

            ArrayBufferWriter <byte> writer = new ArrayBufferWriter <byte>();
            await runtime.SerializeSettingsAndRegisteredTypes(writer);

            // read back the serialized json
            var    array = writer.WrittenSpan.ToArray();
            string s     = Encoding.UTF8.GetString(array, 0, array.Length);

            JsonDocument document = JsonDocument.Parse(s);
            JsonElement  root     = document.RootElement;

            // parse out the entities array
            JsonElement element = root.GetProperty("entities");

            Assert.Equal(1, element.GetArrayLength());

            element = root.GetProperty("reentrancy").GetProperty("enabled");
            Assert.True(element.GetBoolean());

            element = root.GetProperty("reentrancy").GetProperty("maxStackDepth");
            Assert.Equal(64, element.GetInt32());
        }
Пример #26
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <DemoActor> (
                    (context, actorType) =>
                {
                    var service = new ExtendedActorService(context, actorType)
                    {
                        // Optional, log the call before the message is handled
                        BeforeHandleRequestResponseAsync = requestInfo =>
                        {
                            ActorEventSource.Current.Message($"BeforeHandleRequestResponseAsync {requestInfo.ActorService} {requestInfo.Method} for actor {requestInfo.ActorId.ToString()}");
                            return(Task.FromResult <object>(null));
                        },
                        // Optional, log the call after the message is handled
                        AfterHandleRequestResponseAsync = reponseInfo =>
                        {
                            ActorEventSource.Current.Message($"AfterHandleRequestResponseAsync {reponseInfo.ActorService} {reponseInfo.Method} for actor {reponseInfo.ActorId.ToString()}");
                            return(Task.FromResult <object>(null));
                        },
                    };
                    return(service);
                }).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #27
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <MyActor>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                Console.WriteLine("Actor runtime registration completed");

                // Speak with actor a few times. I.e. send messages.
                // Create a randomly distributed actor ID
                ActorId actorId = ActorId.CreateRandom();

                // This only creates a proxy object, it does not activate an actor or invoke any methods yet.
                IMyActor myActor = ActorProxy.Create <IMyActor>(actorId, new Uri("fabric:/MyApp/MyActorService"));

                // Create the token source.
                CancellationTokenSource source = new CancellationTokenSource();
                CancellationToken       cts    = source.Token;

                // This will invoke a method on the actor. If an actor with the given ID does not exist, it will
                // be activated by this method call.
                myActor.SetCountAsync(1, cts);


                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #28
0
        private static void Main()
        {
            try
            {
                var container = new Container()
                                .WithActorFactories();

                container.RegisterMany(new [] { typeof(Program).Assembly },
                                       type => type.IsAssignableTo(typeof(IoCEnabledActorBase)));

                ActorRuntime.RegisterActorAsync <DeviceSensor>((context, typeInformation) =>
                                                               new ActorService(context, typeInformation,
                                                                                container.ActorFactory <DeviceSensor>
                                                                                )).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
        public static void Main(string[] args)
        {
            try
            {
                ThreadPool.SetMinThreads(10000, 500);
                ServicePointManager.DefaultConnectionLimit = int.MaxValue;
                ServicePointManager.UseNagleAlgorithm      = false;
                ServicePointManager.Expect100Continue      = false;

                LoggingSource.Initialize(ActorEventSource.Current.Message);


                ActorRuntime.RegisterActorAsync <StockTrendPredictionActor>().GetAwaiter().GetResult();
                ActorRuntime.RegisterActorAsync <NotificationActor>().GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(e.ToString());
                throw;
            }
        }
Пример #30
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // This line registers an Actor Service to host your actor class with the Service Fabric runtime.
                // The contents of your ServiceManifest.xml and ApplicationManifest.xml files
                // are automatically populated when you build this project.
                // For more information, see https://aka.ms/servicefabricactorsplatform

                ActorRuntime.RegisterActorAsync <PersonActor>(
                    (context, actorType) => new PersonActorService(context, actorType)).GetAwaiter().GetResult();

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                // TODO: Fix this logging, add option to build ActorOrActorServiceDescription from FabricRuntime?
                //FabricRuntime.GetNodeContext().

                new ActorLogger(null).ActorHostInitializationFailed(e);
                throw;
            }
        }
Пример #31
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                //Creating a new event listener to redirect the traces to a file
                ActorEventListener listener = new ActorEventListener();
                listener.EnableEvents(ActorEventSource.Current, EventLevel.LogAlways, EventKeywords.All);

                ActorEventSource.Current.Message("Registering Actor : {0}", "Myactorserv");

                ActorRuntime.RegisterActorAsync <Myactorserv>(
                    (context, actorType) => new ActorService(context, actorType)).GetAwaiter().GetResult();

                ActorEventSource.Current.Message("Registered Actor : {0}", "Myactorserv");

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.ActorHostInitializationFailed(ex.ToString());
                throw;
            }
        }