public static BatcherDataReaderWrapper Create(IBatcher batcher, DbCommand command) { return(new BatcherDataReaderWrapper(batcher, command) { reader = batcher.ExecuteReader(command) }); }
public static async Task <BatcherDataReaderWrapper> CreateAsync(IBatcher batcher, DbCommand command, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); return(new BatcherDataReaderWrapper(batcher, command) { reader = await(batcher.ExecuteReaderAsync(command, cancellationToken)).ConfigureAwait(false) }); }
public async Task BeforeEach() { _singleTaskBatcherTestSetup = new SingleTaskBatcherTestSetup(); _throwWhen = i => i % 2 == 0; _singleTaskBatcherTestSetup.ThrowWhen = _throwWhen; _batcher = _singleTaskBatcherTestSetup.GetBatcher(_synchronicity); _batcher.ExceptionEvent += (o, e) => _exceptionEvents.Add(e as BatchExceptionEventArguments <int>); _batcher.Process(_singleTaskBatcherTestSetup.StartItems); await _batcher.WaitUntilDone(); }
public ConnectionManager(ISessionImplementor session, string connectionString, ConnectionReleaseMode connectionReleaseMode, IInterceptor interceptor) { this.session = session; ConnectionString = connectionString; this.connectionReleaseMode = connectionReleaseMode; this.interceptor = interceptor; batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); ownConnection = true; }
public async Task BeforeAll() { _batchExceptionEvents = new ConcurrentBag <Tuple <object, BatchExceptionEventArguments> >(); _setup = new ChainBatcherTestSetup(); _setup.ThrowWhenSquaring(ThrowWhenSquaring); _setup.ThrowWhenConvertingToString(ThrowWhenConvertingToString); _setup.ThrowWhenPuttingInResultsBag(ThrowWhenPuttingInResultsBag); _batcher = _setup.GetBatcher(_synchronicity); _batcher.ExceptionEvent += (o, e) => _batchExceptionEvents.Add(Tuple.Create(o, e)); _batcher.Process(_setup.StartItems); await _batcher.WaitUntilDone(); }
public async Task BeforeAll() { _singleTaskBatcherTestSetup = new SingleTaskBatcherTestSetup(); _batcher = _singleTaskBatcherTestSetup.GetBatcher(_synchronicity, _multiplicity); _batcher.ExceptionEvent += (o, e) => _exceptionEvents.Add(e as BatchExceptionEventArguments <int>); _batcher.Process(_singleTaskBatcherTestSetup.StartItems); await _batcher.WaitUntilDone(); await _singleTaskBatcherTestSetup.WaitUntil( s => s.ProcessedItems.Count >= s.StartItems.Count, s => s.ProcessedItems.GetMessage()); }
public async Task BeforeAll() { _batcher = TakeAnItem <int> .Then(CreateFile) .WithThreads(CreateFileThreads) .Then(MoveFile) .WithThreads(MoveFileThreads) .AndFinally(MungeFile) .WithThreads(MungeFileThreads); _batcher.Process(1.To(NumberOfFiles)); var logNext = 0; while (true) { var count = Moved.Pipe(Directory.GetFiles).Pipe(f => f.Length); if (count >= logNext) { Console.WriteLine($"{count} files moved"); logNext += NumberOfFiles / 10; } if (count >= NumberOfFiles) { break; } await Task.Delay(100); } Console.WriteLine("**** Files moved ****"); logNext = 0; while (true) { var count = Munged.Pipe(Directory.GetFiles).Pipe(f => f.Length); if (count >= logNext) { Console.WriteLine($"{count} files munged"); logNext += NumberOfFiles / 10; } if (count >= NumberOfFiles) { break; } await Task.Delay(100); } Console.WriteLine("**** Files munged ****"); _results = 1.To(NumberOfFiles) .Select(GetFilename) .Select(f => Path.Combine(Munged, f)) .Select(File.ReadAllText) .Select(JsonConvert.DeserializeObject <List <TaskMetadata> >) .ToList(); }
public async Task BeforeAll() { _setup = new ChainBatcherTestSetup(); _batcher = _setup.GetBatcher(_synchronicity, _multiplicity); _batcher.Process(_setup.StartItems); var expectedCount = _setup.StartItems.Count; await Task.WhenAll( _batcher.WaitUntilDone(), _setup.WaitUntil(s => s.ProcessedItems.Count >= expectedCount, s => s.ProcessedItems.GetMessage()), _setup.WaitUntil(s => s.SquaredItems.Count >= expectedCount, s => s.SquaredItems.GetMessage()), _setup.WaitUntil(s => s.ConvertedToString.Count == expectedCount, s => s.ConvertedToString.GetMessage()), _setup.WaitUntil(s => s.Results.Count >= expectedCount, s => s.Results.GetMessage())); }
public QueueInfo(string entityName, string url, IDictionary <string, string> attributes, IAmazonSQS client, CancellationToken cancellationToken) { Attributes = attributes; EntityName = entityName; Url = url; Arn = attributes.TryGetValue(QueueAttributeName.QueueArn, out var queueArn) ? queueArn : throw new ArgumentException($"The queueArn was not found: {url}", nameof(attributes)); _batchSender = new SendBatcher(client, url, cancellationToken); _batchDeleter = new DeleteBatcher(client, url, cancellationToken); }
protected BatcherDataReaderWrapper(IBatcher batcher, DbCommand command) { if (batcher == null) { throw new ArgumentNullException("batcher"); } if (command == null) { throw new ArgumentNullException("command"); } this.batcher = batcher; this.command = command; }
public BatcherDataReaderWrapper(IBatcher batcher, DbCommand command) { if (batcher == null) { throw new ArgumentNullException("batcher"); } if (command == null) { throw new ArgumentNullException("command"); } this.batcher = batcher; this.command = command; reader = batcher.ExecuteReader(command); }
/// <summary>Returns a <see cref="List{T}"/> of all items in the data <paramref name="source"/></summary> public static List <T> ToList <T>(this IBatcher <T> source) { var result = new List <T>(source.BatchSize); var batch = new T[source.BatchSize]; var e = source.GetBatchEnumerator(); while (e.NextBatch(batch, out int count)) { for (int i = 0; i < count; i++) { result.Add(batch[i]); } } return(result); }
public ConnectionManager( ISessionImplementor session, DbConnection suppliedConnection, ConnectionReleaseMode connectionReleaseMode, IInterceptor interceptor) { this.session = session; connection = suppliedConnection; this.connectionReleaseMode = connectionReleaseMode; this.interceptor = interceptor; batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); ownConnection = suppliedConnection == null; }
/// <summary> /// Aggregate (fold) all the items from the <paramref name="source"/> calling the supplied <paramref name="accumulate"/> /// function for each <typeparamref name="T"/> and passing the <typeparamref name="TAcc"/> generated by the last call. /// The first call to <paramref name="accumulate"/> gets passed the <paramref name="intial"/> value. /// </summary> public static TAcc Aggregate <T, TAcc>(this IBatcher <T> source, TAcc intial, Func <T, TAcc, TAcc> accumulate) { var result = intial; var batch = new T[source.BatchSize]; var e = source.GetBatchEnumerator(); while (e.NextBatch(batch, out int count)) { for (int i = 0; i < count; i++) { result = accumulate(batch[i], result); } } return(result); }
public ConnectionManager( ISessionImplementor session, IDbConnection suppliedConnection, ConnectionReleaseMode connectionReleaseMode, IInterceptor interceptor) { this.session = session; connection = suppliedConnection; this.connectionReleaseMode = connectionReleaseMode; this.interceptor = interceptor; batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); ownConnection = suppliedConnection == null; }
/// <summary> /// Returns of a <see cref="Dictionary{TKey, TValue}"/> of all items in the data <paramref name="source"/> /// using the supplied <paramref name="keySelector"/> to generate a <typeparamref name="TKey"/> for each <typeparamref name="TValue"/>. /// </summary> public static Dictionary <TKey, TValue> ToDictionary <TKey, TValue>(this IBatcher <TValue> source, Func <TValue, TKey> keySelector) { var result = new Dictionary <TKey, TValue>(source.BatchSize); var batch = new TValue[source.BatchSize]; var e = source.GetBatchEnumerator(); while (e.NextBatch(batch, out int count)) { for (int i = 0; i < count; i++) { var key = keySelector(batch[i]); result.Add(key, batch[i]); } } return(result); }
private void _batcher_OnBatched(IBatcher batcher, List <byte[]> data) { if (data != null && data.Any()) { var list = new List <byte>(); foreach (var item in data) { list.AddRange(item); } _clientSocket.Send(list.ToArray()); list.Clear(); } }
public static async Task WaitUntilDone <T>(this IBatcher <T> batcher) { var stopwatch = Stopwatch.StartNew(); while (true) { if (batcher.IsDone) { break; } if (stopwatch.ElapsedMilliseconds > MillisecondsToWait) { Assert.Fail("Timout: shouldn't take this long"); } await Task.Delay(100); } }
/// <summary>Do all of the <paramref name="source"/> items match the <paramref name="predicate"/>?</summary> /// <remarks>Stops at the first value that does not match</remarks> public static bool All <T>(this IBatcher <T> source, Func <T, bool> predicate) { var batch = new T[source.BatchSize]; var e = source.GetBatchEnumerator(); while (e.NextBatch(batch, out int count)) { for (int i = 0; i < count; i++) { if (!predicate(batch[i])) { return(false); } } } return(true); }
public ConnectionManager( ISessionImplementor session, DbConnection suppliedConnection, ConnectionReleaseMode connectionReleaseMode, IInterceptor interceptor, bool shouldAutoJoinTransaction) { Session = session; _connection = suppliedConnection; _connectionReleaseMode = connectionReleaseMode; _interceptor = interceptor; _batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); _ownConnection = suppliedConnection == null; ShouldAutoJoinTransaction = shouldAutoJoinTransaction; }
public ConnectionManager( ISessionImplementor session, DbConnection suppliedConnection, ConnectionReleaseMode connectionReleaseMode, IInterceptor interceptor, bool shouldAutoJoinTransaction, IConnectionAccess connectionAccess) { Session = session; _connection = suppliedConnection; _connectionReleaseMode = connectionReleaseMode; _interceptor = interceptor; _batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); _ownConnection = suppliedConnection == null; ShouldAutoJoinTransaction = shouldAutoJoinTransaction; _connectionAccess = connectionAccess ?? throw new ArgumentNullException(nameof(connectionAccess)); }
private void InitTransientState() { executions = new ArrayList( 50 ); batchLoadableEntityKeys = new SequencedHashMap( 30 ); loadingCollections = new Hashtable(); nonlazyCollections = new ArrayList( 20 ); batcher = factory.IsBatchUpdateEnabled ? ( IBatcher ) new BatchingBatcher( this ) : ( IBatcher ) new NonBatchingBatcher( this ); }
void IDeserializationCallback.OnDeserialization(object sender) { _batcher = Factory.Settings.BatcherFactory.CreateBatcher(this, _interceptor); }
public BasicResultSetsCommand(ISessionImplementor session) { this.session = session; dialect = session.Factory.Dialect; batcher = session.Batcher; }
private void Bacher_OnBatched(IBatcher sender, byte[] data) { var bacher = (Batcher)sender; OnBatched?.Invoke(bacher.Name, data); }
public SkipBatcher(IBatcher <T> source, int skip) { this.source = source; BatchSize = source.BatchSize; this.skip = skip; }
public TakeBatcher(IBatcher <T> source, int count) { this.source = source; take = count; BatchSize = Math.Min(source.BatchSize, take); }
void IDeserializationCallback.OnDeserialization(object sender) { // batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this); }
/// <summary>Transforms a <paramref name="source"/> using a <paramref name="mapFunction"/></summary> /// <remarks>Lazy evaluated</remarks> public static IBatcher <TResult> Select <T, TResult>(this IBatcher <T> source, Func <T, TResult> mapFunction) { return(new SelectBatcher <T, TResult>(source, mapFunction)); }
/// <summary>Filters a <paramref name="source"/> to contain unique elements</summary> /// <remarks>Lazy evaluated</remarks> public static IBatcher <T> Distinct <T>(this IBatcher <T> source, EqualityComparer <T> equality = null) { return(new DistinctBatcher <T>(source, equality)); }
private void _batcher_OnBatched(IBatcher sender, byte[] data) { _client.SendAsync(data); }
public static IBatcher <T> Skip <T>(this IBatcher <T> source, int count) { return(new SkipBatcher <T>(source, count)); }
public static IBatcher <T> Take <T>(this IBatcher <T> source, int count) { return(new TakeBatcher <T>(source, count)); }
public BatcherDataReaderWrapper(IBatcher batcher, IDbCommand command) { if (batcher == null) { throw new ArgumentNullException("batcher"); } if (command == null) { throw new ArgumentNullException("command"); } this.batcher = batcher; this.command = command; reader = batcher.ExecuteReader(command); }
void IDeserializationCallback.OnDeserialization(object sender) { batcher = session.Factory.Settings.BatcherFactory.CreateBatcher(this, interceptor); }
public DistinctBatcher(IBatcher <T> source, EqualityComparer <T> equality) { this.source = source; BatchSize = source.BatchSize; _equality = equality; }