public ModelWrapper Create()
 {
     foreach (var connection in connections)
     {
         (bool success, ModelWrapper model) = connection.Get();
         if (success)
         {
             return(model);
         }
     }
     semaphoreSlim.Wait();
     try
     {
         if (connections.Count < options.MaxConnection)
         {
             var connection = new ConnectionWrapper(connectionFactory.CreateConnection(options.EndPoints), options);
             (bool success, ModelWrapper model) = connection.Get();
             connections.Add(connection);
             if (success)
             {
                 return(model);
             }
         }
         throw new System.OverflowException(nameof(connections));
     }
     finally
     {
         semaphoreSlim.Release();
     }
 }
Ejemplo n.º 2
0
 public ModelWrapper(
     ConnectionWrapper connectionWrapper,
     IModel model)
 {
     Connection                        = connectionWrapper;
     Model                             = model;
     persistentProperties              = Model.CreateBasicProperties();
     persistentProperties.Persistent   = true;
     noPersistentProperties            = Model.CreateBasicProperties();
     noPersistentProperties.Persistent = false;
 }