Ejemplo n.º 1
0
 public void Init(string name, uint localId, ActorDescription desc, IServerNode node)
 {
     _name        = name;
     _localId     = localId;
     _fullName    = string.Format("Actor<Name:{0}, LocalId:{1}, Type:{2}>", name, localId, GetType().Name);
     _description = desc;
     Node         = node;
     Log          = LogManager.GetLogger(_fullName);
     Fiber        = new ServerFiber();
     _handlers    = new Dictionary <uint, NetContractHandler>();
     foreach (NetContractDescription implementedContract in desc.ImplementedContracts)
     {
         _handlers.Add(implementedContract.TypeId, new NetContractHandler(node.Dispatcher, implementedContract.TypeId, this));
     }
     OnCreated();
 }
Ejemplo n.º 2
0
        public Actor Create(IServerNode node, string name, uint primaryContractId)
        {
            Contract.Requires(name != null);
            Contract.Ensures(Contract.Result <Actor>() != null);

            ActorDescription desc = GetDescription(primaryContractId);

            Log.Debug("Creating {0} with name:{1}", desc, name);

            var  actor   = (Actor)Activator.CreateInstance(desc.Type);
            uint localId = (uint)Interlocked.Increment(ref _idCounter);

            actor.Init(name, localId, desc, node);

            lock (_fullLock)
            {
                _actorsByLocalId.Add(actor.LocalId, actor);
            }

            return(actor);
        }
Ejemplo n.º 3
0
        public ActorRepository(IOperationDispatcher dispatcher, IEnumerable <Actor> actorPrototypes)
        {
            Dispatcher = dispatcher;

            foreach (var entity in actorPrototypes)
            {
                Type type      = entity.GetType();
                var  attr      = type.GetAttribute <ActorAttribute>();
                var  contracts = new List <NetContractDescription>();
                foreach (Type netContractType in entity.GetType().GetInterfaces())
                {
                    uint typeId;
                    if (dispatcher.TryGetContractId(netContractType, out typeId))
                    {
                        contracts.Add(Dispatcher.GetContract(typeId));
                    }
                }
                var actorDescription = new ActorDescription(type, contracts, attr);
                _descriptionsByTypeId.Add(actorDescription.PrimaryContract.TypeId, actorDescription);

                Log.Info("Registered {0}", type, actorDescription);
            }
        }