/// <summary> /// Constructs my default state from the <paramref name="configuration"/> /// </summary> /// <param name="configuration">The <code>Configuration</code>.</param> /// <param name="type">The <code>ClientConsumerType</code>.</param> /// <param name="poolSize">The size of the pool of workers.</param> public Client(Configuration configuration, ClientConsumerType type, int poolSize) { _configuration = configuration; Type clientConsumerType; IEnumerable <object> parameters; switch (type) { case ClientConsumerType.Correlating: clientConsumerType = typeof(ClientCorrelatingRequesterConsumerActor); parameters = Definition.Parameters(configuration); break; case ClientConsumerType.RoundRobin: clientConsumerType = typeof(RoundRobinClientRequestConsumerActor); var rrDefinition = Definition.Has <ClientConsumerWorkerActor>(Definition.Parameters(configuration)); var rrSpec = new RouterSpecification <IClientConsumer>(poolSize, rrDefinition); parameters = Definition.Parameters(configuration, rrSpec); break; case ClientConsumerType.LoadBalancing: clientConsumerType = typeof(LoadBalancingClientRequestConsumerActor); var lbDefinition = Definition.Has <ClientConsumerWorkerActor>(Definition.Parameters(configuration)); var lbSpec = new RouterSpecification <IClientConsumer>(poolSize, lbDefinition); parameters = Definition.Parameters(configuration, lbSpec); break; default: throw new ArgumentException($"ClientConsumerType is not mapped: {type}"); } _consumer = configuration.Stage.ActorFor <IClientConsumer>(Definition.Has(clientConsumerType, parameters)); }
/// <summary> /// Answers a new <code>Client</code> from the <paramref name="configuration"/>. /// </summary> /// <param name="configuration">The <code>Configuration</code>.</param> /// <param name="type">The <code>ClientConsumerType</code>.</param> /// <param name="poolSize">The size of the pool of workers.</param> /// <returns></returns> public static Client Using(Configuration configuration, ClientConsumerType type, int poolSize) => new Client(configuration, type, poolSize);