delphi - How can I get the reference to TDSServerClass in TDSServerClass.OnCreateInstance event handler? -


i'm using datasnap build middleware, , business logic independent. support different client apps, encapsulate business logic multiple subclasses of tdatamodule, , expose them client rest api. number of subclasses , class types dynamically changing, , loaded plugin.

according delphi xe's design pattern, need create 1 tdsserver instance "server", , multiple tdsserverclass instances, worked adapters, each serve 1 of tdatamodule subclasses.

the chain of classes are: 1 tdsserver -> multiple tdsserverclass(es) -> tdatamodule subclasses

my problem find correspondence of tdsserverclass instances , tdatamodule subclasses in tdsserverclass.oncreateinstance event handler.

to setup chain , keep correspondence, if have 10 subclasses, example:

  1. i created 1(one) tdsserver instance, , created 10 tdsserverclass instances, each instance serve 1 tdatamodule subclass (i have stored id of subclass in tdsserverclass.tag property.
  2. i created 10 pools every subclasses on middleware startup, in each pool there 10 instances of subclass (there totally 100 instances in pools).
  3. i set tdsserverclass instances' event handler of "ongetclass", "oncreateinstance", "ondestroyinstance" procedures control creation of tdatamodule subclass.
  4. in oncreateinstance event handler (when rest api called client), want pick instance opposite subclass instance pool.

my problem can't keep tdsserverclass->my subclass correspondence.

when middleware startup, creation of tdsserverclass instances below:

fserverclasses[len].ongetclass := dsserverclassgetclass; fserverclasses[len].tag := len; fserverclasses[len].oncreateinstance := dsserverclass1createinstance; fserverclasses[len].ondestroyinstance := dsserverclass1destroyinstance; 

when datasnap server startup, trigger the ongetclass event, worked well, can find correspondence event handler parameter below:

procedure tmainservercontainer.dsserverclassgetclass(   dsserverclass: tdsserverclass; var persistentclass: tpersistentclass); begin   persistentclass := findclass(fserverpersistentclasses[dsserverclass.tag]); end; 

when client app calls rest api, tdsserverclass triggered oncreateinstance event let me pick subclass instance pool. in oncreateinstance , ondestroyinstance event handler, can't make work.

the event handler prototype of oncreateinstance, example, like:

dsserverclasscreateinstance( dscreateinstanceeventobject: tdscreateinstanceeventobject); 

i've done research on tdscreateinstanceeventobject, didn't find reference tdsserverclass triggered event.

please me. lot!

edit

ok, let see if now. have 10 instances of tdsserverclass, right? , need find of 10 called function.

the answer adopt have 10 different dsserverclassxcreateinstance implementations , 10 different dsserverclassxdestroyinstance implementations, 1 each tdatamodule, bit this:

fserverclasses[3].oncreateinstance := dsserverclass3createinstance; 

it may bit cumbersome, , depending on implementation may able use generics neaten things up, simple , effective.

here idea on how use generics if want tdatamodule entry:

.....  function dsserverclasscreateinstance< t : tdatamodule > : tdserverinstance;  ....  fserverclasses[3].oncreateinstance := dsserverclasscreateinstance< mydatamodule3 >; 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -