HasPath() public method

Determine if a HOCON configuration element exists at the specified location
public HasPath ( string path ) : bool
path string The location to check for a configuration value.
return bool
コード例 #1
0
        public SessionSettings(Config config)
        {
            if (config == null) throw new ArgumentNullException("config");

            Builder = Cluster.Builder();
            
            // Get IP and port configuration
            int port = config.GetInt("port", 9042);
            IPEndPoint[] contactPoints = ParseContactPoints(config.GetStringList("contact-points"), port);
            Builder.AddContactPoints(contactPoints);

            // Support user/pass authentication
            if (config.HasPath("credentials"))
                Builder.WithCredentials(config.GetString("credentials.username"), config.GetString("credentials.password"));

            // Support SSL
            if (config.GetBoolean("ssl"))
                Builder.WithSSL();

            // Support compression
            string compressionTypeConfig = config.GetString("compression");
            if (compressionTypeConfig != null)
            {
                var compressionType = (CompressionType) Enum.Parse(typeof (CompressionType), compressionTypeConfig, true);
                Builder.WithCompression(compressionType);
            }
        }
コード例 #2
0
ファイル: Broadcast.cs プロジェクト: Micha-kun/akka.net
 /// <summary>
 /// Initializes a new instance of the <see cref="BroadcastPool"/> class.
 /// </summary>
 /// <param name="config">The configuration used to configure the pool.</param>
 public BroadcastPool(Config config)
     : this(
           nrOfInstances: config.GetInt("nr-of-instances"),
           resizer: Resizer.FromConfig(config),
           supervisorStrategy: Pool.DefaultSupervisorStrategy,
           routerDispatcher: Dispatchers.DefaultDispatcherId,
           usePoolDispatcher: config.HasPath("pool-dispatcher"))
 {
 }
