枚举 Service Fabric Reliable ActorsEnumerate Service Fabric Reliable Actors

Reliable Actors 允许客户端枚举有关该服务托管的执行组件的元数据。The Reliable Actors service allows a client to enumerate metadata about the actors that the service is hosting. 由于执行组件服务是已分区的有状态服务,因此将按分区执行枚举。Because the actor service is a partitioned stateful service, enumeration is performed per partition. 因为每个分区可能包含许多执行组件,所以枚举以一组分页结果的形式返回。Because each partition might contain many actors, the enumeration is returned as a set of paged results. 将循环读取这些页面,直到读取所有页面。The pages are looped over until all pages are read. 以下示例演示了如何创建执行组件服务的一个分区中所有活动执行组件的列表:The following example shows how to create a list of all active actors in one partition of an actor service:

IActorService actorServiceProxy = ActorServiceProxy.Create(
    new Uri("fabric:/MyApp/MyService"), partitionKey);

ContinuationToken continuationToken = null;
List<ActorInformation> activeActors = new List<ActorInformation>();

do
{
    PagedResult<ActorInformation> page = await actorServiceProxy.GetActorsAsync(continuationToken, cancellationToken);

    activeActors.AddRange(page.Items.Where(x => x.IsActive));

    continuationToken = page.ContinuationToken;
}
while (continuationToken != null);
ActorService actorServiceProxy = ActorServiceProxy.create(
    new URI("fabric:/MyApp/MyService"), partitionKey);

ContinuationToken continuationToken = null;
List<ActorInformation> activeActors = new ArrayList<ActorInformation>();

do
{
    PagedResult<ActorInformation> page = actorServiceProxy.getActorsAsync(continuationToken);

    while(ActorInformation x: page.getItems())
    {
         if(x.isActive()){
              activeActors.add(x);
         }
    }

    continuationToken = page.getContinuationToken();
}
while (continuationToken != null);

后续步骤Next steps