public async Task SetGrainState <TGrain, TGrainState>(IGrain grain, TGrainState grainState, string storageProviderName)
            where TGrain : Grain <TGrainState>, IGrain
            where TGrainState : new()
        {
            EnsureClusterIsRunning();

            var storageProvider = ClusterServices.GetServiceByName <IGrainStorage>(storageProviderName);
            await storageProvider.WriteStateAsync(typeof(TGrain).FullName, grain as GrainReference, new GrainState <TGrainState>(grainState));
        }
        public async Task <TGrainState> GetGrainState <TGrain, TGrainState>(IGrain grain, string storageProviderName)
            where TGrain : Grain <TGrainState>, IGrain
            where TGrainState : new()
        {
            var storageProvider = ClusterServices.GetServiceByName <IGrainStorage>(storageProviderName);
            var grainState      = new GrainState <TGrainState>();
            await storageProvider.ReadStateAsync(typeof(TGrain).FullName, grain as GrainReference, grainState);

            return(grainState.State);
        }
 public void Setup()
 {
     clusterMonitor       = new Mock <IClusterMonitor>();
     scaleOutListener     = new Mock <IScaleOutListener>();
     heartBeatSender      = new Mock <IHeartBeatSender>();
     clusterHealthMonitor = new Mock <IClusterHealthMonitor>();
     clusterServices      = new ClusterServices(clusterMonitor.Object,
                                                scaleOutListener.Object,
                                                heartBeatSender.Object,
                                                clusterHealthMonitor.Object);
 }
        public Task <TResult> InvokeMethodAsync <TGrain, TResult>(Expression <Func <TGrain, TResult> > method, Guid primaryKey, string secondaryKey, params object[] arguments)
            where TGrain : IGrainWithGuidCompoundKey
        {
            EnsureClusterIsRunning();

            var grain = GrainFactory.GetGrain <TGrain>(primaryKey, secondaryKey);
            var grainReferenceRuntime = ClusterServices.GetRequiredService <IGrainReferenceRuntime>();
            var methodId = GetMethodId(method);

            return(grainReferenceRuntime.InvokeMethodAsync <TResult>((GrainReference)(object)grain, methodId, arguments, InvokeMethodOptions.None, null));
        }
        public Task WaitForStateOperationAsync <TGrain, TGrainState>(IGrain grain, MockMemoryStorageProvider.Operation operation, string storageProviderName, int calls = 1, object args = null)
            where TGrain : Grain <TGrainState>, IGrain
            where TGrainState : new()
        {
            var storageProvider = ClusterServices.GetServiceByName <IGrainStorage>(storageProviderName) as MockMemoryStorageProvider;

            if (storageProvider == null)
            {
                throw new Exception("Storage provider must be a MockMemoryStorageProvider");
            }
            return(storageProvider.GetOperationAwaitable(typeof(TGrain).FullName, grain as GrainReference, operation, calls, args));
        }
