Hi have the following interface:
public interface KeyValueStore {
public void put(String key, byte[] value);
public byte[] get(String key);
public void putAll(Map<String,byte[]> pairs);
public Map<String,byte[]> getAll(Collection<String> keys);
}
And I have the following client that implements the previous interface:
public class Client implements KeyValueStore{
@Override
public void put(String key, byte[] value) {
}
@Override
public byte[] get(String key) {
}
@Override
public void putAll(Map<String, byte[]> pairs) {
}
@Override
public Map<String, byte[]> getAll(Collection<String> keys) {
}
}
How can I implement the Client in order to interact with the given interface? I want to do this with a client-server architecture.
Another thing I want is a “name server” that knows where the data is stored (basically it has the mapping of keys to “storage servers”), and several other servers where the data is actually persisted.
This is quite an open-ended question. I’ll take a shot at it.
I think you need to keep three different concepts in mind:
Interface
Implementation
Client
Let’s look at each one.
You have the interface already, so it’s all good on that part.
What you’re calling the client, I believe to be the implementation, meaning: it’s the actual code that implements the behavior of the methods defined in your interface.
A client (in my interpretation), would be yet another piece in your system, that interacts with your Interface through the implementation that you’ll write.
Addressing your question:
First step would be figuring out how you’ll persist the data introduced through put and putAll. If you just want to keep some stuff in memory, then a Map will probably suffice. If the number of entries is expected to grow alot, then you probably want to make the implementation interact with a database (or other form of persistence).
Does this add some light on your question? Add some more details, and I’ll give more insight if I can.
Hope it helps.
Edit:
A distributed storage system has quite a few variables brought to the table.
Do you have a centralized endpoint that then chooses where the data will be stored in some way (round-robin or some more complex algorithm)?
How will the clients interact with your system? Is it a web-based system, RMI, something else?
I think you need to focus on the basic architecture before thinking of the actual implementation, since the main problems with a system like this is robustness and handling flaws.
One possibility is having a “name server” that knows where the data is stored (basically it has the mapping of keys to “storage servers”), and several other servers where the data is actually persisted. You need to choose how these will communicate between them, or if each server will be both a “name server” AND a “storage server”… there’s really a lot of possibilities here!