Reputation: 103577
Issue
I want to implement TransparencyChecker Interface
which would verify that from any exchange in the network all trading information from other exchanges is available.
Q: How would TransparencyChecker Inferface
implemented ?
Problem Background
Stock exchanges decided to share trading information with each other. If one exchange wants to share information with another exchange, it installs an outgoing network link to dump all transactions. The network links are one-way and the exchange also shares transactions, which have been received from incoming network links.
Code
interface Exchange {
/**
* Returns list of names of exchanges which receive all trading information
* from this exchange.
* @return list of exchanges
*/
Set<String> getOutgoingConnections ();
/**
* Name of the exchange
* @return name
*/
String getName ();
}
interface TransparencyChecker {
/**
* Checks the transparency of the network. The network is the
* collection of exchanges and each of them has a unique name.
* @param exchanges list of exchanges in the network
* @return true if all trading information is available for every exchange
*/
boolean isTransparent (Set<Exchange> exchanges);
}
Upvotes: 1
Views: 171
Reputation: 55937
Problem: Verify that all trading information from other exchanges is available
There are several problems here, I'm going to focus on one: "All Information is Available", but briefly, mention two other problems
And the brings me to the primary question: what does "Available" mean? Let's just focus on ExchangeA and ExchangeB (if A and B can agree then what ever rules we use we can extend to A->C, A->D, B->C etc.) We could consider several different meanings for A deciding whether B is available: Can A ping B at a network level? Has A received a recent (how recent?) message from B, Can A understand the message it received from B? Perhaps B needs to send several messages to describe its state, did we receive them all? Are the messages sensible?
I suggest that A can determine B's availability by receiving messages from B at some agreed interval. These messages may be as simple as
"Hello, I'm B, at 13:15 GMT on 21st January 2011, I am functioning correctly"
or more complex
"Hello, I'm B, at 13:15 GMT on 21st January 2011, I am about to send you my current status,
it will comprise 3 messages including this one. Data XXX, YYY ..."
"2 of three messages from B, at 13:15 GMT on 21st January 2011, Data XXYX, QQQ ..."
"3 of 3 from B, at 13:15 GMT on 21st January 2011, Data PPP, QQQ ..."
Now A has to then interpret these "Hearbeats". Suppose messages are due every 5 minutes and one hasn't arrived for 8 minutes - is that bad? Suppose one message misses, but all the rest are delivered? Suppose some are delivered out of order? You need to define your rules. You need to assume that networks do have the occasional glitch, small delays will happen.
Following from this there are various questions such as how does B know to tell A its available. Perhaps a Pub/Sub approach is appropriate? Or should there be some central registry that all exchnages talk to, and each exchasge just asks the registry "is everybody up?"
Upvotes: 1
Reputation: 38541
Having understood your question to be:
I need help creating a class that implements the TransparencyChecker
interface, I will offer the following advice (this looks like an academic exercise, not a work project):
Start by creating the following two classes:
public class NYStockExchange implements Exchange {
}
public class MyTransparencyChecker implements TransparencyChecker {
}
and compile.
You'll notice that you will get errors because you haven't implemented the methods in either of these two classes. Start by implementing getName()
in NYStockExchange
. This should be easy, it should just return a String that returns "NYStockExchange"
.
Compile again. You'll notice theres one less method that needs to be implemented. Rinse and repeat. Come back with questions on particular methods you have problems implementing, and what your exact problem is.
Upvotes: 0