Android using rabbitmq singleton connection -


text after "itemprop =" text ">

I create a RabbitMQ singleton connection that I can make that connection loss / internet provider will restart on a switch Design gossip is needed. My problem is that the connection has been felt on another thread (acyntc) due to the Android main thread policy. I use this connection for those two services which consume and push.

  Public class rabbishington connection {Public static RabbitSingletonConnection Example; Private connection connection; Personal RabbitSingletonConnection () {} public static RabbitSingletonConnection getInstance () {if (example == faucet) {Example = New RabbitSingletonConnection (); } Return Example; } Public Zero Connect (RabbitMQConnectionCallback Callback) {If (Connection = Null & amp;! Amp; connection.isOpen ()) {LogUtil.hecsLog ("RabbitSingletonConnection", "Already connected"); Callback.onConnect (connection); Return; } New rebate connective async (callback). Execute ("IP", "User", "Pass"); } Public Zero Set Connection (Connection Connection) {this.connection = connection; } Getting Public Connection () {Return Connection; }}  

The problem is that it is LogUtil.hecsLog ("RabbitSingletonConnection", "already connected"); never happens I have been digging and using something like "classloader announcement or enum approach threads safe singleton" is discovered, but this does not include a callback method.

Edit

  RabbitSingletonConnection.getInstance () .Connect (New RabbitMQConnectionCallback () {@Override Public Zero onConnect (Connection Results) {if (Results = Null & amp; ! & Amp; result.isOpen ()) {RabbitSingletonConnection.getInstance () setConnection (results) ;. LogUtil.hecsLog (log, "service is started");}}});  

This is an example but I can not make a connection in the constructor because it requires a thread to handle timeout exposure .

My goal is to add the RabbitMQ async function after starting the service.

Do I need dependency injection?

"itemprop =" text ">

I think I have understood it, I start / stop services on connectivity profit / loss was doing. I saw the Facebook app and never stopped the services, so the answer to the logic is to restore the workflow in the service, not to serve the service.


Comments