This implementation covers only the basic usage. You may add more features as your application requires.
Create Client and Server
Now, let’s write our own server:
The number of server shards equals to the number of workerPools.
As for the memcache functionality - we specify the number of buffers and their capacity in the config.
Config is used to pass everything MemcacheMultiServerModule needs to handle upcoming requests.
Our client will create put and get requests:
Since MemcacheClientModule uses Rendezvous Hashing Strategy to achieve agreement for requests between
shards of servers, in client we ought to provide addresses of these shards - 9001, 9002, 9003 ports.
In the eventloop we ask to put a message in the current i of the bytes[i] array,
and get it back from the corresponding cell.
So the client will perform these operations asynchronously for three shards, therefore we will receive a disordered output block as a result.
Running the application
First, open and run the MemcacheLikeServer to launch the server;
To launch the client, run main() method of MemcacheLikeClient;
You will see the following output in the server’s console (... omit identical messages):
In the client console you will see that the client received asynchronous responses from the server: