public virtual async Task TestBecomeConsumerSlim(Guid streamIdGuid, string providerName) { InitStream(streamIdGuid, null, providerName); var observer = new MyStreamObserver <int>(logger); //var subsHandle = await State.Stream.SubscribeAsync(observer); IStreamConsumerExtension myExtensionReference; #if USE_CAST myExtensionReference = StreamConsumerExtensionFactory.Cast(this.AsReference()); #else var tup = await this.runtimeClient.BindExtension <StreamConsumerExtension, IStreamConsumerExtension>( () => new StreamConsumerExtension(this.streamProviderRuntime)); StreamConsumerExtension myExtension = tup.Item1; myExtensionReference = tup.Item2; #endif string extKey = providerName + "_" + State.Stream.Namespace; IPubSubRendezvousGrain pubsub = GrainFactory.GetGrain <IPubSubRendezvousGrain>(streamIdGuid, extKey, null); GuidId subscriptionId = GuidId.GetNewGuidId(); await pubsub.RegisterConsumer(subscriptionId, ((StreamImpl <int>)State.Stream).StreamId, myExtensionReference, null); myExtension.SetObserver(subscriptionId, ((StreamImpl <int>)State.Stream), observer, null, null, null); }
public async Task BecomeConsumer(Guid streamId, string streamNamespace, string providerName, bool sendEvensOnly) { _logger = logger; if (logger.IsVerbose) { logger.Verbose("BecomeConsumer StreamId={0} StreamProvider={1} Filter={2} Grain={3}", streamId, providerName, sendEvensOnly, this.AsReference <IFilteredStreamConsumerGrain>()); } InitStream(streamId, streamNamespace, providerName); var observer = new MyStreamObserver <int>(logger); StreamFilterPredicate filterFunc; object filterData; if (sendEvensOnly) { filterFunc = FilterIsEven; filterData = FilterDataEven; } else { filterFunc = FilterIsOdd; filterData = FilterDataOdd; } var subsHandle = await State.Stream.SubscribeAsync(observer, null, filterFunc, filterData); State.ConsumerSubscriptionHandles.Add(subsHandle); Observers.Add(subsHandle, observer); await WriteStateAsync(); }
public virtual async Task BecomeConsumer(StreamId streamId, string providerToUse) { if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("BecomeConsumer StreamId={0} StreamProvider={1} Grain={2}", streamId, providerToUse, this.AsReference <IStreamLifecycleConsumerGrain>()); } InitStream(streamId, providerToUse); var observer = new MyStreamObserver <int>(logger); var subsHandle = await State.Stream.SubscribeAsync(observer); State.ConsumerSubscriptionHandles.Add(subsHandle); Observers.Add(subsHandle, observer); await WriteStateAsync(); }
public async Task SubscribeWithBadFunc(Guid streamId, string streamNamespace, string providerName) { logger.Info("SubscribeWithBadFunc StreamId={0} StreamProvider={1}Grain={2}", streamId, providerName, this.AsReference <IFilteredStreamConsumerGrain>()); InitStream(streamId, streamNamespace, providerName); var observer = new MyStreamObserver <int>(logger); StreamFilterPredicate filterFunc = BadFunc; // This next call should fail because func is not static await State.Stream.SubscribeAsync(observer, null, filterFunc); }
public virtual async Task TestBecomeConsumerSlim(Guid streamIdGuid, string providerName) { InitStream(streamIdGuid, null, providerName); var observer = new MyStreamObserver <int>(logger); var(myExtension, myExtensionReference) = this.streamProviderRuntime.BindExtension <StreamConsumerExtension, IStreamConsumerExtension>( () => new StreamConsumerExtension(streamProviderRuntime)); string extKey = providerName + "_" + State.Stream.Namespace; IPubSubRendezvousGrain pubsub = GrainFactory.GetGrain <IPubSubRendezvousGrain>(streamIdGuid, extKey, null); GuidId subscriptionId = GuidId.GetNewGuidId(); await pubsub.RegisterConsumer(subscriptionId, ((StreamImpl <int>)State.Stream).StreamId, myExtensionReference, null); myExtension.SetObserver(subscriptionId, ((StreamImpl <int>)State.Stream), observer, null, null, null); }
public virtual async Task TestBecomeConsumerSlim(StreamId streamId, string providerName) { InitStream(streamId, providerName); var observer = new MyStreamObserver <int>(logger); //var subsHandle = await State.Stream.SubscribeAsync(observer); var(myExtension, myExtensionReference) = this.streamProviderRuntime.BindExtension <StreamConsumerExtension, IStreamConsumerExtension>( () => new StreamConsumerExtension(streamProviderRuntime)); string extKey = providerName + "_" + Encoding.UTF8.GetString(State.Stream.StreamId.Namespace.ToArray()); var id = new InternalStreamId(providerName, streamId); IPubSubRendezvousGrain pubsub = GrainFactory.GetGrain <IPubSubRendezvousGrain>(id.ToString()); GuidId subscriptionId = GuidId.GetNewGuidId(); await pubsub.RegisterConsumer(subscriptionId, ((StreamImpl <int>)State.Stream).InternalStreamId, myExtensionReference, null); myExtension.SetObserver(subscriptionId, ((StreamImpl <int>)State.Stream), observer, null, null, null); }
public async Task <StreamSubscriptionHandle <int> > AddConsumer(Guid streamId, string providerName) #endif { logger.Info("AddConsumer StreamId={0} StreamProvider={1} Grain={2}", streamId, providerName, this.AsReference <IStreamReliabilityTestGrain>()); TryInitStream(streamId, providerName); #if USE_GENERICS var observer = new MyStreamObserver <T>(); #else var observer = new MyStreamObserver <int>(logger); #endif var subsHandle = await Stream.SubscribeAsync(observer); Observers.Add(subsHandle, observer); State.ConsumerSubscriptionHandles.Add(subsHandle); await WriteStateAsync(); return(subsHandle); }
public virtual async Task TestBecomeConsumerSlim(Guid streamIdGuid, string providerName) { // TODO NOT SURE THIS FUNCTION MAKESE ANY SENSE var streamId = StreamId.Create(null, streamIdGuid); InitStream(streamId, providerName); var observer = new MyStreamObserver <int>(logger); var(myExtension, myExtensionReference) = this.streamProviderRuntime.BindExtension <StreamConsumerExtension, IStreamConsumerExtension>( () => new StreamConsumerExtension(streamProviderRuntime)); var id = new InternalStreamId(providerName, streamId); IPubSubRendezvousGrain pubsub = GrainFactory.GetGrain <IPubSubRendezvousGrain>(id.ToString()); GuidId subscriptionId = GuidId.GetNewGuidId(); await pubsub.RegisterConsumer(subscriptionId, ((StreamImpl <int>)State.Stream).InternalStreamId, myExtensionReference, null); myExtension.SetObserver(subscriptionId, ((StreamImpl <int>)State.Stream), observer, null, null, null); }
public async Task Subscribe(Guid streamId, string providerName) { logger.Info("Subscribe StreamId={0} StreamProvider={1} Grain={2}", streamId, providerName, this.AsReference <IStreamUnsubscribeTestGrain>()); State.StreamProviderName = providerName; if (State.Stream == null) { logger.Info("InitStream StreamId={0} StreamProvider={1}", streamId, providerName); IStreamProvider streamProvider = this.GetStreamProvider(providerName); State.Stream = streamProvider.GetStream <int>(streamId, StreamNamespace); } var observer = new MyStreamObserver <int>(logger); var consumer = State.Stream; var subsHandle = await consumer.SubscribeAsync(observer); State.ConsumerSubscriptionHandles.Add(subsHandle); await WriteStateAsync(); }
private async Task ReconnectConsumerHandles(StreamSubscriptionHandle <int>[] subscriptionHandles) #endif { logger.Info("ReconnectConsumerHandles SubscriptionHandles={0} Grain={1}", Utils.EnumerableToString(subscriptionHandles), this.AsReference <IStreamReliabilityTestGrain>()); foreach (var subHandle in subscriptionHandles) { #if USE_GENERICS // var stream = GetStreamProvider(State.StreamProviderName).GetStream<T>(subHandle.StreamId); var stream = subHandle.Stream; var observer = new MyStreamObserver <T>(); #else var observer = new MyStreamObserver <int>(logger); #endif var subsHandle = await subHandle.ResumeAsync(observer); Observers.Add(subsHandle, observer); State.ConsumerSubscriptionHandles.Add(subsHandle); } await WriteStateAsync(); }
public override async Task OnActivateAsync() { logger = GetLogger(GetType().Name + "-" + IdentityString); if (logger.IsVerbose) { logger.Verbose("OnActivateAsync"); } await RecordActivate(); if (Observers == null) { Observers = new Dictionary <StreamSubscriptionHandle <int>, MyStreamObserver <int> >(); } if (State.Stream != null && State.StreamProviderName != null) { if (State.ConsumerSubscriptionHandles.Count > 0) { var handles = State.ConsumerSubscriptionHandles.ToArray(); logger.Info("ReconnectConsumerHandles SubscriptionHandles={0} Grain={1}", Utils.EnumerableToString(handles), this.AsReference <IStreamLifecycleConsumerGrain>()); foreach (var handle in handles) { var observer = new MyStreamObserver <int>(logger); StreamSubscriptionHandle <int> subsHandle = await handle.ResumeAsync(observer); Observers.Add(subsHandle, observer); } } } else { if (logger.IsVerbose) { logger.Verbose("Not conected to stream yet."); } } }
public override async Task OnActivateAsync(CancellationToken cancellationToken) { if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("OnActivateAsync"); } await RecordActivate(); if (Observers == null) { Observers = new Dictionary <StreamSubscriptionHandle <int>, MyStreamObserver <int> >(); } if (State.Stream != null && State.StreamProviderName != null) { if (State.ConsumerSubscriptionHandles.Count > 0) { var handles = State.ConsumerSubscriptionHandles.ToArray(); logger.Info("ReconnectConsumerHandles SubscriptionHandles={0} Grain={1}", Utils.EnumerableToString(handles), this.AsReference <IStreamLifecycleConsumerGrain>()); foreach (var handle in handles) { var observer = new MyStreamObserver <int>(this.logger); StreamSubscriptionHandle <int> subsHandle = await handle.ResumeAsync(observer); Observers.Add(subsHandle, observer); } } } else { if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("Not conected to stream yet."); } } }