public async Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { ISet<PubSubSubscriptionState> explicitRes = await explicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer); ISet<PubSubSubscriptionState> implicitRes = await implicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer); explicitRes.UnionWith(implicitRes); return explicitRes; }
public async Task UnregisterProducer(StreamId streamId, IStreamProducerExtension streamProducer) { counterProducersRemoved.Increment(); try { int numRemoved = State.Producers.RemoveWhere(s => s.Equals(streamId, streamProducer)); LogPubSubCounts("UnregisterProducer {0} NumRemoved={1}", streamProducer, numRemoved); if (numRemoved > 0) { Task updateStorageTask = State.Producers.Count == 0 && State.Consumers.Count == 0 ? ClearStateAsync() //State contains no producers or consumers, remove it from storage : WriteStateAsync(); await updateStorageTask; } counterProducersTotal.DecrementBy(numRemoved); } catch (Exception exc) { logger.Error(ErrorCode.Stream_UnegisterProducerFailed, $"Failed to unregister a stream producer. Stream: {streamId}, Producer: {streamProducer}", exc); // Corrupted state, deactivate grain. DeactivateOnIdle(); throw; } if (State.Producers.Count == 0 && State.Consumers.Count == 0) { DeactivateOnIdle(); // No producers or consumers left now, so flag ourselves to expedite Deactivation } }
private async Task RegisterAsStreamProducer(StreamId streamId, StreamSequenceToken streamStartToken) { try { if (pubSub == null) { throw new NullReferenceException("Found pubSub reference not set up correctly in RetreaveNewStream"); } IStreamProducerExtension meAsStreamProducer = this.AsReference <IStreamProducerExtension>(); ISet <PubSubSubscriptionState> streamData = await pubSub.RegisterProducer(streamId, streamProviderName, meAsStreamProducer); if (logger.IsVerbose) { logger.Verbose(ErrorCode.PersistentStreamPullingAgent_16, "Got back {0} Subscribers for stream {1}.", streamData.Count, streamId); } var addSubscriptionTasks = new List <Task>(streamData.Count); foreach (PubSubSubscriptionState item in streamData) { addSubscriptionTasks.Add(AddSubscriber_Impl(item.SubscriptionId, item.Stream, item.Consumer, streamStartToken, item.Filter)); } await Task.WhenAll(addSubscriptionTasks); } catch (Exception exc) { // RegisterAsStreamProducer is fired with .Ignore so we should log if anything goes wrong, because there is no one to catch the exception logger.Error(ErrorCode.PersistentStreamPullingAgent_17, "Ignored RegisterAsStreamProducer Error", exc); throw; } }
/// accept and notify only Active producers. private static bool IsActiveProducer(IStreamProducerExtension producer) { var grainRef = producer.AsReference(); if (grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget) return RuntimeClient.Current.GetSiloStatus(grainRef.SystemTargetSilo).Equals(SiloStatus.Active); return true; }
private static bool IsDeadProducer(IStreamProducerExtension producer) { var grainRef = producer as GrainReference; if (grainRef != null && grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget) { return(RuntimeClient.Current.GetSiloStatus(grainRef.SystemTargetSilo).Equals(SiloStatus.Dead)); } return(false); }
/// accept and notify only Active producers. private bool IsActiveProducer(IStreamProducerExtension producer) { var grainRef = producer as GrainReference; if (grainRef != null && grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget) { return(siloStatusOracle.GetApproximateSiloStatus(grainRef.SystemTargetSilo) == SiloStatus.Active); } return(true); }
/// accept and notify only Active producers. private static bool IsActiveProducer(IStreamProducerExtension producer) { var grainRef = producer as GrainReference; if (grainRef != null && grainRef.GrainId.IsSystemTarget && grainRef.IsInitializedSystemTarget) { return(RuntimeClient.Current.GetSiloStatus(grainRef.SystemTargetSilo) == SiloStatus.Active); } return(true); }
public bool Equals(InternalStreamId streamId, IStreamProducerExtension streamProducer) { if (Stream == default) { return(false); } if (ReferenceEquals(null, Producer)) { return(false); } return(Stream.Equals(streamId) && Producer.Equals(streamProducer)); }
public bool Equals(StreamId streamId, IStreamProducerExtension streamProducer) { if (ReferenceEquals(null, Stream)) { return(false); } if (ReferenceEquals(null, Producer)) { return(false); } return(Stream.Equals(streamId) && Producer.Equals(streamProducer)); }
public async Task UnregisterProducer(StreamId streamId, IStreamProducerExtension streamProducer) { int numRemoved = State.Producers.RemoveWhere(s => s.Equals(streamId, streamProducer)); counterProducersRemoved.Increment(); counterProducersTotal.DecrementBy(numRemoved); LogPubSubCounts("UnregisterProducer {0} NumRemoved={1}", streamProducer, numRemoved); if (numRemoved > 0) await State.WriteStateAsync(); if (State.Producers.Count == 0 && State.Consumers.Count == 0) DeactivateOnIdle(); // No producers or consumers left now, so flag ourselves to expedite Deactivation }
private async Task <ISet <PubSubSubscriptionState> > RegisterProducer() { var tup = await providerRuntime.BindExtension <SimpleMessageStreamProducerExtension, IStreamProducerExtension>( () => new SimpleMessageStreamProducerExtension(providerRuntime, fireAndForgetDelivery)); myExtension = tup.Item1; myGrainReference = tup.Item2; myExtension.AddStream(stream.StreamId); // Notify streamRendezvous about new stream streamProducer. Retreave the list of RemoteSubscribers. return(await pubSub.RegisterProducer(stream.StreamId, streamProviderName, myGrainReference)); }
public Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { ISet<PubSubSubscriptionState> result = new HashSet<PubSubSubscriptionState>(); if (String.IsNullOrWhiteSpace(streamId.Namespace)) return Task.FromResult(result); IDictionary<Guid, IStreamConsumerExtension> implicitSubscriptions = implicitTable.GetImplicitSubscribers(streamId); foreach (var kvp in implicitSubscriptions) { GuidId subscriptionId = GuidId.GetGuidId(kvp.Key); result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value)); } return Task.FromResult(result); }
async Task<ISet<PubSubSubscriptionState>> IStreamPubSub.RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { var matches = new PubSubSubscriptionState[0]; if (ShouldMatch(streamProvider)) { matches = (from StreamPubSubMatch m in matcher(new StreamIdentity(streamId)) let subId = GuidId.GetNewGuidId() select new PubSubSubscriptionState(subId, streamId, new PushExtension(m), null)) .ToArray(); } var registered = await registry.RegisterProducer(streamId, streamProvider, streamProducer); registered.UnionWith(matches); return registered; }
private async Task RegisterAsStreamProducer(InternalStreamId streamId, StreamSequenceToken streamStartToken) { try { if (pubSub == null) { throw new NullReferenceException("Found pubSub reference not set up correctly in RetrieveNewStream"); } IStreamProducerExtension meAsStreamProducer = this.AsReference <IStreamProducerExtension>(); ISet <PubSubSubscriptionState> streamData = null; await AsyncExecutorWithRetries.ExecuteWithRetries( async i => { streamData = await PubsubRegisterProducer(pubSub, streamId, meAsStreamProducer, logger); }, AsyncExecutorWithRetries.INFINITE_RETRIES, (exception, i) => !IsShutdown, Constants.INFINITE_TIMESPAN, DeliveryBackoffProvider); if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug( (int)ErrorCode.PersistentStreamPullingAgent_16, "Got back {Count} subscribers for stream {StreamId}.", streamData.Count, streamId); } var addSubscriptionTasks = new List <Task>(streamData.Count); foreach (PubSubSubscriptionState item in streamData) { addSubscriptionTasks.Add(AddSubscriber_Impl(item.SubscriptionId, item.Stream, item.Consumer, item.FilterData, streamStartToken)); } await Task.WhenAll(addSubscriptionTasks); } catch (Exception exc) { // RegisterAsStreamProducer is fired with .Ignore so we should log if anything goes wrong, because there is no one to catch the exception logger.LogError((int)ErrorCode.PersistentStreamPullingAgent_17, exc, "Ignored RegisterAsStreamProducer error"); throw; } }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return(TaskDone.Done); }
public Task <ISet <PubSubSubscriptionState> > RegisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer) { var streamRendezvous = GetRendezvousGrain(streamId); return(streamRendezvous.RegisterProducer(streamId, streamProducer)); }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return(IsImplicitSubscriber(streamProducer, streamId) ? TaskDone.Done : explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer)); }
// This constructor has to be public for JSonSerialization to work! // Implement ISerializable if changing it to non-public public PubSubPublisherState(StreamId streamId, IStreamProducerExtension streamProducer) { Stream = streamId; Producer = streamProducer; }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return(Task.CompletedTask); }
Task IStreamPubSub.UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return(registry.UnregisterProducer(streamId, streamProvider, streamProducer)); }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return(explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer)); }
private static async Task <ISet <PubSubSubscriptionState> > PubsubRegisterProducer(IStreamPubSub pubSub, InternalStreamId streamId, IStreamProducerExtension meAsStreamProducer, ILogger logger) { try { var streamData = await pubSub.RegisterProducer(streamId, meAsStreamProducer); return(streamData); } catch (Exception e) { logger.Error(ErrorCode.PersistentStreamPullingAgent_17, $"RegisterAsStreamProducer failed due to {e}", e); throw; } }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer); }
public Task UnregisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer) { return(explicitPubSub.UnregisterProducer(streamId, streamProducer)); }
public Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { var streamRendezvous = GetRendezvousGrain(streamId); return streamRendezvous.RegisterProducer(streamId, streamProducer); }
public async Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, IStreamProducerExtension streamProducer) { if (!IsActiveProducer(streamProducer)) throw new ArgumentException(String.Format("Trying to register non active IStreamProducerExtension: {0}", streamProducer.ToString()), "streamProducer"); RemoveDeadProducers(); var publisherState = new PubSubPublisherState(streamId, streamProducer); State.Producers.Add(publisherState); counterProducersAdded.Increment(); counterProducersTotal.Increment(); LogPubSubCounts("RegisterProducer {0}", streamProducer); await State.WriteStateAsync(); return State.Consumers; }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { var streamRendezvous = GetRendezvousGrain(streamId); return streamRendezvous.UnregisterProducer(streamId, streamProducer); }
public Task UnregisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer) { var streamRendezvous = GetRendezvousGrain(streamId); return(streamRendezvous.UnregisterProducer(streamId, streamProducer)); }
public async Task<ISet<PubSubSubscriptionState>> RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { ISet<PubSubSubscriptionState> result = await explicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer); if (String.IsNullOrWhiteSpace(streamId.Namespace)) return result; IDictionary<Guid,IStreamConsumerExtension> implicitSubscriptions = implicitPubSub.GetImplicitSubscribers(streamId); foreach (var kvp in implicitSubscriptions) { GuidId subscriptionId = GuidId.GetGuidId(kvp.Key); // we ignore duplicate entries-- there's no way a programmer could prevent the duplicate entry from being added if we threw an exception to communicate the problem. result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value, null, null)); } return result; }
public Task UnregisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer) { return(Task.CompletedTask); }
// This constructor has to be public for JSonSerialization to work! // Implement ISerializable if changing it to non-public public PubSubPublisherState(StreamId streamId, IStreamProducerExtension streamProducer) { Stream = streamId; producerReference = streamProducer as GrainReference; }
public Task <ISet <PubSubSubscriptionState> > RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { ISet <PubSubSubscriptionState> result = new HashSet <PubSubSubscriptionState>(); if (!ImplicitStreamSubscriberTable.IsImplicitSubscribeEligibleNameSpace(streamId.Namespace)) { return(Task.FromResult(result)); } IDictionary <Guid, IStreamConsumerExtension> implicitSubscriptions = implicitTable.GetImplicitSubscribers(streamId, this.grainFactory); foreach (var kvp in implicitSubscriptions) { GuidId subscriptionId = GuidId.GetGuidId(kvp.Key); result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value)); } return(Task.FromResult(result)); }
Task IStreamPubSub.UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return registry.UnregisterProducer(streamId, streamProvider, streamProducer); }
async Task <ISet <PubSubSubscriptionState> > IStreamPubSub.RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { var matches = new PubSubSubscriptionState[0]; if (ShouldMatch(streamProvider)) { matches = (from StreamPubSubMatch m in matcher(new StreamIdentity(streamId)) let subId = GuidId.GetNewGuidId() select new PubSubSubscriptionState(subId, streamId, new PushExtension(m), null)) .ToArray(); } var registered = await registry.RegisterProducer(streamId, streamProvider, streamProducer); registered.UnionWith(matches); return(registered); }
public async Task <ISet <PubSubSubscriptionState> > RegisterProducer(StreamId streamId, IStreamProducerExtension streamProducer) { counterProducersAdded.Increment(); try { var publisherState = new PubSubPublisherState(streamId, streamProducer); State.Producers.Add(publisherState); LogPubSubCounts("RegisterProducer {0}", streamProducer); await WriteStateAsync(); counterProducersTotal.Increment(); } catch (Exception exc) { logger.Error(ErrorCode.Stream_RegisterProducerFailed, $"Failed to register a stream producer. Stream: {streamId}, Producer: {streamProducer}", exc); // Corrupted state, deactivate grain. DeactivateOnIdle(); throw; } return(State.Consumers.Where(c => !c.IsFaulted).ToSet()); }
public async Task <ISet <PubSubSubscriptionState> > RegisterProducer(InternalStreamId streamId, IStreamProducerExtension streamProducer) { ISet <PubSubSubscriptionState> explicitRes = await explicitPubSub.RegisterProducer(streamId, streamProducer); ISet <PubSubSubscriptionState> implicitRes = await implicitPubSub.RegisterProducer(streamId, streamProducer); explicitRes.UnionWith(implicitRes); return(explicitRes); }
public async Task <ISet <PubSubSubscriptionState> > RegisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { ISet <PubSubSubscriptionState> result = await explicitPubSub.RegisterProducer(streamId, streamProvider, streamProducer); if (String.IsNullOrWhiteSpace(streamId.Namespace)) { return(result); } IDictionary <Guid, IStreamConsumerExtension> implicitSubscriptions = implicitPubSub.GetImplicitSubscribers(streamId); foreach (var kvp in implicitSubscriptions) { GuidId subscriptionId = GuidId.GetGuidId(kvp.Key); // we ignore duplicate entries-- there's no way a programmer could prevent the duplicate entry from being added if we threw an exception to communicate the problem. result.Add(new PubSubSubscriptionState(subscriptionId, streamId, kvp.Value, null, null)); } return(result); }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return TaskDone.Done; }
public Task UnregisterProducer(StreamId streamId, string streamProvider, IStreamProducerExtension streamProducer) { return IsImplicitSubscriber(streamProducer, streamId) ? TaskDone.Done : explicitPubSub.UnregisterProducer(streamId, streamProvider, streamProducer); }