Note, this implementation covers the basic usage. You may add more features as your application requires.
Create Client and Server
Now, let’s write own server:
As for the memcache functionality - we specify the number of buffers and their capacity in the config.
Pass with config everything that MemcacheServerModule needs to handle the upcoming requests.
Then make RPC memcacheServer listen on the 8080 port.
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 - 9010, 9020, 9030 ports.
In 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 client will perform these operations asynchronously for three shards, that’s why as the result we will receive
three disordered output blocks.
Running the application
Launch server - run MemcacheLikeServermain() method.
Create and run compound configuration.
For IntelliJ IDEA:
Add three configurations for each address Run -> Edit configurations ->
Add Application -> Run/Debug Configurations -> Main class: MemcacheLikeServer -> VM options: -ea -Dconfig.server.listenAddresses=localhost:9010.
Changing port number correspondingly.
Create compound configuration Run -> Edit configurations -> Add Compound and add three configurations from previous step.
Run compound configuration.
Launch client - run MemcacheLikeClientmain() method.