/// <summary>Constructs a reference to the grain with the specified Id.</summary> /// <param name="grainId">The Id of the grain to refer to.</param> /// <param name="genericArgument">Type arguments in case of a generic grain.</param> /// <param name="runtime">The runtime which this grain reference is bound to.</param> private GrainReference(GrainId grainId, string genericArgument, IGrainReferenceRuntime runtime) { GrainId = grainId; this.genericArguments = genericArgument; this.runtime = runtime; if (string.IsNullOrEmpty(genericArgument)) { genericArguments = null; // always keep it null instead of empty. } // SystemTarget checks var isSystemTarget = grainId.IsSystemTarget(); if (SystemTargetGrainId.TryParse(grainId, out var systemTargetId)) { this.SystemTargetSilo = systemTargetId.GetSiloAddress(); if (SystemTargetSilo == null) { throw new ArgumentNullException("systemTargetSilo", String.Format("Trying to create a GrainReference for SystemTarget grain id {0}, but passing null systemTargetSilo.", grainId)); } if (genericArguments != null) { throw new ArgumentException(String.Format("Trying to create a GrainReference for SystemTarget grain id {0}, and also passing non-null genericArguments {1}.", grainId, genericArguments), "genericArgument"); } } // ObserverId checks var isClient = grainId.IsClient(); if (isClient) { // Note: we can probably just remove this check - it serves little purpose. if (!ObserverGrainId.TryParse(grainId, out _)) { throw new ArgumentNullException("observerId", String.Format("Trying to create a GrainReference for Observer with Client grain id {0}, but passing null observerId.", grainId)); } if (genericArguments != null) { throw new ArgumentException(String.Format("Trying to create a GrainReference for Client grain id {0}, and also passing non-null genericArguments {1}.", grainId, genericArguments), "genericArgument"); } } }
public void SendRequest( GrainReference target, InvokeMethodRequest request, TaskCompletionSource <object> context, InvokeMethodOptions options) { var message = this.messageFactory.CreateMessage(request, options); message.InterfaceType = target.InterfaceType; message.InterfaceVersion = target.InterfaceVersion; // fill in sender if (message.SendingSilo == null) { message.SendingSilo = MySilo; } IGrainContext sendingActivation = RuntimeContext.CurrentGrainContext; if (sendingActivation == null) { var clientAddress = this.HostedClient.Address; message.SendingGrain = clientAddress.Grain; message.SendingActivation = clientAddress.Activation; } else { message.SendingActivation = sendingActivation.ActivationId; message.SendingGrain = sendingActivation.GrainId; } // fill in destination var targetGrainId = target.GrainId; message.TargetGrain = targetGrainId; SharedCallbackData sharedData; if (SystemTargetGrainId.TryParse(targetGrainId, out var systemTargetGrainId)) { message.TargetSilo = systemTargetGrainId.GetSiloAddress(); message.TargetActivation = ActivationId.GetDeterministic(targetGrainId); message.Category = targetGrainId.Type.Equals(Constants.MembershipOracleType) ? Message.Categories.Ping : Message.Categories.System; sharedData = this.systemSharedCallbackData; } else { sharedData = this.sharedCallbackData; } var oneWay = (options & InvokeMethodOptions.OneWay) != 0; if (context is null && !oneWay) { this.logger.Warn(ErrorCode.IGC_SendRequest_NullContext, "Null context {0}: {1}", message, Utils.GetStackTrace()); } if (message.IsExpirableMessage(this.messagingOptions.DropExpiredMessages)) { message.TimeToLive = sharedData.ResponseTimeout; } if (!oneWay) { var callbackData = new CallbackData(sharedData, context, message); callbacks.TryAdd(message.Id, callbackData); } this.messagingTrace.OnSendRequest(message); this.Dispatcher.SendMessage(message, sendingActivation); }