• Post Reply Bookmark Topic Watch Topic
  • New Topic

Handling Server Failovers

 
abhishek roy
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
How to write server failover code. My environment is I have a simple java program that needs to communicate with the server. The current Scenario is , I can communicate with a server object but now they have made the server clustered. So now the same application resides in 4 Servers.

So I need to test that if server 1 is down then i shall retry with the remaining servers.

I have written a piece of code which i want to include:




And the Server objects code is as :


Just to mention . the server object is actually a simulation of failover. I make 3 server objects for the 3 servers and knowingly make it fail to raise IOException.
But I feel this code really smells. Can anybody suggest a better approach than this??
regards,
Abhishek
[ August 01, 2006: Message edited by: abhishek goswamy ]
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly are you trying to test?

My environment is I have a simple java program that needs to communicate with the server. The current Scenario is , I can communicate with a server object but now they have made the server clustered. So I need to test that if server 1 is down then i shall retry with the remaining servers


The basic idea behind clustering the server is to hide the fact that a server has gone down from the client and direct the client request to the other server. The client will not have to have any knowledge of this.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clustering usually provides a load balancing mechanism to send client requests across multiple servers. If one server stops responding the load balancer takes it out of rotation and forwards requests to the remaining servers. Does that sound like your environment - all the servers are up and accepting requests at the same time? If so, I'd expect something in the cluster to do the hard work for you.

An alternative is an active server and a standby. Most of the time the standby is not accepting requests. But if the active server fails the standby can take over. This may have a number of moving parts: something to decide the primary is really most sincerely dead, something to notify the standby to become active, something to switch clients over. I've worked with setups like this and it's tricky to know when the primary is dead and not just suffering a momentary network burp. It's also tricky to switch things back around when the primary is restarted. Some products like DB2 do this very nicely in spite of the complexity.
 
abhishek roy
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically I am trying to say is that:
1. My server is a legacy application which doesnt do load balancing or switch over.
2. Hence I would require my java program to communicate with the server objects.
3. I want to write a piece of code that will contact first server, if it fails it raises the java.io.IOException object. If such thing happens then I have to again send the message to the 2 nd server and so on for all the 4 servers.

I am also including the JUNIT test which I did:



Now the problem is I am writing business logic inside catch block. Is this OK??
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!