public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            string connectionStringName = config.Properties["ConnectionStringName"];

            if (string.IsNullOrEmpty(connectionStringName))
            {
                this.Log.Info("Starting RavenDB Storage Provider InMemory");
                return this.InMemoryMode();
            }

            var settings = ConfigurationManager.ConnectionStrings[connectionStringName];

            var connectionStringBuilder = new DbConnectionStringBuilder
            {
                ConnectionString = settings.ConnectionString
            };

            object url;
            if (connectionStringBuilder.TryGetValue("Url", out url))
            {
                this.Log.Info("Starting RavenDB Storage Provider attached to server {0}", url);
                return this.ServerMode(connectionStringName);
            }

            object dataDir;
            if (connectionStringBuilder.TryGetValue("DataDir", out dataDir))
            {
                this.Log.Info("Starting RavenDB Storage Provider embedded in directory {0}", dataDir);
                return this.LocalMode(connectionStringName);
            }

            return TaskDone.Done;
        }
Пример #2
0
        /// <summary> Init the factory.</summary>
        public virtual void Init(IProviderConfiguration config, string providerName, Logger logger)
        {
            if (config == null) throw new ArgumentNullException("config");
            if (!config.Properties.TryGetValue(DATA_CONNECTION_STRING, out dataConnectionString))
                throw new ArgumentException(String.Format("{0} property not set", DATA_CONNECTION_STRING));
            if (!config.Properties.TryGetValue(DEPLOYMENT_ID, out deploymentId))
                throw new ArgumentException(String.Format("{0} property not set", DEPLOYMENT_ID));
            
            string cacheSizeString;
            cacheSize = DEFAULT_CACHE_SIZE;
            if (config.Properties.TryGetValue(CACHE_SIZE_PARAM, out cacheSizeString))
            {
                if (!int.TryParse(cacheSizeString, out cacheSize))
                    throw new ArgumentException(String.Format("{0} invalid.  Must be int", CACHE_SIZE_PARAM));
            }
            string numQueuesString;
            numQueues = DEFAULT_NUM_QUEUES;
            if (config.Properties.TryGetValue(NUM_QUEUES_PARAM, out numQueuesString))
            {
                if (!int.TryParse(numQueuesString, out numQueues))
                    throw new ArgumentException(String.Format("{0} invalid.  Must be int", NUM_QUEUES_PARAM));
            }

            this.providerName = providerName;
            streamQueueMapper = new HashRingBasedStreamQueueMapper(numQueues, providerName);
            adapterCache = new SimpleQueueAdapterCache(this, cacheSize, logger);
        }
        public override async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            await base.Init(name, providerRuntime, config);

            long grainId = GrainCallBootstrapTestConstants.GrainId;
            int a = GrainCallBootstrapTestConstants.A;
            int b = GrainCallBootstrapTestConstants.B;
            ISimpleGrain grain = providerRuntime.GrainFactory.GetGrain<ISimpleGrain>(grainId, SimpleGrain.SimpleGrainNamePrefix);
            
            logger.Info("Setting A={0} on {1}", a, grainId);
            await grain.SetA(a);
            logger.Info("Setting B={0} on {1}", b, grainId);
            await grain.SetB(b);
            
            logger.Info("Getting AxB from {0}", grainId);
            int axb = await grain.GetAxB();
            logger.Info("Got AxB={0} from {1}", axb, grainId);
            
            int expected = a * b;
            int actual = axb;
            if (expected != actual) {
                throw new Exception(string.Format(
                    "Value returned to {0} by {1} should be {2} not {3}", 
                     GetType().Name, grainId, expected, actual));
            }
        }
Пример #4
0
        /// <summary> Init the factory.</summary>
        public virtual void Init(IProviderConfiguration config, string providerName, Logger logger, IServiceProvider serviceProvider)
        {
            if (config == null) throw new ArgumentNullException("config");
            if (!config.Properties.TryGetValue(DataConnectionStringPropertyName, out dataConnectionString))
                throw new ArgumentException(String.Format("{0} property not set", DataConnectionStringPropertyName));
            if (!config.Properties.TryGetValue(DeploymentIdPropertyName, out deploymentId))
                throw new ArgumentException(String.Format("{0} property not set", DeploymentIdPropertyName));

            cacheSize = SimpleQueueAdapterCache.ParseSize(config, CacheSizeDefaultValue);

            string numQueuesString;
            numQueues = NumQueuesDefaultValue;
            if (config.Properties.TryGetValue(NumQueuesPropertyName, out numQueuesString))
            {
                if (!int.TryParse(numQueuesString, out numQueues))
                    throw new ArgumentException(String.Format("{0} invalid.  Must be int", NumQueuesPropertyName));
            }

            this.providerName = providerName;
            streamQueueMapper = new HashRingBasedStreamQueueMapper(numQueues, providerName);
            adapterCache = new SimpleQueueAdapterCache(cacheSize, logger);
            if (StreamFailureHandlerFactory == null)
            {
                StreamFailureHandlerFactory =
                    qid => Task.FromResult<IStreamFailureHandler>(new NoOpStreamDeliveryFailureHandler(false));
            }
        }
    public async Task Init( string name, IProviderRuntime providerRuntime, IProviderConfiguration config )
    {
      Log = providerRuntime.GetLogger( this.GetType().Name );

      try
      {
        ConfigureJsonSerializerSettings( config );

        if( !config.Properties.ContainsKey( "DataConnectionString" ) )
        {
          throw new BadProviderConfigException(
            "The DataConnectionString setting has not been configured in the cloud role. Please add a DataConnectionString setting with a valid Azure Storage connection string." );
        }
        else
        {
          var account = CloudStorageAccount.Parse( config.Properties[ "DataConnectionString" ] );
          var blobClient = account.CreateCloudBlobClient();
          var containerName = config.Properties.ContainsKey( "ContainerName" ) ? config.Properties[ "ContainerName" ] : "grainstate";
          container = blobClient.GetContainerReference( containerName );
          await container.CreateIfNotExistsAsync();
        }
      }
      catch( Exception ex )
      {
        Log.Error( 0, ex.ToString(), ex );
        throw;
      }
    }
Пример #6
0
        /// <summary> Initialization function for this storage provider. </summary>
        /// <see cref="IProvider.Init"/>
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Log = providerRuntime.GetLogger("Storage.AzureBlobStorage");

            try
            {
                this.Name = name;
                ConfigureJsonSerializerSettings(config);

                if (!config.Properties.ContainsKey("DataConnectionString")) throw new BadProviderConfigException("The DataConnectionString setting has not been configured in the cloud role. Please add a DataConnectionString setting with a valid Azure Storage connection string.");

                var account = CloudStorageAccount.Parse(config.Properties["DataConnectionString"]);
                var blobClient = account.CreateCloudBlobClient();
                var containerName = config.Properties.ContainsKey("ContainerName") ? config.Properties["ContainerName"] : "grainstate";
                container = blobClient.GetContainerReference(containerName);
                await container.CreateIfNotExistsAsync().ConfigureAwait(false);

                Log.Info((int)AzureProviderErrorCode.AzureBlobProvider_InitProvider, "Init: Name={0} ServiceId={1} {2}", name, providerRuntime.ServiceId.ToString(), string.Join(" ", FormatPropertyMessage(config)));
                Log.Info((int)AzureProviderErrorCode.AzureBlobProvider_ParamConnectionString, "AzureBlobStorage Provider is using DataConnectionString: {0}", ConfigUtilities.PrintDataConnectionInfo(config.Properties["DataConnectionString"]));
            }
            catch (Exception ex)
            {
                Log.Error((int)AzureProviderErrorCode.AzureBlobProvider_InitProvider, ex.ToString(), ex);
                throw;
            }
        }
