Esempio n. 1
0
  private static void startSync() {
    RemoteException rex;
    Properties serverList = null;
    if (serverPortal != null) {
      while (true) {
        try {
          System.out.println(serverPortal.hello());
          serverList = serverPortal.getServerList();
          try {
            PropertyHandler.save(SERVER_LIST_FILE, serverList);
            ClientConnection.getInstance().reload();
          } catch (Exception ex) {
            System.out.println("server list save failed");
          }
          sync.setServerPortal(serverPortal);
          sync.start();
          wait(syncInterval);
        } catch (RemoteException ex) {
          rex = ex;

          break;
        }
      }
      System.out.println("Disconnected, trying to reconnect...");
      reconnect(rex);
      startSync();

    } else {
      System.out.println("No ative server");
    }
  }
Esempio n. 2
0
  public static void connect() {
    try {
      serverPortal = connection.connect();

    } catch (RemoteException | NotBoundException ex) {
      reconnect(ex);
    }
  }
Esempio n. 3
0
 private static void reconnect(Exception ex) {
   if (ex.getCause() instanceof java.net.UnknownHostException) {
     System.out.println("no internet connection");
     wait(noInternetInterval);
     connect();
   } else {
     serverPortal = null;
     while (serverPortal == null) {
       serverPortal = connection.findActiveServer();
       if (serverPortal == null) {
         wait(findActiveInterval);
       }
     }
   }
 }
Esempio n. 4
0
 private static void init() {
   connection = ClientConnection.getInstance();
   findActiveInterval = connection.getWaitTime();
   noInternetInterval = connection.getNoInternetInterval();
   syncInterval = connection.getRefreshInterval();
 }