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


C# IActorRef.Tell方法代码示例

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


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

示例1: Hub

        public Hub(IActorRef handler)
        {
            _handler = handler;

            Receive<Signal.Join>(join =>
            {
                if (!_clients.TryAdd(Sender, out _clients))
                    return;

                var joined = new Signal.Joined(Sender.Path.Name, Self.Path.Name);
                Self.Tell(new Signal.Broadcast("self", joined));

                _handler.Tell(joined);
            });

            Receive<Signal.Leave>(leave =>
            {
                if (!_clients.TryRemove(Sender, out _clients))
                    return;

                var left = new Signal.Left(Sender.Path.Name, Self.Path.Name);
                Self.Tell(new Signal.Broadcast("self", left));

                _handler.Tell(left);
            });

            Receive<Signal.Broadcast>(broadcast =>
            {
                var message = WriteObject(broadcast.Message);
                foreach (var client in _clients)
                    client.Tell(message);
            });

            ReceiveAny(o => Self.Forward(new Signal.Broadcast("self", o)));
        }
开发者ID:tstojecki,项目名称:Akka.Signal,代码行数:35,代码来源:Hub.cs

示例2: SignalRBridgeActor

        public SignalRBridgeActor(IGameEventsPusher gameEventsPusher, IActorRef gameController)
        {
            _gameEventsPusher = gameEventsPusher;
            _gameController = gameController;

            Receive<JoinGameMessage>(
                message =>
                {
                    _gameController.Tell(message);
                });

            Receive<AttackPlayerMessage>(
                message =>
                {
                    _gameController.Tell(message);
                });

            Receive<PlayerStatusMessage>(
                message =>
                {
                    _gameEventsPusher.PlayerJoined(message.PlayerName, message.Health);
                });

            Receive<PlayerHealthChangedMessage>(
                message =>
                {
                    _gameEventsPusher.UpdatePlayerHealth(message.PlayerName, message.Health);
                });
        }
开发者ID:stemarie,项目名称:POC_SignalR,代码行数:29,代码来源:SignalRBridgeActor.cs

示例3: ButtonToggler

        /// <summary>
        ///		Create a new <see cref="ButtonToggler"/> actor.
        /// </summary>
        /// <param name="performanceCountersController">
        ///		The actor that controls the <see cref="PerformanceCounterMonitor"/>s for various performance counters.
        /// </param>
        /// <param name="button">
        ///		The button controlled by the <see cref="ButtonToggler"/>.
        /// </param>
        /// <param name="counterType">
        ///		The type of performance counter represented by the button.
        /// </param>
        /// <param name="isToggled">
        ///		Is the button currently toggled ("On")?
        /// </param>
        public ButtonToggler(IActorRef performanceCountersController, Button button, CounterType counterType, bool isToggled = false)
        {
            if (performanceCountersController == null)
                throw new ArgumentNullException("performanceCountersController");

            if (button == null)
                throw new ArgumentNullException("button");

            if (counterType == CounterType.Unknown)
                throw new ArgumentOutOfRangeException(nameof(counterType), counterType, "Invalid performance counter type.");

            _performanceCountersController = performanceCountersController;
            _button = button;
            _counterType = counterType;
            _isToggled = isToggled;

            Receive<Toggle>(_ =>
            {
                if (Flip())
                {
                    _performanceCountersController.Tell(
                        new WatchCounterValue(_counterType)
                    );
                }
                else
                {
                    _performanceCountersController.Tell(
                        new UnwatchCounterValue(_counterType)
                    );
                }
            });
        }
开发者ID:tintoy,项目名称:akkadotnet-bootcamp-unit2,代码行数:47,代码来源:ButtonToggler.cs

示例4: Binding

        private Receive Binding(EndPoint endPoint, IActorRef sender)
        {
            Context.System.Tcp().Tell(new Tcp.Bind(Self, endPoint));

            return message =>
            {
                var failed = message as Tcp.CommandFailed;
                if (failed != null)
                {
                    _log.Error($"Could not bind to endpoint {endPoint}. Reason: {failed.Cmd.FailureMessage}");
                    sender.Tell(new Signal.BindingFailed(endPoint, failed.Cmd.FailureMessage.ToString()));
                    Context.Stop(Self);
                    return true;
                }

                var bound = message as Tcp.Bound;
                if (bound != null)
                {
                    _log.Info($"Listening on {bound.LocalAddress}");
                    sender.Tell(new Signal.Bound(endPoint));
                    Become(Bound);
                    return true;
                }

                Stash.Stash();
                return true;
            };

        }
