Ejemplo n.º 1
0
        internal void AddMap(GrainInterfaceMap map)
        {
            foreach (var kvp in map.typeToInterfaceData)
            {
                if (!typeToInterfaceData.ContainsKey(kvp.Key))
                {
                    typeToInterfaceData.Add(kvp.Key, kvp.Value);
                }
            }

            foreach (var kvp in map.table)
            {
                if (!table.ContainsKey(kvp.Key))
                {
                    table.Add(kvp.Key, kvp.Value);
                }
            }

            foreach (var grainClassTypeCode in map.unordered)
            {
                unordered.Add(grainClassTypeCode);
            }

            foreach (var kvp in map.implementationIndex)
            {
                if (!implementationIndex.ContainsKey(kvp.Key))
                {
                    implementationIndex.Add(kvp.Key, kvp.Value);
                }
            }
        }
Ejemplo n.º 2
0
        public GrainTypeManager(
            ILocalSiloDetails siloDetails,
            IApplicationPartManager applicationPartManager,
            DefaultPlacementStrategy defaultPlacementStrategy,
            SerializationManager serializationManager,
            MultiClusterRegistrationStrategyManager multiClusterRegistrationStrategyManager,
            ILogger <GrainTypeManager> logger,
            IOptions <GrainClassOptions> grainClassOptions)
        {
            var localTestMode = siloDetails.SiloAddress.Endpoint.Address.Equals(IPAddress.Loopback);

            this.logger = logger;
            this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
            this.serializationManager     = serializationManager;
            this.multiClusterRegistrationStrategyManager = multiClusterRegistrationStrategyManager;
            grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap = grainInterfaceMap;
            grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();

            var grainClassFeature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>();

            this.grainTypes = CreateGrainTypeMap(grainClassFeature, grainClassOptions.Value);

            var grainInterfaceFeature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>();

            this.invokers = CreateInvokerMap(grainInterfaceFeature);
            this.InitializeInterfaceMap();
        }
