/// <summary>
        /// Creates simple actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="componentContext">Dependency resolver</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected override void CreateSimpleActor(
            IActorContext context,
            Config actorConfig,
            IComponentContext componentContext,
            string currentPath,
            string pathName)
        {
            var childTypeName = actorConfig.GetString("type");

            if (string.IsNullOrWhiteSpace(childTypeName))
            {
                return;
            }

            var type = Type.GetType(childTypeName);

            if (type != null)
            {
                context.GetLogger()
                .Info(
                    // ReSharper disable FormatStringProblem
                    "{Type}: {NameSpaceName} initializing {ActorType} on {PathString}",
                    // ReSharper restore FormatStringProblem
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    type.Name,
                    pathName);

                if (type == typeof(NameSpaceActor) || type == typeof(NameSpaceForwarder))
                {
                    // this is done for tests, otherwise it would lead to CircularDependencyException
                    context.ActorOf(Props.Create(() => new NameSpaceForwarder(componentContext, this.testActor)), pathName);
                }
                else
                {
                    context.ActorOf(Context.System.DI().Props(type), pathName);
                }
            }
            else
            {
                context.GetLogger()
                .Error(
                    // ReSharper disable FormatStringProblem
                    "{Type}: {ClassTypeString} was not found for actor {NameSpaceName}/{PathString}",
                    // ReSharper restore FormatStringProblem
                    typeof(NameSpaceActor).Name,
                    childTypeName,
                    currentPath,
                    pathName);
            }
        }
        /// <summary>
        /// Creates simple actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="windsorContainer">Dependency resolver</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected override void CreateSimpleActor(
                    IActorContext context,
                    Config actorConfig,
                    IWindsorContainer windsorContainer,
                    string currentPath,
                    string pathName)
        {
            var childTypeName = actorConfig.GetString("type");
            if (string.IsNullOrWhiteSpace(childTypeName))
            {
                return;
            }

            var type = Type.GetType(childTypeName);
            if (type != null)
            {
                context.GetLogger()
                    .Info(
                        // ReSharper disable FormatStringProblem
                        "{Type}: {NameSpaceName} initializing {ActorType} on {PathString}",
                        // ReSharper restore FormatStringProblem
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        type.Name,
                        pathName);

                if (type == typeof(NameSpaceActor) || type == typeof(NameSpaceForwarder))
                {
                    // this is done for tests, otherwise it would lead to CircularDependencyException
                    context.ActorOf(Props.Create(() => new NameSpaceForwarder(windsorContainer, this.testActor)), pathName);
                }
                else
                {
                    context.ActorOf(Context.System.DI().Props(type), pathName);
                }
            }
            else
            {
                context.GetLogger()
                    .Error(
                        // ReSharper disable FormatStringProblem
                        "{Type}: {ClassTypeString} was not found for actor {NameSpaceName}/{PathString}",
                        // ReSharper restore FormatStringProblem
                        typeof(NameSpaceActor).Name,
                        childTypeName,
                        currentPath,
                        pathName);
            }
        }
Beispiel #3
0
 /// <summary>
 /// INTERNAL API.
 ///
 /// Used by actors / infrastructure that are starting up around the same time as the RemoteTransport
 /// is being booted, and therefore can cause problems similar to https://github.com/akkadotnet/akka.net/issues/4677 at startup.
 /// </summary>
 /// <param name="context">The context used to configure the logging adapter.</param>
 /// <param name="logMessageFormatter">The formatter used to format log messages.</param>
 /// <returns>The newly created logging adapter.</returns>
 internal static ILoggingAdapter GetLoggerStartup(this IActorContext context, ILogMessageFormatter logMessageFormatter = null)
 {
     try
     {
         return(context.GetLogger(logMessageFormatter));
     }
     catch // had a failure, don't want to propagate it. Just start the logger without remote context
     {
         var logSource = LogSource.Create(context);
         return(new BusLogging(context.System.EventStream, logSource.Source, logSource.Type, logMessageFormatter ?? new DefaultLogMessageFormatter()));
     }
 }
 public static void LogMessageDebug(this IActorContext context, object msg, string extra = "")
 {
     context.GetLogger()
     .Debug("{0}:{1}:{2}:{3}", context.Self.Path, msg.GetType().FullName, msg.ToString(),
            extra);
 }