Пример #7
0
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            this.logger = providerRuntime.GetLogger("Dashboard");

            var router = new Router();
            new DashboardController(router, TaskScheduler.Current,  providerRuntime);

            var options = new StartOptions
            {
                ServerFactory = "Nowin",
                Port = config.Properties.ContainsKey("Port") ? int.Parse(config.Properties["Port"]) : 8080,
            };

            var username = config.Properties.ContainsKey("Username") ? config.Properties["Username"] : null;
            var password = config.Properties.ContainsKey("Password") ? config.Properties["Password"] : null;
            try
            {
                host = WebApp.Start(options, app => new WebServer(router, username, password).Configuration(app));
            }
            catch (Exception ex)
            {
                this.logger.Error(10001, ex.ToString());
            }

            this.logger.Verbose($"Dashboard listening on {options.Port}");

            this.profiler = new GrainProfiler(TaskScheduler.Current, providerRuntime);

            var dashboardGrain = providerRuntime.GrainFactory.GetGrain<IDashboardGrain>(0);
            return dashboardGrain.Init();
        }
        public void Init(IProviderConfiguration config, string providerName, Logger logger, IServiceProvider serviceProvider)
        {
            if (config == null) throw new ArgumentNullException(nameof(config));
            if (logger == null) throw new ArgumentNullException(nameof(logger));
            if (String.IsNullOrEmpty(providerName)) throw new ArgumentNullException(nameof(providerName));

            // Creating an options object with all the config values
            _options = new KafkaStreamProviderOptions(config);

            if (!_options.UsingExternalMetrics)
            {
                Metric.Config.WithHttpEndpoint($"http://localhost:{_options.MetricsPort}/");
            }

            if (!_options.IncludeMetrics)
            {
                Metric.Context("KafkaStreamProvider").Advanced.CompletelyDisableMetrics();
            }

            _providerName = providerName;
            _streamQueueMapper = new HashRingBasedStreamQueueMapper(_options.NumOfQueues, providerName);
            _logger = logger;
            _adapter = new KafkaQueueAdapter(_streamQueueMapper, _options, providerName, new KafkaBatchFactory(), _logger);
            _adapterCache = new TimedQueueAdapterCache(this, TimeSpan.FromSeconds(_options.CacheTimespanInSeconds), _options.CacheSize, _options.CacheNumOfBuckets, logger);
        }
Пример #9
0
        /// <summary> Initialization function for this storage provider. </summary>
        /// <see cref="IProvider.Init"/>
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Name = name;
            serviceId = providerRuntime.ServiceId.ToString();

            if (!config.Properties.ContainsKey(DATA_CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[DATA_CONNECTION_STRING]))
                throw new ArgumentException("DataConnectionString property not set");

            dataConnectionString = config.Properties["DataConnectionString"];

            if (config.Properties.ContainsKey(TABLE_NAME_PROPERTY))
                tableName = config.Properties[TABLE_NAME_PROPERTY];

            isDeleteStateOnClear = config.Properties.ContainsKey(DELETE_ON_CLEAR_PROPERTY) &&
                "true".Equals(config.Properties[DELETE_ON_CLEAR_PROPERTY], StringComparison.OrdinalIgnoreCase);

            Log = providerRuntime.GetLogger("Storage.AzureTableStorage." + id);

            var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}",
                Name, serviceId, tableName, isDeleteStateOnClear);

            if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY))
                useJsonFormat = "true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase);
            
            if (useJsonFormat)
            {
                jsonSettings = jsonSettings = OrleansJsonSerializer.SerializerSettings;
            }
            initMsg = String.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat);

            Log.Info((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, initMsg);
            Log.Info((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableStorage Provider is using DataConnectionString: {0}", ConfigUtilities.PrintDataConnectionInfo(dataConnectionString));
            tableDataManager = new GrainStateTableDataManager(tableName, dataConnectionString, Log);
            return tableDataManager.InitTableAsync();
        }
 public Task Init(Logger logger, IProviderConfiguration config, string providerName, int numQueues)
 {
     _logger = logger;
     _queues = new ConcurrentDictionary<QueueId, Queue<byte[]>>();
     IsInitialised = true;
     return TaskDone.Done;
 }
 public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     //process uncommit event message(store uncommit event message to event-store)
     //var eventDispatcher = GrainFactory.GetGrain<IEventStoreDispatcher>(0);
     GrainInternalEventHandlerProvider.RegisterInternalEventHandler(this.GetType().Assembly);
      
     return TaskDone.Done;
 }
Пример #12
0
 /// <summary>
 /// Initializes the provider during silo startup.
 /// </summary>
 /// <param name="name">The name of this provider instance.</param>
 /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param>
 /// <param name="config">Configuration info for this provider instance.</param>
 /// <returns>Completion promise for this operation.</returns>
 public override Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     this.Name = name;
     this.RootDirectory = config.Properties["RootDirectory"];
     if (string.IsNullOrWhiteSpace(RootDirectory)) throw new ArgumentException("RootDirectory property not set");
     DataManager = new GrainStateFileDataManager(RootDirectory);
     return base.Init(name, providerRuntime, config);
 }
 public virtual void PopulateFromProviderConfig(IProviderConfiguration providerConfiguration)
 {
     EventHubSettingsType = providerConfiguration.GetTypeProperty(EventHubConfigTypeName, null);
     if (string.IsNullOrWhiteSpace(StreamProviderName))
     {
         throw new ArgumentOutOfRangeException("providerConfiguration", "StreamProviderName not set.");
     }
 }
Пример #14
0
 // used only for testing
 internal async Task AddAndInitProvider(string name, IProvider provider, IProviderConfiguration config = null)
 {
     if (provider != null)
     {
         await provider.Init(name, this, config);
         statisticsProviderLoader.AddProvider(name, provider, config);
     }
 }
Пример #15
0
 public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     Name = name;
     logger = providerRuntime.GetLogger(GetType().Name);
     logger.Info("Init Name={0}", Name);
     Interlocked.Increment(ref initCount);
     return TaskDone.Done;
 }
Пример #16
0
        //---------------------------------------------------------------------
        public async Task Init(string name, IProviderRuntime provider_runtime, IProviderConfiguration config)
        {
            Console.Title = "GameCloud.IM v1.00.000 build20161014";
            Console.WriteLine("GameCloud.IM v1.00.000 build20161014");

            var startup = new IMStartup();
            await startup.Start();
        }
Пример #17
0
 /// <summary>
 /// Utility function to populate config from provider config
 /// </summary>
 /// <param name="providerConfiguration"></param>
 public virtual void PopulateFromProviderConfig(IProviderConfiguration providerConfiguration)
 {
     GeneratorConfigType = providerConfiguration.GetTypeProperty(GeneratorConfigTypeName, null);
     if (string.IsNullOrWhiteSpace(StreamProviderName))
     {
         throw new ArgumentOutOfRangeException("providerConfiguration", "StreamProviderName not set.");
     }
     TotalQueueCount = providerConfiguration.GetIntProperty(TotalQueueCountName, TotalQueueCountDefault);
 }
        /// <summary> Init the factory.</summary>
        public virtual void Init(IProviderConfiguration config, string providerName, Logger logger, IServiceProvider serviceProvider)
        {
            if (config == null) throw new ArgumentNullException("config");
            if (!config.Properties.TryGetValue(AzureQueueAdapterFactory.DATA_CONNECTION_STRING, out dataConnectionString))
                throw new ArgumentException(String.Format("{0} property not set", AzureQueueAdapterFactory.DATA_CONNECTION_STRING));
            if (!config.Properties.TryGetValue(QUEUE_NAME_STRING, out queueName))
                throw new ArgumentException(String.Format("{0} property not set", QUEUE_NAME_STRING));

            this.providerName = providerName;
        }