Ejemplo n.º 3
0
        public GrainTypeManager(
            ILocalSiloDetails siloDetails,
            IApplicationPartManager applicationPartManager,
            PlacementStrategy defaultPlacementStrategy,
            SerializationManager serializationManager,
            ILogger <GrainTypeManager> logger,
            IOptions <GrainClassOptions> grainClassOptions)
        {
            this.logger = logger;
            this.defaultPlacementStrategy = defaultPlacementStrategy;
            this.serializationManager     = serializationManager;
            grainInterfaceMap             = new GrainInterfaceMap(this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap      = grainInterfaceMap;
            GrainTypeResolver             = grainInterfaceMap.GetGrainTypeResolver();
            grainInterfaceMapsBySilo      = new Dictionary <SiloAddress, GrainInterfaceMap>();

            var grainClassFeature = applicationPartManager.CreateAndPopulateFeature <GrainClassFeature>();

            this.grainTypes = CreateGrainTypeMap(grainClassFeature, grainClassOptions.Value);

            var grainInterfaceFeature = applicationPartManager.CreateAndPopulateFeature <GrainInterfaceFeature>();

            this.invokers = CreateInvokerMap(grainInterfaceFeature);
            this.InitializeInterfaceMap();
        }
Ejemplo n.º 4
0
 public GrainTypeManager(bool localTestMode, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager, MultiClusterRegistrationStrategyManager multiClusterRegistrationStrategyManager)
 {
     this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
     this.loader = loader;
     this.serializationManager = serializationManager;
     this.multiClusterRegistrationStrategyManager = multiClusterRegistrationStrategyManager;
     grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
     ClusterGrainInterfaceMap = grainInterfaceMap;
     grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();
 }
Ejemplo n.º 5
0
 public GrainTypeManager(bool localTestMode, IGrainFactory grainFactory)
 {
     this.grainFactory = grainFactory;
     grainInterfaceMap = new GrainInterfaceMap(localTestMode);
     lock (lockable)
     {
         if (Instance != null)
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         Instance = this;
     }
 }
Ejemplo n.º 6
0
 public GrainTypeManager(bool localTestMode, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy)
 {
     this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
     this.loader = loader;
     grainInterfaceMap = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
     lock (lockable)
     {
         if (Instance != null)
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         Instance = this;
     }
 }
Ejemplo n.º 7
0
 public GrainTypeManager(bool localTestMode)
 {
     grainInterfaceMap = new GrainInterfaceMap(localTestMode);
     lock (lockable)
     {
         if (Instance != null)
         {
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         }
         Instance = this;
     }
 }
Ejemplo n.º 8
0
        public GrainTypeManager(ILocalSiloDetails siloDetails, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager, MultiClusterRegistrationStrategyManager multiClusterRegistrationStrategyManager)
        {
            var localTestMode = siloDetails.SiloAddress.Endpoint.Address.Equals(IPAddress.Loopback);

            this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
            this.loader = loader;
            this.serializationManager = serializationManager;
            this.multiClusterRegistrationStrategyManager = multiClusterRegistrationStrategyManager;
            grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap = grainInterfaceMap;
            grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();
        }
Ejemplo n.º 9
0
 public GrainTypeManager(bool localTestMode, IGrainFactory grainFactory, SiloAssemblyLoader loader)
 {
     this.grainFactory = grainFactory;
     this.loader       = loader;
     grainInterfaceMap = new GrainInterfaceMap(localTestMode);
     lock (lockable)
     {
         if (Instance != null)
         {
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         }
         Instance = this;
     }
 }
Ejemplo n.º 10
0
 public GrainTypeManager(bool localTestMode, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy)
 {
     this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
     this.loader       = loader;
     grainInterfaceMap = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
     lock (lockable)
     {
         if (Instance != null)
         {
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         }
         Instance = this;
     }
 }
Ejemplo n.º 11
0
 public GrainTypeManager(bool localTestMode, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy, SerializationManager serializationManager)
 {
     this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
     this.loader = loader;
     this.serializationManager = serializationManager;
     grainInterfaceMap         = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
     ClusterGrainInterfaceMap  = grainInterfaceMap;
     grainInterfaceMapsBySilo  = new Dictionary <SiloAddress, GrainInterfaceMap>();
     lock (lockable)
     {
         if (Instance != null)
         {
             throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
         }
         Instance = this;
     }
 }
Ejemplo n.º 12
0
        public GrainTypeManager(SiloInitializationParameters silo, SiloAssemblyLoader loader, DefaultPlacementStrategy defaultPlacementStrategy)
        {
            var localTestMode = silo.SiloAddress.Endpoint.Address.Equals(IPAddress.Loopback);

            this.defaultPlacementStrategy = defaultPlacementStrategy.PlacementStrategy;
            this.loader              = loader;
            grainInterfaceMap        = new GrainInterfaceMap(localTestMode, this.defaultPlacementStrategy);
            ClusterGrainInterfaceMap = grainInterfaceMap;
            grainInterfaceMapsBySilo = new Dictionary <SiloAddress, GrainInterfaceMap>();
            lock (lockable)
            {
                if (Instance != null)
                {
                    throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");
                }
                Instance = this;
            }
        }
Ejemplo n.º 13
0
        private void RebuildFullGrainInterfaceMap()
        {
            var newClusterGrainInterfaceMap  = new GrainInterfaceMap(false, this.defaultPlacementStrategy);
            var newSupportedSilosByTypeCode  = new Dictionary <int, List <SiloAddress> >();
            var newSupportedSilosByInterface = new Dictionary <int, Dictionary <ushort, List <SiloAddress> > >();

            foreach (var kvp in grainInterfaceMapsBySilo)
            {
                newClusterGrainInterfaceMap.AddMap(kvp.Value);

                foreach (var supportedInterface in kvp.Value.SupportedInterfaces)
                {
                    var ifaceId = supportedInterface.InterfaceId;
                    var version = supportedInterface.InterfaceVersion;

                    var supportedSilosByVersion  = newSupportedSilosByInterface.GetValueOrAddNew(ifaceId);
                    var supportedSilosForVersion = supportedSilosByVersion.GetValueOrAddNew(version);
                    supportedSilosForVersion.Add(kvp.Key);
                }

                foreach (var grainClassData in kvp.Value.SupportedGrainClassData)
                {
                    var grainType = grainClassData.GrainTypeCode;

                    var supportedSilos = newSupportedSilosByTypeCode.GetValueOrAddNew(grainType);
                    supportedSilos.Add(kvp.Key);
                }
            }
            foreach (var silos in newSupportedSilosByTypeCode.Values)
            {
                // We need to sort this so the list of silos returned will
                // be the same accross all silos in the cluster
                silos.Sort();
            }
            ClusterGrainInterfaceMap  = newClusterGrainInterfaceMap;
            GrainTypeResolver         = ClusterGrainInterfaceMap.GetGrainTypeResolver();
            supportedSilosByTypeCode  = newSupportedSilosByTypeCode;
            supportedSilosByInterface = newSupportedSilosByInterface;
        }
Ejemplo n.º 14
0
        private void RebuildFullGrainInterfaceMap()
        {
            var newClusterGrainInterfaceMap = new GrainInterfaceMap(false, defaultPlacementStrategy);
            var newSupportedSilosByTypeCode = new Dictionary <int, IList <SiloAddress> >();

            newClusterGrainInterfaceMap.AddMap(grainInterfaceMap);
            foreach (var kvp in grainInterfaceMapsBySilo)
            {
                newClusterGrainInterfaceMap.AddMap(kvp.Value);
                foreach (var grainType in kvp.Value.SupportedGrainTypes)
                {
                    IList <SiloAddress> supportedSilos;
                    if (!newSupportedSilosByTypeCode.TryGetValue(grainType, out supportedSilos))
                    {
                        newSupportedSilosByTypeCode[grainType] = supportedSilos = new List <SiloAddress>();
                    }
                    supportedSilos.Add(kvp.Key);
                }
            }
            ClusterGrainInterfaceMap = newClusterGrainInterfaceMap;
            supportedSilosByTypeCode = newSupportedSilosByTypeCode;
        }
Ejemplo n.º 15
0
        public bool TryGetGrainClassData(Type interfaceType, out GrainClassData implementation, string grainClassNamePrefix)
        {
            implementation = null;
            GrainInterfaceData interfaceData;

            // First, try to find a non-generic grain implementation:
            if (this.typeToInterfaceData.TryGetValue(GrainInterfaceMap.GetTypeKey(interfaceType, false), out interfaceData) &&
                TryGetGrainClassData(interfaceData, out implementation, grainClassNamePrefix))
            {
                return(true);
            }

            // If a concrete implementation was not found and the interface is generic,
            // try to find a generic grain implementation:
            if (interfaceType.IsGenericType &&
                this.typeToInterfaceData.TryGetValue(GrainInterfaceMap.GetTypeKey(interfaceType, true), out interfaceData) &&
                TryGetGrainClassData(interfaceData, out implementation, grainClassNamePrefix))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 16
0
        private void RebuildFullGrainInterfaceMap()
        {
            var newClusterGrainInterfaceMap  = new GrainInterfaceMap(false, this.defaultPlacementStrategy);
            var newSupportedSilosByTypeCode  = new Dictionary <int, List <SiloAddress> >();
            var newSupportedSilosByInterface = new Dictionary <int, Dictionary <ushort, List <SiloAddress> > >();
            var newInterfaceVersions         = new Dictionary <int, HashSet <ushort> >();

            foreach (var kvp in grainInterfaceMapsBySilo)
            {
                newClusterGrainInterfaceMap.AddMap(kvp.Value);

                foreach (var supportedInterface in kvp.Value.SupportedInterfaces)
                {
                    var ifaceId = supportedInterface.InterfaceId;
                    var version = supportedInterface.InterfaceVersion;

                    var ifaceVersions = newInterfaceVersions.GetValueOrAddNew(ifaceId);
                    ifaceVersions.Add(version);

                    var supportedSilosByVersion  = newSupportedSilosByInterface.GetValueOrAddNew(ifaceId);
                    var supportedSilosForVersion = supportedSilosByVersion.GetValueOrAddNew(version);
                    supportedSilosForVersion.Add(kvp.Key);
                }

                foreach (var grainClassData in kvp.Value.SupportedGrainClassData)
                {
                    var grainType = grainClassData.GrainTypeCode;

                    var supportedSilos = newSupportedSilosByTypeCode.GetValueOrAddNew(grainType);
                    supportedSilos.Add(kvp.Key);
                }
            }
            ClusterGrainInterfaceMap  = newClusterGrainInterfaceMap;
            supportedSilosByTypeCode  = newSupportedSilosByTypeCode;
            supportedSilosByInterface = newSupportedSilosByInterface;
            supportedSilosCache       = new ConcurrentDictionary <Tuple <int, int, ushort>, List <SiloAddress> >();
        }
Ejemplo n.º 17
0
        // used for testing to (carefully!) allow two clients in the same process
        internal void StartInternal()
        {
            transport.Start();
            TraceLogger.MyIPEndPoint = transport.MyAddress.Endpoint; // transport.MyAddress is only set after transport is Started.
            CurrentActivationAddress = ActivationAddress.NewActivationAddress(transport.MyAddress, clientId);

            ClientStatistics = new ClientStatisticsManager(config);
            ClientStatistics.Start(config, statisticsProviderManager, transport, clientId)
                .WaitWithThrow(initTimeout);

            listeningCts = new CancellationTokenSource();
            var ct = listeningCts.Token;
            listenForMessages = true;

            // Keeping this thread handling it very simple for now. Just queue task on thread pool.
            Task.Factory.StartNew(() => 
                {
                    try
                    {
                        RunClientMessagePump(ct);
                    }
                    catch(Exception exc)
                    {
                        logger.Error(ErrorCode.Runtime_Error_100326, "RunClientMessagePump has thrown exception", exc);
                    }
                }
            );
            grainInterfaceMap = transport.GetTypeCodeMap(grainFactory).Result;
            StreamingInitialize();
        }
Ejemplo n.º 18
0
 internal void Start()
 {
     grainInterfaceMap = typeManager.GetTypeCodeMap();
 }
Ejemplo n.º 19
0
 internal void Start()
 {
     grainInterfaceMap = typeManager.GetTypeCodeMap();
 }
Ejemplo n.º 20
0
        internal void AddMap(GrainInterfaceMap map)
        {
            foreach (var kvp in map.typeToInterfaceData)
            {
                if (!typeToInterfaceData.ContainsKey(kvp.Key))
                {
                    typeToInterfaceData.Add(kvp.Key, kvp.Value);
                }
            }

            foreach (var kvp in map.table)
            {
                if (!table.ContainsKey(kvp.Key))
                {
                    table.Add(kvp.Key, kvp.Value);
                }
            }

            foreach (var grainClassTypeCode in map.unordered)
            {
                unordered.Add(grainClassTypeCode);
            }

            foreach (var kvp in map.implementationIndex)
            {
                if (!implementationIndex.ContainsKey(kvp.Key))
                {
                    implementationIndex.Add(kvp.Key, kvp.Value);
                }
            }
        }
Ejemplo n.º 21
0
 internal GrainClassData(int grainTypeCode, string grainClass, bool isGeneric, GrainInterfaceMap.GrainInterfaceData interfaceData, PlacementStrategy placement, MultiClusterRegistrationStrategy registrationStrategy)
 {
     GrainTypeCode = grainTypeCode;
     GrainClass = grainClass;
     this.isGeneric = isGeneric;
     this.interfaceData = interfaceData;
     genericClassNames = new Dictionary<string, string>(); // TODO: initialize only for generic classes
     placementStrategy = placement ?? PlacementStrategy.GetDefault();
     this.registrationStrategy = registrationStrategy ?? MultiClusterRegistrationStrategy.GetDefault();
 }