Beispiel #5
0
        /// <summary>
        /// Creates cluster singleton proxy actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected virtual void CreateSingletonProxyActor(
            IActorContext context,
            Config actorConfig,
            string currentPath,
            string pathName)
        {
            var singletonName = actorConfig.GetString("singleton-name");
            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-name was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            var singletonManagerPath = actorConfig.GetString("singleton-path");
            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-path was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            var role = actorConfig.GetString("singleton-node-role");
            if (string.IsNullOrEmpty(role))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-node-role was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            context.GetLogger()
                .Info(
                    "{Type}: {NameSpaceName} initializing singleton proxy {SingletonManagerPath} / {SingletonName} for {PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    singletonManagerPath,
                    singletonName,
                    pathName);

            context.ActorOf(
                ClusterSingletonProxy.Props(
                    singletonManagerPath: singletonManagerPath,
                    settings:
                        new ClusterSingletonProxySettings(
                            singletonName,
                            role,
                            actorConfig.GetTimeSpan("singleton-identification-interval", TimeSpan.FromSeconds(1), false),
                            actorConfig.GetInt("buffer-size", 2048))),
                name: pathName);
        }
Beispiel #6
0
        /// <summary>
        /// Creates cluster singleton actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected virtual void CreateSingletonActor(
            IActorContext context,
            Config actorConfig,
            string currentPath,
            string pathName)
        {
            var childTypeName = actorConfig.GetString("type");
            if (string.IsNullOrWhiteSpace(childTypeName))
            {
                return;
            }

            var type = Type.GetType(childTypeName);
            if (type == null)
            {
                context.GetLogger()
                    .Error(
                        "{Type}: {ClassTypeString} was not found for actor {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        childTypeName,
                        currentPath,
                        pathName);
                return;
            }

            var singletonName = actorConfig.GetString("singleton-name");
            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-name was not defined for{NameSpaceName}/ {PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            var role = actorConfig.GetString("singleton-node-role");
            if (string.IsNullOrEmpty(role))
            {
                context.GetLogger()
                    .Error(
                        "{Type}: singleton-node-role was not defined for {NameSpaceName}/{PathString}",
                        typeof(NameSpaceActor).Name,
                        currentPath,
                        pathName);
                return;
            }

            context.GetLogger()
                .Info(
                    "{Type}: {NameSpaceName} initializing singleton {SingletonName} of type {ActorType} on {PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    singletonName,
                    type.Name,
                    pathName);

            context.ActorOf(
                ClusterSingletonManager.Props(
                    context.System.DI().Props(type),
                    new ClusterSingletonManagerSettings(
                        singletonName,
                        role,
                        actorConfig.GetTimeSpan("removal-margin", TimeSpan.FromSeconds(1), false),
                        actorConfig.GetTimeSpan("handover-retry-interval", TimeSpan.FromSeconds(5), false))),
                pathName);
        }
Beispiel #7
0
 /// <summary>
 /// Gets the Serilog specific logger that enables Serilog-style context enrichment
 /// and gives access to the
 /// <see cref="SerilogLoggingAdapterExtensions.ForContext(ILoggingAdapter, string, object, bool)"/>
 /// extension method
 /// </summary>
 /// <param name="actorContext"></param>
 /// <returns></returns>
 // public static ILoggingAdapter WithSerilog(this IActorContext actorContext)
 // {
 //     return actorContext.GetLogger<SerilogLoggingAdapter>();
 // }
 public static ILoggingAdapter WithSerilog(this IActorContext context) => context.GetLogger <SerilogLoggingAdapter>();
        /// <summary>
        /// Creates cluster singleton proxy actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected virtual void CreateSingletonProxyActor(
            IActorContext context,
            Config actorConfig,
            string currentPath,
            string pathName)
        {
            var singletonName = actorConfig.GetString("singleton-name");

            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                .Error(
                    "{Type}: singleton-name was not defined for {NameSpaceName}/{PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    pathName);
                return;
            }

            var singletonManagerPath = actorConfig.GetString("singleton-path");

            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                .Error(
                    "{Type}: singleton-path was not defined for {NameSpaceName}/{PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    pathName);
                return;
            }

            var role = actorConfig.GetString("singleton-node-role");

            if (string.IsNullOrEmpty(role))
            {
                context.GetLogger()
                .Error(
                    "{Type}: singleton-node-role was not defined for {NameSpaceName}/{PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    pathName);
                return;
            }

            context.GetLogger()
            .Info(
                "{Type}: {NameSpaceName} initializing singleton proxy {SingletonManagerPath} / {SingletonName} for {PathString}",
                typeof(NameSpaceActor).Name,
                currentPath,
                singletonManagerPath,
                singletonName,
                pathName);

            context.ActorOf(
                ClusterSingletonProxy.Props(
                    singletonManagerPath: singletonManagerPath,
                    settings:
                    new ClusterSingletonProxySettings(
                        singletonName,
                        role,
                        actorConfig.GetTimeSpan("singleton-identification-interval", TimeSpan.FromSeconds(1), false),
                        actorConfig.GetInt("buffer-size", 2048))),
                name: pathName);
        }
        /// <summary>
        /// Creates cluster singleton actor from config
        /// </summary>
        /// <param name="context">Current actor context (will create child actor)</param>
        /// <param name="actorConfig">Configuration to create from</param>
        /// <param name="currentPath">Parent (current) actor path</param>
        /// <param name="pathName">New actor's path name</param>
        protected virtual void CreateSingletonActor(
            IActorContext context,
            Config actorConfig,
            string currentPath,
            string pathName)
        {
            var childTypeName = actorConfig.GetString("type");

            if (string.IsNullOrWhiteSpace(childTypeName))
            {
                return;
            }

            var type = Type.GetType(childTypeName);

            if (type == null)
            {
                context.GetLogger()
                .Error(
                    "{Type}: {ClassTypeString} was not found for actor {NameSpaceName}/{PathString}",
                    typeof(NameSpaceActor).Name,
                    childTypeName,
                    currentPath,
                    pathName);
                return;
            }

            var singletonName = actorConfig.GetString("singleton-name");

            if (string.IsNullOrEmpty(singletonName))
            {
                context.GetLogger()
                .Error(
                    "{Type}: singleton-name was not defined for{NameSpaceName}/ {PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    pathName);
                return;
            }

            var role = actorConfig.GetString("singleton-node-role");

            if (string.IsNullOrEmpty(role))
            {
                context.GetLogger()
                .Error(
                    "{Type}: singleton-node-role was not defined for {NameSpaceName}/{PathString}",
                    typeof(NameSpaceActor).Name,
                    currentPath,
                    pathName);
                return;
            }

            context.GetLogger()
            .Info(
                "{Type}: {NameSpaceName} initializing singleton {SingletonName} of type {ActorType} on {PathString}",
                typeof(NameSpaceActor).Name,
                currentPath,
                singletonName,
                type.Name,
                pathName);

            context.ActorOf(
                ClusterSingletonManager.Props(
                    context.System.DI().Props(type),
                    new ClusterSingletonManagerSettings(
                        singletonName,
                        role,
                        actorConfig.GetTimeSpan("removal-margin", TimeSpan.FromSeconds(1), false),
                        actorConfig.GetTimeSpan("handover-retry-interval", TimeSpan.FromSeconds(5), false))),
                pathName);
        }
Beispiel #10
0
        public static void Log(this IActorContext context, Action <ILoggingAdapter> run)
        {
            var log = context.GetLogger(new SerilogLogMessageFormatter());

            run(log);
        }