Пример #19
0
 /// <summary>
 /// Initializes the storage provider.
 /// </summary>
 /// <param name="name">The name of this provider instance.</param>
 /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param>
 /// <param name="config">Configuration info for this provider instance.</param>
 /// <returns>Completion promise for this operation.</returns>
 public override Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     this.Name = name;
     this.ConnectionString = config.Properties["ConnectionString"];
     this.Database = config.Properties["Database"];
     if (string.IsNullOrWhiteSpace(ConnectionString)) throw new ArgumentException("ConnectionString property not set");
     if (string.IsNullOrWhiteSpace(Database)) throw new ArgumentException("Database property not set");
     DataManager = new GrainStateMongoDataManager(Database, ConnectionString);
     return base.Init(name, providerRuntime, config);
 }
Пример #20
0
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Name = name;
            logger = providerRuntime.GetLogger("SqlStatisticsPublisher");

            //TODO: Orleans does not yet provide the type of database used (to, e.g., to load dlls), so SQL Server is assumed.            
            database = RelationalStorageUtilities.CreateGenericStorageInstance(WellKnownRelationalInvariants.SqlServer, config.Properties["ConnectionString"]);

            await InitOrleansQueriesAsync();           
        }
Пример #21
0
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            providerRuntime.SetInvokeInterceptor((method, request, grain, invoker) =>
            {
                RequestContext.Set("GrainInfo", 38);
                return invoker.Invoke(grain, request);
            });

            return Task.FromResult(0);
        }
 public async Task Init(Logger logger, IProviderConfiguration config, string providerName, int numQueues)
 {
     _logger = logger;
     _redisListBaseName = $"orleans-{providerName}-queue";
     ReadRedisConnectionParams(config);
     _connection = await ConnectionMultiplexer.ConnectAsync(_server);
     _database = _connection.GetDatabase(_databaseNum);
     logger.AutoInfo($"connection to Redis successful.");
     IsInitialised = true;
 }
 public void PopulateFromProviderConfig(IProviderConfiguration providerConfiguration)
 {
     EventHubSettingsType = providerConfiguration.GetTypeProperty(EventHubConfigTypeName, null);
     CheckpointSettingsType = providerConfiguration.GetTypeProperty(CheckpointSettingsTypeName, null);
     if (string.IsNullOrWhiteSpace(StreamProviderName))
     {
         throw new ArgumentOutOfRangeException("providerConfiguration", "StreamProviderName not set.");
     }
     CacheSizeMb = providerConfiguration.GetIntProperty(CacheSizeMbName, DefaultCacheSizeMb);
 }
Пример #24
0
        /// <summary>
        /// Initializes publisher
        /// </summary>
        /// <param name="name">Provider name</param>
        /// <param name="providerRuntime">Provider runtime API</param>
        /// <param name="config">Provider configuration</param>
        /// <returns></returns>
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Name = name;
            logger = providerRuntime.GetLogger("SqlStatisticsPublisher");

            string adoInvariant = AdoNetInvariants.InvariantNameSqlServer;
            if (config.Properties.ContainsKey("AdoInvariant"))
                adoInvariant = config.Properties["AdoInvariant"];

            orleansQueries = await RelationalOrleansQueries.CreateInstance(adoInvariant, config.Properties["ConnectionString"]);
        }
Пример #25
0
        public override async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            await base.Init(name, providerRuntime, config);

            string latencyParam = config.Properties[LATENCY_PARAM_STRING];
            latency = latencyParam == null ? DefaultLatency : TimeSpan.Parse(latencyParam);
            Log.Info("Init: Fixed Store Latency={0}", latency);

            mockCallsOnly = config.Properties.ContainsKey(MOCK_CALLS_PARAM_STRING) &&
                "true".Equals(config.Properties[MOCK_CALLS_PARAM_STRING], StringComparison.OrdinalIgnoreCase);
        }
Пример #26
0
    private void ConfigureJsonSerializerSettings( IProviderConfiguration config )
    {
      // By default, use automatic type name handling, simple assembly names, and no JSON formatting
      settings = new JsonSerializerSettings {
        TypeNameHandling = TypeNameHandling.Auto,
        TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple,
        Formatting = Formatting.None
      };

      if( config.Properties.ContainsKey( "SerializeTypeNames" ) )
      {
        bool serializeTypeNames = false;
        var serializeTypeNamesValue = config.Properties[ "SerializeTypeNames" ];
        bool.TryParse( serializeTypeNamesValue, out serializeTypeNames );
        if( serializeTypeNames )
        {
          settings.TypeNameHandling = TypeNameHandling.All;
        }
      }

      if (config.Properties.ContainsKey("PreserveReferencesHandling"))
      {
        bool preserveReferencesHandling;
        var preserveReferencesHandlingValue = config.Properties["PreserveReferencesHandling"];
        bool.TryParse(preserveReferencesHandlingValue, out preserveReferencesHandling);
        if (preserveReferencesHandling)
        {
          settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
        }
      }

      if( config.Properties.ContainsKey( "UseFullAssemblyNames" ) )
      {
        bool useFullAssemblyNames = false;
        var UseFullAssemblyNamesValue = config.Properties[ "UseFullAssemblyNames" ];
        bool.TryParse( UseFullAssemblyNamesValue, out useFullAssemblyNames );
        if( useFullAssemblyNames )
        {
          settings.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full;
        }
      }

      if( config.Properties.ContainsKey( "IndentJSON" ) )
      {
        bool indentJSON = false;
        var indentJSONValue = config.Properties[ "IndentJSON" ];
        bool.TryParse( indentJSONValue, out indentJSON );
        if( indentJSON )
        {
          settings.Formatting = Formatting.Indented;
        }
      }
    }
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            var system = ClusterActorSystem.Current;
            var providers = config.Properties["providers"].Split(';');

            StreamPubSubWrapper.Hook(providers, stream => 
                StreamSubscriptionMatcher
                    .Match(system, stream)
                    .Select(x => new StreamPubSubMatch(x.Receive))
                    .ToArray());

            return TaskDone.Done;
        }
        //---------------------------------------------------------------------
        public async Task Init(string name, IProviderRuntime provider_runtime, IProviderConfiguration config)
        {
            Console.Title = "GameCloud.IM.Test.App v1.00.000";

            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            Console.WriteLine("IMTestAppOrleansBootstrap.Init()");
            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            IMTestAppContext.Instance.Setup();

            var grain_player = provider_runtime.GrainFactory.GetGrain<IGrainIMTestAppPlayer>(Guid.NewGuid());
            await grain_player.Setup();

        }
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Name = name;
            logger = providerRuntime.GetLogger("SqlStatisticsPublisher");

            string adoInvariant = AdoNetInvariants.InvariantNameSqlServer;
            if (config.Properties.ContainsKey("AdoInvariant"))
                adoInvariant = config.Properties["AdoInvariant"];

            database = RelationalStorageUtilities.CreateGenericStorageInstance(adoInvariant, config.Properties["ConnectionString"]);

            queryConstants = await database.InitializeOrleansQueriesAsync(); 
        }
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Log = providerRuntime.GetLogger(this.GetType().FullName);

            ConnectString = config.Properties["DataConnectionString"];

            if (config.Properties.ContainsKey("Table"))
            {
                Table = config.Properties["Table"];
                CustomTable = true;
            }

            return TaskDone.Done;
        }
