Class NonblockRenderer<T>
Decorates a IRenderer<T> instance and lets all rendering events be non-blocking.
Every method call on the renderer will immediately return and the rendering will be performed in a background thread. Note that the order of render events is still guaranteed. In other words, a later event never arrives before events earlier than it.
Namespace: Libplanet.Blockchain.Renderers
Assembly: Libplanet.dll
Syntax
public class NonblockRenderer<T> : object, IRenderer<T>, IDisposable where T : IAction, new()
Type Parameters
Name | Description |
---|---|
T | An IAction type. It should match to BlockChain<T>'s type parameter. |
Remarks
As rendering events become performed in a background thread instead of the main thread, some graphics/UI drawings might be disallowed. In such case, communicate with the main thread through producer/consumer channels.
Examples
IRenderer<ExampleAction> renderer = new SomeRenderer();
// Wraps the renderer with NonblockRenderer; the SomeRenderer instance becomes to receive
// event messages in NonblockRenderer's backround thread:
renderer = new NonblockRenderer<ExampleAction>(
renderer,
queue: 1024,
fullFallback: droppedEvent => ShowError("Too many rendering events in a short time."));
/// ...
// Should be disposed when no longer needed:
renderer.Dispose();
Constructors
| Improve this Doc View SourceNonblockRenderer(IRenderer<T>, Int32, NonblockRenderer<T>.FullFallback)
Creates a new instance of NonblockRenderer<T> decorating the given
renderer
instance.
Declaration
public NonblockRenderer(IRenderer<T> renderer, int queueSize, NonblockRenderer<T>.FullFallback fullFallback)
Parameters
Type | Name | Description |
---|---|---|
IRenderer<T> | renderer | The renderer to decorate which has the actual implementations and receives events in a background thread. |
Int32 | queueSize | The size of the internal event queue. |
NonblockRenderer.FullFallback<> | fullFallback | Specifies the custom behavior when the internal event queue is full so that no more event can be added. |
NonblockRenderer(IRenderer<T>, Int32, NonblockRenderer<T>.FullMode)
Creates a new instance of NonblockRenderer<T> decorating the given
renderer
instance.
Declaration
public NonblockRenderer(IRenderer<T> renderer, int queueSize, NonblockRenderer<T>.FullMode fullMode)
Parameters
Type | Name | Description |
---|---|---|
IRenderer<T> | renderer | The renderer to decorate which has the actual implementations and receives events in a background thread. |
Int32 | queueSize | The size of the internal event queue. |
NonblockRenderer.FullMode<> | fullMode | Specifies the behavior when the internal event queue is full so that no more event can be added. |
Properties
| Improve this Doc View SourceRenderer
The inner renderer which has the actual implementations and receives events.
Declaration
public IRenderer<T> Renderer { get; }
Property Value
Type | Description |
---|---|
IRenderer<T> |
Methods
| Improve this Doc View SourceDispose()
Declaration
public void Dispose()
Queue(System.Action)
Queues the callback to be executed in the worker thread.
Declaration
protected void Queue(System.Action action)
Parameters
Type | Name | Description |
---|---|---|
System.Action | action | The callback to be executed in the worker thread. |
RenderBlock(Block<T>, Block<T>)
Does things that should be done right after a new Block<T> is appended to a BlockChain<T> (so that its Tip has changed).
Declaration
public void RenderBlock(Block<T> oldTip, Block<T> newTip)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | The previous Tip. |
Block<T> | newTip | The current Tip. |
Remarks
It is guaranteed to be called only once for a block, and only after applied to the blockchain, unless it has been stale due to reorg (for that case, RenderReorg(Block<T>, Block<T>, Block<T>) is called in advance).
RenderReorg(Block<T>, Block<T>, Block<T>)
Does things that should be done right before reorg happens to a BlockChain<T>.
Declaration
public void RenderReorg(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | The Tip right before reorg. |
Block<T> | newTip | The Tip after reorg. |
Block<T> | branchpoint | The highest common Block<T> between
|
Remarks
For every call to this method, calls to
RenderBlock(Block<T>, Block<T>) and
RenderReorgEnd(Block<T>, Block<T>, Block<T>) methods with the same
newTip
is made too. Note that this method is guaranteed to be called
before RenderBlock(Block<T>, Block<T>) method for the same
newTip
.
RenderReorgEnd(Block<T>, Block<T>, Block<T>)
Does things that should be done right after reorg happens to a BlockChain<T>.
Declaration
public void RenderReorgEnd(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type | Name | Description |
---|---|---|
Block<T> | oldTip | The Tip right before reorg. |
Block<T> | newTip | The Tip after reorg. |
Block<T> | branchpoint | The highest common Block<T> between
|
Remarks
Note that this method is guaranteed to be called after
RenderReorg(Block<T>, Block<T>, Block<T>) and
RenderBlock(Block<T>, Block<T>) methods for the same
newTip
.