ClientSocket: TCustomWinSocket;Params: TAstaParamList)
One of the design goals of ASTA was to provide scalable threaded servers without having ASTA developers to have to create any threads themselves. Since ASTA 2 there have been threaded messaging calls that allow for ASTA messaging to be used in threads on the server. Immediately ASTA users started to push the envelope on asynchronous database access. The problem arose that one remote client would want to be able to have multiple database queries executing on a server, and if left un-checked, this could result in one client using many, many database sessions.
In Asta 2.108 an attempt was made to cache asynchronous threaded database calls so that a limit could be set on the amount of concurrent database sessions used by any remote user. To send a message to an ASTA client, normally a ClientSocket (TCustomWinSocket) is used. Internally, ASTA uses the ClientSocket to lookup the UserRecord from the UserList of the TAstaServerSocket. In order to make this thread safe, instead of using the UserList, ASTAThreads now make a full copy of the UserRecord that can be used within threaded util calls in order to make it thread safe. In addition, critical sections have been added to code where it was not needed before when using non-blocking event driven sockets.
The prototypes of the ThreadedUtil events have changed. In the past, the Sender (TObject) parameter passed was the AstaServerSocket, and now it will be a TAstaThread. This will allow you to use the UserRecord of the AstaThread to send messages.
The following shows the use of a ThreadedDBUtility
event from an ASTA server. Notice the ServerSocket.SendCodedParamListSocket call which uses the ThreadedClient
copy of the UserRecord. Note: If a client is disconnected at this point the thread will be marked as terminated,
so perhaps a call to
Exit is needed before the actual send
is made. The one scenario where we still seem to have problems is when there are queued UtilityEvents
that have not been launched, and the client disconnects.
procedure TForm1.TestUtilSQLEvent(Sender: TObject;
ServerSocket: TAstaServerSocket; ClientSocket: TCustomWinSocket;
Query: TComponent; Params: TAstaParamList);
//the Sender is now a TAstaThread
TQuery(Query).SQL.Text := Params.AsString;
p := TAstaParamList.Create;
p.FastAdd(IntToStr(TQuery(Query).RecordCount) + ' records retrieved.');
p.FastAdd(CloneDataSetToString(Query as TQuery));
//don't call the AstaServerSocket1 as we are in a thread
//use the passed in ServerSocket
ThreadedClient, 1550, P);
//Asta disposes of the query
//if you want additional components you can call
//ThreadedDBSupplyQuery since you now have the Sender TAstaThread
//and the client socket