Пример #31
0
 /// <summary>
 /// Cria uma instancia com o provedor de configuração.
 /// </summary>
 /// <param name="providerConfiguration">Instancia do provedor de configuração.</param>
 /// <param name="isolationLevel"></param>
 public GDATransaction(IProviderConfiguration providerConfiguration, IsolationLevel isolationLevel) : base(providerConfiguration)
 {
     _isolationLevel = isolationLevel;
 }
Пример #32
0
 /// <summary>
 /// Cria uma instancia com o provedor de configuração.
 /// </summary>
 /// <param name="providerConfiguration">Instancia do provedor de configuração.</param>
 public GDATransaction(IProviderConfiguration providerConfiguration) : this(providerConfiguration, IsolationLevel.Unspecified)
 {
 }
Пример #33
0
 /// <summary>
 /// Utility function to populate config from provider config
 /// </summary>
 /// <param name="providerConfiguration"></param>
 public void PopulateFromProviderConfig(IProviderConfiguration providerConfiguration)
 {
     TotalQueueCount = providerConfiguration.GetIntProperty(TotalQueueCountName, TotalQueueCountDefault);
 }
Пример #34
0
        /// <summary>
        /// Customises the given serializer settings using provider configuration.
        /// Can be used by any provider, allowing the users to use a standard set of configuration attributes.
        /// </summary>
        /// <param name="settings">The settings to update.</param>
        /// <param name="config">The provider config.</param>
        /// <returns>The updated <see cref="JsonSerializerSettings" />.</returns>
        public static JsonSerializerSettings UpdateSerializerSettings(JsonSerializerSettings settings, IProviderConfiguration config)
        {
            bool             useFullAssemblyNames = config.GetBoolProperty(UseFullAssemblyNamesProperty, false);
            bool             indentJson           = config.GetBoolProperty(IndentJsonProperty, false);
            TypeNameHandling typeNameHandling     = config.GetEnumProperty(TypeNameHandlingProperty, settings.TypeNameHandling);

            return(UpdateSerializerSettings(settings, useFullAssemblyNames, indentJson, typeNameHandling));
        }
Пример #35
0
        public override async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            await base.Init(name, providerRuntime, config);

            serviceId = providerRuntime.ServiceId;
            siloId    = providerRuntime.SiloIdentity;
            logger.Info("Finished Init instance id {0} on silo {1} in service {2}", myId, siloId, serviceId);
        }
Пример #36
0
 /// <summary>
 /// Parce the size property from configuration
 /// </summary>
 /// <param name="config"></param>
 /// <param name="defaultSize"></param>
 /// <returns></returns>
 public static int ParseSize(IProviderConfiguration config, int defaultSize)
 {
     return(config.GetIntProperty(CacheSizePropertyName, defaultSize));
 }
Пример #37
0
 /// <summary>
 /// Retrieves an existing provider configuration
 /// </summary>
 /// <param name="providerTypeFullName">Full name of the stream provider type</param>
 /// <param name="providerName">Name of the stream provider</param>
 /// <param name="config">The provider configuration, if exists</param>
 /// <returns>True if a configuration for this provider already exists, false otherwise.</returns>
 public bool TryGetProviderConfiguration(string providerTypeFullName, string providerName, out IProviderConfiguration config)
 {
     return(ProviderConfigurationUtility.TryGetProviderConfiguration(ProviderConfigurations, providerTypeFullName, providerName, out config));
 }
Пример #38
0
 public static int ParseSize(IProviderConfiguration config, int defaultSize)
 {
     return(config.GetIntProperty(CACHE_SIZE_PARAM, defaultSize));
 }
Пример #39
0
 /// <summary>
 /// Initializes the storage provider.
 /// </summary>
 /// <param name="name">The name of this provider instance.</param>
 /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param>
 /// <param name="config">Configuration info for this provider instance.</param>
 /// <returns>Completion promise for this operation.</returns>
 public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     Log = providerRuntime.GetLogger(this.GetType().FullName);
     return(TaskDone.Done);
 }
Пример #40
0
        //---------------------------------------------------------------------
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            EntityMgr = new EntityMgr((byte)NodeType.Cell, NodeType.Cell.ToString());

            EntityMgr.regComponent <CellActor <DefActor> >();
            EntityMgr.regComponent <CellActorMirror <DefActorMirror> >();
            EntityMgr.regComponent <CellActorMirrorAi <DefActorMirrorAi> >();
            EntityMgr.regComponent <CellBag <DefBag> >();
            EntityMgr.regComponent <CellDesktop <DefDesktop> >();
            EntityMgr.regComponent <CellEquip <DefEquip> >();
            EntityMgr.regComponent <CellPlayer <DefPlayer> >();
            EntityMgr.regComponent <CellPlayerChat <DefPlayerChat> >();
            EntityMgr.regComponent <CellPlayerDesktop <DefPlayerDesktop> >();
            EntityMgr.regComponent <CellPlayerFriend <DefPlayerFriend> >();
            EntityMgr.regComponent <CellPlayerLobby <DefPlayerLobby> >();
            EntityMgr.regComponent <CellPlayerMailBox <DefPlayerMailBox> >();
            EntityMgr.regComponent <CellPlayerTask <DefPlayerTask> >();
            EntityMgr.regComponent <CellPlayerTrade <DefPlayerTrade> >();
            EntityMgr.regComponent <CellPlayerRanking <DefPlayerRanking> >();
            EntityMgr.regComponent <CellStatus <DefStatus> >();

            EntityMgr.regEntityDef <EtDesktop>();
            EntityMgr.regEntityDef <EtPlayer>();
            EntityMgr.regEntityDef <EtPlayerMirror>();

            DbClientCouchbase = new DbClientCouchbase();
            EntityCouchbase et_couchbase = new EntityCouchbase(EntityMgr, DbClientCouchbase.Bucket);

            // 创建视图
            //var couchbase_mgr = DbClientCouchbase.Instance.Bucket.CreateManager("Cragon", "123321");
            //var get = couchbase_mgr.GetDesignDocument("dev_team");
            //if (!get.Success)
            //{
            //    var design_doc = File.ReadAllText(@"..\\..\\..\\Media\\Fishing\\CouchbaseView\\dev_team.json");
            //    var inserted = couchbase_mgr.InsertDesignDocument("dev_team", design_doc);
            //    if (inserted.Success)
            //    {
            //        EbLog.Note("Created 'team' design doc.  Success");
            //    }
            //    else
            //    {
            //        EbLog.Note("Created 'team' design doc.  Failed, Msg=" + inserted.Message);
            //    }
            //}

            // 初始化DataMgr
            {
                string path_media  = ServerPath.getPathMediaRoot();
                string db_filename = Path.Combine(path_media, "Fishing\\Config\\Fishing.db");
                EbLog.Note(db_filename);
                TbDataMgr.setup(db_filename);
            }

            // 初始化单位模块
            UnitSys.setup(false);

            // 初始化效果系统
            EffectSys.regEffect(new EffectCreateStatus());
            EffectSys.regEffect(new EffectStatus1());
            EffectSys.regEffect(new EffectStatus2());
            EffectSys.regEffect(new EffectStatusCreator1());
            EffectSys.regEffect(new EffectStatusCreator2());
            EffectSys.regEffect(new EffectTakeoffEquip());
            EffectSys.regEffect(new EffectTakeonEquip());
            EffectSys.regEffect(new EffectUseConsumable());
            EffectSys.regEffect(new EffectUseSkillBook());

            // 初始化CellApp
            CellApp = new CellApp();

            //// 加载所有Bot
            //var map_databot = EbDataMgr.Instance.getMapData<TbDataBot>();
            //foreach (var i in map_databot)
            //{
            //    TbDataBot data_bot = (TbDataBot)i.Value;

            //    //var grain_player = CellPlayerFactory.GetGrain(new Guid(data_bot.EtGuid));
            //    //var grain_player = GrainFactory.GetGrain<ICellPlayer>(new Guid(data_bot.EtGuid));
            //    //await grain_player.botNewAndEnterWorld(data_bot.NickName);
            //}

            //return TaskDone.Done;
        }
