当前位置: 首页>>代码示例>>C#>>正文


C# IActorRef.Ask方法代码示例

本文整理汇总了C#中IActorRef.Ask方法的典型用法代码示例。如果您正苦于以下问题:C# IActorRef.Ask方法的具体用法?C# IActorRef.Ask怎么用?C# IActorRef.Ask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IActorRef的用法示例。


在下文中一共展示了IActorRef.Ask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");
            _system = ActorSystem.Create("test", section.AkkaConfig);

            _coordinator = _system.ActorOf(Props.Create(() => new IdentityActor())
                .WithRouter(FromConfig.Instance), "fred");

            //_coordinator =
            //    _system.ActorOf(Props.Create(() => new IdentityActor()).WithRouter(new ConsistentHashingPool(5000)),
            //        "fred2");

            int routees = _coordinator.Ask<Routees>(new GetRoutees()).Result.Members.Count();
            Console.WriteLine(routees);

            // Lazy wait for the co-ordinator to deploy.
            Thread.Sleep(5000);

            for (int i = 1; i <= 5000; i++)
            {
                for (int x = 1; x <= 4; x++)
                {
                    _coordinator.Tell(new EntityMessage<long>(i));
                }
            }

            Thread.Sleep(500);

            Console.ReadLine();
        }
开发者ID:DevEnable,项目名称:AkkaHash,代码行数:30,代码来源:Program.cs

示例2: IdentityManagerActor

        public IdentityManagerActor(IActorRef authenticationActor, TimeSpan timeout)
        {
            _authenticator = authenticationActor;
            _timeout = timeout;

            Receive<CreateUser>(create =>
            {
                // since we're using the PipeTo pattern, we need to close over state
                // that can change between messages, such as Sender
                // for more, see the PipeTo sample: https://github.com/petabridge/akkadotnet-code-samples/tree/master/PipeTo
                var senderClosure = Sender;

                // this actor needs it create user request to be authenticated
                // within 2 seconds or this operation times out & cancels 
                // the Task returned by Ask<>
                _authenticator.Ask<UserResult>(create, _timeout)
                    .ContinueWith(tr =>
                    {
                        // if the task got messed up / failed, return failure result
                        if (tr.IsCanceled || tr.IsFaulted)
                            return new UserResult(false);

                        // otherwise return whatever the actual result was
                        return tr.Result;
                    }).PipeTo(senderClosure);
            });
        }
开发者ID:AshWilliams,项目名称:akkadotnet-code-samples,代码行数:27,代码来源:Blackhole.cs

示例3: ActorSelectionSpec

        public ActorSelectionSpec() : base(Config)
        {
            _c1 = Sys.ActorOf(Props, "c1");
            _c2 = Sys.ActorOf(Props, "c2");
            _c21 = _c2.Ask<IActorRef>(new Create("c21")).Result;

            _all = new[] {_c1, _c2, _c21};
        }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:8,代码来源:ActorSelectionSpec.cs

示例4: CreateAd

        private static void CreateAd(IActorRef adsRoot, string adName, string adUrl, decimal pricePerImpression, decimal availableFunds, params string[] keywords)
        {
            IActorRef adActor = adsRoot.Ask<IActorRef>(new CreateAd(adName)).Result; // Create the ad and keep a reference.
            adActor.Tell(new SetPrice(pricePerImpression));
            adActor.Tell(new SetKeywords(keywords));
            adActor.Tell(new SetAdUrl(adUrl));
            adActor.Tell(new AddFunds(availableFunds));

            _allAdActors.Add(adActor);
        }
开发者ID:jweimann,项目名称:AdService,代码行数:10,代码来源:Program.cs

示例5: AskNode

        private IActorRef AskNode(IActorRef node, IQuery query)
        {
            var result = node.Ask(query).Result;

            var actorRef = result as IActorRef;
            if (actorRef != null)
                return actorRef;
            
            var selection = result as ActorSelection;
            return selection != null ? Identify(selection) : null;
        }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:11,代码来源:ActorSelectionSpec.cs

示例6: StressPersistentActor

        private static void StressPersistentActor(IActorRef pref, long? failAt, string description)
        {
            if (failAt.HasValue) pref.Tell(new FailAt(failAt.Value));

            var m = new Measure(LoadCycles);
            m.StartMeasure();

            for (int i = 1; i <= LoadCycles; i++) pref.Tell("msg" + i);

            pref.Ask(StopMeasure.Instance, TimeSpan.FromSeconds(100)).Wait();
            var ratio = m.StopMeasure();
            Console.WriteLine("Throughtput: {0} {1} per second", ratio, description);
        }
