Interface DataRenderer<DataType>
- Type Parameters:
DataType- the type of the data passed to therendermethod
DataRender is usually passed
to an AsyncRenderer and the AsyncRenderer must take care to
invoke the appropriate methods of the DataRender.
Instances of a DataRenderer are need to be used in the following
ways:
-
Before actually calling any of the methods of
DataRenderer, thestartRenderingmethod need to be called. That is, none of the other methods defined by theDataRendererinterface can be called before callingstartRendering. -
After
startRenderinghas been called, therendermethod can be called multiple times (zero or more) passing more and more accurate data to it with each invocation. The data is intended to be provided by anAsyncDataLinkbut this is not strictly necessary (although anAsyncDataLinkcan model each valid uses). -
Once no more data is available the
finishRenderingmethod of theDataRenderer. must be called. ThefinishRenderingmethod is mandatory to be called ifstartRenderinghas been called previously.
startRendering, render and
finishRendering methods are all allowed to do some rendering and
each invocation to these methods expected to overwrite the previously done
rendering by any of these methods. Multiple invocations to render
need to overwrite each other's result as well.
Significant rendering: Each method of this interface which is allowed
to do some rendering may do a significant or insignificant rendering (or no
rendering at all which is handled the same way as insignificant rendering).
If a significant rendering was done by a DataRenderer, it means that
this DataRenderer might be canceled if there is another
DataRenderer which would overwrite its results. This property is
required because if DataRenderer would be canceled without regard if
it has done a significant rendering or not and new DataRenderer
instances were supplied rapidly overwriting its result: It would be possible
that no significant rendering is done for a significant amount of time.
When painting a component this would manifest as the component does not get
repainted until the DataRenderer instances are no longer provided
rapidly. Note: Once any of the rendering methods of this interface
returns that it has done a significant rendering, subsequent rendering method
invocations must also be significant or do no rendering at all (must leave
the results of the previous rendering intact).
Thread safety
Implementations of this interface are not required to be safe to be accessed from multiple threads concurrently. In fact, thestartRendering,
render and finishRendering methods must never be called
concurrently because their result must overwrite each other's results
and if they were called concurrently it could not be determined which call
needs to overwrite the results of which call.
Synchronization transparency
Implementations of this interface are not required to be synchronization transparent.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidfinishRendering(CancellationToken cancelToken, AsyncReport report) This method is called to allow for a final rendering after no morerendercall will be done.booleanrender(CancellationToken cancelToken, DataType data) This method may be called multiple times to do the implementation defined rendering.booleanstartRendering(CancellationToken cancelToken) This method is invoked before calling any of the other methods of this interface.booleanThis method might be optionally called to determine if a subsequent invocation to therendermethod will be significant or not.
-
Method Details
-
startRendering
This method is invoked before calling any of the other methods of this interface. This method may also do some initial rendering if it can.Note: Once this method has been called, it is mandatory to call the
finishRenderingmethod of thisDataRendererbefore it becomes eligible for garbage collection.This method should not throw an exception but if it does, the rendering process should be continued as if this method returned
false.- Parameters:
cancelToken- theCancellationTokensignaling cancellation a request when the rendering request has been canceled. Upon cancellation this method may simply returnfalseor throw anOperationCanceledExceptionexception or even continue as if nothing happened. This argument cannot benull.- Returns:
trueif this method actually did some significant rendering,falseotherwise- Throws:
OperationCanceledException- implementation may throw this exception if they detect a cancellation request. They are not required to do so, they may even returnfalseor even ignore the cancellation request.
-
willDoSignificantRender
This method might be optionally called to determine if a subsequent invocation to therendermethod will be significant or not.That is, in case this method returns
truefor a particular data, it promises that a subsequent call to therendermethod (of the sameDataRenderer) will also returntrueif the same data is passed to therendermethod. Returningfalseif simply the refusal of making such commitment. Note: When cancellation is requested, implementations are allowed to break this promise and therendermethod may returnfalse.Notice that returning
falseis always safe, it does not promises thatrendermethod will also returnfalse.Unlike other methods of this interface this method must be very quick to return and if this method cannot determine if
rendermethod will returntrueorfalse, it must simply returnfalserather than doing some expensive test. For example, this method might check the existence of a property in the passed data but may not analyze the pixels of an image (if the data contains an image).This method is provided for performance reasons only, so that callers may be able to more eagerly cancel the rendering process if required. However, it is always safe for this method to simply return
false.- Parameters:
data- the data object to be checked if passing this data to therendermethod will cause a significant rendering. This argument can benullif the provider of the data can providenullobjects.- Returns:
trueif a subsequent invocation to therendermethod with the same data will cause a significant rendering,falseotherwise
-
render
This method may be called multiple times to do the implementation defined rendering. When this method is called multiple times it will be done so with a more and more accurate data and each invocation is expected to overwrite the results of the previous rendering. This method is not called if there is no data available.This method should not throw an exception but if it does, the rendering process should be continued as if this method returned
false.- Parameters:
data- the data object which is the input of the rendering process. This argument can benullif the provider of the data can providenullobjects.cancelToken- theCancellationTokensignaling cancellation a request when the rendering request has been canceled. Upon cancellation this method may simply returnfalseor throw anOperationCanceledExceptionexception or even continue as if nothing happened. This argument cannot benull.- Returns:
trueif this method actually did some significant rendering,falseotherwise- Throws:
OperationCanceledException- implementation may throw this exception if they detect a cancellation request. They are not required to do so, they may even returnfalseor even ignore the cancellation request.
-
finishRendering
This method is called to allow for a final rendering after no morerendercall will be done. This method must be called ifstartRenderingis called on thisDataRenderer. Also, this method may not be called more than once.Note that in general it is not allowed to restart a
DataRenderer, oncefinishRenderinghas been called, thisDataRendererobject is no longer useful regarding rendering.- Parameters:
report- theAsyncReportobject defining how the rendering has been completed (the same as with theAsyncDataListener). This argument cannot benull.cancelToken- theCancellationTokensignaling cancellation a request when the rendering request has been canceled. Upon cancellation this method may simply return or throw anOperationCanceledExceptionexception or even continue as if nothing happened. This argument cannot benull.- Throws:
OperationCanceledException- implementation may throw this exception if they detect a cancellation request. They are not required to do so, they may even return normally or simply ignore the cancellation request.
-