Class NonblockActionRenderer<T>
Decorates a IActionRenderer<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.
Inherited Members
Namespace: Libplanet.Blockchain.Renderers
Assembly: Libplanet.dll
Syntax
public class NonblockActionRenderer<T> : NonblockRenderer<T>, IDisposable, IActionRenderer<T>, IRenderer<T> 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
IActionRenderer<ExampleAction> actionRenderer = new SomeActionRenderer();
// Wraps the actionRenderer with NonblockActionRenderer; the SomeActionRenderer instance
// becomes to receive event messages in NonblockActionRenderer's backround thread:
actionRenderer = new NonblockActionRenderer<ExampleAction>(
actionRenderer,
queue: 1024,
fullFallback: droppedEvent => ShowError("Too many rendering events in a short time."));
/// ...
// Should be disposed when no longer needed:
actionRenderer.Dispose();
Constructors
| Improve this Doc View SourceNonblockActionRenderer(IActionRenderer<T>, Int32, NonblockRenderer<T>.FullFallback)
Creates a new instance of NonblockActionRenderer<T> decorating the given
renderer
instance.
Declaration
public NonblockActionRenderer(IActionRenderer<T> renderer, int queueSize, NonblockRenderer<T>.FullFallback fullFallback)
Parameters
Type | Name | Description |
---|---|---|
IActionRenderer<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. |
NonblockActionRenderer(IActionRenderer<T>, Int32, NonblockRenderer<T>.FullMode)
Creates a new instance of NonblockActionRenderer<T> decorating the given
renderer
instance.
Declaration
public NonblockActionRenderer(IActionRenderer<T> renderer, int queueSize, NonblockRenderer<T>.FullMode fullMode)
Parameters
Type | Name | Description |
---|---|---|
IActionRenderer<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 SourceActionRenderer
The inner action renderer which has the actual implementations and receives events.
Declaration
public IActionRenderer<T> ActionRenderer { get; }
Property Value
Type | Description |
---|---|
IActionRenderer<T> |
Methods
| Improve this Doc View SourceRenderAction(IAction, IActionContext, IAccountStateDelta)
Does things that should be done right after an action
is executed and applied to the blockchain.
Declaration
public void RenderAction(IAction action, IActionContext context, IAccountStateDelta nextStates)
Parameters
Type | Name | Description |
---|---|---|
IAction | action | An executed action. |
IActionContext | context | The equivalent context object to an object passed to
the |
IAccountStateDelta | nextStates | The states right after this action executed,
which means it is equivalent to the states |
Remarks
It is guaranteed to be called only once for an action
,
and only after applied to the blockchain, unless an exception is thrown during executing
the action
(in that case RenderActionError(IAction, IActionContext, Exception) is called instead) or
once the action
has been unrendered.
Also note that this method is invoked after RenderBlock(Block<T>, Block<T>) method is called
(where its second parameter newTip
contains a transaction the action
belongs to).
The reason why the parameter action
takes
IAction instead of T
is because it can take
block actions (BlockAction) besides transaction
actions (Actions).
RenderActionError(IAction, IActionContext, Exception)
Does the similar things to RenderAction(IAction, IActionContext, IAccountStateDelta), except that this method
is invoked when action
has terminated with an exception.
Declaration
public void RenderActionError(IAction action, IActionContext context, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
IAction | action | An action which threw an exception during execution. |
IActionContext | context | The equivalent context object to an object passed to
the |
Exception | exception | The exception thrown during executing the |
Remarks
Also note that this method is invoked after RenderBlock(Block<T>, Block<T>) method is called
(where its second parameter newTip
contains a transaction the action
belongs to).
The reason why the parameter action
takes
IAction instead of T
is because it can take
block actions (BlockAction) besides transaction
actions (Actions).
RenderBlockEnd(Block<T>, Block<T>)
Does things that should be done right all actions in a new Block<T> are rendered.
Declaration
public void RenderBlockEnd(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.
UnrenderAction(IAction, IActionContext, IAccountStateDelta)
Does things that should be undone right after the given action
is
invalidated (mostly due to reorg, i.e., a block which the action has belonged to becomes
considered stale).
This method takes the equivalent arguments to RenderAction(IAction, IActionContext, IAccountStateDelta) method.
Declaration
public void UnrenderAction(IAction action, IActionContext context, IAccountStateDelta nextStates)
Parameters
Type | Name | Description |
---|---|---|
IAction | action | A stale action. |
IActionContext | context | The equivalent context object to an object passed to
the |
IAccountStateDelta | nextStates | The states right after this action executed,
which means it is equivalent to the states |
Remarks
As a rule of thumb, this should be the inverse of RenderAction(IAction, IActionContext, IAccountStateDelta) method with redrawing the graphics on the display at the finish.
UnrenderActionError(IAction, IActionContext, Exception)
Does the similar things to UnrenderAction(IAction, IActionContext, IAccountStateDelta), except that
this method is invoked when action
has terminated with an exception.
This method takes the equivalent arguments to RenderActionError(IAction, IActionContext, Exception) method.
Declaration
public void UnrenderActionError(IAction action, IActionContext context, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
IAction | action | An action which threw an exception during execution. |
IActionContext | context | The equivalent context object to an object passed to
the |
Exception | exception | The exception thrown during executing the |
Remarks
The reason why the parameter action
takes
IAction instead of T
is because it can take
block actions (BlockAction) besides transaction
actions (Actions).