Exemplo n.º 1
0
    public void run() {
      try {
        out = new PrintWriter(this.socket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));

        while (true) {
          synchronized (this) {
            out.println(HEARTBEAT);
          }
          reallySleep(NORMAL_HEARTBEAT_INTERVAL);
        }
      } catch (SocketException e) {
        log("Socket Exception: client may have already shutdown.");
        log(e.getClass() + ": " + Arrays.asList(e.getStackTrace()));
      } catch (Exception e) {
        log("Heartbeat thread for child process (port " + port + ") got exception");
        log(e.getClass() + ": " + Arrays.asList(e.getStackTrace()));
      } finally {
        log("Heartbeat thread for child process (port " + port + ") terminating.");
        try {
          socket.close();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    }
Exemplo n.º 2
0
  @Override
  public void upload(UploadRequest uploadRequest) {
    ServerInfo serverInfo = uploadRequest.getServerInfo();
    String host = serverInfo.getHost();

    if (uploadRequest.isUseProxy()) {
      initializeProxy(host);
    }
    int attemptCount = 0;
    while (true) {
      try {

        login(serverInfo.getHost(), serverInfo.getLogin(), serverInfo.getPassword());

        try {
          ftpClient.setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
        } catch (SocketException e) {
          LOGGER.error("socket exception: {} {}", e.getMessage(), e.getStackTrace());

          throw new RuntimeException("socket exception: " + e.getMessage());
        }

        String prefixDirectory = serverInfo.getPrefix();
        if (prefixDirectory != null) {
          ftpClient.changeWorkingDirectory(prefixDirectory);
        }

        File directory = new File(uploadRequest.getUploadDir());
        uploadDir(directory);

        ftpClient.logout();
        break;

      } catch (IOException e) {
        LOGGER.error("i/o error: {}, retrying", e.getMessage());

        attemptCount++;

        if (attemptCount > 5) {
          LOGGER.debug("choosing another proxy after 5 attempts");
          initializeProxy(host);

          attemptCount = 0;
        }
      } finally {
        if (ftpClient.isConnected()) {
          try {
            ftpClient.disconnect();
          } catch (IOException ioe) {
            // do nothing
          }
        }
      }
    }
  }