コード例 #3
0
ファイル: Dispatchers.cs プロジェクト: Micha-kun/akka.net
        private MessageDispatcherConfigurator ConfiguratorFrom(Config cfg)
        {
            if (!cfg.HasPath("id")) throw new ConfigurationException($"Missing dispatcher `id` property in config: {cfg.Root}");

            var id = cfg.GetString("id");
            var type = cfg.GetString("type");


            MessageDispatcherConfigurator dispatcher;
            /*
             * Fallbacks are added here in order to preserve backwards compatibility with versions of AKka.NET prior to 1.1,
             * before the ExecutorService system was implemented
             */
            switch (type)
            {
                case "Dispatcher":
                    dispatcher = new DispatcherConfigurator(cfg, Prerequisites);
                    break;
                case "TaskDispatcher":
                    dispatcher = new DispatcherConfigurator(TaskExecutorConfig.WithFallback(cfg), Prerequisites);
                    break;
                case "PinnedDispatcher":
                    dispatcher = new PinnedDispatcherConfigurator(cfg, Prerequisites);
                    break;
                case "ForkJoinDispatcher":
                    dispatcher = new DispatcherConfigurator(ForkJoinExecutorConfig.WithFallback(cfg), Prerequisites);
                    break;
                case "SynchronizedDispatcher":
                    dispatcher = new CurrentSynchronizationContextDispatcherConfigurator(cfg, Prerequisites);
                    break;
                case null:
                    throw new ConfigurationException($"Could not resolve dispatcher for path {id}. type is null");
                default:
                    Type dispatcherType = Type.GetType(type);
                    if (dispatcherType == null)
                    {
                        throw new ConfigurationException($"Could not resolve dispatcher type {type} for path {id}");
                    }
                    dispatcher = (MessageDispatcherConfigurator)Activator.CreateInstance(dispatcherType, cfg, Prerequisites);
                    break;
            }

            return dispatcher;
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsistentHashingPool"/> class.
 /// 
 /// <note>
 /// 'virtual-nodes-factor' defaults to 0 (zero) if it is not defined in the provided configuration.
 /// </note>
 /// </summary>
 /// <param name="config">The configuration used to configure the pool.</param>
 public ConsistentHashingPool(Config config)
     : this(
           nrOfInstances: config.GetInt("nr-of-instances"),
           resizer: Resizer.FromConfig(config),
           supervisorStrategy: Pool.DefaultSupervisorStrategy,
           routerDispatcher: Dispatchers.DefaultDispatcherId,
           usePoolDispatcher: config.HasPath("pool-dispatcher"))
 {
     VirtualNodesFactor = config.GetInt("virtual-nodes-factor");
 }
コード例 #5
0
ファイル: TailChopping.cs プロジェクト: Micha-kun/akka.net
 /// <summary>
 /// Initializes a new instance of the <see cref="TailChoppingPool"/> class.
 /// <note>
 /// 'nr-of-instances', 'within', and 'tail-chopping-router.interval'
 /// must be defined in the provided configuration.
 /// </note>
 /// </summary>
 /// <param name="config">The configuration used to configure the pool.</param>
 public TailChoppingPool(Config config)
     : this(
           config.GetInt("nr-of-instances"),
           Resizer.FromConfig(config),
           Pool.DefaultSupervisorStrategy,
           Dispatchers.DefaultDispatcherId,
           config.GetTimeSpan("within"), config.GetTimeSpan("tail-chopping-router.interval"), config.HasPath("pool-dispatcher"))
 {
 }
コード例 #6
0
 /// <summary>
 /// Creates an instance of the TailChoppingPool.
 /// </summary>
 /// <param name="config">The configuration to use with this instance.</param>
 public TailChoppingPool(Config config)
     : this(config.GetInt("nr-of-instances"),
         DefaultResizer.FromConfig(config),
         null,
         null,   //TODO: what are our defaults? null?
         config.GetTimeSpan("within"),
         config.GetTimeSpan("tail-chopping-router.interval"),
         config.HasPath("pool-dispatcher")
         )
 {
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScatterGatherFirstCompletedPool"/> class.
 /// </summary>
 /// <param name="config">
 /// The configuration to use to lookup paths used by the group router.
 /// 
 /// <note>
 /// 'within' must be defined in the provided configuration.
 /// </note>
 /// </param>
 public ScatterGatherFirstCompletedPool(Config config)
     : this(
           nrOfInstances: config.GetInt("nr-of-instances"),
           resizer: Resizer.FromConfig(config),
           within: config.GetTimeSpan("within"),
           supervisorStrategy: Pool.DefaultSupervisorStrategy,
           routerDispatcher: Dispatchers.DefaultDispatcherId,
           usePoolDispatcher: config.HasPath("pool-dispatcher"))
 {
 }
コード例 #8
0
 /// <summary>
 /// Creates an instance of the TailChoppingPool.
 /// </summary>
 /// <param name="config">The configuration to use with this instance.</param>
 public TailChoppingPool(Config config)
 {
     NrOfInstances = config.GetInt("nr-of-instances");
     within = config.GetTimeSpan("within");
     interval = config.GetTimeSpan("tail-chopping-router.interval");
     Resizer = DefaultResizer.FromConfig(config);
     UsePoolDispatcher = config.HasPath("pool-dispatcher");
 }
コード例 #9
0
ファイル: Mailboxes.cs プロジェクト: rogeralsing/akka.net
        public Type GetMailboxType(Props props, Config dispatcherConfig)
        {
            if (!string.IsNullOrEmpty(props.Mailbox))
            {
                return FromConfig(props.Mailbox);
            }

            if (dispatcherConfig == null)
                dispatcherConfig = ConfigurationFactory.Empty;
            var id = dispatcherConfig.GetString("id");
            var deploy = props.Deploy;
            var actorType = props.Type;
            var actorRequirement = new Lazy<Type>(() => GetRequiredType(actorType));

            var mailboxRequirement = GetMailboxRequirement(dispatcherConfig);
            var hasMailboxRequirement = mailboxRequirement != typeof (IMessageQueue);

            var hasMailboxType = dispatcherConfig.HasPath("mailbox-type") &&
                                 dispatcherConfig.GetString("mailbox-type") != Deploy.NoMailboxGiven;

            Func<Type, Type> verifyRequirements = mailboxType =>
            {
                // TODO Akka code after introducing IProducesMessageQueue
                // if (hasMailboxRequirement && !mailboxRequirement.isAssignableFrom(mqType))
                //   throw new IllegalArgumentException(
                //     s"produced message queue type [$mqType] does not fulfill requirement for dispatcher [$id]. " +
                //       s"Must be a subclass of [$mailboxRequirement].")
                // if (hasRequiredType(actorClass) && !actorRequirement.isAssignableFrom(mqType))
                //   throw new IllegalArgumentException(
                //     s"produced message queue type [$mqType] does not fulfill requirement for actor class [$actorClass]. " +
                //       s"Must be a subclass of [$actorRequirement].")
                return mailboxType;
            };

            if (!deploy.Mailbox.Equals(Deploy.NoMailboxGiven))
                return verifyRequirements(FromConfig(deploy.Mailbox));
            if (!deploy.Dispatcher.Equals(Deploy.NoDispatcherGiven) && hasMailboxType)
                return verifyRequirements(FromConfig(id));
            if (actorRequirement.Value != null)
            {
                try
                {
                    return verifyRequirements(LookupByQueueType(actorRequirement.Value));
                }
                catch (Exception e)
                {
                    if (hasMailboxRequirement)
                        return verifyRequirements(LookupByQueueType(mailboxRequirement));
                    throw;
                }
            }
            if (hasMailboxRequirement)
                return verifyRequirements(LookupByQueueType(mailboxRequirement));
            return verifyRequirements(_defaultMailboxType);
        }
コード例 #10
0
ファイル: Mailboxes.cs プロジェクト: Micha-kun/akka.net
        /// <summary></summary>
        /// <exception cref="ArgumentException">
        /// This exception is thrown if the 'mailbox-requirement' in the given <paramref name="dispatcherConfig"/> isn't met.
        /// </exception>
        public MailboxType GetMailboxType(Props props, Config dispatcherConfig)
        {
            if (dispatcherConfig == null)
                dispatcherConfig = ConfigurationFactory.Empty;
            var id = dispatcherConfig.GetString("id");
            var deploy = props.Deploy;
            var actorType = props.Type;
            var actorRequirement = new Lazy<Type>(() => GetRequiredType(actorType));

            var mailboxRequirement = GetMailboxRequirement(dispatcherConfig);
            var hasMailboxRequirement = mailboxRequirement != typeof(IMessageQueue);

            var hasMailboxType = dispatcherConfig.HasPath("mailbox-type") &&
                                 dispatcherConfig.GetString("mailbox-type") != Deploy.NoMailboxGiven;

            if (!hasMailboxType && !_mailboxSizeWarningIssued && dispatcherConfig.HasPath("mailbox-size"))
            {
                Warn($"Ignoring setting 'mailbox-size for disaptcher [{id}], you need to specify 'mailbox-type=bounded`");
                _mailboxSizeWarningIssued = true;
            }

            Func<MailboxType, MailboxType> verifyRequirements = mailboxType =>
            {
                Lazy<Type> mqType = new Lazy<Type>(() => GetProducedMessageQueueType(mailboxType));
                if (hasMailboxRequirement && !mailboxRequirement.IsAssignableFrom(mqType.Value))
                    throw new ArgumentException($"produced message queue type [{mqType.Value}] does not fulfill requirement for dispatcher [{id}]." +
                                                $"Must be a subclass of [{mailboxRequirement}]");
                if (HasRequiredType(actorType) && !actorRequirement.Value.IsAssignableFrom(mqType.Value))
                    throw new ArgumentException($"produced message queue type of [{mqType.Value}] does not fulfill requirement for actor class [{actorType}]." +
                                                $"Must be a subclass of [{mailboxRequirement}]");
                return mailboxType;
            };

            if (!deploy.Mailbox.Equals(Deploy.NoMailboxGiven))
                return verifyRequirements(Lookup(deploy.Mailbox));
            if (!deploy.Dispatcher.Equals(Deploy.NoDispatcherGiven) && hasMailboxType)
                return verifyRequirements(Lookup(dispatcherConfig.GetString("id")));
            if (actorRequirement.Value != null)
            {
                try
                {
                    return verifyRequirements(LookupByQueueType(actorRequirement.Value));
                }
                catch (Exception e)
                {
                    if (hasMailboxRequirement)
                        return verifyRequirements(LookupByQueueType(mailboxRequirement));
                    throw;
                }
            }
            if (hasMailboxRequirement)
                return verifyRequirements(LookupByQueueType(mailboxRequirement));
            return verifyRequirements(Lookup(DefaultMailboxId));
        }
コード例 #11
0
        public override Deploy ParseConfig(string key, Config config)
        {
            Config config2 = config;
            if (config.HasPath("cluster.enabled")
                && config.GetBoolean("cluster.enabled")
                && !config.HasPath("nr-of-instances"))
            {
                var maxTotalNrOfInstances = config
                    .WithFallback(Default)
                    .GetInt("cluster.max-total-nr-of-instances");
                config2 = ConfigurationFactory.ParseString("nr-of-instances=" + maxTotalNrOfInstances)
                    .WithFallback(config);
            }

            var deploy = base.ParseConfig(key, config2);
            if (deploy != null)
            {
                if (deploy.Config.GetBoolean("cluster.enabled"))
                {
                    if (deploy.Scope != Deploy.NoScopeGiven)
                        throw new ConfigurationException(string.Format("Cluster deployment can't be combined with scope [{0}]", deploy.Scope));
                    if (deploy.RouterConfig is RemoteRouterConfig)
                        throw new ConfigurationException(string.Format("Cluster deployment can't be combined with [{0}]", deploy.Config));

                    if (deploy.RouterConfig is Pool)
                    {
                        return
                            deploy.WithScope(scope: ClusterScope.Instance)
                                .WithRouterConfig(new ClusterRouterPool(deploy.RouterConfig as Pool,
                                    ClusterRouterPoolSettings.FromConfig(deploy.Config)));
                    }
                    else if (deploy.RouterConfig is Group)
                    {
                        return
                            deploy.WithScope(scope: ClusterScope.Instance)
                                .WithRouterConfig(new ClusterRouterGroup(deploy.RouterConfig as Group,
                                    ClusterRouterGroupSettings.FromConfig(deploy.Config)));
                    }
                    else
                    {
                        throw new ArgumentException(string.Format("Cluster-aware router can only wrap Pool or Group, got [{0}]", deploy.RouterConfig.GetType()));
                    }
                }
                else
                {
                    return deploy;
                }
            }
            else
            {
                return null;
            }
        }