You are not logged in.
Hello,
I am testing mormot (mORMotNightlyBuild 2015-08-01).
If apply the RttiInstanceType.GetMethod to execute the method is generated exception of more 30% of the requisitions when executed with more of instance.
//... The class name and method are sent via parameters. Ctxt.InputString['NameClasseController'] ...
RttiInstanceType := Contexto.FindType('CfopController.TCfopController') as TRttiInstanceType;
return := TExtjsVO(RttiInstanceType.GetMethod('Consult').Invoke(RttiInstanceType.MetaclassType, MyParameters).AsObject);
//...
But if execute without the RttiInstanceType is not generated exception.
return := TExtjsVO(TCfopController.Consult('id=1', '1', True));
Please This is a problem in rtti or mormot?
Thanks
Last edited by fenix (2015-08-02 15:52:13)
Offline
I do not understand what your code is doing.
Sounds to me like RTTI abuse.
If you have the type information, transtype the instance to its final type, using "as" or "is", and call the Consult method.
Use class types, and not RTTI here.
I guess there is no problem in mORMot or in RTTI, but in how you are using the RTTI.
Offline
Thanks for your reply.
I do not know what the class and the method will depend on the parameter.
http://localhost:777/restSF/ObjectJson/?NameClassController=CfopController.TCfopController&NameMethod=Consult&Parameters=id=1|1|True
procedure TServiceServer.ObjectJson(Ctxt: TSQLRestServerURIContext);
var
Context: TRttiContext;
RttiInstanceType: TRttiInstanceType;
parameters: TArrayParameters;
pNameClassController: String;
pNameMethod: String;
pParameters: String;
return: TExtjsVO;
begin
try
if UrlDecodeNeedParameters(Ctxt.Parameters, 'NameClassController') then
begin
pNameClassController := Ctxt.InputString['NameClassController'];
pNameMethod := Ctxt.InputString['NameMethod'];
pParameters := Ctxt.InputString['Parameters'];
end;
Parameters := MountParameters(pParameters);
RttiInstanceType := Context.FindType(pNameClassController) as TRttiInstanceType;
return := TExtjsVO(RttiInstanceType.GetMethod(pNameMethod).Invoke(RttiInstanceType.MetaclassType, Parameters).AsObject);
if Assigned(return ) then
begin
Ctxt.Returns(ObjectToJson(return , []));
FreeAndNil(return);
end;
Ctxt.success;
finally
Contexto.Free;
end;
//
end;
There are several classes (TPersistent) and through the rtti will perform to called the Class/Method according with parameters.
Now, can you understand?
The following detailed example.
class function TCfopController.Consult(pFilter, pPage: String; pComplete: Boolean): TExtjsVO;
var
objReturn TExtjsVO;
begin
objReturn := TExtjsVO.Create;
objReturn.success := true;
objReturn.total := 1;
objReturn.rows := 'It is Okay, worked. [TCfoController]';
result := objReturn;
end;
Other exemple
http://localhost:777/restSF/ObjectJson/?NameClassController=CustomerController.TCustomerController&NameMethod=Consult&Parameters=id=1|1|True
class function TCustomerController.Consult(pFilter, pPage: String; pComplete: Boolean): TExtjsVO;
var
objReturn TExtjsVO;
begin
objReturn := TExtjsVO.Create;
objReturn.success := true;
objReturn.total := 1;
objReturn.rows := 'It is Okay, worked. [TCustomerController]';
result := objReturn;
end;
The code works perfectly with the consumption of a client, but when testo with two clients (threads) on, begin to occur error.
What can I change to no longer the error occurs?
Offline
By default, method-based services are re-entrant, so it is up to your code to be thread safe.
I guess the way you are using RTTI is not thread-safe.
You should add some critical sections.
See http://synopse.info/files/html/Synopse% … ml#TITL_25
And IMHO not (ab)use of RTTI as such.
Consider defining a list of classes, inheriting from a parent class, to execute methods.
Or even better use interfaces.
Offline
Okay, thanks.
If I use interface, could I use restful?
I tried receive via TSQLRestServerURIContext, but not allow.
I need receive the data via POST/PUT (Ctxt.Call.InBody), but I do not found how do.
Could you give me some tip of how do?
Please, sorry me by my english.
Last edited by fenix (2015-08-03 13:23:08)
Offline