Package com.fathomdb

Examples of com.fathomdb.TimeSpan


    if (response instanceof HttpServletResponse) {
      String requestUri = ((HttpServletRequest) request).getRequestURI();

      HttpServletResponse httpServletResponse = (HttpServletResponse) response;

      TimeSpan cacheFor = null;

      if (requestUri.contains(".cache.")) {
        // Cache forever
        cacheFor = TimeSpan.ONE_DAY.multiplyBy(365);
      } else if (requestUri.contains(".nocache.")) {
        // Don't ever cache
        cacheFor = null;
      } else {
        // Micro cache
        cacheFor = TimeSpan.TEN_MINUTES;
      }

      if (cacheFor == null) {
        httpServletResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
        httpServletResponse.setHeader("Expires", "0");
      } else {
        long now = System.currentTimeMillis() / 1000L;
        long timeoutAt = now + cacheFor.getTotalSeconds();

        long deltaSeconds = timeoutAt - now;

        httpServletResponse.setHeader("Cache-Control", "max-age=" + deltaSeconds);
View Full Code Here


    return runnable;
  }

  private JobScheduleCalculator parseSchedule(JobSchedule schedule, boolean tolerant) {
    TimeSpan interval = null;
    Date base = null;

    if (schedule == null) {
      if (tolerant) {
        log.warn("Expected schedule; was null");
View Full Code Here

      if (cancelled) {
        log.debug("Task cancelled; won't schedule");
        return;
      }

      TimeSpan delay = TimeSpan.timeUntil(nextExecution);
      delay = TimeSpan.max(delay, MIN_DELAY);

      // We can't reissue tasks, so we have to create a new TimerTask every time
      // (as we want more complicated scheduling)
      TimerTask timerTask = new TimerTask() {
View Full Code Here

  @Override
  protected ProcessExecution executeCommandUnchecked(Command command) throws ProcessExecutionException {
    try {
      String commandString = command.buildCommandString();
      TimeSpan timeout = command.getTimeout();

      if (command.getKeyPair() != null) {
        SshConnection agentConnection = sshConnection.buildAgentConnection(command.getKeyPair());
        try {
          return agentConnection.sshExecute(commandString, timeout);
View Full Code Here

          synchronized (random) {
            fraction = random.nextDouble();
          }
        } while (fraction < MIN_RANDOM_FRACTION);

        TimeSpan delay = TimeSpan.fromMilliseconds((long) (fraction * previousInterval.getTotalMilliseconds()));
        return new Date(now + delay.getTotalMilliseconds());
      } else {
        return currentInterval.addTo(previousExecution.getStartTimestamp());
      }
    } else {
      // Based e.g. every morning at 2AM
View Full Code Here

    String remoteDir = remoteFile.substring(0, lastSlash);
    String filename = remoteFile.substring(lastSlash + 1);

    try {
      TimeSpan timeout = TimeSpan.FIVE_MINUTES;
      scp.put(fileData, dataLength, filename, remoteDir, mode, timeout, sudo);
    } catch (IOException ioException) {
      throw new SshException("Cannot doing scp on file", ioException);
    } catch (RuntimeSshException e) {
      throw new SshException("Error doing scp on file", e);
View Full Code Here

    MinaSshConnectionWrapper sshConnection = ensureConnected();

    MinaScpClient scp = new MinaScpClient(sshConnection);
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      TimeSpan timeout = TimeSpan.FIVE_MINUTES;
      scp.get(remoteFile, baos, timeout, sudo);
      return baos.toByteArray();
    } catch (IOException ioException) {
      throw new SshException("Cannot read file", ioException);
    } catch (SshException sshException) {
View Full Code Here

    return httpProxyEnvironment;
  }

  private String chooseProxy(OpsTarget target, List<String> proxies) {
    String bestProxy = null;
    TimeSpan bestTime = null;
    for (String proxy : proxies) {
      // {
      // // We choose the fastest proxy that gives us a 200 response
      // String url = proxy + "acng-report.html";
      // CurlRequest request = new CurlRequest(url);
      // request.setTimeout(5);
      // try {
      // CurlResult result = request.executeRequest(target);
      // if (result.getHttpResult() != 200) {
      // log.info("Unexpected response code while testing proxy: " + proxy + ".  Code=" + result.getHttpResult());
      // continue;
      // }
      // TimeSpan timeTotal = result.getTimeTotal();
      // if (bestTime == null || timeTotal.isLessThan(bestTime)) {
      // bestProxy = proxy;
      // bestTime = timeTotal;
      // }
      // } catch (ProcessExecutionException e) {
      // log.info("Error while testing proxy: " + proxy, e);
      // }
      // }

      {
        // We choose the fastest proxy that gives us a 200 response
        String url = "http://ftp.debian.org/debian/dists/stable/Release.gpg";
        CurlRequest request = new CurlRequest(url);
        request.proxy = proxy;
        request.timeout = TimeSpan.FIVE_SECONDS;
        try {
          CurlResult result = request.executeRequest(target);
          if (result.getHttpResult() != 200) {
            log.info("Unexpected response code while testing proxy: " + proxy + ".  Code="
                + result.getHttpResult());
            continue;
          }
          TimeSpan timeTotal = result.getTimeTotal();
          if (bestTime == null || timeTotal.isLessThan(bestTime)) {
            bestProxy = proxy;
            bestTime = timeTotal;
          }
        } catch (OpsException e) {
          log.info("Error while testing proxy: " + proxy, e);
View Full Code Here

        log.warn("Job finished with FAILED");

        // boolean isDone = false; // We will retry
        activeJob.setState(JobState.FAILED);

        TimeSpan retry = null;

        HasRetryInfo retryInfo = ExceptionHelpers.findRetryInfo(e);
        if (retryInfo != null) {
          retry = retryInfo.getRetry();
        }
View Full Code Here

      return map;
    }
  }

  public static ZookeeperResponse sendCommand(InetSocketAddress socketAddress, String command) throws IOException {
    TimeSpan connectionTimeout = TimeSpan.TEN_SECONDS;

    Socket s = new Socket();
    s.setTcpNoDelay(true);
    s.setSoTimeout((int) connectionTimeout.getTotalMilliseconds());

    s.connect(socketAddress);

    s.getOutputStream().write(command.getBytes());
    s.getOutputStream().flush();
View Full Code Here

TOP

Related Classes of com.fathomdb.TimeSpan

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.