private bool GetDescriptionDocument(HttpEntityManager manager, UriTemplateMatch match) { if (manager.ResponseCodec.ContentType == ContentType.DescriptionDocJson) { var stream = match.BoundVariables["stream"]; var accepts = manager.HttpEntity.Request.AcceptTypes == null || manager.HttpEntity.Request.AcceptTypes.Contains(ContentType.Any); var responseStatusCode = accepts ? HttpStatusCode.NotAcceptable : HttpStatusCode.OK; var responseMessage = manager.HttpEntity.Request.AcceptTypes == null ? "We are unable to represent the stream in the format requested." : "Description Document"; var envelope = new SendToHttpEnvelope( _networkSendQueue, manager, (args, message) => { var m = message as MonitoringMessage.GetPersistentSubscriptionStatsCompleted; if (m == null) { throw new Exception("Could not get subscriptions for stream " + stream); } string[] persistentSubscriptionGroups = null; if (m.Result == MonitoringMessage.GetPersistentSubscriptionStatsCompleted.OperationStatus.Success) { persistentSubscriptionGroups = m.SubscriptionStats.Select(x => x.GroupName).ToArray(); } manager.ReplyTextContent(Format.GetDescriptionDocument(manager, stream, persistentSubscriptionGroups), responseStatusCode, responseMessage, manager.ResponseCodec.ContentType, null, e => Log.ErrorException(e, "Error while writing HTTP response")); return(String.Empty); }, (args, message) => new ResponseConfiguration(HttpStatusCode.OK, manager.ResponseCodec.ContentType, manager.ResponseCodec.Encoding)); var cmd = new MonitoringMessage.GetStreamPersistentSubscriptionStats(envelope, stream); Publish(cmd); return(true); } return(false); }
public void Handle(MonitoringMessage.GetStreamPersistentSubscriptionStats message) { if (!_started) { message.Envelope.ReplyWith(new MonitoringMessage.GetPersistentSubscriptionStatsCompleted( MonitoringMessage.GetPersistentSubscriptionStatsCompleted.OperationStatus.NotReady, null) ); return; } List <PersistentSubscription> subscribers; if (!_subscriptionTopics.TryGetValue(message.EventStreamId, out subscribers)) { message.Envelope.ReplyWith(new MonitoringMessage.GetPersistentSubscriptionStatsCompleted( MonitoringMessage.GetPersistentSubscriptionStatsCompleted.OperationStatus.NotFound, null) ); return; } var stats = subscribers.Select(sub => sub.GetStatistics()).ToList(); message.Envelope.ReplyWith(new MonitoringMessage.GetPersistentSubscriptionStatsCompleted( MonitoringMessage.GetPersistentSubscriptionStatsCompleted.OperationStatus.Success, stats) ); }