本文整理汇总了C#中IActorRef类的典型用法代码示例。如果您正苦于以下问题:C# IActorRef类的具体用法?C# IActorRef怎么用?C# IActorRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IActorRef类属于命名空间,在下文中一共展示了IActorRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClusterMetricsCollector
public ClusterMetricsCollector(IActorRef publisher)
{
_publisher = publisher;
_cluster = Cluster.Get(Context.System);
Collector = MetricsCollector.Get(Context.System.AsInstanceOf<ExtendedActorSystem>(), _cluster.Settings);
LatestGossip = MetricsGossip.Empty;
Nodes = ImmutableHashSet.Create<Address>();
_metricsCancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(
_cluster.Settings.PeriodicTasksInitialDelay.Max(_cluster.Settings.MetricsInterval),
_cluster.Settings.MetricsInterval, Self, InternalClusterAction.MetricsTick.Instance, Self);
_gossipCancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(
_cluster.Settings.PeriodicTasksInitialDelay.Max(_cluster.Settings.GossipInterval),
_cluster.Settings.GossipInterval, Self, InternalClusterAction.GossipTick.Instance, Self);
Receive<InternalClusterAction.GossipTick>(tick => Gossip());
Receive<InternalClusterAction.MetricsTick>(tick => Collect());
Receive<MetricsGossipEnvelope>(envelope => ReceiveGossip(envelope));
Receive<ClusterEvent.CurrentClusterState>(state => ReceiveState(state));
Receive<ClusterEvent.MemberUp>(up => AddMember(up.Member));
Receive<ClusterEvent.MemberRemoved>(removed => RemoveMember(removed.Member));
Receive<ClusterEvent.MemberExited>(exited => RemoveMember(exited.Member));
Receive<ClusterEvent.UnreachableMember>(member => RemoveMember(member.Member));
Receive<ClusterEvent.ReachableMember>(member =>
{
if (member.Member.Status == MemberStatus.Up) AddMember(member.Member);
});
Receive<ClusterEvent.IMemberEvent>(@event => { }); //not interested in other types of member event
}
示例2: StockActor
public StockActor(string stockSymbol)
{
_stockSymbol = stockSymbol;
_subscribers = new HashSet<IActorRef>();
_priceLookupChild = Context.ActorOf(Context.DI().Props<StockPriceLookupActor>());
Receive<SubscribeToNewStockPricesMessage>(message => _subscribers.Add(message.Subscriber));
Receive<UnSubscribeFromNewStockPricesMessage>(message => _subscribers.Remove(message.Subscriber));
Receive<RefreshStockPriceMessage>(message => _priceLookupChild.Tell(message));
Receive<UpdatedStockPriceMessage>(message =>
{
_stockPrice = message.Price;
var stockPriceMessage = new StockPriceMessage(_stockSymbol, _stockPrice, message.Date);
foreach (var subscriber in _subscribers)
{
subscriber.Tell(stockPriceMessage);
}
});
}
示例3: FileObserver
public FileObserver(IActorRef tailActor, string absoluteFilePath)
{
_tailActor = tailActor;
_absoluteFilePath = absoluteFilePath;
_fileDir = Path.GetDirectoryName(absoluteFilePath);
_fileNameOnly = Path.GetFileName(absoluteFilePath);
}
示例4: 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));
}
示例5: MediWatchCommanderActor
private readonly Dictionary<int, IActorRef> _hospitalCoordinatorActors; // maps hospital id -> actor ref
#endregion Fields
#region Constructors
public MediWatchCommanderActor( IEnumerable<Hospital> hospitals, IActorRef dashboardActor )
{
_dashboardActor = dashboardActor;
_hospitalCoordinatorActors = InitializeHospitalCoordinatorActors( hospitals );
Processing();
}
示例6: LifeCycleTest2Actor
public LifeCycleTest2Actor(IActorRef testActor, string id, AtomicCounter generationProvider)
{
this.testActor = testActor;
this.id = id;
this.generationProvider = generationProvider;
this.CurrentGeneration = generationProvider.Next();
}
示例7: Receive
/// <summary>
/// Directly inject messages into actor receive behavior. Any exceptions
/// thrown will be available to you, while still being able to use
/// become/unbecome.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="sender">The sender.</param>
public void Receive(object message, IActorRef sender = null)
{
var cell = Cell;
sender = sender.IsNobody() ? cell.System.DeadLetters : sender;
var envelope = new Envelope { Message = message, Sender = sender };
cell.UseThreadContext(() => cell.ReceiveMessageForTest(envelope));
}
示例8: ConnectionAssociationHandle
public ConnectionAssociationHandle(IActorRef connection, Address localAddress, Address remoteAddress)
: base(localAddress, remoteAddress)
{
_connection = connection;
ReadHandlerSource = new TaskCompletionSource<IHandleEventListener>();
ReadHandlerSource.Task.PipeTo(connection);
}
示例9: MailInActor
public MailInActor(IActorRef commander)
{
this.commander = commander;
Receive<CheckMail>(m =>
{
Console.Write("[MailInActor ]: Checking e-mail inbox ...");
var ex = Helpers.GetRandomInt(CalcConfig.NetworkExceptionChance);
if (ex == 2)
{
throw new SocketException();
}
ex = Helpers.GetRandomInt(CalcConfig.FatalExceptionChance);
if (ex == 5)
{
throw new ArgumentNullException();
}
// emulate receiving n e-mails
int n = Helpers.GetRandomInt(CalcConfig.MaxNumberEmailsReceived);
Console.WriteLine(" {0} e-mails found.", n);
for (int i = 0; i < n; i++)
{
var from = Helpers.GetRandomEmail();
var loanId = Helpers.GetRandomLoadId();
var calculationOrder = new CalculateLoan(from, loanId);
this.commander.Tell(calculationOrder);
}
});
}
示例10: Master
public Master()
{
var layersCount = LayerDimentions.Count;
var dataShards = Enumerable.Repeat(DataSet, DataPerReplica).ToList();
var parameterShardActors = new IActorRef[layersCount - 1];
for (int i = 0; i < layersCount -1; i++)
{
parameterShardActors[i] = Context.ActorOf(new Props(typeof(ParameterShard), new object[]{ new ParameterShard(i, LearningRate, new double[3,3])}));
}
var dataShardActors = new List<IActorRef>();
foreach (var dataShard in dataShards)
{
dataShardActors.Add(Context.ActorOf(new Props(typeof(DataShard), new []{new DataShard
{
} })));
}
var shardsFinishedCount = 0;
Receive<Start>(start =>
{
foreach (var dataShardActor in dataShardActors)
{
dataShardActor.Tell(new ReadyToProcess());
}
});
Receive<Done>(done =>
{
shardsFinishedCount++;
if (shardsFinishedCount == dataShards.Count)
Console.WriteLine("Done");
});
}
示例11: RoomActor
public RoomActor(long id, string name,
IActorRef roomAccess,
IActorRef messageAccess,
ICanTell signalR)
{
_roomId =id;
_name = name;
_users = new Dictionary<long, User>();
_roomAccess = roomAccess;
_messageAccess = messageAccess;
_signalR = signalR;
Receive<UsersInRoomMessage>(message =>
{
message.Users.ForEach(user =>
{
_users.Add(user.Id, user);
});
_log.Info("RoomActor-" + _name + " established");
Become(Established);
});
Receive<FailedToGetUsersInRoomMessage>(message =>
{
_log.Error("FailedToGetUsersInRoomMessage-" + _roomId + ": " + message.Message);
ScheduleUserLoading(TimeSpan.FromSeconds(30));
});
ReceiveAny(x => Stash.Stash());
}
示例12: ConnectionRequest
public ConnectionRequest(Guid clientId, ClientStatus initialStatus, string username, IActorRef clientsActor)
{
ClientId = clientId;
InitialStatus = initialStatus;
Username = username;
ClientsHandler = clientsActor;
}
示例13: EchoConnectionHandler
public EchoConnectionHandler(EndPoint remote, IActorRef connection)
{
// we want to know when the connection dies (without using Tcp.ConnectionClosed)
Context.Watch(connection);
Receive<Tcp.Received>(received =>
{
var text = Encoding.UTF8.GetString(received.Data.ToArray()).Trim();
Console.WriteLine("Received '{0}' from remote address [{1}]", text, remote);
if (text == "exit")
Context.Stop(Self);
else
Sender.Tell(Tcp.Write.Create(received.Data));
});
Receive<Tcp.ConnectionClosed>(closed =>
{
Console.WriteLine("Stopped, remote connection [{0}] closed", remote);
Context.Stop(Self);
});
Receive<Terminated>(terminated =>
{
Console.WriteLine("Stopped, remote connection [{0}] died", remote);
Context.Stop(Self);
});
}
示例14: ConnectionResponse
public ConnectionResponse(IActorRef activeClientsActor, IActorRef hearbeatReceiver, IEnumerable<ConnectedClient> connectedClients, IActorRef messageHandler)
{
ActiveClientsActor = activeClientsActor;
HearbeatReceiver = hearbeatReceiver;
ConnectedClients = connectedClients;
MessageHandler = messageHandler;
}
示例15: PreStart
protected override void PreStart()
{
var errorSelector =
Context.ActorSelection(ClientActorPaths.ErrorDialogActor.Path)
.ResolveOne(TimeSpan.FromSeconds(1));
_errorActor = errorSelector.Result;
var settingsSelector =
Context.ActorSelection(ClientActorPaths.SettingsActor.Path)
.ResolveOne(TimeSpan.FromSeconds(1));
_settingsActor = settingsSelector.Result;
var clientsSelector =
Context.ActorSelection(ClientActorPaths.ClientsActor.Path)
.ResolveOne(TimeSpan.FromSeconds(1));
_clientsActor = clientsSelector.Result;
_messagingActor =
Context.ActorSelection(ClientActorPaths.ChatMessageRouter.Path)
.ResolveOne(TimeSpan.FromSeconds(1))
.Result;
Become(Disconnected);
base.PreStart();
}