コード例 #1
0
ファイル: LeaseProvider.cs プロジェクト: jarlrasm/akka.net
        /// <summary>
        /// The configuration define at <paramref name="configPath"/> must have a property `lease-class` that defines
        /// the fully qualified class name of the <see cref="Lease"/> implementation.
        /// The class must implement <see cref="Lease"/> and have constructor with <see cref="LeaseSettings"/> parameter and
        /// optionally <see cref="ActorSystem"/> parameter.
        /// </summary>
        /// <param name="leaseName">the name of the lease resource</param>
        /// <param name="configPath">the path of configuration for the lease</param>
        /// <param name="ownerName">the owner that will `acquire` the lease, e.g. hostname and port of the ActorSystem</param>
        /// <returns></returns>
        public Lease GetLease(string leaseName, string configPath, string ownerName)
        {
            var leaseKey = new LeaseKey(leaseName, configPath, ownerName);

            return(_leases.GetOrAdd(leaseKey, lk =>
            {
                var leaseConfig = _system.Settings.Config
                                  .GetConfig(configPath)
                                  .WithFallback(_system.Settings.Config.GetConfig("akka.coordination.lease"));

                var settings = LeaseSettings.Create(leaseConfig, leaseName, ownerName);

                var leaseClassName = settings.LeaseConfig.GetString("lease-class", null);
                if (string.IsNullOrEmpty(leaseClassName))
                {
                    throw new ArgumentException("lease-class must not be empty");
                }
                var leaseType = Type.GetType(leaseClassName, true);

                try
                {
                    try
                    {
                        return (Lease)Activator.CreateInstance(leaseType, settings, _system);
                    }
                    catch
                    {
                        return (Lease)Activator.CreateInstance(leaseType, settings);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(
                        ex,
                        "Invalid lease configuration for leaseName [{0}], configPath [{1}] lease-class [{2}]. " +
                        "The class must implement Akka.Coordination.Lease and have constructor with LeaseSettings parameter and " +
                        "optionally ActorSystem parameter.",
                        settings.LeaseName,
                        configPath,
                        leaseType);

                    throw;
                }
            }));
        }
コード例 #2
0
        /// <summary>
        /// The configuration define at <paramref name="configPath"/> must have a property `lease-class` that defines
        /// the fully qualified class name of the <see cref="Lease"/> implementation.
        /// The class must implement <see cref="Lease"/> and have constructor with <see cref="LeaseSettings"/> parameter and
        /// optionally <see cref="ActorSystem"/> parameter.
        /// </summary>
        /// <param name="leaseName">the name of the lease resource</param>
        /// <param name="configPath">the path of configuration for the lease</param>
        /// <param name="ownerName">the owner that will `acquire` the lease, e.g. hostname and port of the ActorSystem</param>
        /// <returns></returns>
        public Lease GetLease(string leaseName, string configPath, string ownerName)
        {
            var leaseKey = new LeaseKey(leaseName, configPath, ownerName);

            return(leases.GetOrAdd(leaseKey, lk =>
            {
                var leaseConfig = _system.Settings.Config
                                  .GetConfig(configPath)
                                  .WithFallback(_system.Settings.Config.GetConfig("akka.coordination.lease"));

                var settings = LeaseSettings.Create(leaseConfig, leaseName, ownerName);

                try
                {
                    try
                    {
                        return (Lease)Activator.CreateInstance(settings.LeaseType, settings, _system);
                    }
                    catch
                    {
                        return (Lease)Activator.CreateInstance(settings.LeaseType, settings);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(
                        ex,
                        "Invalid lease configuration for leaseName [{0}], configPath [{1}] lease-class [{2}]. " +
                        "The class must implement scaladsl.Lease or javadsl.Lease and have constructor with LeaseSettings parameter and " +
                        "optionally ActorSystem parameter.",
                        settings.LeaseName,
                        configPath,
                        settings.LeaseType);

                    throw;
                }
            }));
        }
コード例 #3
0
ファイル: Lease.cs プロジェクト: yildizoglu/akka.net
 /// <summary>
 /// Creates a new <see cref="Lease"/> instance.
 /// </summary>
 /// <param name="settings">Lease settings</param>
 public Lease(LeaseSettings settings)
 {
     Settings = settings;
 }