Example #1
0
        public static void Main(string[] args)
        {
            try
            {
                // Sets window size and cursor color
                Console.SetWindowSize(130, 30);
                Console.ForegroundColor = ConsoleColor.White;

                // Reads configuration settings
                ReadConfiguration();

                // Sets actor service URIs
                workerActorServiceUri    = ActorNameFormat.GetFabricServiceUri(typeof(IWorkerActor), ApplicationName);
                queueActorServiceUri     = ActorNameFormat.GetFabricServiceUri(typeof(IQueueActor), ApplicationName);
                processorActorServiceUri = ActorNameFormat.GetFabricServiceUri(typeof(IProcessorActor), ApplicationName);

                int i;
                while ((i = SelectOption()) != TestList.Count + 1)
                {
                    try
                    {
                        PrintTestParameters(TestList[i - 1].Name);
                        TestList[i - 1].Action();
                    }
                    catch (Exception ex)
                    {
                        PrintException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                PrintException(ex);
            }
        }
Example #2
0
        void IStateProviderReplica.Initialize(StatefulServiceInitializationParameters initializationParameters)
        {
            this.initiParams = initializationParameters;
            this.traceId     = ActorTrace.GetTraceIdForReplica(this.initiParams.PartitionId, this.initiParams.ReplicaId);

            var statefulServiceContext = new StatefulServiceContext(
                FabricRuntime.GetNodeContext(),
                this.initiParams.CodePackageActivationContext,
                this.initiParams.ServiceTypeName,
                this.initiParams.ServiceName,
                this.initiParams.InitializationData,
                this.initiParams.PartitionId,
                this.initiParams.ReplicaId);

            var stateManagerConfig = this.userDefinedStateManagerConfig;

            if (stateManagerConfig == null)
            {
                var actorImplType = this.actorTypeInformation.ImplementationType;

                stateManagerConfig = new ReliableStateManagerConfiguration(
                    ActorNameFormat.GetConfigPackageName(actorImplType),
                    ActorNameFormat.GetFabricServiceReplicatorSecurityConfigSectionName(actorImplType),
                    ActorNameFormat.GetFabricServiceReplicatorConfigSectionName(actorImplType));
            }

            this.stateManager = new ReliableStateManager(statefulServiceContext, stateManagerConfig);

            ReleaseAssert.AssertIfNull(this.onDataLossAsyncFunc, "onDataLossAsync event handler cannot be null.");
            this.stateManager.OnDataLossAsync = this.onDataLossAsyncFunc;

            this.stateManager.Initialize(this.initiParams);
        }
        internal static IActorStateProvider GetActorStateProviderOverride()
        {
            IActorStateProvider stateProvider = null;

            try
            {
                var configurationPackageName         = ActorNameFormat.GetConfigPackageName();
                var stateProviderOverrideSectionName = ActorNameFormat.GetActorStateProviderOverrideSectionName();
                var attributeTypeKey = ActorNameFormat.GetActorStateProviderOverrideKeyName();

                // Load the ActorStateProviderAttribute Type from the Configuration settings
                var context = FabricRuntime.GetActivationContext();
                var config  = context.GetConfigurationPackageObject(configurationPackageName);

                if ((config.Settings.Sections != null) &&
                    (config.Settings.Sections.Contains(stateProviderOverrideSectionName)))
                {
                    var section           = config.Settings.Sections[stateProviderOverrideSectionName];
                    var stateProviderType = section.Parameters[attributeTypeKey].Value;
                    stateProvider = Activator.CreateInstance(Type.GetType(stateProviderType)) as IActorStateProvider;
                }
            }
            catch (Exception)
            {
                // ignore
            }

            return(stateProvider);
        }
        /// <summary>
        /// This is used by Kvs and Volatile actor state provider.
        /// </summary>
        /// <param name="codePackage"></param>
        /// <param name="actorImplType"></param>
        /// <returns></returns>
        internal static ReplicatorSettings GetActorReplicatorSettings(CodePackageActivationContext codePackage, Type actorImplType)
        {
            var settings = ReplicatorSettings.LoadFrom(
                codePackage,
                ActorNameFormat.GetConfigPackageName(actorImplType),
                ActorNameFormat.GetFabricServiceReplicatorConfigSectionName(actorImplType));

            settings.SecurityCredentials = SecurityCredentials.LoadFrom(
                codePackage,
                ActorNameFormat.GetConfigPackageName(actorImplType),
                ActorNameFormat.GetFabricServiceReplicatorSecurityConfigSectionName(actorImplType));

            var nodeContext = FabricRuntime.GetNodeContext();
            var endpoint    = codePackage.GetEndpoint(ActorNameFormat.GetFabricServiceReplicatorEndpointName(actorImplType));

            settings.ReplicatorAddress = string.Format(
                CultureInfo.InvariantCulture,
                "{0}:{1}",
                nodeContext.IPAddressOrFQDN,
                endpoint.Port);

            if (!settings.MaxPrimaryReplicationQueueSize.HasValue)
            {
                settings.MaxPrimaryReplicationQueueSize = DefaultMaxPrimaryReplicationQueueSize;
            }

            if (!settings.MaxSecondaryReplicationQueueSize.HasValue)
            {
                settings.MaxSecondaryReplicationQueueSize = DefaultMaxSecondaryReplicationQueueSize;
            }

            return(settings);
        }
Example #5
0
        internal static FabricTransportRemotingListenerSettings GetActorListenerSettings(ActorService actorService)
        {
            FabricTransportRemotingListenerSettings listenerSettings;

            if (!FabricTransportRemotingListenerSettings.TryLoadFrom(ActorNameFormat.GetFabricServiceTransportSettingsSectionName(actorService.ActorTypeInformation.ImplementationType), out listenerSettings, (string)null))
            {
                listenerSettings = GetDefaultFabricTransportListenerSettings("TransportSettings");
            }
            return(listenerSettings);
        }
 /// <summary>
 /// Constructs a WCF based actor remoting listener.
 /// </summary>
 /// <param name="listenerBinding">WCF binding to use for the listener. If the listener binding is not specified or null,
 /// a default listener binding is created using <see cref="Microsoft.ServiceFabric.Services.Communication.Wcf.WcfUtility.CreateTcpListenerBinding"/> method which creates
 /// a <see cref="System.ServiceModel.NetTcpBinding"/> with no security.
 /// </param>
 /// <param name="actorService">The actor service.</param>
 public WcfActorServiceRemotingListener(
     ActorService actorService,
     Binding listenerBinding = null)
     : base(
         GetContext(actorService),
         new ActorServiceRemotingDispatcher(actorService),
         listenerBinding,
         ActorNameFormat.GetFabricServiceEndpointName(actorService.ActorTypeInformation.ImplementationType))
 {
 }
Example #7
0
 public WebFront(StatelessServiceContext context)
     : base(context)
 {
     this.LoadLiveCounterSettings();
     this.counter = new LivenessCounter <string>(expirationIntervalInSeconds, fuzzIntervalInSeconds);
     nodeName     = context.NodeContext.NodeName;
     serviceUri   = ActorNameFormat.GetFabricServiceUri(typeof(IContainerAggregatorActor));
     proxy        = ActorServiceProxy.Create <IContainerAggregator>(serviceUri, 0);
     reportTimer  = new Timer(this.Report, null, TimeSpan.FromSeconds(reportIntervalInSeconds), TimeSpan.FromSeconds(reportIntervalInSeconds));
 }
Example #8
0
        public void GetFabricService_PassServiceName_ReturnServiceName()
        {
            // Arrange
            string serviceName = "serviceName";

            // Act
            var result = ActorNameFormat.GetFabricServiceName(typeof(object), serviceName);

            // Assert
            result.Should().Be(serviceName);
        }
Example #9
0
        public void GetFabricService_NoServiceNameProvided_ReturnServiceName()
        {
            // Arrange
            string serviceName = "ObjectActorService";

            // Act
            var result = ActorNameFormat.GetFabricServiceName(typeof(object));

            // Assert
            result.Should().Be(serviceName);
        }
Example #10
0
        /// <summary>
        /// Creates a proxy to the actor object that implements an actor interface.
        /// </summary>
        /// <typeparam name="TActorInterface">
        /// The actor interface implemented by the remote actor object.
        /// The returned proxy object will implement this interface.
        /// </typeparam>
        /// <param name="actorId">Actor Id of the proxy actor object. Methods called on this proxy will result in requests
        /// being sent to the actor with this id.</param>
        /// <param name="applicationName">
        /// Name of the Service Fabric application that contains the actor service hosting the actor objects.
        /// This parameter can be null if the client is running as part of that same Service Fabric application. For more information, see Remarks.
        /// </param>
        /// <param name="serviceName">
        /// Name of the Service Fabric service as configured by <see cref="Microsoft.ServiceFabric.Actors.Runtime.ActorServiceAttribute"/> on the actor implementation.
        /// By default, the name of the service is derived from the name of the actor interface. However <see cref="Microsoft.ServiceFabric.Actors.Runtime.ActorServiceAttribute"/>
        /// is required when an actor implements more than one actor interfaces or an actor interface derives from another actor interface as the determination of the
        /// serviceName cannot be made automatically.
        /// </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>An actor proxy object that implements <see cref="IActorProxy"/> and TActorInterface.</returns>
        public TActorInterface CreateActorProxy <TActorInterface>(ActorId actorId, string applicationName = null,
                                                                  string serviceName = null, string listenerName = null) where TActorInterface : IActor
        {
            if (string.IsNullOrEmpty(applicationName))
            {
                applicationName = ActorNameFormat.GetCurrentFabricApplicationName();
            }
            var actorInterfaceType = typeof(TActorInterface);
            var serviceUri         = ActorNameFormat.GetFabricServiceUri(actorInterfaceType, applicationName, serviceName);

            return(this.CreateActorProxy <TActorInterface>(serviceUri, actorId, listenerName));
        }
 /// <summary>
 /// Constructs a WCF based actor remoting listener.
 /// </summary>
 /// <param name="listenerBinding">WCF binding to use for the listener. If the listener binding is not specified or null,
 /// a default listener binding is created using <see cref="Microsoft.ServiceFabric.Services.Communication.Wcf.WcfUtility.CreateTcpListenerBinding"/> method which creates
 /// a <see cref="System.ServiceModel.NetTcpBinding"/> with no security.
 /// </param>
 /// <param name="actorService">The actor service.</param>
 public WcfActorServiceRemotingListener(
     ActorService actorService,
     Binding listenerBinding = null)
     : base(
         GetContext(actorService),
         new ActorServiceRemotingDispatcher(actorService, new DataContractRemotingMessageFactory()),
         new ActorRemotingSerializationManager(new BasicDataContractSerializationProvider(),
                                               new BasicDataContractActorHeaderSerializer()),
         listenerBinding,
         ActorNameFormat.GetFabricServiceEndpointName(actorService.ActorTypeInformation.ImplementationType))
 {
 }
        internal static FabricTransportRemotingListenerSettings GetActorListenerSettings(ActorService actorService)
        {
            var sectionName = ActorNameFormat.GetFabricServiceTransportSettingsSectionName(
                actorService.ActorTypeInformation.ImplementationType);
            FabricTransportRemotingListenerSettings listenerSettings;
            var isSucceded = FabricTransportRemotingListenerSettings.TryLoadFrom(sectionName, out listenerSettings);

            if (!isSucceded)
            {
                listenerSettings = FabricTransportRemotingListenerSettings.GetDefault();
            }

            return(listenerSettings);
        }
Example #13
0
        public Task Subscribe(TSubscription subscription)
        {
            return(WithLock(async() =>
            {
                var topicId = subscription.GetTopicId();
                if (!_proxies.ContainsKey(topicId))
                {
                    var uri = ActorNameFormat.GetFabricServiceUri(typeof(ITopicActor));
                    var actor = _actorProxyFactory.CreateActorProxy <ITopicActor>(uri, new ActorId(topicId));
                    await actor.SubscribeAsync(this);

                    _proxies.Add(topicId, actor);
                }
            }));
        }
        public async Task Publish(TMessage message, TSubscription subscription)
        {
            var uri     = ActorNameFormat.GetFabricServiceUri(typeof(ITopicActor));
            var topicId = subscription.GetTopicId();
            var actor   = _actorProxyFactory.CreateActorProxy <ITopicActor>(uri, new ActorId(topicId));

            var serialisedMessage      = JsonConvert.SerializeObject(message);
            var serialisedSubscription = JsonConvert.SerializeObject(subscription);

            await actor.PublishMessage(new TopicActorMessage
            {
                Subscription = serialisedSubscription,
                Message      = serialisedMessage
            });
        }
        private static FabricTransportRemotingListenerSettings SetEndPointResourceName(
            FabricTransportRemotingListenerSettings listenerSettings, ActorService actorService)
        {
            if (listenerSettings == null)
            {
                listenerSettings = GetActorListenerSettings(actorService);
            }

            if (listenerSettings.EndpointResourceName.Equals(FabricTransportRemotingListenerSettings.DefaultEndpointResourceName))
            {
                listenerSettings.EndpointResourceName = ActorNameFormat.GetFabricServiceEndpointName(
                    actorService.ActorTypeInformation.ImplementationType);
            }
            return(listenerSettings);
        }
Example #16
0
        /// <summary>
        /// Registers an actor service with Service Fabric runtime. This allows the runtime to create instances of the replicas for the actor service.
        /// </summary>
        /// <typeparam name="TActor">Type implementing actor.</typeparam>
        /// <param name="actorServiceFactory">Delegate that create new actor service.</param>
        /// <param name="timeout">A timeout period after which the registration operation will be canceled.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A task that represents the asynchronous operation to register actor service with Service Fabric runtime.</returns>
        public static async Task RegisterActorAsync <TActor>(
            Func <StatefulServiceContext, ActorTypeInformation, ActorService> actorServiceFactory,
            TimeSpan timeout = default(TimeSpan),
            CancellationToken cancellationToken = default(CancellationToken))
            where TActor : ActorBase
        {
            actorServiceFactory.ThrowIfNull("actorServiceFactory");

            var actorType            = typeof(TActor);
            var actorServiceType     = actorServiceFactory.GetMethodInfo().ReturnType;
            var actorTypeInformation = ActorTypeInformation.Get(actorType);
            var serviceTypeName      = ActorNameFormat.GetFabricServiceTypeName(actorTypeInformation.ImplementationType);

            try
            {
                var customActorServiceFactory = new ActorServiceFactory(
                    actorTypeInformation,
                    new ActorMethodFriendlyNameBuilder(actorTypeInformation),
                    actorServiceFactory,
                    new ActorMethodDispatcherMap(actorTypeInformation));

                await ServiceRuntime.RegisterServiceAsync(
                    serviceTypeName,
                    context => customActorServiceFactory.CreateActorService(context),
                    timeout,
                    cancellationToken);

                ActorFrameworkEventSource.Writer.ActorTypeRegistered(
                    actorType.ToString(),
                    actorServiceType.ToString(),
                    NodeName);
            }
            catch (Exception e)
            {
                ActorFrameworkEventSource.Writer.ActorTypeRegistrationFailed(
                    e.ToString(),
                    actorType.ToString(),
                    actorServiceType.ToString(),
                    NodeName);
                throw;
            }
        }