开发者ID:njimenez,项目名称:akka.net,代码行数:13,代码来源:Program.cs

示例7: Setup

        public void Setup(BenchmarkContext context)
        {
            MsgReceived = context.GetCounter("MsgReceived");
            System = ActorSystem.Create("PerfSys");
            Action<IActorDsl> actor = d => d.ReceiveAny((o, c) =>
            {
                MsgReceived.Increment();
            });
            TestActor = System.ActorOf(Props.Create(() => new Act(actor)), "testactor");
            var id = TestActor.Ask<ActorIdentity>(new Identify(null), TimeSpan.FromSeconds(3)).Result;

            Mailbox = new Mailbox(new UnboundedMessageQueue());
            Mailbox.SetActor(TestActor.AsInstanceOf<RepointableActorRef>().Underlying.AsInstanceOf<ActorCell>());
        }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:14,代码来源:MailboxBenchmarks.cs

示例8: GetSectionsForNotebook

        public async Task<ImmutableArray<SectionDto>> GetSectionsForNotebook(IActorRef actor, NotebookDto notebook)
        {
            var answer = await actor.Ask(new SectionActor.GetSectionsForNotebook(notebook));

            if (answer is SectionActor.GetSectionsForNotebookResult)
            {
                var result = answer as SectionActor.GetSectionsForNotebookResult;

                return result.Sections;
            }

            LogFailure(answer);

            return ImmutableArray<SectionDto>.Empty;
        }
开发者ID:eaardal,项目名称:delbert,代码行数:15,代码来源:SectionFacade.cs

示例9: GetRootDirectoryFromCommandLine

        public async Task<DirectoryInfo> GetRootDirectoryFromCommandLine(IActorRef actor)
        {
            var answer = await actor.Ask(new CommandLineArgsParserActor.GetRootDirectoryFromCommandLineArgs());

            if (answer is CommandLineArgsParserActor.GetRootDirectoryFromCommandLineArgsResult)
            {
                var result = answer as CommandLineArgsParserActor.GetRootDirectoryFromCommandLineArgsResult;

                return result.Success ? result.Directory : null;
            }

            LogFailure(answer);

            return null;
        } 
开发者ID:eaardal,项目名称:delbert,代码行数:15,代码来源:CommandLineArgsParserFacade.cs

示例10: GetPagesForSection

        public async Task<ImmutableArray<PageDto>> GetPagesForSection(IActorRef actor, SectionDto section)
        {
            var answer = await actor.Ask(new PageActor.GetPagesForSection(section));

            if (answer is PageActor.GetPagesForSectionResult)
            {
                var result = answer as PageActor.GetPagesForSectionResult;

                return result.Pages;
            }

            LogFailure(answer);

            return ImmutableArray<PageDto>.Empty;
        }
开发者ID:eaardal,项目名称:delbert,代码行数:15,代码来源:PageFacade.cs

示例11: GetNotebooks

        public async Task<ImmutableArray<NotebookDto>> GetNotebooks(IActorRef actor)
        {
            var answer = await actor.Ask(new NotebookActor.GetNotebooks());

            if (answer is NotebookActor.GetNotebooksResult)
            {
                var result = answer as NotebookActor.GetNotebooksResult;

                return result.Notebooks;
            }

            LogFailure(answer);

            return ImmutableArray<NotebookDto>.Empty;
        }
开发者ID:eaardal,项目名称:delbert,代码行数:15,代码来源:NotebookFacade.cs

示例12: CurrentRoutees

 private IEnumerable<Routee> CurrentRoutees(IActorRef router)
 {
     return router.Ask<Routees>(new GetRoutees(), GetTimeoutOrDefault(null)).Result.Members;
 }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:4,代码来源:ClusterConsistentHashingRouterSpec.cs