Beispiel #6
0
        public void Build()
        {
            AssertDependencyResolverSet();

            var configurationProvider             = new ConfigurationProvider(resolver.Resolve <KinoConfiguration>());
            var scaleOutSocketConfiguration       = configurationProvider.GetScaleOutConfiguration();
            var clusterMembershipConfiguration    = configurationProvider.GetClusterMembershipConfiguration();
            var clusterHealthMonitorConfiguration = configurationProvider.GetClusterHealthMonitorConfiguration();
            var heartBeatSenderConfiguration      = configurationProvider.GetHeartBeatSenderConfiguration();
            var socketConfiguration = configurationProvider.GetSocketConfiguration();
            var rendezvousEndpoints = configurationProvider.GetRendezvousEndpointsConfiguration();
            var socketFactory       = new SocketFactory(socketConfiguration);
            var logger = resolver.Resolve <ILogger>();
            var roundRobinDestinationList  = new RoundRobinDestinationList(logger);
            var internalRoutingTable       = new InternalRoutingTable(roundRobinDestinationList);
            var externalRoutingTable       = new ExternalRoutingTable(roundRobinDestinationList, logger);
            var localSocketFactory         = new LocalSocketFactory();
            var routerLocalSocket          = new LocalSocket <IMessage>();
            var internalRegistrationSocket = new LocalSocket <InternalRouteRegistration>();

#if NET47
            var instanceNameResolver      = resolver.Resolve <IInstanceNameResolver>() ?? new InstanceNameResolver();
            var performanceCounterManager = new PerformanceCounterManager <KinoPerformanceCounters>(instanceNameResolver,
                                                                                                    logger);
#else
            var performanceCounterManager = default(IPerformanceCounterManager <KinoPerformanceCounters>);
#endif

            var hashCodeProvider = resolver.Resolve <Func <HMAC> >() ?? (() => HMAC.Create("HMACMD5"));

            var securityProvider = resolver.Resolve <ISecurityProvider>()
                                   ?? new SecurityProvider(hashCodeProvider,
                                                           resolver.Resolve <IDomainScopeResolver>(),
                                                           resolver.Resolve <IDomainPrivateKeyProvider>());
            var heartBeatSenderConfigurationManager = new HeartBeatSenderConfigurationManager(heartBeatSenderConfiguration);
            var configurationStorage = resolver.Resolve <IConfigurationStorage <RendezvousClusterConfiguration> >()
                                       ?? new RendezvousClusterConfigurationReadonlyStorage(rendezvousEndpoints);
            var rendezvousCluster = new RendezvousCluster(configurationStorage);

            var scaleoutConfigurationProvider = new ServiceLocator <ScaleOutConfigurationManager,
                                                                    NullScaleOutConfigurationManager,
                                                                    IScaleOutConfigurationManager>(clusterMembershipConfiguration,
                                                                                                   new ScaleOutConfigurationManager(scaleOutSocketConfiguration),
                                                                                                   new NullScaleOutConfigurationManager())
                                                .GetService();
            var connectedPeerRegistry = new ConnectedPeerRegistry(clusterHealthMonitorConfiguration);
            var clusterHealthMonitor  = new ServiceLocator <ClusterHealthMonitor,
                                                            NullClusterHealthMonitor,
                                                            IClusterHealthMonitor>(clusterMembershipConfiguration,
                                                                                   new ClusterHealthMonitor(socketFactory,
                                                                                                            localSocketFactory,
                                                                                                            securityProvider,
                                                                                                            routerLocalSocket,
                                                                                                            connectedPeerRegistry,
                                                                                                            clusterHealthMonitorConfiguration,
                                                                                                            logger),
                                                                                   new NullClusterHealthMonitor())
                                        .GetService();

            var heartBeatSender = new ServiceLocator <HeartBeatSender,
                                                      NullHeartBeatSender,
                                                      IHeartBeatSender>(clusterMembershipConfiguration,
                                                                        new HeartBeatSender(socketFactory,
                                                                                            heartBeatSenderConfigurationManager,
                                                                                            scaleoutConfigurationProvider,
                                                                                            logger),
                                                                        new NullHeartBeatSender())
                                  .GetService();
            var scaleOutListener = new ServiceLocator <ScaleOutListener,
                                                       NullScaleOutListener,
                                                       IScaleOutListener>(clusterMembershipConfiguration,
                                                                          new ScaleOutListener(socketFactory,
                                                                                               routerLocalSocket,
                                                                                               scaleoutConfigurationProvider,
                                                                                               securityProvider,
                                                                                               performanceCounterManager,
                                                                                               logger),
                                                                          new NullScaleOutListener())
                                   .GetService();
            var autoDiscoverSender = new AutoDiscoverySender(rendezvousCluster,
                                                             socketFactory,
                                                             clusterMembershipConfiguration,
                                                             performanceCounterManager,
                                                             logger);
            var autoDiscoveryListener = new AutoDiscoveryListener(rendezvousCluster,
                                                                  socketFactory,
                                                                  scaleoutConfigurationProvider,
                                                                  clusterMembershipConfiguration,
                                                                  performanceCounterManager,
                                                                  routerLocalSocket,
                                                                  logger);
            var routeDiscovery = new RouteDiscovery(autoDiscoverSender,
                                                    scaleoutConfigurationProvider,
                                                    clusterMembershipConfiguration,
                                                    securityProvider,
                                                    logger);
            var clusterMonitor = new ServiceLocator <ClusterMonitor,
                                                     NullClusterMonitor,
                                                     IClusterMonitor>(clusterMembershipConfiguration,
                                                                      new ClusterMonitor(scaleoutConfigurationProvider,
                                                                                         autoDiscoverSender,
                                                                                         autoDiscoveryListener,
                                                                                         heartBeatSenderConfigurationManager,
                                                                                         routeDiscovery,
                                                                                         securityProvider,
                                                                                         clusterMembershipConfiguration,
                                                                                         logger),
                                                                      new NullClusterMonitor())
                                 .GetService();
            var clusterServices = new ClusterServices(clusterMonitor,
                                                      scaleOutListener,
                                                      heartBeatSender,
                                                      clusterHealthMonitor);
            var nodeRoutesRegistrar = new NodeRoutesRegistrar(clusterServices,
                                                              internalRoutingTable,
                                                              securityProvider);
            var internalMessageRouteRegistrationHandler = new InternalMessageRouteRegistrationHandler(clusterMonitor,
                                                                                                      internalRoutingTable,
                                                                                                      securityProvider);
            var serviceMessageHandlers = new IServiceMessageHandler[]
            {
                new ClusterMessageRoutesRequestHandler(securityProvider,
                                                       nodeRoutesRegistrar),
                new PingHandler(),
                new ExternalMessageRouteRegistrationHandler(externalRoutingTable,
                                                            securityProvider,
                                                            clusterHealthMonitor,
                                                            logger),
                new MessageRouteDiscoveryHandler(clusterMonitor,
                                                 internalRoutingTable,
                                                 securityProvider,
                                                 logger),
                new MessageRouteUnregistrationHandler(clusterHealthMonitor,
                                                      externalRoutingTable,
                                                      securityProvider,
                                                      logger),
                new NodeMessageRoutesRequestHandler(securityProvider,
                                                    nodeRoutesRegistrar),
                new NodeUnregistrationHandler(clusterHealthMonitor,
                                              externalRoutingTable,
                                              securityProvider),
                new UnreachableNodeUnregistrationHandler(clusterHealthMonitor,
                                                         externalRoutingTable)
            };
            var serviceMessageHandlerRegistry = new ServiceMessageHandlerRegistry(serviceMessageHandlers);
            messageRouter = new MessageRouter(socketFactory,
                                              internalRoutingTable,
                                              externalRoutingTable,
                                              scaleoutConfigurationProvider,
                                              clusterServices,
                                              serviceMessageHandlerRegistry,
                                              performanceCounterManager,
                                              securityProvider,
                                              routerLocalSocket,
                                              internalRegistrationSocket,
                                              internalMessageRouteRegistrationHandler,
                                              roundRobinDestinationList,
                                              logger);
            var actorHostFactory = new ActorHostFactory(securityProvider,
                                                        routerLocalSocket,
                                                        internalRegistrationSocket,
                                                        localSocketFactory,
                                                        logger);
            var callbackHandlerStack = new CallbackHandlerStack();
            createMessageHub = (keepLocal) => new MessageHub(callbackHandlerStack,
                                                             routerLocalSocket,
                                                             internalRegistrationSocket,
                                                             localSocketFactory,
                                                             scaleoutConfigurationProvider,
                                                             securityProvider,
                                                             logger,
                                                             keepLocal);
            var messageHub = createMessageHub(false);
            getMessageHub    = () => messageHub;
            actorHostManager = new ActorHostManager(actorHostFactory, logger);

            internalActorHostManager = new ActorHostManager(actorHostFactory, logger);
            var internalActor = new MessageRoutesActor(externalRoutingTable, internalRoutingTable);
            internalActorHostManager.AssignActor(internalActor);
            //
            isBuilt = true;
        }
 public IStreamProvider GetStreamProvider(string providerName)
 {
     return(ClusterServices.GetServiceByName <IStreamProvider>(providerName));
 }
        public IStreamProvider GetStreamProvider(string providerName)
        {
            EnsureClusterIsRunning();

            return(ClusterServices.GetServiceByName <IStreamProvider>(providerName));
        }