Exemplo n.º 1
0
        public static ActorInterfaceMapping Of(Type type, IEnumerable <Assembly> assemblies)
        {
            var name = ActorTypeName.Of(type);

            Type @interface = null;
            Type @class     = null;

            if (type.IsClass)
            {
                @class     = type;
                @interface = ActorTypeName.CustomInterface(type);
            }

            if (type.IsInterface)
            {
                var classes = assemblies.SelectMany(a => a.GetTypes()
                                                    .Where(x => x.IsClass && type.IsAssignableFrom(x)))
                              .ToArray();

                if (classes.Length > 1)
                {
                    throw new InvalidOperationException(
                              $"Custom actor interface [{type.FullName}] is implemented by " +
                              $"multiple classes: {string.Join(" ; ", classes.Select(x => x.ToString()))}");
                }

                @interface = type;
                @class     = classes.Length != 0 ? classes[0] : null;
            }

            return(new ActorInterfaceMapping(name, @interface, @class));
        }
Exemplo n.º 2
0
        ActorTypeDeclaration(Type actor)
        {
            this.actor = actor;

            var path = ActorTypeName.Of(actor).Split(separator, StringSplitOptions.RemoveEmptyEntries);

            clazz = path.Last();

            namespaces = path.TakeWhile(x => x != clazz).ToList();
            namespaces.Insert(0, "Fun");
        }
Exemplo n.º 3
0
        internal ActorType(Type actor, Type endpoint)
        {
            this.actor = actor;

            Name             = ActorTypeName.Of(actor);
            Sticky           = StickyAttribute.IsApplied(actor);
            keepAliveTimeout = Sticky ? TimeSpan.FromDays(365 * 10) : KeepAliveAttribute.Timeout(actor);
            Invoker          = InvocationPipeline.Instance.GetInvoker(actor, InvokerAttribute.From(actor));

            interleavePredicate = ReentrantAttribute.MayInterleavePredicate(actor);

            dispatcher = new Dispatcher(actor);
            dispatchers.Add(actor, dispatcher);

            Init(endpoint);
        }
        public static ActorInterfaceMapping Of(Type type)
        {
            var name  = ActorTypeName.Of(type);
            var types = new List <Type> {
                type
            };

            var @interface = ActorTypeName.CustomInterface(type);

            if (@interface != null)
            {
                types.Add(@interface);
            }

            return(new ActorInterfaceMapping(name, types.ToArray()));
        }
Exemplo n.º 5
0
        internal static void Register(Assembly[] assemblies, string[] conventions)
        {
            var unregistered = assemblies
                               .SelectMany(x => x.ActorTypes())
                               .Where(x => !types.ContainsKey(ActorTypeName.Of(x)));

            using (Trace.Execution("Generation of actor implementation assemblies"))
            {
                var actors = ActorTypeDeclaration.Generate(assemblies.ToArray(), unregistered, conventions);

                foreach (var actor in actors)
                {
                    types.Add(actor.Name, actor);
                    typeCodes.Add(actor.TypeCode, actor);
                    typeCodes.Add(actor.Interface.TypeCode, actor);
                }
            }
        }
Exemplo n.º 6
0
 public static ActorInterface Of(Type type) => Of(ActorTypeName.Of(type));