示例13: Mp3RecordManager

        public Mp3RecordManager(IActorRef resourceDownloader, IActorRef resourceStorer)
        {
            Receive<NewRecordMessage>(async message =>
            {
                newRecord = message;
                path = message.Artist + "\\" + message.Album + "\\" + message.Track + ".mp3";
                var pathHash = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(path));
                var rowKey = message.Album + " - " + message.Track; //BitConverter.ToString(pathHash).Replace("-", "");
                var tableClient = storageAccount.CreateCloudTableClient();
                var table = tableClient.GetTableReference(StorageTableName);
                trackEntity = new TrackEntity
                {
                    Album = message.Album,
                    AlbumArtUrl = message.AlbumImageLocation.AbsoluteUri,
                    AlbumArtDownloaded = false,
                    Artist = message.Artist,
                    Track = message.Track,
                    TrackDownloaded = false,
                    TrackUrl = message.FileLocation.AbsoluteUri,
                    PartitionKey = message.Artist,
                    RowKey = rowKey,
                    Timestamp = DateTime.UtcNow
                };
                var partitionFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal,
                    trackEntity.PartitionKey);
                var rowFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, trackEntity.RowKey);
                var finalFilter = TableQuery.CombineFilters(partitionFilter, TableOperators.And, rowFilter);
                var query = new TableQuery<TrackEntity>().Where(finalFilter);

                var entities = table.ExecuteQuery(query, new TableRequestOptions {RetryPolicy = new NoRetry()});
                if (!entities.Any())
                {
                    var insertOperation = TableOperation.Insert(trackEntity);
                    table.Execute(insertOperation);

                    if (message.AlbumImageLocation != null)
                    {
                        var albumArtDownloadedMessage =
                            await
                                resourceDownloader.Ask<AlbumArtDownloaded>(
                                    new DownloadAlbumArt(message.AlbumImageLocation));
                        trackEntity.AlbumImage = albumArtDownloadedMessage.Resource;
                    }
                    var mp3Downloaded =
                        await resourceDownloader.Ask<Mp3Downloaded>(new DownloadMp3(message.FileLocation));

                    Log.Information("Received downloaded MP3. Length: {length}, Location: {resourceUri}", mp3Downloaded.Resource.Length,
                        mp3Downloaded.ResourceUri);

                    var memoryStream = new MemoryStream();
                    memoryStream.Write(mp3Downloaded.Resource, 0, mp3Downloaded.Resource.Length);

                    var simpleFile = new SimpleFile(path, memoryStream);
                    var simpleFileAbstraction = new SimpleFileAbstraction(simpleFile);
                    var file = File.Create(simpleFileAbstraction);

                    file.Tag.Composers = new[] {newRecord.Artist};
                    file.Tag.AlbumArtists = new[] {newRecord.Artist};
                    file.Tag.Title = newRecord.Track;
                    file.Tag.Album = newRecord.Album;

                    file.Tag.Pictures = new IPicture[]
                    {
                        new Picture(trackEntity.AlbumImage)
                    };

                    file.Save();
                    var savedFile = ReadToEnd(simpleFile.Stream);
                    resourceStorer.Tell(new StoreBlobRequest(path, savedFile));

                    Log.Information("Creating record: {artist}", message.Artist);
                }
            });

            Receive<Mp3Downloaded>(message =>
            {
                Log.Information("receieved downloaded MP3. Length: {length}, Resource URI: {resourceUri}",
                    message.Resource.Length,
                    message.ResourceUri);

                var memoryStream = new MemoryStream();
                memoryStream.Write(message.Resource, 0, message.Resource.Length);

                var simpleFile = new SimpleFile(path, memoryStream);
                var simpleFileAbstraction = new SimpleFileAbstraction(simpleFile);
                var file = File.Create(simpleFileAbstraction);

                file.Tag.Composers = new[] {newRecord.Artist};
                file.Tag.AlbumArtists = new[] {newRecord.Artist};
                file.Tag.Title = newRecord.Track;
                file.Tag.Album = newRecord.Album;

                file.Tag.Pictures = new IPicture[]
                {
                    new Picture(trackEntity.AlbumImage)
                };

                file.Save();
                var savedFile = ReadToEnd(simpleFile.Stream);
                resourceStorer.Tell(new StoreBlobRequest(path, savedFile));
//.........这里部分代码省略.........
开发者ID:paulfryer,项目名称:eventprocessing,代码行数:101,代码来源:Mp3RecordManager.cs

示例14: CurrentRoutees

 protected Routees CurrentRoutees(IActorRef router)
 {
     var routerAsk = router.Ask<Routees>(new GetRoutees(), GetTimeoutOrDefault(null));
     return routerAsk.Result;
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:5,代码来源:ClusterConsistentHashingGroupSpec.cs

示例15: BlockingAsker

 public BlockingAsker(IActorRef other)
 {
     Receive<string>(_ =>
     {
         //not async, blocking wait
         var res = other.Ask("start").Result;
         Sender.Tell(res);
     });
 }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:9,代码来源:AsyncAwaitSpec.cs


注:本文中的IActorRef.Ask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。