Class ScyllaRingBuffer<T>.Builder
Fluent builder for constructing ScyllaRingBuffer<T> instances with complex configurations. Supports capacity configuration, overwrite-on-full mode, and optional synchronized wrapper creation.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaRingBuffer<T>.Builder
Remarks
The builder provides a discoverable, named-parameter alternative to the positional constructor. Use Build() to obtain the configured collection as an IScyllaCollection<T>, which may be either a ScyllaRingBuffer<T> or a ScyllaRingBuffer<T>.SynchronizedScyllaRingBuffer depending on whether Synchronized(object) was called.
Use BuildConcrete() when the concrete unsynchronized type is required (e.g., to call ring-buffer-specific methods not exposed by the interface). This method throws if Synchronized(object) has been configured.
// Basic usage with defaults
var buffer = ScyllaRingBuffer<int>.CreateBuilder().Build();
// Configure capacity and overwrite-on-full mode
var buffer = ScyllaRingBuffer<string>.CreateBuilder()
.WithCapacity(64)
.OverwriteOnFull()
.Build();
// Create synchronized (thread-safe) wrapper
var buffer = ScyllaRingBuffer<Task>.CreateBuilder()
.WithCapacity(128)
.Synchronized()
.Build();
Methods
Build()
Builds and returns the configured ring buffer or synchronized wrapper as an IScyllaCollection<T>.
Declaration
public IScyllaCollection<T> Build()
Returns
| Type | Description |
|---|---|
| IScyllaCollection<T> | An IScyllaCollection<T> that is either the unsynchronized ScyllaRingBuffer<T> or a ScyllaRingBuffer<T>.SynchronizedScyllaRingBuffer wrapper, depending on whether Synchronized(object) was configured. |
Remarks
If Synchronized(object) was called, the returned value is a ScyllaRingBuffer<T>.SynchronizedScyllaRingBuffer that wraps the ring buffer. Otherwise, the returned value is the concrete ScyllaRingBuffer<T> itself. Both implement IScyllaCollection<T>.
BuildConcrete()
Builds and returns the concrete unsynchronized ScyllaRingBuffer<T> instance directly.
Declaration
public ScyllaRingBuffer<T> BuildConcrete()
Returns
| Type | Description |
|---|---|
| ScyllaRingBuffer<T> | The configured unsynchronized ScyllaRingBuffer<T> instance. |
Remarks
Use this method instead of Build() when you need access to the concrete type to call ring-buffer-specific methods not exposed by IScyllaCollection<T> (e.g., RemoveWhere(Predicate<T>), PeekAt(int), or AsSynchronized(object)).
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when Synchronized(object) was called on this builder. Use Build() to obtain the ScyllaRingBuffer<T>.SynchronizedScyllaRingBuffer wrapper instead. |
OverwriteOnFull(bool)
Configures whether writing to a full buffer silently overwrites the oldest element.
Declaration
public ScyllaRingBuffer<T>.Builder OverwriteOnFull(bool value = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value |
|
Returns
| Type | Description |
|---|---|
| ScyllaRingBuffer<T>.Builder | This builder instance for method chaining. |
Remarks
When enabled (value is true), calls to TryWrite(T)
always succeed - even when the buffer is at capacity - by discarding the oldest element.
When disabled (the default), write operations return false when the buffer is full.
Synchronized(object)
Configures the builder to wrap the constructed ring buffer in a ScyllaRingBuffer<T>.SynchronizedScyllaRingBuffer, making all operations thread-safe.
Declaration
public ScyllaRingBuffer<T>.Builder Synchronized(object syncRoot = null)
Parameters
| Type | Name | Description |
|---|---|---|
| object | syncRoot | Optional external lock object to use for synchronization. If |
Returns
| Type | Description |
|---|---|
| ScyllaRingBuffer<T>.Builder | This builder instance for method chaining. |
Remarks
When this method has been called, Build() returns a ScyllaRingBuffer<T>.SynchronizedScyllaRingBuffer and BuildConcrete() throws an InvalidOperationException. All operations on the synchronized wrapper are protected by the provided (or internally created) lock object.
WithCapacity(int)
Sets the fixed maximum capacity of the ring buffer backing array.
Declaration
public ScyllaRingBuffer<T>.Builder WithCapacity(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | The maximum number of elements the ring buffer can hold. Must be at least |
Returns
| Type | Description |
|---|---|
| ScyllaRingBuffer<T>.Builder | This builder instance for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |