internal void OnDispatcherForwardingFailed(Message message, GrainAddress oldAddress, GrainAddress forwardingAddress, string failedOperation, Exception exception) { if (this.IsEnabled(DispatcherForwardingFailedEventName)) { this.Write(DispatcherForwardingFailedEventName, new { Message = message, OldAddress = oldAddress, ForwardingAddress = forwardingAddress, FailedOperation = failedOperation, Exception = exception }); } LogDispatcherForwardingFailed(this, message, oldAddress, forwardingAddress, failedOperation, message.ForwardCount, exception); }
internal SystemTarget(SystemTargetGrainId grainId, SiloAddress silo, bool lowPriority, ILoggerFactory loggerFactory) { this.id = grainId; this.Silo = silo; this.ActivationAddress = GrainAddress.GetAddress(this.Silo, this.id.GrainId, this.ActivationId); this.IsLowPriority = lowPriority; this.ActivationId = ActivationId.GetDeterministic(grainId.GrainId); this.timerLogger = loggerFactory.CreateLogger <GrainTimer>(); this.logger = loggerFactory.CreateLogger(this.GetType()); }
internal void OnDispatcherForwardingMultiple(int messageCount, GrainAddress oldAddress, GrainAddress forwardingAddress, string failedOperation, Exception exception) { if (this.IsEnabled(DispatcherForwardingMultipleEventName)) { this.Write(DispatcherForwardingMultipleEventName, new { MessageCount = messageCount, OldAddress = oldAddress, ForwardingAddress = forwardingAddress, FailedOperation = failedOperation, Exception = exception }); } if (this.IsEnabled(LogLevel.Information)) { LogDispatcherForwardingMultiple(this, messageCount, oldAddress, forwardingAddress, failedOperation, exception); } }
/// <summary> /// If activation already exists, use it /// Otherwise, create an activation of an existing grain by reading its state. /// Return immediately using a dummy that will queue messages. /// Concurrently start creating and initializing the real activation and replace it when it is ready. /// </summary> /// <param name="address">Grain's activation address</param> /// <param name="requestContextData">Request context data.</param> /// <returns></returns> public IGrainContext GetOrCreateActivation( GrainAddress address, Dictionary <string, object> requestContextData) { if (TryGetGrainContext(address.GrainId, out var result)) { return(result); } // Lock over all activations to try to prevent multiple instances of the same activation being created concurrently. lock (activations) { if (TryGetGrainContext(address.GrainId, out result)) { return(result); } if (!SiloStatusOracle.CurrentStatus.IsTerminating()) { result = this.grainActivator.CreateInstance(address); RegisterMessageTarget(result); } } // End lock if (result is null) { // Did not find and did not start placing new if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug((int)ErrorCode.CatalogNonExistingActivation2, "Non-existent activation {Activation}", address.ToFullString()); } CounterStatistic.FindOrCreate(StatisticNames.CATALOG_ACTIVATION_NON_EXISTENT_ACTIVATIONS).Increment(); this.directory.InvalidateCacheEntry(address); // Unregister the target activation so we don't keep getting spurious messages. // The time delay (one minute, as of this writing) is to handle the unlikely but possible race where // this request snuck ahead of another request, with new placement requested, for the same activation. // If the activation registration request from the new placement somehow sneaks ahead of this unregistration, // we want to make sure that we don't unregister the activation we just created. _ = this.UnregisterNonExistentActivation(address); return(null); } else { // Initialize the new activation asynchronously. var cancellation = new CancellationTokenSource(collectionOptions.Value.ActivationTimeout); result.Activate(requestContextData, cancellation.Token); return(result); } }
internal void OnDispatcherForwarding(Message message, GrainAddress oldAddress, GrainAddress forwardingAddress, string failedOperation, Exception exception) { if (this.IsEnabled(DispatcherForwardingEventName)) { this.Write(DispatcherForwardingEventName, new { Message = message, OldAddress = oldAddress, ForwardingAddress = forwardingAddress, FailedOperation = failedOperation, Exception = exception }); } if (this.IsEnabled(LogLevel.Information)) { LogDispatcherForwarding(this, message, oldAddress, forwardingAddress, failedOperation, message.ForwardCount, exception); } MessagingProcessingStatisticsGroup.OnDispatcherMessageForwared(message); }
private async Task UnregisterNonExistentActivation(GrainAddress address) { try { await this.grainLocator.Unregister(address, UnregistrationCause.NonexistentActivation); } catch (Exception exc) { logger.LogWarning( (int)ErrorCode.Dispatcher_FailedToUnregisterNonExistingAct, exc, "Failed to unregister non-existent activation {Address}", address); } }
/// <summary> /// Creates a new grain context for the provided grain address. /// </summary> /// <param name="address">The grain address.</param> /// <returns>The grain context.</returns> public IGrainContext CreateInstance(GrainAddress address) { var grainId = address.GrainId; if (!_activators.TryGetValue(grainId.Type, out var activator)) { activator = this.CreateActivator(grainId.Type); } var result = activator.Activator.CreateContext(address); foreach (var configure in activator.ConfigureActions) { configure.Configure(result); } return(result); }
public IGrainContext CreateContext(GrainAddress activationAddress) { var context = new ActivationData( activationAddress, _createWorkItemGroup, _serviceProvider, _sharedComponents); RuntimeContext.SetExecutionContext(context, out var existingContext); try { // Instantiate the grain itself var grainInstance = (Grain)_grainActivator.CreateInstance(context); context.SetGrainInstance(grainInstance); } finally { RuntimeContext.SetExecutionContext(existingContext); } return(context); }
public IGrainContext CreateContext(GrainAddress address) => new StatelessWorkerGrainContext(address, _sharedContext, _innerActivator);
/// <summary> /// Two grain addresses match if they are equal ignoring their <see cref="MembershipVersion"/> value. /// </summary> /// <param name="address"> The other GrainAddress to compare this one with.</param> /// <returns> Returns <c>true</c> if the two GrainAddress are considered to match</returns> public bool Matches(GrainAddress address) { return(this.SiloAddress == address.SiloAddress && this.GrainId == address.GrainId && this.ActivationId == address.ActivationId); }