Пример #41
0
        //---------------------------------------------------------------------
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            EntityMgr = new EntityMgr((byte)NodeType.Cell, NodeType.Cell.ToString());

            EntityMgr.regComponent <CellActor <DefActor> >();
            EntityMgr.regComponent <CellActorMirror <DefActorMirror> >();
            EntityMgr.regComponent <CellActorMirrorAi <DefActorMirrorAi> >();
            EntityMgr.regComponent <CellBag <DefBag> >();
            EntityMgr.regComponent <CellDesktop <DefDesktop> >();
            EntityMgr.regComponent <CellEquip <DefEquip> >();
            EntityMgr.regComponent <CellPlayer <DefPlayer> >();
            EntityMgr.regComponent <CellPlayerChat <DefPlayerChat> >();
            EntityMgr.regComponent <CellPlayerDesktop <DefPlayerDesktop> >();
            EntityMgr.regComponent <CellPlayerFriend <DefPlayerFriend> >();
            EntityMgr.regComponent <CellPlayerLobby <DefPlayerLobby> >();
            EntityMgr.regComponent <CellPlayerMailBox <DefPlayerMailBox> >();
            EntityMgr.regComponent <CellPlayerTask <DefPlayerTask> >();
            EntityMgr.regComponent <CellPlayerTrade <DefPlayerTrade> >();
            EntityMgr.regComponent <CellPlayerRanking <DefPlayerRanking> >();
            EntityMgr.regComponent <CellStatus <DefStatus> >();

            EntityMgr.regEntityDef <EtDesktop>();
            EntityMgr.regEntityDef <EtPlayer>();
            EntityMgr.regEntityDef <EtPlayerMirror>();

            // 初始化DataMgr
            {
                string path_media  = ServerPath.getPathMediaRoot();
                string db_filename = Path.Combine(path_media, "Fishing\\Config\\Fishing.db");
                EbLog.Note(db_filename);
                TbDataMgr.setup(db_filename);
            }

            // 初始化单位模块
            UnitSys.setup(false);

            // 初始化效果系统
            EffectSys.regEffect(new EffectCreateStatus());
            EffectSys.regEffect(new EffectStatus1());
            EffectSys.regEffect(new EffectStatus2());
            EffectSys.regEffect(new EffectStatusCreator1());
            EffectSys.regEffect(new EffectStatusCreator2());
            EffectSys.regEffect(new EffectTakeoffEquip());
            EffectSys.regEffect(new EffectTakeonEquip());
            EffectSys.regEffect(new EffectUseConsumable());
            EffectSys.regEffect(new EffectUseSkillBook());

            // 初始化CellApp
            CellApp = new CellApp();

            //// 加载所有Bot
            //var map_databot = EbDataMgr.Instance.getMapData<TbDataBot>();
            //foreach (var i in map_databot)
            //{
            //    TbDataBot data_bot = (TbDataBot)i.Value;

            //    //var grain_player = CellPlayerFactory.GetGrain(new Guid(data_bot.EtGuid));
            //    //var grain_player = GrainFactory.GetGrain<ICellPlayer>(new Guid(data_bot.EtGuid));
            //    //await grain_player.botNewAndEnterWorld(data_bot.NickName);
            //}

            return(TaskDone.Done);
        }
Пример #42
0
        private async Task SendAndReceiveFromQueueAdapter(IQueueAdapterFactory adapterFactory, IProviderConfiguration config)
        {
            IQueueAdapter adapter = await adapterFactory.CreateAdapter();

            IQueueAdapterCache cache = adapterFactory.GetQueueAdapterCache();

            // Create receiver per queue
            IStreamQueueMapper mapper = adapterFactory.GetStreamQueueMapper();
            Dictionary <QueueId, IQueueAdapterReceiver> receivers = mapper.GetAllQueues().ToDictionary(queueId => queueId, adapter.CreateReceiver);
            Dictionary <QueueId, IQueueCache>           caches    = mapper.GetAllQueues().ToDictionary(queueId => queueId, cache.CreateQueueCache);

            await Task.WhenAll(receivers.Values.Select(receiver => receiver.Initialize(TimeSpan.FromSeconds(5))));

            // test using 2 streams
            Guid streamId1 = Guid.NewGuid();
            Guid streamId2 = Guid.NewGuid();

            int receivedBatches = 0;
            var streamsPerQueue = new ConcurrentDictionary <QueueId, HashSet <IStreamIdentity> >();

            // reader threads (at most 2 active queues because only two streams)
            var work = new List <Task>();

            foreach (KeyValuePair <QueueId, IQueueAdapterReceiver> receiverKvp in receivers)
            {
                QueueId queueId  = receiverKvp.Key;
                var     receiver = receiverKvp.Value;
                var     qCache   = caches[queueId];
                Task    task     = Task.Factory.StartNew(() =>
                {
                    while (receivedBatches < NumBatches)
                    {
                        var messages = receiver.GetQueueMessagesAsync(SQSStorage.MAX_NUMBER_OF_MESSAGE_TO_PEAK).Result.ToArray();
                        if (!messages.Any())
                        {
                            continue;
                        }
                        foreach (var message in messages.Cast <SQSBatchContainer>())
                        {
                            streamsPerQueue.AddOrUpdate(queueId,
                                                        id => new HashSet <IStreamIdentity> {
                                new StreamIdentity(message.StreamGuid, message.StreamGuid.ToString())
                            },
                                                        (id, set) =>
                            {
                                set.Add(new StreamIdentity(message.StreamGuid, message.StreamGuid.ToString()));
                                return(set);
                            });
                            output.WriteLine("Queue {0} received message on stream {1}", queueId,
                                             message.StreamGuid);
                            Assert.Equal(NumMessagesPerBatch / 2, message.GetEvents <int>().Count());    // "Half the events were ints"
                            Assert.Equal(NumMessagesPerBatch / 2, message.GetEvents <string>().Count()); // "Half the events were strings"
                        }
                        Interlocked.Add(ref receivedBatches, messages.Length);
                        qCache.AddToCache(messages);
                    }
                });
                work.Add(task);
            }

            // send events
            List <object> events = CreateEvents(NumMessagesPerBatch);

            work.Add(Task.Factory.StartNew(() => Enumerable.Range(0, NumBatches)
                                           .Select(i => i % 2 == 0 ? streamId1 : streamId2)
                                           .ToList()
                                           .ForEach(streamId =>
                                                    adapter.QueueMessageBatchAsync(streamId, streamId.ToString(),
                                                                                   events.Take(NumMessagesPerBatch).ToArray(), null, RequestContext.Export(this.fixture.SerializationManager)).Wait())));
            await Task.WhenAll(work);

            // Make sure we got back everything we sent
            Assert.Equal(NumBatches, receivedBatches);

            // check to see if all the events are in the cache and we can enumerate through them
            StreamSequenceToken firstInCache = new EventSequenceTokenV2(0);

            foreach (KeyValuePair <QueueId, HashSet <IStreamIdentity> > kvp in streamsPerQueue)
            {
                var receiver = receivers[kvp.Key];
                var qCache   = caches[kvp.Key];

                foreach (IStreamIdentity streamGuid in kvp.Value)
                {
                    // read all messages in cache for stream
                    IQueueCacheCursor cursor         = qCache.GetCacheCursor(streamGuid, firstInCache);
                    int messageCount                 = 0;
                    StreamSequenceToken tenthInCache = null;
                    StreamSequenceToken lastToken    = firstInCache;
                    while (cursor.MoveNext())
                    {
                        Exception ex;
                        messageCount++;
                        IBatchContainer batch = cursor.GetCurrent(out ex);
                        output.WriteLine("Token: {0}", batch.SequenceToken);
                        Assert.True(batch.SequenceToken.CompareTo(lastToken) >= 0, $"order check for event {messageCount}");
                        lastToken = batch.SequenceToken;
                        if (messageCount == 10)
                        {
                            tenthInCache = batch.SequenceToken;
                        }
                    }
                    output.WriteLine("On Queue {0} we received a total of {1} message on stream {2}", kvp.Key, messageCount, streamGuid);
                    Assert.Equal(NumBatches / 2, messageCount);
                    Assert.NotNull(tenthInCache);

                    // read all messages from the 10th
                    cursor       = qCache.GetCacheCursor(streamGuid, tenthInCache);
                    messageCount = 0;
                    while (cursor.MoveNext())
                    {
                        messageCount++;
                    }
                    output.WriteLine("On Queue {0} we received a total of {1} message on stream {2}", kvp.Key, messageCount, streamGuid);
                    const int expected = NumBatches / 2 - 10 + 1; // all except the first 10, including the 10th (10 + 1)
                    Assert.Equal(expected, messageCount);
                }
            }
        }
