Asynchronous Database Access: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Kymara minor typos |
imported>Kymara |
||
| Line 44: | Line 44: | ||
== Implementation == |
|||
== Some quick ideas on how to == |
|||
| ⚫ | |||
| ⚫ | |||
Note: This section needs more thinking. |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
new GameEvent(attacker.getName(), |
new GameEvent(attacker.getName(), |
||
"attack", target.getName()); |
"attack", target.getName()); |
||
| Line 61: | Line 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: |
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 = |
UUID uuid = DBCommandQueue.get().enqueueAndAwaitResult( |
||
this, new GetCharacterList(username)); |
this, new GetCharacterList(username)); |
||
The |
The DBCommandQueue will process the GetCharacterList at some future time in the background thread. It will then put the GetCharacterList which now contains the results from the database in a second queue ("waiting to be fetched by program"). Here comes the tricky part: We need a way to notify the program in the thread that requested the operation about the results. The easiest way is to remember the requesting thread by Thread.getCurrentThread() and provide a List<DBCommand> |
||
getResults() method, which fetches all results of |
getResults() method, which fetches all results of Commands enqueued by the current thread. |
||
| ⚫ | We had to decide here whether we wanted 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 DBCommandResultReceiver<T extends DBCommand>, which is implemented by those classes who requested the data. We chose a a polling based |
||
| ⚫ | |||
| ⚫ | |||
{{TODO|Maybe I understood this wrong and the other approach is still possible, change this if so}} |
|||
| ⚫ | We |
||
| ⚫ | |||
| ⚫ | |||