Ejemplo 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");
    }
  }
Ejemplo n.º 2
0
  public static void connect() {
    try {
      serverPortal = connection.connect();

    } catch (RemoteException | NotBoundException ex) {
      reconnect(ex);
    }
  }
Ejemplo 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);
       }
     }
   }
 }
Ejemplo n.º 4
0
 private static void init() {
   connection = ClientConnection.getInstance();
   findActiveInterval = connection.getWaitTime();
   noInternetInterval = connection.getNoInternetInterval();
   syncInterval = connection.getRefreshInterval();
 }