private static List <Action> ResourceActionsOf( HttpProperties properties, string resourceName, string[] resourceActionNames) { var resourceActions = new List <Action>(resourceActionNames.Length); foreach (var actionName in resourceActionNames) { try { var keyPrefix = $"action.{resourceName}.{char.ToLowerInvariant(actionName[0])}{actionName.Substring(1)}."; var actionId = resourceActions.Count; var method = properties.GetProperty($"{keyPrefix}method", null); var uri = properties.GetProperty($"{keyPrefix}uri", null); var to = properties.GetProperty($"{keyPrefix}to", null); var mapper = properties.GetProperty($"{keyPrefix}mapper", null); resourceActions.Add(new Action(actionId, method, uri, to, mapper)); } catch (Exception e) { Console.WriteLine($"vlingo-net/http: Failed to load resource: {resourceName} action:{actionName} because: {e.Message}"); throw; } } return(resourceActions); }
private static IDictionary <string, IConfigurationResource> LoadStaticFilesResource(HttpProperties properties, ILogger logger) { var staticFilesResourceActions = new Dictionary <string, IConfigurationResource>(); var root = properties.GetProperty(StaticFilesResourceRoot); if (root == null) { return(staticFilesResourceActions); } var poolSize = properties.GetProperty(StaticFilesResourcePool, "5") !; var validSubPaths = properties.GetProperty(StaticFilesResourceSubPaths); var actionSubPaths = ActionNamesFrom(validSubPaths, StaticFilesResourceSubPaths); LoadStaticFileResource(staticFilesResourceActions, root, poolSize, validSubPaths, actionSubPaths, logger); return(staticFilesResourceActions); }
private static IDictionary <string, IConfigurationResource> LoadFeedResources(HttpProperties properties, ILogger logger) { var feedResourceActions = new Dictionary <string, IConfigurationResource>(); foreach (var feedResourceName in FindResources(properties, FeedProducerNamePrefix)) { var feedUri = properties.GetProperty(feedResourceName); var resourceName = feedResourceName.Substring(FeedProducerNamePrefix.Length); var feedProducerClassnameKey = $"feed.resource.{resourceName}.producer.class"; var feedProducerClassname = properties.GetProperty(feedProducerClassnameKey); var feedElementsKey = $"feed.resource.{resourceName}.elements"; var maybeFeedElements = int.Parse(properties.GetProperty(feedElementsKey, "20") ?? "20"); var feedElements = maybeFeedElements <= 0 ? 20 : maybeFeedElements; var poolKey = $"feed.resource.{resourceName}.pool"; var maybePoolSize = int.Parse(properties.GetProperty(poolKey, "1") ?? "1"); int handlerPoolSize = maybePoolSize <= 0 ? 1 : maybePoolSize; var feedRequestUri = $"{feedUri?.Replace(resourceName, FeedNamePathParameter)}/{FeedProductIdPathParameter}"; try { var feedClass = ActorClassWithProtocol(feedProducerClassname, typeof(IFeedProducer)); var mappedParameterProducerClass = new Action.MappedParameter("Type", feedClass); var mappedParameterProductElements = new Action.MappedParameter("int", feedElements); var actions = new List <Action>(1); var additionalParameters = new List <Action.MappedParameter> { mappedParameterProducerClass, mappedParameterProductElements }; actions.Add(new Action(0, Method.Get.Name(), feedRequestUri, FeedProducerFeed, null, additionalParameters)); var resource = ResourceFor(resourceName, typeof(FeedResource), handlerPoolSize, actions, logger); feedResourceActions.Add(resourceName, resource); } catch (Exception e) { Console.WriteLine($"vlingo/http: Failed to load feed resource: {resourceName} because: {e.Message}"); Console.WriteLine(e.StackTrace); throw; } } return(feedResourceActions); }
private Configuration(HttpProperties properties) : this() { Port = int.Parse(properties.GetProperty("server.http.port", Port.ToString())); var processorPoolSize = int.Parse(properties.GetProperty("server.processor.pool.size", Sizing.ProcessorPoolSize.ToString())); var dispatcherPoolSize = int.Parse(properties.GetProperty("server.dispatcher.pool", Sizing.DispatcherPoolSize.ToString())); var maxBufferPoolSize = int.Parse(properties.GetProperty("server.buffer.pool.size", Sizing.MaxBufferPoolSize.ToString())); var maxMessageSize = int.Parse(properties.GetProperty("server.message.buffer.size", Sizing.MaxMessageSize.ToString())); var probeInterval = long.Parse(properties.GetProperty("server.probe.interval", Timing.ProbeInterval.ToString())); var probeTimeout = long.Parse(properties.GetProperty("server.probe.timeout", Timing.ProbeInterval.ToString())); var requestMissingContentTimeout = long.Parse(properties.GetProperty("server.request.missing.content.timeout", Timing.RequestMissingContentTimeout.ToString())); Sizing = new SizingConf(processorPoolSize, dispatcherPoolSize, maxBufferPoolSize, maxMessageSize); Timing = new TimingConf(probeInterval, probeTimeout, requestMissingContentTimeout); }
private static IConfigurationResource LoadResource(HttpProperties properties, string resourceNameKey, ILogger logger) { var resourceName = resourceNameKey.Substring(ResourceNamePrefix.Length); var resourceActionNames = ActionNamesFrom(properties.GetProperty(resourceNameKey), resourceNameKey); var resourceHandlerKey = $"resource.{resourceName}.handler"; var resourceHandlerClassname = properties.GetProperty(resourceHandlerKey); var handlerPoolKey = $"resource.{resourceName}.pool"; var maybeHandlerPoolSize = int.Parse(properties.GetProperty(handlerPoolKey, "1") ?? "1"); var handlerPoolSize = maybeHandlerPoolSize <= 0 ? 1 : maybeHandlerPoolSize; try { var resourceActions = ResourceActionsOf(properties, resourceName, resourceActionNames); var resourceHandlerClass = ConfigurationResource.NewResourceHandlerTypeFor(resourceHandlerClassname); return(ResourceFor(resourceName, resourceHandlerClass !, handlerPoolSize, resourceActions, logger)); } catch (Exception e) { Console.WriteLine("vlingo-net/http: Failed to load resource: " + resourceName + " because: " + e.Message); throw; } }
private static IDictionary <string, IConfigurationResource> LoadSseResources(HttpProperties properties, ILogger logger) { var sseResourceActions = new Dictionary <string, IConfigurationResource>(); foreach (var streamResourceName in FindResources(properties, SsePublisherNamePrefix)) { var streamUri = properties.GetProperty(streamResourceName); var resourceName = streamResourceName.Substring(SsePublisherNamePrefix.Length); var feedClassnameKey = $"sse.stream.{resourceName}.feed.class"; var feedClassname = properties.GetProperty(feedClassnameKey); var feedPayloadKey = "sse.stream." + resourceName + ".feed.payload"; var maybeFeedPayload = int.Parse(properties.GetProperty(feedPayloadKey, "20") ?? "20"); var feedPayload = maybeFeedPayload <= 0 ? 20 : maybeFeedPayload; var feedIntervalKey = $"sse.stream.{resourceName}.feed.interval"; var maybeFeedInterval = int.Parse(properties.GetProperty(feedIntervalKey, "1000") ?? "1000"); var feedInterval = maybeFeedInterval <= 0 ? 1000 : maybeFeedInterval; var feedDefaultIdKey = $"sse.stream.{resourceName}.feed.default.id"; var feedDefaultId = properties.GetProperty(feedDefaultIdKey, ""); var poolKey = $"sse.stream.{resourceName}.pool"; var maybePoolSize = int.Parse(properties.GetProperty(poolKey, "1") ?? "1"); var handlerPoolSize = maybePoolSize <= 0 ? 1 : maybePoolSize; var subscribeUri = streamUri?.Replace(resourceName, SsePublisherNamePathParameter); var unsubscribeUri = subscribeUri + "/" + SsePublisherIdPathParameter; try { var feedClass = ActorClassWithProtocol(feedClassname, typeof(ISseFeed)); var mappedParameterClass = new Action.MappedParameter("Type", feedClass); var mappedParameterPayload = new Action.MappedParameter("int", feedPayload); var mappedParameterInterval = new Action.MappedParameter("int", feedInterval); var mappedParameterDefaultId = new Action.MappedParameter("string", feedDefaultId); var actions = new List <Action>(2); var additionalParameters = new List <Action.MappedParameter> { mappedParameterClass, mappedParameterPayload, mappedParameterInterval, mappedParameterDefaultId }; actions.Add(new Action(0, Method.Get.Name(), subscribeUri, SsePublisherSubscribeTo, null, additionalParameters)); actions.Add(new Action(1, Method.Delete.Name(), unsubscribeUri, SsePublisherUnsubscribeTo, null)); var resource = ResourceFor(resourceName, typeof(SseStreamResource), handlerPoolSize, actions, logger); sseResourceActions[resourceName] = resource; } catch (Exception e) { Console.WriteLine("vlingo-net/http: Failed to load SSE resource: " + streamResourceName + " because: " + e.Message); Console.WriteLine(e.StackTrace); throw; } } return(sseResourceActions); }