Question

I have a client(android)-server app containing tasks that are to be distributed to users. A user can see all available tasks, and when he enters a task the client sends a "READ" notification to the server, indicating that the task has been read.

When connection on the android client is down I want to buffer up server calls, and execute them once connection is back.

Use case:

Connection is down and user A opens task1. The client will call a handle on its service layer, but this service will not call the REST handle on the server until connection comes back.

Was it helpful?

Solution

I would create:

  • A Command class that represent an action to perform (interaction with the server). Store in this object information such as endpointUrl, httpMethod, parameters and anything else you need to perform a call to the server. Make this class serializable.

  • An Executor class that, given a Command, can perform the action (calling server endpoint with correct parameters and everything).

When the Executor received a command that cannot be executed because the server is down it serialize this command. It needs to be on a permanent storage (not in memory) for the case the application is stopped with pending commands.

When the application start you should add logic to deserialize all commands and execute them. You can also implement a listener on network state, when connectivity is back do the same thing as startup: deserialize commands and execute them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top