public InsideRuntimeClient( ILocalSiloDetails siloDetails, GrainTypeManager typeManager, TypeMetadataCache typeMetadataCache, OrleansTaskScheduler scheduler, IServiceProvider serviceProvider, MessageFactory messageFactory, Factory <ITransactionAgent> transactionAgent, ILoggerFactory loggerFactory, IOptions <SiloMessagingOptions> messagingOptions, IGrainCancellationTokenRuntime cancellationTokenRuntime, IOptions <SchedulingOptions> schedulerOptions) { this.ServiceProvider = serviceProvider; this.MySilo = siloDetails.SiloAddress; this.disposables = new List <IDisposable>(); this.callbacks = new ConcurrentDictionary <CorrelationId, CallbackData>(); this.ResponseTimeout = messagingOptions.Value.ResponseTimeout; this.typeManager = typeManager; this.messageFactory = messageFactory; this.transactionAgent = new Lazy <ITransactionAgent>(() => transactionAgent()); this.Scheduler = scheduler; this.ConcreteGrainFactory = new GrainFactory(this, typeMetadataCache); this.tryResendMessage = msg => this.Dispatcher.TryResendMessage(msg); this.unregisterCallback = msg => this.UnRegisterCallback(msg.Id); this.logger = loggerFactory.CreateLogger <InsideRuntimeClient>(); this.invokeExceptionLogger = loggerFactory.CreateLogger($"{typeof(Grain).FullName}.InvokeException"); this.loggerFactory = loggerFactory; this.messagingOptions = messagingOptions.Value; this.callbackDataLogger = loggerFactory.CreateLogger <CallbackData>(); this.timerLogger = loggerFactory.CreateLogger <SafeTimer>(); this.cancellationTokenRuntime = cancellationTokenRuntime; this.schedulingOptions = schedulerOptions.Value; }
public CancellationSourcesExtension(ILoggerFactory loggerFactory, IGrainCancellationTokenRuntime cancellationRuntime) { _logger = loggerFactory.CreateLogger <CancellationSourcesExtension>(); _cancellationTokenRuntime = cancellationRuntime; _cleanupTimer = new Timer(obj => ((CancellationSourcesExtension)obj).ExpireTokens(), this, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30)); _createToken = id => new Entry(new GrainCancellationToken(id, false, _cancellationTokenRuntime)); }
/// <summary> /// Adds CancellationToken to the grain extension /// so that it can be cancelled through remote call to the CancellationSourcesExtension. /// </summary> /// <param name="target"></param> /// <param name="request"></param> /// <param name="loggerFactory">logger factory configured in current cluster</param> /// <param name="logger">caller's logger</param> /// <param name="siloRuntimeClient"></param> /// <param name="cancellationTokenRuntime"></param> internal static void RegisterCancellationTokens( IAddressable target, InvokeMethodRequest request, ILoggerFactory loggerFactory, ILogger logger, ISiloRuntimeClient siloRuntimeClient, IGrainCancellationTokenRuntime cancellationTokenRuntime) { for (var i = 0; i < request.Arguments.Length; i++) { var arg = request.Arguments[i]; if (!(arg is GrainCancellationToken)) { continue; } var grainToken = ((GrainCancellationToken)request.Arguments[i]); CancellationSourcesExtension cancellationExtension; if (!siloRuntimeClient.TryGetExtensionHandler(out cancellationExtension)) { cancellationExtension = new CancellationSourcesExtension(loggerFactory); if (!siloRuntimeClient.TryAddExtension(cancellationExtension)) { logger.Error( ErrorCode.CancellationExtensionCreationFailed, $"Could not add cancellation token extension to: {target}"); return; } } // Replacing the half baked GrainCancellationToken that came from the wire with locally fully created one. request.Arguments[i] = cancellationExtension.RecordCancellationToken(grainToken.Id, grainToken.IsCancellationRequested, cancellationTokenRuntime); } }
public InsideRuntimeClient( ILocalSiloDetails siloDetails, GrainTypeManager typeManager, TypeMetadataCache typeMetadataCache, OrleansTaskScheduler scheduler, IServiceProvider serviceProvider, MessageFactory messageFactory, ITransactionAgent transactionAgent, ILoggerFactory loggerFactory, IOptions <SiloMessagingOptions> messagingOptions, IGrainCancellationTokenRuntime cancellationTokenRuntime, IOptions <SchedulingOptions> schedulerOptions, ApplicationRequestsStatisticsGroup appRequestStatistics) { this.ServiceProvider = serviceProvider; this.MySilo = siloDetails.SiloAddress; this.disposables = new List <IDisposable>(); this.callbacks = new ConcurrentDictionary <CorrelationId, CallbackData>(); this.typeManager = typeManager; this.messageFactory = messageFactory; this.transactionAgent = transactionAgent; this.Scheduler = scheduler; this.ConcreteGrainFactory = new GrainFactory(this, typeMetadataCache); this.logger = loggerFactory.CreateLogger <InsideRuntimeClient>(); this.invokeExceptionLogger = loggerFactory.CreateLogger($"{typeof(Grain).FullName}.InvokeException"); this.loggerFactory = loggerFactory; this.messagingOptions = messagingOptions.Value; this.cancellationTokenRuntime = cancellationTokenRuntime; this.appRequestStatistics = appRequestStatistics; this.schedulingOptions = schedulerOptions.Value; }
internal void AddGrainReference(IGrainCancellationTokenRuntime runtime, GrainReference grainReference) { if (_cancellationTokenRuntime == null) { _cancellationTokenRuntime = runtime; } _targetGrainReferences.TryAdd(grainReference.GrainId, grainReference); }
/// <summary> /// Initializes the <see cref="T:Orleans.GrainCancellationToken"/>. /// </summary> internal GrainCancellationToken(Guid id, bool canceled, IGrainCancellationTokenRuntime runtime = null) : this(id) { _cancellationTokenRuntime = runtime; if (canceled) { // we Cancel _cancellationTokenSource just "to store" the cancelled state. _cancellationTokenSource.Cancel(); } }
public GrainReferenceRuntime( ILogger <GrainReferenceRuntime> logger, IRuntimeClient runtimeClient, IGrainCancellationTokenRuntime cancellationTokenRuntime, IInternalGrainFactory internalGrainFactory, SerializationManager serializationManager) { this.responseCallbackDelegate = this.ResponseCallback; this.logger = logger; this.RuntimeClient = runtimeClient; this.cancellationTokenRuntime = cancellationTokenRuntime; this.internalGrainFactory = internalGrainFactory; this.serializationManager = serializationManager; }
public GrainReferenceRuntime( IRuntimeClient runtimeClient, IGrainCancellationTokenRuntime cancellationTokenRuntime, IEnumerable <IOutgoingGrainCallFilter> outgoingCallFilters, GrainReferenceActivator referenceActivator, GrainInterfaceTypeResolver interfaceTypeResolver) { this.RuntimeClient = runtimeClient; this.cancellationTokenRuntime = cancellationTokenRuntime; this.referenceActivator = referenceActivator; this.interfaceTypeResolver = interfaceTypeResolver; this.filters = outgoingCallFilters.ToArray(); this.sendRequest = (GrainReference reference, IResponseCompletionSource callback, IInvokable body, InvokeMethodOptions options) => RuntimeClient.SendRequest(reference, body, callback, options); }
public GrainReferenceRuntime( IRuntimeClient runtimeClient, IGrainCancellationTokenRuntime cancellationTokenRuntime, SerializationManager serializationManager, IEnumerable <IOutgoingGrainCallFilter> outgoingCallFilters, TypeMetadataCache typeMetadataCache) { this.grainReferenceMethodCache = new InterfaceToImplementationMappingCache(); this.sendRequestDelegate = SendRequest; this.RuntimeClient = runtimeClient; this.cancellationTokenRuntime = cancellationTokenRuntime; this.GrainReferenceFactory = new GrainReferenceFactory(typeMetadataCache, this); this.serializationManager = serializationManager; this.filters = outgoingCallFilters.ToArray(); }
public GrainReferenceRuntime( IRuntimeClient runtimeClient, IGrainCancellationTokenRuntime cancellationTokenRuntime, IEnumerable <IOutgoingGrainCallFilter> outgoingCallFilters, GrainReferenceActivator referenceActivator, GrainInterfaceTypeResolver interfaceTypeResolver, DeepCopier deepCopier) { this.RuntimeClient = runtimeClient; this.cancellationTokenRuntime = cancellationTokenRuntime; this.referenceActivator = referenceActivator; this.interfaceTypeResolver = interfaceTypeResolver; this.filters = outgoingCallFilters.ToArray(); this.sendRequest = this.SendRequest; this.deepCopier = deepCopier; }
public GrainReferenceRuntime( ILogger <GrainReferenceRuntime> logger, IRuntimeClient runtimeClient, IGrainCancellationTokenRuntime cancellationTokenRuntime, IInternalGrainFactory internalGrainFactory, SerializationManager serializationManager, IEnumerable <IOutgoingGrainCallFilter> outgoingCallFilters) { this.grainReferenceMethodCache = new InterfaceToImplementationMappingCache(); this.sendRequestDelegate = SendRequest; this.logger = logger; this.RuntimeClient = runtimeClient; this.cancellationTokenRuntime = cancellationTokenRuntime; this.internalGrainFactory = internalGrainFactory; this.serializationManager = serializationManager; this.filters = outgoingCallFilters.ToArray(); }
public GrainReferenceRuntime( IRuntimeClient runtimeClient, IGrainCancellationTokenRuntime cancellationTokenRuntime, SerializationManager serializationManager, IEnumerable <IOutgoingGrainCallFilter> outgoingCallFilters, GrainReferenceActivator referenceActivator, GrainInterfaceTypeResolver interfaceTypeResolver) { this.grainReferenceMethodCache = new InterfaceToImplementationMappingCache(); this.sendRequestDelegate = SendRequest; this.RuntimeClient = runtimeClient; this.cancellationTokenRuntime = cancellationTokenRuntime; this.serializationManager = serializationManager; this.referenceActivator = referenceActivator; this.interfaceTypeResolver = interfaceTypeResolver; this.filters = outgoingCallFilters.ToArray(); }
public InsideRuntimeClient( ILocalSiloDetails siloDetails, ClusterConfiguration config, GrainTypeManager typeManager, TypeMetadataCache typeMetadataCache, OrleansTaskScheduler scheduler, IServiceProvider serviceProvider, SerializationManager serializationManager, MessageFactory messageFactory, IEnumerable <IGrainCallFilter> registeredInterceptors, Factory <ITransactionAgent> transactionAgent, ILoggerFactory loggerFactory, IOptions <SiloMessagingOptions> messagingOptions, IGrainCancellationTokenRuntime cancellationTokenRuntime) { this.ServiceProvider = serviceProvider; this.SerializationManager = serializationManager; MySilo = siloDetails.SiloAddress; disposables = new List <IDisposable>(); callbacks = new ConcurrentDictionary <CorrelationId, CallbackData>(); Config = config; config.OnConfigChange("Globals/Message", () => ResponseTimeout = Config.Globals.ResponseTimeout); this.typeManager = typeManager; this.messageFactory = messageFactory; this.transactionAgent = new Lazy <ITransactionAgent>(() => transactionAgent()); this.Scheduler = scheduler; this.ConcreteGrainFactory = new GrainFactory(this, typeMetadataCache); tryResendMessage = msg => this.Dispatcher.TryResendMessage(msg); unregisterCallback = msg => UnRegisterCallback(msg.Id); this.siloInterceptors = new List <IGrainCallFilter>(registeredInterceptors); this.logger = loggerFactory.CreateLogger <InsideRuntimeClient>(); this.invokeExceptionLogger = loggerFactory.CreateLogger($"{typeof(Grain).FullName}.InvokeException"); this.loggerFactory = loggerFactory; this.messagingOptions = messagingOptions.Value; this.callbackDataLogger = new LoggerWrapper <CallbackData>(loggerFactory); this.timerLogger = loggerFactory.CreateLogger <SafeTimer>(); this.cancellationTokenRuntime = cancellationTokenRuntime; }
private GrainCancellationToken RecordCancellationToken(Guid tokenId, bool isCancellationRequested, IGrainCancellationTokenRuntime cancellationTokenRuntime) { GrainCancellationToken localToken; if (_cancellationTokens.TryFind(tokenId, out localToken)) { return(localToken); } return(_cancellationTokens.Intern(tokenId, new GrainCancellationToken(tokenId, isCancellationRequested, cancellationTokenRuntime))); }
public GrainCancellationTokenCodec(IGrainCancellationTokenRuntime runtime, IValueSerializer <GrainCancellationTokenSurrogate> surrogateSerializer) : base(surrogateSerializer) { _runtime = runtime; }