Esempio n. 1
0
 /// <summary>
 /// Create a proxy to the actor service that is hosting the specified actor id and implementing specified type of the service interface.
 /// </summary>
 /// <typeparam name="TServiceInterface">The service interface implemented by the actor service.</typeparam>
 /// <param name="serviceUri">Uri of the actor service to connect to.</param>
 /// <param name="actorId">Id of the actor. The created proxy will be connected to the partition of the actor service hosting actor with this id.</param>
 /// <param name="listenerName">
 /// By default an actor service has only one listener for clients to connect to and communicate with.
 /// However it is possible to configure an actor service with more than one listeners, the listenerName parameter specifies the name of the listener to connect to.
 /// </param>
 /// <returns>A service proxy object that implements <see cref="IServiceProxy"/> and TServiceInterface.</returns>
 public TServiceInterface CreateActorServiceProxy <TServiceInterface>(Uri serviceUri,
                                                                      ActorId actorId,
                                                                      string listenerName = null) where TServiceInterface : IService
 {
     return(this.CreateActorServiceProxy <TServiceInterface>(
                serviceUri,
                actorId.GetPartitionKey(),
                listenerName));
 }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var id = new ActorId(Guid.NewGuid());

            var actor = ActorProxy.Create <IActor1>(id, url);
            //Console.WriteLine($"ActorId: {id} - P: {id.GetPartitionKey()}");
            var msg = $"ActorId: {id} - P: {id.GetPartitionKey()}";

            messages.Add(msg);
            this.textBox1.Lines = messages.ToArray();

            actor.DoWorkAsync();
        }
 public ActorServicePartitionClient(
     IServiceRemotingClientFactory remotingClientFactory,
     Uri serviceUri,
     ActorId actorId,
     string listenerName = null,
     OperationRetrySettings retrySettings = null)
     : base(remotingClientFactory, serviceUri,
            new ServicePartitionKey(actorId.GetPartitionKey()),
            TargetReplicaSelector.Default,
            listenerName,
            retrySettings)
 {
     this.ActorId            = actorId;
     this.messageBodyFactory = remotingClientFactory.GetRemotingMessageBodyFactory();
 }
Esempio n. 4
0
        private bool DoesActorBelongToThisPartition(ActorId actorId)
        {
            var partitionKey = actorId.GetPartitionKey();

            return(partitionKey >= this.lowKey && partitionKey <= this.highkey);
        }
Esempio n. 5
0
        public static async void DoWork()
        {
            for (var i = 1; i <= 10; i++)
            {
                var id = new ActorId(Guid.NewGuid());

                var actor = ActorProxy.Create <IActor1>(id, url);
                Console.WriteLine($"ActorId: {id} - P: {id.GetPartitionKey()}");

                actor.DoWorkAsync();
            }

            using (var client = new FabricClient())
            {
                var serviceName = new Uri(url2);
                var partitions  = await client.QueryManager.GetPartitionListAsync(serviceName);

                foreach (var partition in partitions)
                {
                    Debug.Assert(partition.PartitionInformation.Kind == ServicePartitionKind.Int64Range);
                    var partitionInformation = (Int64RangePartitionInformation)partition.PartitionInformation;
                    //var proxy = ServiceProxy.Create<IActor1>(serviceName, new ServicePartitionKey(partitionInformation.LowKey));
                    var actorServiceProxy = ActorServiceProxy.Create(new Uri(url2), partitionInformation.LowKey);

                    ContinuationToken continuationToken = null;

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

                        foreach (var actor in page.Items)
                        {
                            var msg = $"P: {partitionInformation.LowKey} - {actor.ActorId} - {actor.IsActive}";
                            Console.WriteLine(msg);
                        }

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

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


            //var partitionIds = new long[] { -3074457345618258603, 3074457345618258602, 9223372036854775807 };
            //var partitionIds = new string[] { "767931d4-e5b7-4e87-b8cf-185ae39ef9a5", "861ae5ff-648a-4e6d-928f-2729961cf6b3", "f9b8ebb8-a7e0-4c43-be84-28d106d58b7d" };
            //for (var i = 0; i < partitionIds.Length; i++)
            //{
            //    var pk = partitionIds[i];

            //    var actorServiceProxy = ActorServiceProxy.Create(new Uri(url2), pk.GetHashCode());

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

            //    do
            //    {
            //        PagedResult<ActorInformation> page = await actorServiceProxy.GetActorsAsync(continuationToken, CancellationToken.None);
            //        foreach (var actor in page.Items)
            //        {
            //            var msg = $"P: {pk} - {actor.ActorId} - {actor.IsActive}";
            //            Console.WriteLine(msg);
            //        }

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

            //        continuationToken = page.ContinuationToken;
            //    }
            //    while (continuationToken != null);


            //}
        }