/** <inheritdoc /> */ public IGridClientData Data(String cacheName) { lock (dataMap) { GridClientDataImpl data; if (!dataMap.TryGetValue(cacheName, out data)) { IGridClientDataConfiguration dataCfg = cfg.DataConfiguration(cacheName); if (dataCfg == null && cacheName != null) { throw new GridClientException("Data configuration for given cache name was not provided: " + cacheName); } IGridClientLoadBalancer balancer = dataCfg != null ? dataCfg.PinnedBalancer : new GridClientRandomBalancer(); Predicate <IGridClientNode> filter = delegate(IGridClientNode e) { return(e.Caches.ContainsKey(cacheName)); }; data = new GridClientDataImpl(cacheName, this, null, filter, balancer); dataMap.Add(cacheName, data); } return(data); } }
/** * <summary> * Creates a data projection.</summary> * * <param name="cacheName">Cache name for projection.</param> * <param name="cfg">Projection configuration.</param> * <param name="nodes">Pinned nodes.</param> * <param name="filter">Node filter.</param> * <param name="balancer">Pinned node balancer.</param> */ internal GridClientDataImpl(String cacheName, IGridClientProjectionConfig cfg, IEnumerable <N> nodes, Predicate <N> filter, IGridClientLoadBalancer balancer) : base(cfg, nodes, filter, balancer) { CacheName = cacheName; CacheFlags = new HashSet <GridClientCacheFlag>(); }
/** * <summary> * Creates projection with specified client.</summary> * * <param name="cfg">Progjection configuration.</param> * <param name="nodes">Collections of nodes included in this projection.</param> * <param name="filter">Node filter to be applied.</param> * <param name="balancer">Balancer to use.</param> */ protected internal GridClientAbstractProjection(IGridClientProjectionConfig cfg, IEnumerable <N> nodes, Predicate <N> filter, IGridClientLoadBalancer balancer) { A.NotNull(cfg, "projection config"); this.cfg = cfg; this._nodes = nodes == null ? null : new List <N>(nodes); this._filter = filter; this._balancer = balancer; }
/** * <summary> * Creates a sub-projection for current projection.</summary> * * <param name="nodes">Collection of nodes that sub-projection will be restricted to. If <c>null</c>,</param> * created projection is dynamic and will take nodes from topology. * <param name="filter">Filter to be applied to nodes in projection.</param> * <param name="balancer">Balancer to use in projection.</param> * <returns>Created projection.</returns> * <exception cref="GridClientException"> * If resulting projection is empty. Note that this exception may only be thrown on * case of static projections, i.e. where collection of nodes is not null.</exception> */ protected T CreateProjection(ICollection <N> nodes, Predicate <N> filter, IGridClientLoadBalancer balancer) { if (nodes != null && nodes.Count == 0) { throw new GridClientException("Failed to create projection: given nodes collection is empty."); } if (filter != null && this._filter != null) { filter = U.And <N>(this._filter, filter); } else if (filter == null) { filter = this._filter; } ICollection <N> subset = Intersection(this._nodes, nodes); if (subset != null && subset.Count == 0) { throw new GridClientException("Failed to create projection (given node set does not overlap with " + "existing node set) [prjNodes=" + this._nodes + ", nodes=" + nodes); } if (filter != null && subset != null) { subset = U.ApplyFilter(subset, filter); if (subset != null && subset.Count == 0) { throw new GridClientException("Failed to create projection (none of the nodes in projection node " + "set passed the filter) [prjNodes=" + subset + ", filter=" + filter + ']'); } } if (balancer == null) { balancer = this._balancer; } return(CreateProjectionImpl(nodes, filter, balancer)); }
/** <inheritdoc /> */ override protected GridClientDataImpl CreateProjectionImpl(IEnumerable <N> nodes, Predicate <N> filter, IGridClientLoadBalancer balancer) { return(new GridClientDataImpl(CacheName, cfg, nodes, filter, balancer)); }
/** <inheritdoc /> */ public IGridClientCompute Projection(ICollection <N> nodes, IGridClientLoadBalancer balancer) { return(CreateProjection(nodes, null, balancer)); }
/** <inheritdoc /> */ public IGridClientCompute Projection(Predicate <N> filter, IGridClientLoadBalancer balancer) { return(CreateProjection(null, filter, balancer)); }
/** * <summary> * Creates a new compute projection.</summary> * * <param name="cfg">Projection configuration.</param> * <param name="nodes">Nodes to be included in this projection.</param> * <param name="nodeFilter">Node filter to be used for this projection.</param> * <param name="balancer">Balancer to be used in this projection.</param> */ internal GridClientComputeImpl(IGridClientProjectionConfig cfg, IEnumerable <N> nodes, Predicate <N> nodeFilter, IGridClientLoadBalancer balancer) : base(cfg, nodes, nodeFilter, balancer) { }
/** * <summary> * Subclasses must implement this method and return concrete implementation of projection needed.</summary> * * <param name="nodes">Nodes that are included in projection.</param> * <param name="filter">Filter to be applied.</param> * <param name="balancer">Balancer to be used.</param> * <returns>Created projection.</returns> */ protected abstract T CreateProjectionImpl(IEnumerable <N> nodes, Predicate <N> filter, IGridClientLoadBalancer balancer);