开发者ID:chris-ray,项目名称:Akka.Signal,代码行数:29,代码来源:HubManager.cs

示例5: Connected

        private Receive Connected(IActorRef connection)
        {
            connection.Tell(new Tcp.Register(Self));
            connection.Tell(Tcp.Write.Create(MessageSeriliazer.Serialize(Context.System, new Signal.Join(_hub))));

            return message =>
            {
                var received = message as Tcp.Received;
                if (received != null)
                {
                    var messages = MessageSeriliazer.Deserialize(Context.System, received.Data);
                    messages.ForEach(_handler.Tell);
                    return true;
                }
                
                var closed = message as Tcp.ConnectionClosed;
                if (closed != null)
                {
                    _handler.Tell(new Signal.Disconnected());
                    Become(Reconnecting());
                    return true;
                }

                if (Sender == _handler)
                {
                    connection.Tell(WriteObject(new Signal.Broadcast(_hub, message)));
                    return true;
                }

                return false;
            };
        }
开发者ID:chris-ray,项目名称:Akka.Signal,代码行数:32,代码来源:HubClient.cs

示例6: ClientReceiveActor

 public ClientReceiveActor(IActorRef actor, long repeat, TaskCompletionSource<bool> latch)
 {
     var received=0L;
     var sent=0L;
     Receive<Messages.Msg>(m =>
     {
         received++;
         if(sent < repeat)
         {
             actor.Tell(m);
             sent++;
         }
         else if(received >= repeat)
         {
             latch.SetResult(true);
         }
     });
     Receive<Messages.Run>(r =>
     {
         var msg = new Messages.Msg();
         for(int i = 0; i < Math.Min(1000, repeat); i++)
         {
             actor.Tell(msg);
             sent++;
         }
     });
     Receive<Messages.Started>(s => Sender.Tell(s));
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:28,代码来源:ClientReceiveActor.cs

示例7: FixInterpreterTests

        public FixInterpreterTests()
        {
            var actorSystem = ActorSystem.Create("System");

            var props = Props.Create(() => new FixInterpreterActor(new FakeFixParser()));
            _fixInterpreterActor = actorSystem.ActorOf(props);

            _serverActor = CreateTestProbe("Server");
            _clientActor = CreateTestProbe("Client");

            _fixInterpreterActor.Tell(new FixInterpreterActor.SetServer(_serverActor));
            _fixInterpreterActor.Tell(new FixInterpreterActor.SetClient(_clientActor));
        }
开发者ID:gderham,项目名称:fixity,代码行数:13,代码来源:FixInterpreterTests.cs

示例8: PersistentViewSpec

        public PersistentViewSpec()
            : base(Configuration("inmem", "PersistentViewSpec"))
        {
            _prefProbe = CreateTestProbe();
            _viewProbe = CreateTestProbe();

            _pref = ActorOf(() => new TestPersistentActor(Name, _prefProbe.Ref));
            _pref.Tell("a");
            _pref.Tell("b");

            _prefProbe.ExpectMsg("a-1");
            _prefProbe.ExpectMsg("b-2");
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:13,代码来源:PersistentViewSpec.cs

示例9: 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

示例10: HubProxy

        public HubProxy(IActorRef handler)
        {
            _handler = handler;

            Receive<Signal.Join>(join =>
            {
                Sender.Tell(WriteObject(new Signal.Joined(Sender.Path.Name, Self.Path.Name, true)));

                //Client hasn't received the previous joined message so we don't need to forward it again to the other clients
                if (_clientDictionary.ContainsKey(Sender.Path.Name))
                    return;

                var joined = new Signal.Joined(Sender.Path.Name, Self.Path.Name);
                var joinedSerialized = WriteObject(joined);
                foreach (var client in _clientDictionary.Values)
                    client.Tell(joinedSerialized);

                _handler.Tell(joined);

                _clientDictionary[Sender.Path.Name] = Sender;
            });

            Receive<Signal.Leave>(leave =>
            {
                if (_clientDictionary.ContainsKey(Sender.Path.Name))
                    _clientDictionary.Remove(Sender.Path.Name);

                var left = new Signal.Left(Sender.Path.Name, Self.Path.Name);
                Self.Tell(new Signal.Broadcast("self", left));

                _handler.Tell(left);
            });

            Receive<Signal.Broadcast>(broadcast =>
            {
                var message = WriteObject(broadcast.Message);
                if (broadcast.ClientId == null)
                {
                    foreach (var client in _clientDictionary.Values)
                        client.Tell(message);
                }
                else if (_clientDictionary.ContainsKey(broadcast.ClientId))
                {
                    _clientDictionary[broadcast.ClientId].Tell(message);
                }
            });

            Receive<Signal.ClientBroadcast>(broadcast => _handler.Tell(broadcast));
        }
开发者ID:chris-ray,项目名称:Akka.Signal,代码行数:49,代码来源:HubProxy.cs

示例11: RequestProducer

        public RequestProducer(int numberOfWorkers, string[] uris)
        {
            this.numberOfWorkers = numberOfWorkers;
            this.uris = uris;
            logger = Context.ActorOf<RequestLogger>("consoleLogger");

            Receive<NewWorker>(worker =>
            {
                log.Debug("Adding http request worker: {Worker}", Sender);
                //Console.WriteLine("Adding worker: " + Sender.Path);
                workers.Add(Sender);
                RequestHttpWork(Sender);
            });

            Receive<Result>(worker =>
            {
                logger.Tell(worker);
                RequestHttpWork(Sender);
            });

            Receive<StopGenerationOfRequests>(stop =>
            {
                Task.WaitAll(workerPool.GracefulStop(TimeSpan.FromSeconds(60)), logger.GracefulStop(TimeSpan.FromSeconds(60)));

                Sender.Tell("Done", Self);
            });
        }
开发者ID:orjan,项目名称:http-pump,代码行数:27,代码来源:RequestProducer.cs

示例12: GenericDBEntity

        public GenericDBEntity(string entityType, long id)
        {
            _entityChangeNotificationActor = Context.System.ActorSelection($"/user/EntityChangeNotificationRootActor/{entityType}").ResolveOne(TimeSpan.FromSeconds(1)).Result;

            var entityAssembly = Assembly.GetAssembly(typeof(IModelObject)); // Removed DTOs - ModelObject = ef entity
            var allEntityTypes = entityAssembly.GetTypes().ToList();

            EntityType = allEntityTypes.FirstOrDefault(t => t.Name == entityType);
            Id = id;

            _modelObject = LoadEntityFromDb();

            Receive<UpdateEntityRequest>(message =>
            {
                _undoStack.Push(_modelObject);

                _modelObject = message.GetModelObject();
                SaveModelObject();
                Sender.Tell(_modelObject);
                _entityChangeNotificationActor.Tell(new NotifySubscribersOfEntityChange(this.Id));
            });

            Receive<UndoRequest>(message =>
            {
                if (_undoStack.Count > 0)
                {
                    _modelObject = _undoStack.Pop();
                    SaveModelObject();
                }
                Sender.Tell(_modelObject);
            });
        }
开发者ID:jweimann,项目名称:webdb,代码行数:32,代码来源:GenericDBEntity.cs

示例13: Actor1NonAsync

            public Actor1NonAsync(IActorRef testActor)
            {
                _testActor = testActor;
                Receive<string>(m => { _testActor.Tell(m); });

                Context.ActorOf(Props.Create<Actor2>(), "actor-2");
            }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:7,代码来源:BugFix2176Spec.cs

示例14: Handle

        /// <summary>
        /// Handle file processing message.
        /// Actor will count one file.
        /// </summary>
        /// <param name="message"></param>
        public void Handle( FileToProcess message )
        {
            IncrementMessagesReceived();

            lineCount = 0;
            linesProcessed = 0;
            result = 0;
            m_sw.Start();
            fileName = message.FileName;
            router = Context.ActorOf( new RoundRobinPool(8).Props( StringCounterActor.GetProps() ), String.Format( "liner{0}", message.Fileno ) );
            //var router = Context.ActorOf( StringCounterActor.GetProps(), String.Format( "liner{0}", message.Fileno ) );
            try
            {
                foreach ( var line in File.ReadLines( fileName ) )
                {
                    lineCount++;
                    router.Tell( new ProcessLine( line, lineCount ) );
                }
            }
            catch ( Exception ex )
            {
                Sender.Tell( new FailureMessage( ex, Self ) );
            }

            // handle when file is empty
            if ( lineCount == 0 )
            {
                Sender.Tell( new CompletedFile( fileName, result, lineCount, 0 ) );
            }
        }
开发者ID:njimenez,项目名称:AkkaProjects,代码行数:35,代码来源:WordCounterActor.cs

示例15: ForwardMessages

 private void ForwardMessages(BufferedMessages messages, IActorRef recipient)
 {
     messages.ForEach(c =>
     {
         recipient.Tell(c.Key, c.Value);
     });
 }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:7,代码来源:PerGroupingBuffer.cs


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