Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 03-08-2007
acbell acbell is offline
Registered User
 
Name: Andrew Bell
Organization: Iowa State University
Project: National Resources Inventory
 
Join Date: Jan 2005
Location: Ames, IA, USA
Posts: 89
Bi-directional conn. reestablishment

Hi,

I've got a client that makes a bi-directional connection with a server. I thought that I had found a way to detect when the server went down and have the client properly reestablish the connection. This seemed to fail the other day in production, though I have yet to get it to fail in test.

What I do on the client is have a thread that pings the server every so often. After the ping, I check to see if the adapter registered on the connection is NULL, if so, I reset the adapter and register the callback object with the server. Should this ALWAYS work? Any suggestions or thoughts appreciated.

Code:
  ScheduleVersionIFPrx ver;
  Ice::Identity ident;
  IceUtil::Monitor<IceUtil::Mutex>::Lock lock(m_connMonitor);

  Ice::ObjectAdapterPtr adapter = m_server->adapter();
  try {
    ident.name = IceUtil::generateUUID();
    adapter->add(m_listener, ident);
    m_scheduleServer->ice_connection()->setAdapter(adapter);
    m_scheduleServer->regTxListenerIdent(ident, m_listener->lastReceived());
//
// Do a ping every once in a while to test the state of the connection.  If the
// connection is the same as before, nothing happens.  If the connection was
// reestablished, set the adapter and register the listener.  If the connection
// can't be reestablished (server down), throw and exception and let everything
// start over.
//
    while (true) {
      m_scheduleServer->ice_ping();
      if (m_scheduleServer->ice_connection()->getAdapter() == 0) {
        m_scheduleServer->ice_connection()->setAdapter(adapter);
        m_scheduleServer->regTxListenerIdent(ident, m_listener->lastReceived());
      }
    }
  }
Reply With Quote
  #2 (permalink)  
Old 03-09-2007
benoit's Avatar
benoit benoit is online now
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,474
Hi,

You should add a call to sleep in your loop, otherwise you'll continuously ping the server. In any case, I can't think of any reasons why this wouldn't work. However without more information about the failure it's hard to say what could have gone wrong.

Cheers,
Benoit.
Reply With Quote
  #3 (permalink)  
Old 03-09-2007
acbell acbell is offline
Registered User
 
Name: Andrew Bell
Organization: Iowa State University
Project: National Resources Inventory
 
Join Date: Jan 2005
Location: Ames, IA, USA
Posts: 89
Thanks

There was a sleep in there. I must have removed it in haste when I posted the code. As long as this *should* work, I won't fret.

Thanks again,
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 04:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.