/** * <summary> * This method executes request to a communication layer and handles connection error, if it occurs. Server * is picked up according to the projection affinity and key given. Connection will be made with the node * on which key is cached. In case of communication exception client instance is notified and new instance * of client is created. If none of servers can be reached, an exception is thrown.</summary> * * <param name="c">Closure to be executed.</param> * <param name="cacheName">Cache name for which mapped node will be calculated.</param> * <param name="affKey">Affinity key.</param> * <returns>Closure result.</returns> */ protected IGridClientFuture <TRes> WithReconnectHandling <TRes>(Func <IGridClientConnection, Guid, IGridClientFuture <TRes> > c, String cacheName, Object affKey) { IGridClientDataAffinity affinity = cfg.Affinity(cacheName); // If pinned (fixed-nodes) or no affinity provided use balancer. if (_nodes != null || affinity == null) { return(WithReconnectHandling(c)); } try { IList <N> prjNodes = ProjectionNodes(); if (prjNodes.Count == 0) { throw new GridClientServerUnreachableException("Failed to get affinity node" + " (no nodes in topology were accepted by the filter): " + _filter); } N node = affinity.Node(affKey, prjNodes); GridClientConnectionManager connMgr = cfg.ConnectionManager; for (int i = 0; i < RetryCount; i++) { IGridClientConnection conn = null; try { conn = connMgr.connection(node); return(c(conn, node.Id)); } catch (GridClientConnectionIdleClosedException e) { connMgr.onFacadeFailed(node, conn, e); } catch (GridClientConnectionResetException e) { connMgr.onFacadeFailed(node, conn, e); if (!CheckNodeAlive(node.Id)) { throw new GridClientServerUnreachableException("Failed to communicate with mapped grid node" + " for given affinity key (node left the grid)" + " [nodeId=" + node.Id + ", affKey=" + affKey + ']'); } } } throw new GridClientServerUnreachableException("Failed to communicate with mapped grid node for given affinity " + "key (did node left the grid?) [nodeId=" + node.Id + ", affKey=" + affKey + ']'); } catch (GridClientException e) { return(new GridClientFinishedFuture <TRes>(() => { throw e; })); } }