示例#1
0
        public void TestMemberRemoteInvocation()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;
            IXmlDocument config           = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config.xml");

            ccf.Config = config;
            IInvocationService service = (IInvocationService)CacheFactory.GetService("RemoteInvocationService");

            IMember member = new LocalMember();

            member.MachineName = "machine1";
            member.MemberName  = "member1";
            member.ProcessName = "process1";
            member.RackName    = "rack1";
            member.RoleName    = "role1";
            member.SiteName    = "site1";

            POFObjectInvocable invocable = new POFObjectInvocable();

            invocable.PofObject = member;

            IDictionary result = service.Query(invocable, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 1);
            IMember copy = (IMember)result[((DefaultConfigurableCacheFactory)CacheFactory
                                            .ConfigurableCacheFactory).OperationalContext.LocalMember];

            Assert.AreEqual(member.MachineName, copy.MachineName);
            Assert.AreEqual(member.MemberName, copy.MemberName);
            Assert.AreEqual(member.ProcessName, copy.ProcessName);
            Assert.AreEqual(member.RackName, copy.RackName);
            Assert.AreEqual(member.RoleName, copy.RoleName);
            Assert.AreEqual(member.SiteName, copy.SiteName);

            service.Shutdown();
        }
示例#2
0
        /// <summary>
        /// Parse and configure local <see cref="IMember"/> information.
        /// </summary>
        private void ParseLocalMemberConfig()
        {
            LocalMember member = new LocalMember();

            IXmlElement xmlConfig = Config.FindElement("cluster-config/member-identity");

            if (xmlConfig != null)
            {
                member.ClusterName = xmlConfig.GetSafeElement("cluster-name").GetString();
                member.SiteName    = xmlConfig.GetSafeElement("site-name").GetString();
                member.RackName    = xmlConfig.GetSafeElement("rack-name").GetString();
                member.MachineName = xmlConfig.GetSafeElement("machine-name").GetString();
                member.ProcessName = xmlConfig.GetSafeElement("process-name").GetString();
                member.MemberName  = xmlConfig.GetSafeElement("member-name").GetString();
                member.RoleName    = xmlConfig.GetSafeElement("role-name").GetString();
            }

            if (StringUtils.IsNullOrEmpty(member.ClusterName))
            {
                // set default cluster name to the user name
                string name = Environment.UserName;
                if (StringUtils.IsNullOrEmpty(name))
                {
                    // we can't obtain the user name, this could be a transient error for instance in the case of NIS.
                    // while we could generate some random or fixed default that wouldn't defend well against transient errors
                    // and we could end up with multiple clusters.  Given that any production system should actually set the
                    // cluster name rather then using a default we will treat this as a hard error.  Note don't try to obtain
                    // the name by other means such as reading env variables because they may produce a different string then
                    // reading "user.name" and again if the error is transient multiple clusters could be unintentionally produced.

                    throw new NotSupportedException(
                              "unable to generate a default cluster name, user name is not available, explicit cluster name configuration is required");
                }

                // this suffix in addition to be cute and suggesting this is not a production cluster also helps
                // minimize the possibility of a collision with a manually named cluster which would be very unlikely
                // to use such a cute name.
                member.ClusterName = name = name + "'s cluster";
                CacheFactory.Log("The cluster name has not been configured, a value of \"" + name + "\" has been automatically generated", CacheFactory.LogLevel.Info);
            }

            if (StringUtils.IsNullOrEmpty(member.MachineName))
            {
                var host  = System.Net.Dns.GetHostName();
                var delim = host.IndexOf('.');

                if (delim == -1 || !Char.IsLetter(host[0]))
                {
                    member.MachineName = host;
                }
                else
                {
                    member.MachineName = host.Substring(0, delim);
                    member.SiteName    = host.Substring(delim + 1);
                }
            }

            if (StringUtils.IsNullOrEmpty(member.RoleName))
            {
                member.RoleName = ".NET " + EditionName + " client";
            }

            if (StringUtils.IsNullOrEmpty(member.ProcessName))
            {
                member.ProcessName = Process.GetCurrentProcess().ProcessName;
            }

            LocalMember = member;
        }