Asynchronous Database Access: Difference between revisions
Content deleted Content added
imported>Kymara minor typos |
imported>Kymara |
||
Line 44:
== Implementation ==
The following example for a simple write operation assumes that GameEvent implements/extends
▲There should be a DatabaseOperationQueue, which is singleton and has a background thread to execute enqueued DatabaseOperations. DatabaseOperation is an interface that specifies an execute()-method, that handles the database operation by invoking the DAO-classes. It is called from the background thread of DatabaseOperationQueue.
▲The following example for a simple write operation assumes that GameEvent implements/extends DatabaseOperation:
▲ DatabaseOperationQueue.get().enqueue(
new GameEvent(attacker.getName(),
"attack", target.getName());
Line 61 ⟶ 58:
Since we ignore 1) for now, this leaves us with 2): We need a way to receive the data produced by an read operation:
UUID uuid =
this, new GetCharacterList(username));
The
getResults() method, which fetches all results of
We
approach.
{{TODO|Maybe I understood this wrong and the other approach is still possible, change this if so}}
▲We have to decide here whether we want an interrupt or polling based approach: An interrupt based approach would then distribute the results to various program parts of the current thread using an interface DatabaseOperationResultReceiver<T extends DatabaseOperation>, which is implemented by those classes who requested the data. A polling based
▲approach would result in the program parts to look for specific results. So the program part that sends the character list back to the client would call:
▲ List<GetCharacterList> DatabaseOperationQueue.get().getResults(this).
| |||