Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

reconnects in standalone api
 Post subject: reconnects in standalone api Post rating: 0   New post Posted: Thu 07 Mar, 2013, 13:36 

User rating: 0
Joined: Sat 02 Feb, 2013, 03:32
Posts: 5
Location: Switzerland,
Hi all,

Im the sample code there is a reconnection handling which does 3 light reconnects on a onDisconnect() event, if that fails
all it does is:

try {
    client.connect(JNLP_URL, JNLP_USERNAME, JNLP_PASSWORD);
} catch (final Exception e) {
    e.printStackTrace();
}


If I get an Exception while client.connect(...), this ends up in an unconnected client.
I decided to implement the following onDisconnect(..):

         @Override
         public void onDisconnect() {
            LOGGER.warn("Disconnected");
            if (lightReconnects > 0) {
               client.reconnect();
               --lightReconnects;
            } else {
               while (!client.isConnected()) {
                                                LOGGER.warn("reconnecting in 3 sec...");
                  try {
                     Thread.sleep(3000);
                  } catch (InterruptedException e) {
                     e.printStackTrace();
                  }
                  try {
                     client.connect(jnlpUrl, userName, password);
                  } catch (JFAuthenticationException e) {
                     LOGGER.error("JFAuthenticationException",
                           e.getMessage());
                  } catch (JFVersionException e) {
                     LOGGER.error("JFVersionException", e.getMessage());
                  } catch (Exception e) {
                     LOGGER.error("Exception", e.getMessage());
                  }
               }
            }
         }


1. Do I need to resubscribe the instruments or set the client.setSystemListener(new ISystemListener() again after a full reconnect?
2. Since I reuse the same "client" instance, I would say not. But that would mean I can subscribe instruments on the client while I'm offline (before I connect) - is that correct?

Regards,
Chris


 
 Post subject: Re: reconnects in standalone api Post rating: 0   New post Posted: Mon 11 Mar, 2013, 09:25 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You don't need to resubscribe the instruments on reconnect, you can check that this is the case by launching the following program (let some ticks to be printed) and pulling the internet cable plug:
Attachment:
MainReconnect.java [5.61 KiB]
Downloaded 333 times


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com