protected virtual void Send(ClientConnection connection, ClientInvocation clientInvocation) { var correlationId = NextCorrelationId(); clientInvocation.Message.SetCorrelationId(correlationId); clientInvocation.Message.AddFlag(ClientMessage.BeginAndEndFlags); clientInvocation.SentConnection = connection; if (clientInvocation.PartitionId != -1) { clientInvocation.Message.SetPartitionId(clientInvocation.PartitionId); } if (clientInvocation.MemberUuid != null && clientInvocation.MemberUuid != connection.GetMember().GetUuid()) { HandleException(clientInvocation, new TargetNotMemberException( "The member UUID on the invocation doesn't match the member UUID on the connection.")); } if (_isShutDown) { FailRequestDueToShutdown(clientInvocation); } else { RegisterInvocation(correlationId, clientInvocation); //enqueue to write queue if (!connection.WriteAsync((ISocketWritable) clientInvocation.Message)) { UnregisterCall(correlationId); RemoveEventHandler(correlationId); FailRequest(connection, clientInvocation); } } }
private bool TrySend(ClientInvocation clientInvocation, ClientConnection connection) { var correlationId = clientInvocation.Message.GetCorrelationId(); if (!TryRegisterInvocation(correlationId, clientInvocation)) return false; //enqueue to write queue if (connection.WriteAsync((ISocketWritable) clientInvocation.Message)) { return true; } //Rollback sending failed if (Logger.IsFinestEnabled()) { Logger.Finest("Unable to write request " + clientInvocation.Message + " to connection " + connection); } UnregisterInvocation(correlationId); RemoveEventHandler(correlationId); return false; }