Class AsynchronousHandler<TAsynchronousHandlerProcessor, TAsynchronousArgument>
Base class for services that have an asynchronous part. Knowledge about processing is held by a separate processor.
Inheritance
Namespace: SuperOffice.Threading
Assembly: SoCore.dll
Syntax
public abstract class AsynchronousHandler<TAsynchronousHandlerProcessor, TAsynchronousArgument> : Object where TAsynchronousHandlerProcessor : AsynchronousHandlerProcessor<TAsynchronousArgument>, new()
where TAsynchronousArgument : class
Type Parameters
Name | Description |
---|---|
TAsynchronousHandlerProcessor | Processor used for actually carrying out the work. This class is instantiated with the AsynchronousHandler |
TAsynchronousArgument | Type of object used as argument for processing asynchronous. |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
Constructors
AsynchronousHandler()
Constructor, only called from derived classes
Declaration
protected AsynchronousHandler()
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
Properties
HasWorkToDo
A flag property that reflects the output of SynchronousSetup(TAsynchronousArgument). It is true if there is work to do for the AsynchronousOperation().
Declaration
public bool HasWorkToDo { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
Processor
Processor executing the operation.
Declaration
protected TAsynchronousHandlerProcessor Processor { get; }
Property Value
Type | Description |
---|---|
TAsynchronousHandlerProcessor |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
ThreadName
Thread name. The default implementation returns the query type and the table/record of the first query in the batch. Subclasses can override and add their content.
Declaration
public virtual string ThreadName { get; }
Property Value
Type | Description |
---|---|
String |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
WasSetupCalled
A flag property that keeps track of whether the SynchronousSetup(TAsynchronousArgument) method has been called. It is illegal to call AsynchronousOperation() if this flag is false.
Declaration
protected bool WasSetupCalled { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
Methods
AsynchronousOperation()
Public interface for the asynchronous part of the operation. Any data needed
for its execution has to be copied by the SynchronousSetup(TAsynchronousArgument), because
you DO NOT KNOW when the
Declaration
public void AsynchronousOperation()
Remarks
You should not really call this method if the SynchronousSetup(TAsynchronousArgument) returned false, which can be checked
by accessing the
Examples
AsynchronousHandler someOperation = new SomeOperation();
someOperation.SynchronousSetup( currentQuery );
...
if( someOperation.WorkToDo )
someOperation.AsynchronousOperation();
// we're done, async thread will sooner or later do the work
ExecuteWork()
Template method that executes the actual work, by calling the
Declaration
protected virtual void ExecuteWork()
Remarks
ExecuteWork is called by the thread delegates provided by the various
execution models. It can be overridden for special needs, but overriders should note that
they MUST call
OnSetup(TAsynchronousArgument)
Derived classes that need other behaviour than simply copying the ArgumentParameterCollection and PrimaryKey information from the incoming query should override this method.
Declaration
protected virtual bool OnSetup(TAsynchronousArgument inputQuery)
Parameters
Type | Name | Description |
---|---|---|
TAsynchronousArgument | inputQuery | Incoming query to be copied |
Returns
Type | Description |
---|---|
Boolean | true - this default implementation signals that there IS something to do in the main routine |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
ScheduleNewWork()
Strategy method for starting processing of new work.
Declaration
protected abstract void ScheduleNewWork()
Remarks
Derived classes must provide an implementation that somehow queues, spawns, executes or in other ways processes directly, or sets up for later processing, whatever work is in the InputQueryCopy (or the derived class' other unit of work storage).
SynchronousSetup(TAsynchronousArgument)
Public interface for the synchronous part of the operation. The query to be processed must be a parameter to this operation.
Declaration
public bool SynchronousSetup(TAsynchronousArgument inputQuery)
Parameters
Type | Name | Description |
---|---|---|
TAsynchronousArgument | inputQuery | Query to be processed by the actual service |
Returns
Type | Description |
---|---|
Boolean | TRUE if there is something to do, i.e., if AsynchronousOperation should be called |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc
ToString()
Returns value of ThreadName.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | Value of ThreadName. |
Remarks
See design documentation in //crm/Documents/CRM Web Spec and Design Documents/NetServer/Core Services.doc