Пример #43
0
 internal static bool TryGetProviderConfiguration(IDictionary <string, ProviderCategoryConfiguration> providerConfigurations,
                                                  string providerTypeFullName, string providerName, out IProviderConfiguration config)
 {
     foreach (ProviderCategoryConfiguration category in providerConfigurations.Values)
     {
         foreach (IProviderConfiguration providerConfig in category.Providers.Values)
         {
             if (providerConfig.Type.Equals(providerTypeFullName) && providerConfig.Name.Equals(providerName))
             {
                 config = providerConfig;
                 return(true);
             }
         }
     }
     config = null;
     return(false);
 }
Пример #44
0
        /// <summary> Initialization function for this storage provider. </summary>
        /// <see cref="IProvider.Init"/>
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("The parameter must contain characters", nameof(name));
            }

            if (providerRuntime == null)
            {
                throw new ArgumentNullException(nameof(providerRuntime));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (!config.Properties.ContainsKey(DataConnectionStringPropertyName))
            {
                throw new BadProviderConfigException($"The {DataConnectionStringPropertyName} setting has not been configured. Add a {DataConnectionStringPropertyName} setting with a valid connection string.");
            }

            this.serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>();

            //NOTE: StorageSerializationPicker should be defined outside and given as a parameter in constructor or via Init in IProviderConfiguration perhaps.
            //Currently this limits one's options to much to the current situation of providing only one serializer for serialization and deserialization
            //with no regard to state update or serializer changes. Maybe have this serialized as a JSON in props and read via a key?
            StorageSerializationPicker = new DefaultRelationalStoragePicker(this.ConfigureDeserializers(config, providerRuntime), this.ConfigureSerializers(config, providerRuntime));

            //NOTE: Currently there should be only one pair of providers given. That is, only UseJsonFormatPropertyName, UseXmlFormatPropertyName or UseBinaryFormatPropertyName.
            if (StorageSerializationPicker.Deserializers.Count > 1 || StorageSerializationPicker.Serializers.Count > 1)
            {
                throw new ArgumentException("Configuration error, only one serializer and deserializer should be given.", nameof(config));
            }

            if (StorageSerializationPicker.Deserializers.Count == 0 || StorageSerializationPicker.Serializers.Count == 0)
            {
                StorageSerializationPicker.Deserializers.Add(new OrleansStorageDefaultBinaryDeserializer(this.serializationManager, UseBinaryFormatPropertyName));
                StorageSerializationPicker.Serializers.Add(new OrleansStorageDefaultBinarySerializer(this.serializationManager, UseBinaryFormatPropertyName));
            }

            var connectionInvariant = config.Properties.ContainsKey(DataConnectionInvariantPropertyName) ? config.Properties[DataConnectionInvariantPropertyName] : DefaultAdoInvariantInvariantPropertyName;

            Storage   = RelationalStorage.CreateInstance(connectionInvariant, config.Properties[DataConnectionStringPropertyName]);
            ServiceId = providerRuntime.ServiceId.ToString();
            var queries = await Storage.ReadAsync(DefaultInitializationQuery, command => { }, (selector, resultSetCount, token) =>
            {
                return(Task.FromResult(Tuple.Create(selector.GetValue <string>("QueryKey"), selector.GetValue <string>("QueryText"))));
            }).ConfigureAwait(false);

            CurrentOperationalQueries = new RelationalStorageProviderQueries(
                queries.Single(i => i.Item1 == "WriteToStorageKey").Item2,
                queries.Single(i => i.Item1 == "ReadFromStorageKey").Item2,
                queries.Single(i => i.Item1 == "ClearStorageKey").Item2);

            var loggerFactory = providerRuntime.ServiceProvider.GetService <ILoggerFactory>();

            this.logger = loggerFactory.CreateLogger <AdoNetStorageProvider>();
            Name        = name;

            logger.Info((int)RelationalStorageProviderCodes.RelationalProviderInitProvider, $"Initialized storage provider: ServiceId={ServiceId} ProviderName={Name} Invariant={Storage.InvariantName} ConnectionString={Storage.ConnectionString}.");
        }
Пример #45
0
        public override async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            await base.Init(name, providerRuntime, config);

            long         grainId = GrainCallBootstrapTestConstants.GrainId;
            int          a       = GrainCallBootstrapTestConstants.A;
            int          b       = GrainCallBootstrapTestConstants.B;
            ISimpleGrain grain   = providerRuntime.GrainFactory.GetGrain <ISimpleGrain>(grainId, SimpleGrain.SimpleGrainNamePrefix);

            logger.Info("Setting A={0} on {1}", a, grainId);
            await grain.SetA(a);

            logger.Info("Setting B={0} on {1}", b, grainId);
            await grain.SetB(b);

            logger.Info("Getting AxB from {0}", grainId);
            int axb = await grain.GetAxB();

            logger.Info("Got AxB={0} from {1}", axb, grainId);

            int expected = a * b;
            int actual   = axb;

            if (expected != actual)
            {
                throw new Exception(string.Format(
                                        "Value returned to {0} by {1} should be {2} not {3}",
                                        GetType().Name, grainId, expected, actual));
            }
        }
Пример #46
0
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
#pragma warning disable 618

            return(Task.FromResult(0));
        }
Пример #47
0
        public override async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            await base.Init(name, providerRuntime, config);

            ILocalContentGrain grain = providerRuntime.GrainFactory.GetGrain <ILocalContentGrain>(Guid.NewGuid());
            // issue any grain call to activate this grain.
            await grain.Init();

            logger.Info("Finished Init Name={0}", name);
        }
