private void Route(ExecutionPlan plan, ExecutionToken token, CancellationToken cancel) { if (token.IsCancelled) { return; } if (token.SubscriptionOperation != null) { _subscriber.Execute(token, cancel); } if (token.CommandOperation != null) { if (plan.ContextOperation.RequiresStandaloneConnection && _heldConnection == null) { _heldConnection = _exclusivePool.Provide(); } if (_heldConnection != null) { _heldConnection.Execute(token, cancel); } else { _multiplexedCommander.Execute(token, cancel); } } _context.Apply(plan.ContextOperation); }
protected override void ProcessResponse(RESPObject response) { if (response == null) { if (_current != null) { _current.SetCancelled(); _current = null; } return; } if (_current == null && !_pending.TryDequeue(out _current)) { throw new InvalidOperationException("Received command response but no token available."); } try { HandleResponseWithToken(response); } catch (OperationCanceledException) { _current.SetCancelled(); throw; } catch (Exception ex) { _current.SetFaulted(ex); throw; } }
protected override void OnDisconnection() { if (_current != null) { _current.SetCancelled(); _current = null; } }
private static void CancelToken(ExecutionToken token) { try { token.SetCancelled(); } catch { // it does not matter } }
private void HandleResponseWithToken(RESPObject response) { _current.CommandOperation.HandleResponse(response); if (_current.CommandOperation.IsCompleted) { if (!_current.IsCancelled) { _connectionCancellation.Token.ThrowIfCancellationRequested(); _current.SetCompleted(); } _current = null; } }
private void HandleResponseWithToken(RESPObject response) { Contract.Assert(_current.SubscriptionOperation != null, "A token without subscription reached the subscriber connection response handler."); if (!_current.SubscriptionOperation.IsCompleted) { _current.SubscriptionOperation.HandleResponse(response); } if (_current.SubscriptionOperation.IsCompleted) { _current.SetCompleted(); _current = null; } }
public void Execute(ExecutionToken token, CancellationToken cancel) { try { _requests.Add(token, cancel); } catch (OperationCanceledException) { token.SetCancelled(); } catch (Exception ex) { token.SetFaulted(ex); } }
private void WriteToken(SocketWriter writer, ExecutionToken token) { try { _logger.Debug("{0} Received token {1}.", _code, token); var hasCommands = false; foreach (var command in ExecuteOperation(token)) { // some subscription commands are aggregated // and produce no commands. if (!hasCommands) { hasCommands = true; _pending.Enqueue(token); } command.WriteTo(writer); } if (hasCommands) { writer.Flush(); // using the async version kills performance, worth investigating why _logger.Debug("{0} flushed buffer.", _code); } } catch (OperationCanceledException) { token.SetCancelled(); throw; } catch (Exception ex) { token.SetFaulted(ex); throw; } }
protected override IEnumerable <RESPCommand> ExecuteOperation(ExecutionToken token) { return(token.SubscriptionOperation.Execute()); }
public void Execute(ExecutionToken token, CancellationToken cancel) { _inner.Execute(token, cancel); }
protected abstract IEnumerable <RESPCommand> ExecuteOperation(ExecutionToken token);
public void Execute(ExecutionToken token, CancellationToken cancel) { _selector.Select(_commanders).Execute(token, cancel); }