Reputation: 316
I have a small-project which requires me to have a state knowledge of all the servers active in the project.
ANALOGY :- As soon as a pair leaves the table in hotels, the new ones are always ready to occupy those.
But, my case is somewhat different. I want to keep track of all the servers which are active. Say, if Server A, B , C, ... , Z are all active and are responding to a central server. Now, say, if C, P, X and Z have lost their power and are switched off, then my data-structure should store A,B,D,.,O,Q,...,W,Y. And, again if those threaded-servers area restored in alive state, then it'd be easy to put those servers in the way they are coming to life,i.e, they are being restored.
So, in which data-structure (Java) should I keep this record so that the insertion and removal of periodic-status is easy, and the complexity is as least as possible. Also, if a Library/class of Java(Oracle) is referred, it'd be most welcome and appreciated.
Upvotes: 1
Views: 79
Reputation: 21106
Why not just use an array, give every server a unique ID from 0 to count - 1
int NUM_OF_SERVERS = 32;
Server[] servers = new Server[NUM_OF_SERVERS];
...
// server alive
servers[aliveServer.Id] = aliveServer;
...
// server dead
servers[deadServer.Id] = null;
...
// modify server
servers[serverId].property = something;
Upvotes: 0