Пример #48
0
        public virtual void Init(IProviderConfiguration config, string providerName, Logger logger, IServiceProvider serviceProvider)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (!config.Properties.TryGetValue(PubSubAdapterConstants.PROJECT_ID, out _projectId))
            {
                throw new ArgumentException($"{PubSubAdapterConstants.PROJECT_ID} property not set");
            }
            if (!config.Properties.TryGetValue(PubSubAdapterConstants.TOPIC_ID, out _topicId))
            {
                throw new ArgumentException($"{PubSubAdapterConstants.TOPIC_ID} property not set");
            }
            if (!config.Properties.TryGetValue(PubSubAdapterConstants.DEPLOYMENT_ID, out _deploymentId))
            {
                throw new ArgumentException($"{PubSubAdapterConstants.DEPLOYMENT_ID} property not set");
            }

            _logger = logger;

            config.Properties.TryGetValue(PubSubAdapterConstants.CUSTOM_ENDPOINT, out _customEndpoint);

            string deadlineStr;

            if (config.Properties.TryGetValue(PubSubAdapterConstants.DEADLINE, out deadlineStr))
            {
                int seconds;
                if (!int.TryParse(deadlineStr, out seconds))
                {
                    throw new ArgumentException(
                              $"Failed to parse {PubSubAdapterConstants.DEADLINE} value '{deadlineStr}' as a TimeSpan");
                }

                _deadline = TimeSpan.FromSeconds(seconds);

                if (_deadline == TimeSpan.MinValue || _deadline > PubSubAdapterConstants.MAX_DEADLINE)
                {
                    _deadline = PubSubAdapterConstants.MAX_DEADLINE;
                }
            }
            else
            {
                _deadline = null;
            }

            _cacheSize = SimpleQueueAdapterCache.ParseSize(config, PubSubAdapterConstants.CACHE_SIZE_DEFAULT);

            string numSubscriptionsString;

            _numSubscriptions = PubSubAdapterConstants.NUMBER_SUBSCRIPTIONS_DEFAULT;
            if (config.Properties.TryGetValue(PubSubAdapterConstants.NUMBER_SUBSCRIPTIONS, out numSubscriptionsString))
            {
                if (!int.TryParse(numSubscriptionsString, out _numSubscriptions))
                {
                    throw new ArgumentException($"{PubSubAdapterConstants.NUMBER_SUBSCRIPTIONS} invalid.  Must be int");
                }
            }

            _providerName      = providerName;
            _streamQueueMapper = new HashRingBasedStreamQueueMapper(_numSubscriptions, providerName);
            _adapterCache      = new SimpleQueueAdapterCache(_cacheSize, logger);
            if (StreamFailureHandlerFactory == null)
            {
                StreamFailureHandlerFactory =
                    qid => Task.FromResult <IStreamFailureHandler>(new NoOpStreamDeliveryFailureHandler());
            }

            SerializationManager = serviceProvider.GetRequiredService <SerializationManager>();
            _adaptorFactory      = () => ActivatorUtilities.GetServiceOrCreateInstance <TDataAdapter>(serviceProvider);
        }
Пример #49
0
        public async Task Init(string name, IProviderRuntime providerUtilitiesManager, IProviderConfiguration config)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (providerUtilitiesManager == null)
            {
                throw new ArgumentNullException("providerUtilitiesManager");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            Name            = name;
            providerRuntime = (IStreamProviderRuntime)providerUtilitiesManager;
            logger          = providerRuntime.GetLogger(this.GetType().Name);
            adapterFactory  = new TAdapterFactory();
            adapterFactory.Init(config, Name, logger);
            queueAdapter = await adapterFactory.CreateAdapter();

            string timePeriod;

            if (!config.Properties.TryGetValue(GET_QUEUE_MESSAGES_TIMER_PERIOD, out timePeriod))
            {
                getQueueMsgsTimerPeriod = DEFAULT_GET_QUEUE_MESSAGES_TIMER_PERIOD;
            }
            else
            {
                getQueueMsgsTimerPeriod = ConfigUtilities.ParseTimeSpan(timePeriod,
                                                                        "Invalid time value for the " + GET_QUEUE_MESSAGES_TIMER_PERIOD + " property in the provider config values.");
            }

            string timeout;

            if (!config.Properties.TryGetValue(INIT_QUEUE_TIMEOUT, out timeout))
            {
                initQueueTimeout = DEFAULT_INIT_QUEUE_TIMEOUT;
            }
            else
            {
                initQueueTimeout = ConfigUtilities.ParseTimeSpan(timeout,
                                                                 "Invalid time value for the " + INIT_QUEUE_TIMEOUT + " property in the provider config values.");
            }

            string balanceTypeString;

            balancerType = !config.Properties.TryGetValue(QUEUE_BALANCER_TYPE, out balanceTypeString)
                ? DEFAULT_STREAM_QUEUE_BALANCER_TYPE
                : (StreamQueueBalancerType)Enum.Parse(typeof(StreamQueueBalancerType), balanceTypeString);

            if (!config.Properties.TryGetValue(MAX_EVENT_DELIVERY_TIME, out timeout))
            {
                maxEventDeliveryTime = DEFAULT_MAX_EVENT_DELIVERY_TIME;
            }
            else
            {
                maxEventDeliveryTime = ConfigUtilities.ParseTimeSpan(timeout,
                                                                     "Invalid time value for the " + MAX_EVENT_DELIVERY_TIME + " property in the provider config values.");
            }

            logger.Info("Initialized PersistentStreamProvider<{0}> with name {1}, {2} = {3}, {4} = {5} and with Adapter {6}.",
                        typeof(TAdapterFactory).Name, Name,
                        GET_QUEUE_MESSAGES_TIMER_PERIOD, getQueueMsgsTimerPeriod,
                        INIT_QUEUE_TIMEOUT, this.initQueueTimeout,
                        queueAdapter.Name);
        }
Пример #50
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="providerConfiguration">Provider de configuração usado na analise.</param>
 public DatabaseAnalyzer(IProviderConfiguration providerConfiguration)
 {
     this.providerConfiguration = providerConfiguration;
     tablesMaps = new Hashtable();
 }
Пример #51
0
        /// <inheritdoc/>
        public override Task Initialize(string strProviderName, IStreamQueueMapper queueMapper, TimeSpan siloMaturityPeriod, IProviderConfiguration providerConfig)
        {
            if (queueMapper == null)
            {
                throw new ArgumentNullException("queueMapper");
            }
            var balancerConfig = new LeaseBasedQueueBalancerConfig(providerConfig);

            this.leaseProvider      = this.serviceProvider.GetRequiredService(balancerConfig.LeaseProviderType) as ILeaseProvider;
            this.leaseLength        = balancerConfig.LeaseLength;
            this.allQueues          = new ReadOnlyCollection <QueueId>(queueMapper.GetAllQueues().ToList());
            this.siloMaturityPeriod = siloMaturityPeriod;
            NotifyAfterStart().Ignore();
            //make lease renew frequency to be every half of lease time, to avoid renew failing due to timing issues, race condition or clock difference.
            var timerLogger = this.loggerFactory.CreateLogger <AsyncTaskSafeTimer>();

            this.renewLeaseTimer = new AsyncTaskSafeTimer(timerLogger, this.MaintainAndBalanceQueues, null, this.siloMaturityPeriod, this.leaseLength.Divide(2));
            //try to acquire maximum leases every leaseLength
            this.tryAcquireMaximumLeaseTimer = new AsyncTaskSafeTimer(timerLogger, this.AcquireLeaseToMeetMaxResponsibilty, null, this.siloMaturityPeriod, this.leaseLength);
            //Selector default to round robin selector now, but we can make a further change to make selector configurable if needed.  Selector algorithm could
            //be affecting queue balancing stablization time in cluster initializing and auto-scaling
            this.queueSelector = new RoundRobinSelector <QueueId>(this.allQueues);
            return(MaintainAndBalanceQueues(null));
        }
