Implement an online trading application. Each running instance communicates with other running instances and also with the bank.
The assignment describes a message-based communication protocol that implements a simple trading system. Understanding the assignment requires no special knowledge.
Parts of the implementation are provided. Download source code from https://d3s.mff.cuni.cz/files/teaching/nswi080/labs/Files/sources-3.zip
The chosen messaging standard is JMS (Java Message Service), using the ActiveMQ 5.16 or ActiveMQ Artemis 2.17 implementation. The following knowledge is needed for the implementation:
Connection
, Session
, Queue
, Topic
etc.).MessageProducer
and MessageConsumer
objects).TextMessage
, ObjectMessage
, MapMessage
etc.),
knowledge of criteria for choosing an appropriate message type.Application must provide the following functionality:
After its startup, create random unique names of goods,
that the user (seller) provides, together with random price of each
item.
This list should be sent as a message via the Offers
topic to the
other running instances.
The application should also send the Bank a message requesting account creation. The bank will respond with a message containing the account number.
Present to the users (in any trivial form) a list of goods and
prices, offered by the other running instances. This list should be
updated, whenever a new message from the Offers
topic arrives, and
any items no longer offered by the sending instance should be removed
from the list.
Allow the user to choose (again, using any trivial method) goods to buy from another instance. The sale is realized as follows:
The buyer sends a message to the seller, containing the name of the requested item and the buyer's account number.
The seller sends a message to the buyer, containing the seller's account number, or indicating a refusal to sell (the item was already sold etc.).
The buyer sends a message to the Bank, requesting transfer of appropriate amount of money from the buyer's account to the seller's account.
The bank sends a message to the seller, notifying the seller of the money transfer from the buyer's account.
The seller removes the item from its list and sends a message to the buyer, confirming the finished sale.
Note: The buyer does not have to offer the item bought for sale.
Consider the weaknesses of the communication protocols described above. Extend, document and implement a more robust variant of the protocol (reusing the provided parts is allowed) that will have these features:
Keep proper account balances. For simplicity, newly created accounts can have fixed balance.
Support for account balance queries. Add a new user command to the client, to show the current balance.
More robust sell/buy protocol:
Improve availability of the goods offered by existing clients to newly connected clients. After a new client connects, it should see offers of all other clients without any user action on those clients.
The messages used to implement the functionality may contain further
information that might be needed but not mentioned above.
You are to choose the appropriate message types.
(For example, the provided Bank implementation uses TextMessage
and
MapMessage
, you are free to choose different types for the
communication between the client instances.)
The implementation should behave reasonably when possible - refuse to sell an item already requested by a different buyer, etc.
Session
instances
MessageProducer
from one Session
should not be used in a
different sessionMessageProducer
for each Session
equals()
instead of ==
for String
comparisondata
and activemq-data
Bank.java
: bank implementation
Client.java
: skeleton of the client
TODO
in the codeconnect()
methodpublishGoodsList()
methodprocessOffer()
methodconnect()
methodMapMessage
? ObjectMessage
?buy()
methodprocessSale()
methodprocessSale()
methodprocessSale()
methodbuy()
methodbuy()
method (already implemented)processBankReport()
methodbuy()
method