This task is about cross-language communication using remote procedure calls (RPC), using Apache Thrift. Implement a simple client-server application which will use given a communication protocol. The protocol is based on a given language-independent interface description in Thrift IDL. Then, extend the protocol while maintaining full run-time compatibility.
Download the input source code https://d3s.mff.cuni.cz/legacy/files/teaching/nswi080/labs/Files/sources-2.zip . Install Apache Thrift and try the example https://d3s.mff.cuni.cz/legacy/files/teaching/nswi080/labs/Files/lab-2thrift-en.html . We will use C++ to implement the server. Choose a different programming language supported by Thrift for implementing the client.
The task requires understanding of the following:
The application that will be implemented does not perform any meaningful task, it is designed to merely show working with various data types using cross-language RPC.
The main idea is that the client logs in to the server, then lets the server perform a search for some items. The result of the search is a list of items, which are returned to the client one by one. The client generates a summary based on the items and saves it on the server.
Because the focus of this task is just the communication not an actual functionality of the application, we will work with just random data without any meaning.
The client and server should communicate like this:
logIn
of a Login
service, with a user name an integer key.InvalidKeyEception
, which will contain the correct key.logIn
again, now with the correct key.ItemA
and fetching them one by one.fetch
to fetch the items.
FetchResult
either contains an item from the result, or indicates why no item was returned.
state
field of FetchResult
is ENDED
, then no item was returned, because there are no more items (all were already fetched).state
field of FetchResult
is PENDING
, then no item was returned, because the server is still searching for items and does not currently have any items to return.
state
field of FetchResult
is ITEMS
, then the item
field contains an item."fieldX"
, "fieldY"
, etc.saveSummary
in Reports
.logOut
.Implement a client which will communicate with the server using the protocol defined by the IDL file and the description above.
Test that the client works with our server at lab.d3s.mff.cuni.cz:5001
.
Login
, Search
and Reports
.Implement the server side of the application in C++.
login
, you may use a random value per connection, or some hash of the user name.database.hpp
. (Note: The database generates multiple types of items, to be used in the next part of the assignment. In the basic version of the server, we are only interested in items of type "ItemA".)PENDING
from fetch
to simulate a long-running search.saveSummary
, check that the summary is correct - you can use code in the file summary.hpp
to generate the expected summary and compare it with the client-provided summary.ProtocolException
.An important feature of Thrift and its IDL is the ability to evolve the interface while keeping compatibility.
For example, new fields can be added to user-defined types, fields which are not required
may be removed, function parameters may be added, etc.
The client and server may use different definition of a type or a function.
ItemB
, ItemC
) in addition to ItemA
. The C++ variants of these types are in items.hpp
.
Search
service in some way to allow the client to initiate a search, specifying:
Search
service in some way to allow fetching multiple items at once.
Submit by e-mail, a zip file containing:
You must use the provided interface file and modify it only as described.
You may use the provided C++ code an modify it as you wish.
The server must be able to serve multiple clients at the same time without interference.
Do not crash or leak memory, perform undefined behavior, race conditions (if multiple threads access shared mutable data, the accesses must be synchronized, for example using a mutex lock).
Properly handle exceptions (do not crash or terminate just because the other side does not follow the protocol, etc.).
Keep the implementation simple.
It should be easy to build and run (preferrably should work on the computers in the school labs).
You may use parts of the example codes and scripts.
If you are using git to keep track of different versions, do not submit your git history - all parts of the solution should accessible directly as files.
If something is unclear, ask on the mailing list.