Show / Hide Table of Contents

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.

Inheritance
Object
NonblockRenderer<T>
NonblockActionRenderer<T>
Implements
IRenderer<T>
IDisposable
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 Source

NonblockRenderer(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.

| Improve this Doc View Source

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 Source

Renderer

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 Source

Dispose()

Declaration
public void Dispose()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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).

| Improve this Doc View Source

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 oldTip and newTip.

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.

| Improve this Doc View Source

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 oldTip and newTip.

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.

Implements

IRenderer<T>
IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium