Example usage for org.joda.time Duration getMillis

List of usage examples for org.joda.time Duration getMillis

Introduction

In this page you can find the example usage for org.joda.time Duration getMillis.

Prototype

public long getMillis() 

Source Link

Document

Gets the length of this duration in milliseconds.

Usage

From source file:com.metamx.druid.merger.coordinator.scaling.SimpleResourceManagementStrategy.java

License:Open Source License

@Override
public boolean doTerminate(Collection<TaskRunnerWorkItem> pendingTasks, Collection<ZkWorker> zkWorkers) {
    Set<String> workerNodeIds = Sets.newHashSet(autoScalingStrategy
            .ipToIdLookup(Lists.newArrayList(Iterables.transform(zkWorkers, new Function<ZkWorker, String>() {
                @Override//w w  w. jav a 2  s.  com
                public String apply(ZkWorker input) {
                    return input.getWorker().getIp();
                }
            }))));

    Set<String> stillExisting = Sets.newHashSet();
    for (String s : currentlyTerminating) {
        if (workerNodeIds.contains(s)) {
            stillExisting.add(s);
        }
    }
    currentlyTerminating.clear();
    currentlyTerminating.addAll(stillExisting);
    boolean nothingTerminating = currentlyTerminating.isEmpty();

    if (nothingTerminating) {
        final int minNumWorkers = workerSetupdDataRef.get().getMinNumWorkers();
        if (zkWorkers.size() <= minNumWorkers) {
            log.info("Only [%d <= %d] nodes in the cluster, not terminating anything.", zkWorkers.size(),
                    minNumWorkers);
            return false;
        }

        List<ZkWorker> thoseLazyWorkers = Lists
                .newArrayList(FunctionalIterable.create(zkWorkers).filter(new Predicate<ZkWorker>() {
                    @Override
                    public boolean apply(ZkWorker input) {
                        return input.getRunningTasks().isEmpty() && System.currentTimeMillis()
                                - input.getLastCompletedTaskTime().getMillis() >= config
                                        .getMaxWorkerIdleTimeMillisBeforeDeletion();
                    }
                }));

        int maxPossibleNodesTerminated = zkWorkers.size() - minNumWorkers;
        int numNodesToTerminate = Math.min(maxPossibleNodesTerminated, thoseLazyWorkers.size());
        if (numNodesToTerminate <= 0) {
            log.info("Found no nodes to terminate.");
            return false;
        }

        AutoScalingData terminated = autoScalingStrategy.terminate(Lists
                .transform(thoseLazyWorkers.subList(0, numNodesToTerminate), new Function<ZkWorker, String>() {
                    @Override
                    public String apply(ZkWorker input) {
                        return input.getWorker().getIp();
                    }
                }));

        if (terminated != null) {
            currentlyTerminating.addAll(terminated.getNodeIds());
            lastTerminateTime = new DateTime();
            scalingStats.addTerminateEvent(terminated);

            return true;
        }
    } else {
        Duration durSinceLastTerminate = new Duration(lastTerminateTime, new DateTime());

        log.info("%s still terminating. Wait for all nodes to terminate before trying again.",
                currentlyTerminating);

        if (durSinceLastTerminate.isLongerThan(config.getMaxScalingDuration())) {
            log.makeAlert("Worker node termination taking too long!")
                    .addData("millisSinceLastTerminate", durSinceLastTerminate.getMillis())
                    .addData("terminatingCount", currentlyTerminating.size()).emit();

            currentlyTerminating.clear();
        }
    }

    return false;
}

From source file:com.metamx.http.client.NettyHttpClient.java

License:Apache License

private NettyHttpClient(ResourcePool<String, ChannelFuture> pool, Duration defaultReadTimeout, Timer timer) {
    this.pool = Preconditions.checkNotNull(pool, "pool");
    this.defaultReadTimeout = defaultReadTimeout;
    this.timer = timer;

    if (defaultReadTimeout != null && defaultReadTimeout.getMillis() > 0) {
        Preconditions.checkNotNull(timer, "timer");
    }//from   w  ww  . ja v a  2 s  .  c  o  m
}

From source file:com.metamx.http.client.NettyHttpClient.java

License:Apache License

private long getReadTimeout(Duration requestReadTimeout) {
    final long timeout;
    if (requestReadTimeout != null) {
        timeout = requestReadTimeout.getMillis();
    } else if (defaultReadTimeout != null) {
        timeout = defaultReadTimeout.getMillis();
    } else {// w  w w.  j a va2s  . c om
        timeout = 0;
    }

    if (timeout > 0 && timer == null) {
        log.warn("Cannot time out requests without a timer! Disabling timeout for this request.");
        return 0;
    } else {
        return timeout;
    }
}

From source file:com.microsoft.azure.management.graphrbac.implementation.CertificateCredentialImpl.java

License:Open Source License

@Override
public CertificateCredentialImpl<T> withDuration(Duration duration) {
    inner().withEndDate(startDate().plus(duration.getMillis()));
    return this;
}

From source file:com.microsoft.azure.management.graphrbac.implementation.PasswordCredentialImpl.java

License:Open Source License

@Override
public PasswordCredentialImpl<T> withDuration(Duration duration) {
    inner().withEndDate(startDate().plus(duration.getMillis()));
    return this;
}

From source file:com.moss.joda.time.xml.DurationAdapter.java

License:Open Source License

@Override
public Long marshal(Duration duration) throws Exception {
    if (duration == null)
        return null;
    else//  w w w .  j  av  a  2 s .  c  o m
        return duration.getMillis();
}

From source file:com.nesscomputing.cache.PrefixedCache.java

License:Apache License

public PrefixedCache(final NessCache nessCache, final String namespace, final Duration expiration,
        final Duration jitter, final Function<Pair<P, K>, String> keySerializer,
        final Function<? super V, byte[]> valueSerializer,
        final Function<byte[], ? extends V> valueDeserializer) {
    Preconditions.checkNotNull(namespace, "the namespace must not be null!");
    this.nessCache = nessCache;
    this.namespace = namespace;
    this.expiration = expiration;

    if (expiration != null) {
        Preconditions.checkNotNull(jitter, "the jitter value must not be null!");
        this.jitter = jitter.getMillis();
    } else {// w w  w  .  ja v  a 2 s.  c  o m
        this.jitter = 0;
    }

    this.keySerializer = keySerializer;
    this.valueSerializer = valueSerializer;
    this.valueDeserializer = valueDeserializer;
}

From source file:com.ninja_squad.core.time.JodaClocks.java

License:Open Source License

/**
 * Returns an instance of a clock, that returns the current time with the given offset added.
 * @param offset the offset that is added to the actual current time
 * @return a clock that returns the current time + the offset
 *//*from w w  w . j  a  v a2 s.c om*/
public static JodaClock startingIn(@Nonnull Duration offset) {
    Preconditions.checkNotNull(offset, "offset may not be null");
    return new FakeOffsetJodaClock(offset.getMillis());
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraTestTools.java

License:Open Source License

static void waitTillServiceIsUp(String host, int port, Duration timeout) {
    try {//from   w  w  w.j ava  2s. c  o  m
        Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS)
                .atMost(timeout.getMillis(), TimeUnit.MILLISECONDS).until(isPortListening(host, port));
    } catch (ConditionTimeoutException e) {
        throw new IllegalStateException("Timeout for port " + port + " on host " + host + ".");
    }
}

From source file:com.peertopark.java.dates.Intervals.java

License:Apache License

public static Collection<Interval> split(Interval interval, Duration duration) {
    ArrayList<Interval> intervals = new ArrayList<Interval>();
    long startMillis = interval.getStartMillis();
    long endMillis = interval.getEndMillis();
    long chunks = interval.toDurationMillis() / duration.getMillis();
    for (int i = 0; i < chunks; i++) {
        long temporalEndMillis = startMillis + duration.getMillis();
        intervals.add(getInterval(startMillis, temporalEndMillis));
        startMillis = temporalEndMillis;
    }/*from w  w w .j av a  2  s .c om*/
    if (startMillis < endMillis) {
        intervals.add(getInterval(startMillis, endMillis));
    }
    return intervals;
}