/// <summary>
        /// The <see cref="Configure"/> implementation method.
        /// </summary>
        /// <remarks>
        /// This method must only be called by a thread that has synchronized
        /// on this RemoteService.
        /// </remarks>
        /// <param name="xml">
        /// The <see cref="IXmlElement"/> containing the new configuration
        /// for this RemoteService.
        /// </param>
        protected virtual void DoConfigure(IXmlElement xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml", "xml configuration must not be null");
            }

            Xml = xml;

            // find the configuration for the Initiator
            IXmlElement xmlInitiator = Tangosol.Util.Daemon.QueueProcessor.
                                       Service.Peer.Initiator.Initiator.FindInitiatorConfig(xml);

            // inject service configuration
            IXmlElement xmlHandler = XmlHelper.EnsureElement(xmlInitiator, "incoming-message-handler");

            IXmlElement xmlSub = XmlHelper.EnsureElement(xmlHandler, "request-timeout");

            if (xmlSub.Value == null)
            {
                xmlSub.SetString(xml.GetSafeElement("request-timeout").GetString());
            }

            // create the Initiator
            IConnectionInitiator initiator = Tangosol.Util.Daemon.QueueProcessor.
                                             Service.Peer.Initiator.Initiator.CreateInitiator(xmlInitiator, OperationalContext);

            if (initiator is Initiator)
            {
                var initiatorImpl = (Initiator)initiator;
                initiatorImpl.ServiceName   = ServiceName + ':' + initiatorImpl.ServiceName;
                initiatorImpl.ParentService = this;
            }
            Initiator = initiator;

            RemoteClusterName = xml.GetSafeElement("cluster-name").GetString();
            RemoteServiceName = xml.GetSafeElement("proxy-service-name").GetString();
            ScopeName         = xml.GetSafeElement("scope-name").GetString();

            if (initiator is TcpInitiator)
            {
                IsNameServiceAddressProvider = ((TcpInitiator)initiator).IsNameService;
            }
        }
        /// <summary>
        /// The <see cref="RemoteService.Configure"/> implementation method.
        /// </summary>
        /// <remarks>
        /// This method must only be called by a thread that has synchronized
        /// on this RemoteService.
        /// </remarks>
        /// <param name="xml">
        /// The <see cref="IXmlElement"/> containing the new configuration
        /// for this RemoteService.
        /// </param>
        protected override void DoConfigure(IXmlElement xml)
        {
            base.DoConfigure(xml);

            DeferKeyAssociationCheck =
                xml.GetSafeElement("defer-key-association-check")
                .GetBoolean(DeferKeyAssociationCheck);

            // register all Protocols
            IConnectionInitiator initiator = Initiator;

            initiator.RegisterProtocol(CacheServiceProtocol.Instance);
            initiator.RegisterProtocol(NamedCacheProtocol.Instance);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return a child <b>IXmlElement</b> of the given <b>IXmlElement</b>
        /// that can be used to  create and configure a new
        /// <b>IConnectionInitiator</b>.
        /// </summary>
        /// <remarks>
        /// The given <b>IXmlElement</b> must have a child element with one
        /// of the following names:
        /// <list type="number">
        /// <item>
        /// tcp-initiator: used to create and configure a new TcpInitiator
        /// </item>
        /// </list>
        /// </remarks>
        /// <param name="xml">
        /// The parent <b>IXmlElement</b> of the <b>IXmlElement</b> used to
        /// create and configure a new <b>IConnectionInitiator</b>.
        /// </param>
        /// <returns>
        /// A child <b>IXmlElement</b> that can be used to create and
        /// configure a new <b>IConnectionInitiator</b> or <c>null</c> if no
        /// such <b>IXmlElement</b> exists.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// If the given <b>IXmlElement</b> does not have a valid
        /// <b>IConnectionInitiator</b> configuration child element.
        /// </exception>
        public static IXmlElement FindInitiatorConfig(IXmlElement xml)
        {
            IXmlElement xmlConfig = xml.Name.Equals("initiator-config")
                    ? xml : xml.GetSafeElement("initiator-config");

            if (xmlConfig.GetElement("tcp-initiator") != null)
            {
                return((IXmlElement)xmlConfig.Clone());
            }

            throw new ArgumentException("the \"initiator-config\" element is either"
                                        + " missing, empty, or does not contain a valid transport-specific"
                                        + " child element:\n" + xml);
        }
        /// <summary>
        /// Parse the given <b>IXmlElement</b> as a local <b>IPEndPoint</b>.
        /// </summary>
        /// <remarks>
        /// If the specified <b>IXmlElement</b> contains an empty address,
        /// <c>null</c> is returned.
        /// </remarks>
        /// <param name="xml">
        /// The <b>IXmlElement</b> to parse.
        /// </param>
        /// <returns>
        /// A new <b>IPEndPoint</b> representing the contents of the given
        /// <b>XmlNode</b>.
        /// </returns>
        protected static IPEndPoint ParseLocalSocketAddress(IXmlElement xml)
        {
            IXmlElement xmlAddr         = xml.GetElement("address");
            IXmlElement xmlPort         = xml.GetElement("port");
            String      sAddressFamiliy =
                xml.GetSafeElement("address-family").GetString(
                    "InterNetwork");

            if (xmlAddr == null && xmlPort == null)
            {
                return(null);
            }

            string addr = xmlAddr == null ? "localhost" : xmlAddr.GetString();
            int    port = xmlPort == null ? 0 : xmlPort.GetInt();

            NetworkUtils.PreferredAddressFamily =
                (AddressFamily)
                Enum.Parse(typeof(AddressFamily), sAddressFamiliy);

            IPAddress ipAddress;

            try
            {
                ipAddress = addr.Equals("localhost")
                                    ? NetworkUtils.GetLocalHostAddress()
                                    : NetworkUtils.GetHostAddress(addr);
            }
            catch (Exception e)
            {
                throw new Exception("The \"" + xml.Name + "\" configuration "
                                    +
                                    "element contains an invalid \"address\" element",
                                    e);
            }

            try
            {
                return(new IPEndPoint(ipAddress, port));
            }
            catch (Exception e)
            {
                throw new Exception("The \"" + xml.Name + "\" configuration "
                                    +
                                    "element contains an invalid \"port\" element",
                                    e);
            }
        }
        public static IDictionary CreateFilterConfigMap(IXmlElement filterConfig)
        {
            IDictionary mapConfigByName = new Hashtable();
            IXmlElement config          = filterConfig;

            if (config != null)
            {
                for (IEnumerator enumerator = config.GetElements("filter"); enumerator.MoveNext();)
                {
                    IXmlElement xmlFilter = (IXmlElement)enumerator.Current;
                    string      name      = xmlFilter.GetSafeElement("filter-name").GetString();
                    mapConfigByName.Add(name, xmlFilter);
                }
            }
            return(mapConfigByName);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Construct a new DefaultOperationalContext.
        /// </summary>
        /// <param name="config">
        /// An XML element corresponding to coherence.xsd.
        /// </param>
        public DefaultOperationalContext(IXmlElement config)
        {
            if (config == null)
            {
                config = LoadDefaultOperationalConfig();
            }
            m_config = config;

            ParseEditionConfig();
            ParseLoggingConfig();
            ParseLocalMemberConfig();
            ParseFilterConfig();
            ParseSerializerConfig();
            ParseAddressProviderConfig();
            ParseSecurityConfig();

            DiscoveryTimeToLive = config.GetSafeElement("multicast-listener/time-to-live").GetInt(4);
        }
Exemplo n.º 7
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;
        }
        /// <summary>
        /// Configure the controllable service.
        /// </summary>
        /// <remarks>
        /// <p/>
        /// This method can only be called before the controllable service
        /// is started.
        /// </remarks>
        /// <param name="xml">
        /// An <see cref="IXmlElement"/> carrying configuration information
        /// specific to the IControllable object.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if the service is already running.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown if the configuration information is invalid.
        /// </exception>
        public override void Configure(IXmlElement xml)
        {
            lock (this)
            {
                base.Configure(xml);
                if (xml == null)
                {
                    return;
                }

                // <tcp-initiator>
                IXmlElement xmlCat = xml.GetSafeElement("tcp-initiator");

                // <stream-provider/>
                IXmlElement xmlSub = xmlCat.GetSafeElement("stream-provider");
                StreamProvider = StreamProviderFactory.CreateProvider(xmlSub);

                // <local-address>
                xmlSub = xmlCat.GetSafeElement("local-address");

                // <address>
                // <port>
                LocalAddress = ParseLocalSocketAddress(xmlSub);

                // <reusable>
                IsLocalAddressReusable = xmlSub.GetSafeElement("reusable").
                                         GetBoolean(IsLocalAddressReusable);

                // <remote-addresses>
                bool isNameService = false;
                xmlSub = xmlCat.GetElement("name-service-addresses");
                if (xmlSub == null)
                {
                    xmlSub = xmlCat.GetSafeElement("remote-addresses");
                }
                else
                {
                    isNameService = true;
                }
                IAddressProviderFactory factory;

                IXmlElement xmlProvider = xmlSub.GetElement("address-provider");
                bool        missing     = xmlProvider == null;
                bool        empty       = !missing && xmlProvider.IsEmpty;
                if (empty || missing)
                {
                    ConfigurableAddressProviderFactory factoryImpl =
                        new ConfigurableAddressProviderFactory();
                    factoryImpl.Config = missing ? xmlSub : xmlProvider;
                    factory            = factoryImpl;
                }
                else
                {
                    String name = xmlProvider.GetString();
                    factory = (IAddressProviderFactory)
                              OperationalContext.AddressProviderMap[name];
                    if (factory == null)
                    {
                        throw new ArgumentException("Address provider "
                                                    + name + " not found.");
                    }
                }
                RemoteAddressProvider = factory.CreateAddressProvider();
                if (RemoteAddressProvider is ConfigurableAddressProvider && ConnectTimeout > 0)
                {
                    ((ConfigurableAddressProvider)RemoteAddressProvider).RequestTimeout = ConnectTimeout;
                }

                IsNameService = isNameService;
                if (isNameService)
                {
                    Subport = (int)WellKnownSubPorts.NameService;
                }
                else
                {
                    Subport = -1;
                }

                // <reuse-address>
                IsLocalAddressReusable = xmlCat.GetSafeElement("reuse-address").
                                         GetBoolean(IsLocalAddressReusable);

                // <keep-alive-enabled/>
                IsKeepAliveEnabled = xmlCat.GetSafeElement("keep-alive-enabled")
                                     .
                                     GetBoolean(IsKeepAliveEnabled);

                // <tcp-delay-enabled>
                IsTcpDelayEnabled = xmlCat.GetSafeElement("tcp-delay-enabled").
                                    GetBoolean(IsTcpDelayEnabled);

                // <receive-buffer-size>
                ReceiveBufferSize = ParseMemorySize(
                    xmlCat, "receive-buffer-size", ReceiveBufferSize);

                // <send-buffer-size>
                SendBufferSize = ParseMemorySize(
                    xmlCat, "send-buffer-size", SendBufferSize);

                // <linger-timeout>
                LingerTimeout = ParseTime(
                    xmlCat, "linger-timeout", LingerTimeout);
            }
        }