Пример #52
0
        /// <summary>
        /// Customises the given serializer settings using provider configuration.
        /// Can be used by any provider, allowing the users to use a standard set of configuration attributes.
        /// </summary>
        /// <param name="settings">The settings to update.</param>
        /// <param name="config">The provider config.</param>
        /// <returns>The updated <see cref="JsonSerializerSettings" />.</returns>
        public static JsonSerializerSettings UpdateSerializerSettings(JsonSerializerSettings settings, IProviderConfiguration config)
        {
            if (config.Properties.ContainsKey(UseFullAssemblyNamesProperty))
            {
                bool useFullAssemblyNames;
                if (bool.TryParse(config.Properties[UseFullAssemblyNamesProperty], out useFullAssemblyNames) && useFullAssemblyNames)
                {
                    settings.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full;
                }
            }

            if (config.Properties.ContainsKey(IndentJsonProperty))
            {
                bool indentJson;
                if (bool.TryParse(config.Properties[IndentJsonProperty], out indentJson) && indentJson)
                {
                    settings.Formatting = Formatting.Indented;
                }
            }

            if (config.Properties.ContainsKey(TypeNameHandlingProperty))
            {
                TypeNameHandling typeNameHandling;
                if (Enum.TryParse <TypeNameHandling>(config.Properties[TypeNameHandlingProperty], out typeNameHandling))
                {
                    settings.TypeNameHandling = typeNameHandling;
                }
            }
            return(settings);
        }
 public async override Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     Log = providerRuntime.GetLogger(this.GetType().FullName);
     Log.Info(0, "Init ErrorInjection={0}", ErrorInjection);
     try
     {
         SetErrorInjection(ErrorInjectionPoint.None);
         await base.Init(name, providerRuntime, config);
     }
     catch (Exception exc)
     {
         Log.Error(0, "Unexpected error during Init", exc);
         throw;
     }
 }
Пример #54
0
        public PersistentStreamProviderConfig(IProviderConfiguration config)
        {
            string timePeriod;

            if (!config.Properties.TryGetValue(GET_QUEUE_MESSAGES_TIMER_PERIOD, out timePeriod))
            {
                GetQueueMsgsTimerPeriod = DEFAULT_GET_QUEUE_MESSAGES_TIMER_PERIOD;
            }
            else
            {
                GetQueueMsgsTimerPeriod = ConfigUtilities.ParseTimeSpan(timePeriod,
                                                                        "Invalid time value for the " + GET_QUEUE_MESSAGES_TIMER_PERIOD + " property in the provider config values.");
            }

            string timeout;

            if (!config.Properties.TryGetValue(INIT_QUEUE_TIMEOUT, out timeout))
            {
                InitQueueTimeout = DEFAULT_INIT_QUEUE_TIMEOUT;
            }
            else
            {
                InitQueueTimeout = ConfigUtilities.ParseTimeSpan(timeout,
                                                                 "Invalid time value for the " + INIT_QUEUE_TIMEOUT + " property in the provider config values.");
            }

            string balanceTypeString;

            BalancerType = !config.Properties.TryGetValue(QUEUE_BALANCER_TYPE, out balanceTypeString)
                ? DEFAULT_STREAM_QUEUE_BALANCER_TYPE
                : (StreamQueueBalancerType)Enum.Parse(typeof(StreamQueueBalancerType), balanceTypeString);

            if (!config.Properties.TryGetValue(MAX_EVENT_DELIVERY_TIME, out timeout))
            {
                MaxEventDeliveryTime = DEFAULT_MAX_EVENT_DELIVERY_TIME;
            }
            else
            {
                MaxEventDeliveryTime = ConfigUtilities.ParseTimeSpan(timeout,
                                                                     "Invalid time value for the " + MAX_EVENT_DELIVERY_TIME + " property in the provider config values.");
            }

            if (!config.Properties.TryGetValue(STREAM_INACTIVITY_PERIOD, out timeout))
            {
                StreamInactivityPeriod = DEFAULT_STREAM_INACTIVITY_PERIOD;
            }
            else
            {
                StreamInactivityPeriod = ConfigUtilities.ParseTimeSpan(timeout,
                                                                       "Invalid time value for the " + STREAM_INACTIVITY_PERIOD + " property in the provider config values.");
            }

            string pubSubTypeString;

            PubSubType = !config.Properties.TryGetValue(STREAM_PUBSUB_TYPE, out pubSubTypeString)
                ? DEFAULT_STREAM_PUBSUB_TYPE
                : (StreamPubSubType)Enum.Parse(typeof(StreamPubSubType), pubSubTypeString);

            string immaturityPeriod;

            if (!config.Properties.TryGetValue(SILO_MATURITY_PERIOD, out immaturityPeriod))
            {
                SiloMaturityPeriod = DEFAULT_SILO_MATURITY_PERIOD;
            }
            else
            {
                SiloMaturityPeriod = ConfigUtilities.ParseTimeSpan(immaturityPeriod,
                                                                   "Invalid time value for the " + SILO_MATURITY_PERIOD + " property in the provider config values.");
            }
        }
Пример #55
0
 public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     Name = name;
     await GetLocalHub().Init();
 }
 public async override Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     this.logger = providerRuntime.ServiceProvider.GetRequiredService <ILogger <ErrorInjectionStorageProvider> >();
     logger.Info(0, "Init ErrorInjection={0}", ErrorInjection);
     try
     {
         SetErrorInjection(ErrorInjectionBehavior.None);
         await base.Init(name, providerRuntime, config);
     }
     catch (Exception exc)
     {
         logger.Error(0, "Unexpected error during Init", exc);
         throw;
     }
 }
 /// <summary>
 /// Populate data generating config from provider config
 /// </summary>
 /// <param name="providerConfiguration"></param>
 public void PopulateDataGeneratingConfigFromProviderConfig(IProviderConfiguration providerConfiguration)
 {
     this.streamDataGeneratorType = providerConfiguration.GetTypeProperty(StreamDataGeneratorTypeName, DefaultStreamDataGeneratorType);
     this.EventHubPartitionCount  = providerConfiguration.GetIntProperty(EventHubPartitionCountName, DefaultEventHubPartitionCount);
 }
Пример #58
0
        // used only for testing
        internal async Task AddAndInitProvider(string name, IStorageProvider provider, IProviderConfiguration config = null)
        {
            await provider.Init(name, this, config);

            storageProviderLoader.AddProvider(name, provider, config);
        }
 public override void Init(IProviderConfiguration providerCfg, string providerName, Logger log, IServiceProvider svcProvider)
 {
     this.ReceiverMonitorFactory        = (dimensions, logger) => EventHubReceiverMonitorForTesting.Instance;
     this.cachePressureInjectionMonitor = new CachePressureInjectionMonitor();
     base.Init(providerCfg, providerName, log, svcProvider);
 }
Пример #60
0
 /// <summary>
 /// Populate data generating config from provider config
 /// </summary>
 /// <param name="providerConfiguration"></param>
 public void PopulateDataGeneratingConfigFromProviderConfig(IProviderConfiguration providerConfiguration)
 {
     this.streamDataGeneratorType = providerConfiguration.GetTypeProperty(StreamDataGeneratorTypeName, DefaultStreamDataGeneratorType);
 }