Class TRequestBroker (unit RBroker)

Inherits from

TComponent

:The RequestBroker (ORB) main job is to instanciate objects to satisfy client requests, passing to the object the parameters from the request and giving the result back to the client when the object has finished. A request is made of a function code, a space and some parameters in a special format (TMWBuffer). The RequestBroker object is linked to the application server object and receive client requests from him, brokening those requests and dispatching them to server objects for execution.

Constructors


constructor Create(AOwner : TComponent);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Functions

procedure AddServerObject(ServerObjectClass : TServerObjectClass);

:AddServerObject is called from the main application server code, at startup to build the request broker object table.

procedure BrokeRequest(RqBuffer : PChar; RqLength : Integer; Tag : TObject; SendResp : TSendResponseToClient);

:BrokeRequest is the ORB main method.

destructor Destroy;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure EnumServerFunctions(CallBack : TEnumServerFunctions);

:This method is used to enumerate all server functions.

procedure CrackHeader( RqBuffer : PChar; { Given request buffer } RqLength : Integer; { Given request length } var FunctionCode : String; { Returned function code } var ParamPtr : PChar; { Returned parameters start } var ParamLen : LongInt { Returned parameters length } );

:A client request is constitued of two parts: a function code and some parameters.

function FindServerObject(FunctionCode : String) : Integer;

:Find a server object by using function code as a key.

function RemoveServerObject(FunctionCode : String) : Integer;

:Remove an object from the obejct list.

procedure ServerObjectRequestDone(Sender : TObject);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure TriggerObjCreate(ServerObject : TServerObject);

Returned parameters length

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure TriggerObjDestroy(ServerObject : TServerObject);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Properties

property IniFileName : String

:Used to store permanent data.

property UserData : LongInt

:UserData is not used by the request broker nor the application server component.

property ObjectCount : Integer

:Number of currently instanciated server objects.

Events

event OnDisplay : TDisplayEvent

:Triggered when the component need to display something on the user interface such as error or informatinal messages.

event OnObjCreate : TInstanciationEvent

:Triggered when an object has been instanciated.

event OnObjDestroy : TInstanciationEvent

:Triggered when an object has been destroyed.

Variables

FIniFileName : String;

:Just passed to ServerObject instances.

FObjectCount : Integer;

:Number of instanciated objects.

FObjectList : TList;

:List of all TDispatchObject.

FOnDisplay : TDisplayEvent;


FOnObjCreate : TInstanciationEvent;

:Triggered when an object has been instanciated.

FOnObjDestroy : TInstanciationEvent;

:Triggered when an object has been destroyed.

FUserData : LongInt;

:Just passed to ServerObject instances.


Constructors


constructor Create(AOwner : TComponent);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Functions


procedure AddServerObject(ServerObjectClass : TServerObjectClass);

:AddServerObject is called from the main application server code, at startup to build the request broker object table. This table associates objects and request. Each server object has a functions code (which default to the server object name without the leading TServerObject). Note hat the argument for AddServerObject is an object class, not an object instance.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure BrokeRequest(RqBuffer : PChar; RqLength : Integer; Tag : TObject; SendResp : TSendResponseToClient);

:BrokeRequest is the ORB main method. This is the method which does all the work: creack header, find and instanciate server object, execute server object code and send result back to the client.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


destructor Destroy;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure EnumServerFunctions(CallBack : TEnumServerFunctions);

:This method is used to enumerate all server functions. The mains purpose is to built some way to display all the server functionnalities such as function code list.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure CrackHeader( RqBuffer : PChar; { Given request buffer } RqLength : Integer; { Given request length } var FunctionCode : String; { Returned function code } var ParamPtr : PChar; { Returned parameters start } var ParamLen : LongInt { Returned parameters length } );

:A client request is constitued of two parts: a function code and some parameters. The CrackHeader method is responsible to split both parts. By default, it consider the function code to be the first word in the data received from the client and the parameter being the remaining data after this function code and any trailing spaces. You can overrie this method if you like to have a more complex headder for example to pass more info from the client to the server.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Extract the function code and separate parameters from header


function FindServerObject(FunctionCode : String) : Integer;

:Find a server object by using function code as a key. Returns the server object index in the table of object.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Find a FunctionCode in the FObjectList and return the item index or -1 } { if function code not found.


function RemoveServerObject(FunctionCode : String) : Integer;

:Remove an object from the obejct list.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Remove a FunctionCode from FObjectList. Return 0 if Ok, -1 if not found


procedure ServerObjectRequestDone(Sender : TObject);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure TriggerObjCreate(ServerObject : TServerObject);

Returned parameters length

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure TriggerObjDestroy(ServerObject : TServerObject);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Properties


property IniFileName : String

:Used to store permanent data.


property UserData : LongInt

:UserData is not used by the request broker nor the application server component. It is there for the application server's writer to pass global data between the main application server code and each server object, such as TTable of any other data.


property ObjectCount : Integer

:Number of currently instanciated server objects.


Events


event OnDisplay : TDisplayEvent

:Triggered when the component need to display something on the user interface such as error or informatinal messages.


event OnObjCreate : TInstanciationEvent

:Triggered when an object has been instanciated.


event OnObjDestroy : TInstanciationEvent

:Triggered when an object has been destroyed.


Variables


FIniFileName : String;

:Just passed to ServerObject instances.


FObjectCount : Integer;

:Number of instanciated objects.


FObjectList : TList;

:List of all TDispatchObject.


FOnDisplay : TDisplayEvent;


FOnObjCreate : TInstanciationEvent;

:Triggered when an object has been instanciated.


FOnObjDestroy : TInstanciationEvent;

:Triggered when an object has been destroyed.


FUserData : LongInt;

:Just passed to ServerObject instances.