In this guide we will create a memcached-like client-server application that is based on the RPC communication protocol and ActiveJ technologies.
You can find full example sources on GitHub.
First of all, consider the initial ActiveJ RPC implementation of these modules since our application will be built with their help:
- MemcacheServerModule exports an RpcServer for handling the
putrequests. To launch several servers on a single JVM, we provide the MemcacheMultiServerModule with integrated WorkerPools.
- MemcacheClientModule sets a Rendezvous Hashing Strategy for request arrangement between shards of servers.
This implementation covers only the basic usage. You may add more features as your application requires.
Since we extend Launcher, we need to override 2 methods: getModule to provide ServiceGraphModule and run to describe the main logic of the example.
- The number of server shards equals the number of workerPools
- As for the "memcached" functionality - we specify the number of buffers and their capacity in the Config
- Config is used to set up everything MemcacheMultiServerModule needs to handle upcoming requests.
Our MemcacheLikeClient will create
- Since MemcacheClientModule uses Rendezvous Hashing Strategy to achieve agreement for requests between
shards of servers, in client we need to provide the addresses of these shards -
- In the Eventloop we ask to
puta message in the current i of the bytes[i] array, and
getit 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.
is a manually created class. It uses RawMemcacheClient (a MemcacheClient
implementation) and defines the logic of
getmethods for our MemcacheLikeClient.
- First, open and run the MemcacheLikeServer to launch the server;
- To launch the client, run
main()method of MemcacheLikeClient;
You will see roughly the same output in the server's console (
... omits similar messages):
In the client console you will see a similar output confirming the client received asynchronous responses from the server: