예제 #1
0
        /**
         * <summary>
         * Creates client node instance from message.</summary>
         *
         * <param name="nodeBean">Node bean message.</param>
         * <returns>Created node.</returns>
         */
        private GridClientNodeImpl nodeBeanToNode(GridClientNodeBean nodeBean)
        {
            if (nodeBean == null)
            {
                return(null);
            }

            Guid nodeId = nodeBean.NodeId;

            GridClientNodeImpl node = new GridClientNodeImpl(nodeId);

            node.TcpAddresses.AddAll <String>(nodeBean.TcpAddresses);
            node.JettyAddresses.AddAll <String>(nodeBean.JettyAddresses);
            node.TcpPort      = nodeBean.TcpPort;
            node.ConsistentId = nodeBean.ConsistentId;
            node.HttpPort     = nodeBean.JettyPort;
            node.ReplicaCount = nodeBean.ReplicaCount;

            if (nodeBean.Caches != null && nodeBean.Caches.Count > 0)
            {
                node.Caches.AddAll <KeyValuePair <String, GridClientCacheMode> >(parseCacheModes(nodeBean.Caches));
            }

            if (nodeBean.Attributes != null && nodeBean.Attributes.Count > 0)
            {
                node.Attributes.AddAll <KeyValuePair <String, Object> >(nodeBean.Attributes);
            }

            if (nodeBean.Metrics != null && nodeBean.Metrics.Count > 0)
            {
                node.Metrics = parseNodeMetrics(nodeBean.Metrics);
            }

            return(node);
        }
예제 #2
0
        /** <inheritdoc /> */
        override public bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            GridClientNodeImpl that = obj as GridClientNodeImpl;

            return(that != null && Id.Equals(that.Id));
        }
        /**
         * <summary>
         * Requests for the node.</summary>
         *
         * <param name="args">Request parameters.</param>
         * <param name="includeAttrs">Whether to include attributes.</param>
         * <param name="includeMetrics">Whether to include metrics.</param>
         * <param name="destNodeId">Node ID to route request to.</param>
         * <returns>Node.</returns>
         */
        private IGridClientFuture <IGridClientNode> Node(IDictionary <String, Object> args, bool includeAttrs, bool includeMetrics, Guid destNodeId)
        {
            Dbg.Assert(args != null);

            args.Add("cmd", "node");
            args.Add("attr", includeAttrs.ToString());
            args.Add("mtr", includeMetrics.ToString());

            return(MakeJettyRequest <IGridClientNode>(destNodeId, args, o => {
                GridClientNodeImpl node = JsonBeanToNode((IDictionary <String, Object>)o);

                if (node != null)
                {
                    Top.UpdateNode(node);
                }

                return node;
            }));
        }
예제 #4
0
        /**
         * <summary>
         * Clears attributes and metrics map in case if node cache is disabled.</summary>
         *
         * <param name="node">Node to be cleared.</param>
         * <returns>The same node if cache is enabled or node contains no attributes and metrics,</returns>
         *      otherwise will return new node without attributes and metrics.
         */
        private N ClearAttributes(N node)
        {
            if (topCache || (node.Attributes.Count == 0 && node.Metrics == null))
            {
                return(node);
            }

            // Fill all fields but attributes and metrics since we do not cache them.
            GridClientNodeImpl updated = new GridClientNodeImpl(node.Id);

            updated.TcpAddresses.AddAll <String>(node.TcpAddresses);
            updated.TcpHostNames.AddAll <String>(node.TcpHostNames);
            updated.JettyAddresses.AddAll <String>(node.JettyAddresses);
            updated.JettyHostNames.AddAll <String>(node.JettyHostNames);
            updated.TcpPort      = node.TcpPort;
            updated.HttpPort     = node.HttpPort;
            updated.ConsistentId = node.ConsistentId;
            updated.Metrics      = null;
            updated.Caches.AddAll <KeyValuePair <String, GridClientCacheMode> >(node.Caches);

            return(updated);
        }
        /**
         * <summary>
         * Creates client node impl from json object representation.</summary>
         *
         * <param name="json">JSONObject (possibly JSONNull).</param>
         * <returns>Converted client node.</returns>
         */
        private GridClientNodeImpl JsonBeanToNode(IDictionary <String, Object> json)
        {
            Guid nodeId = Guid.Parse(json["nodeId"].ToString());

            GridClientNodeImpl node = new GridClientNodeImpl(nodeId);

            node.TcpAddresses.AddAll <String>(AsList <String>(json["tcpAddresses"]));
            node.TcpHostNames.AddAll <String>(AsList <String>(json["tcpHostNames"]));
            node.JettyAddresses.AddAll <String>(AsList <String>(json["jettyAddresses"]));
            node.JettyHostNames.AddAll <String>(AsList <String>(json["jettyHostNames"]));
            node.TcpPort      = (int)json["tcpPort"];
            node.HttpPort     = (int)json["jettyPort"];
            node.ConsistentId = json["consistentId"];
            node.ReplicaCount = (int)json["replicaCount"];

            IDictionary <String, GridClientCacheMode> caches = new GridClientNullDictionary <String, GridClientCacheMode>();

            if (json.ContainsKey("caches"))
            {
                IDictionary <String, String> rawCaches = AsMap <String, String>(json["caches"]);

                Object dfltCacheMode;

                if (json.TryGetValue("defaultCacheMode", out dfltCacheMode))
                {
                    String mode = dfltCacheMode as String;

                    if (!String.IsNullOrEmpty(mode))
                    {
                        rawCaches = rawCaches.ToNullable();

                        rawCaches.Add(null, mode);
                    }
                }

                caches = parseCacheModes(rawCaches);
            }

            if (caches.Count > 0)
            {
                node.Caches.AddAll <KeyValuePair <String, GridClientCacheMode> >(caches);
            }

            Object o;

            if (json.TryGetValue("attributes", out o) && o != null)
            {
                var map = AsMap <String, Object>(o);

                if (map.Count > 0)
                {
                    node.Attributes.AddAll <KeyValuePair <String, Object> >(map);
                }
            }

            if (json.TryGetValue("metrics", out o) && o != null)
            {
                var map = AsMap <String, Object>(o);

                if (map.Count > 0)
                {
                    node.Metrics = parseNodeMetrics(AsMap <String, Object>(o));
                }
            }

            return(node);
        }