last day (30 days later) » 

8:45 PM
@SylvainBoisse Thanks for your detailed code review. I'd like to make some point to clear few things as looks like maybe you misunderstood few things which I was not trying to show (or maybe I am wrong on this, but let's see).
I could have asked everything there in the question itself but it will make comments very big and long which won't look good so apologize for creating a new chat room for this.
I have a messaging queue on which we are sending data using socket from this program. We have 3 datacenters and each datacenter has 5 machines and each machine has 4 available sockets on which we can send the data. So each datacenter has 20 sockets on which we can send data, total making it to 60 sockets for three datacenters.
And that's why I have a constant define as Utils.Servers which has a mapping of which DC has what sockets but you raised a good point, we can instead represent that with Enum. So now if we are sending data from DC1, then we should try to send data to either of 20 sockets of my messaging queue in DC1 first and if they are not available then try other DC's (and that's what my code does from Datacenters.getOrderedDatacenters() as you noticed). Let me know if you have any confusion on this part.
Now since you know I have around 60 sockets available so I need to know whether they are live or dead and that I can only figure out by pinging each available socket(make a note here, pinging each available socket which is all 60 sockets) and that I am doing from updateLiveSockets method. That method, pings all available socket one by one sequentially (maybe we can do parallel not sure on this yet, or it won't be a good idea I think now) by calling
synchronous method (send method) of SendToQueue class and figures out whether they are live or dead and basis on that we put their status (isLive) in SocketHolder class so that was not the mistake which you thought of, I was deliberately putting all the socket in liveUpdatedSockets list. And then when all the business threads were calling getLiveSocket method to get the next live available socket,
at that time I return only those socket to business threads which are live by doing that if check. And then business thread will send business message on that live socket. Let me know if anything is unclear on this.
Now I can only know whether socket is live or dead only basis on acknowledgment received from the messaging queue. So when I call send method to send ping message then that method will send data and wait for acknowledgment to receive and if acknowledgment is not received then it returns false otherwise it returns true and basis on that I mark that socket live or dead in updateLiveSockets method.
I have another question on this which shows full code of my SendToQueue class where I have explained on how I am sending data and that will give you better idea.
2
Q: Send records and retry them if acknowledgement is not received

davidI am using below class to send data to our messaging queue by using socket either in a synchronous way or asynchronous way as shown below. It depends on requirement whether I want to call synchronous or asynchronous method to send data on a socket. Most of the times we will send data through aysn...

And since you know that I don't want to share same socket between two threads (Business thread and pinger thread) at all so thats why I was using synchronization on a socket but as you noticed it can cause deadlock and slow things down and that's what we are noticing in production that data is arriving little bit late and that's why I want to get rid of this synchronization and completely avoid deadlock.
I saw your algorithm but I am still unclear on how that will work with PriorityBlockingQueue. I have never worked with that so wanted to see if you can provide an example on that basis on my code to make things clear for me.
 

  last day (30 days later) »