Java Code Examples for java.util.concurrent.TimeUnit.toSeconds()

The following are Jave code examples for showing how to use toSeconds() of the java.util.concurrent.TimeUnit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: outland   File: FeatureResourceReal.java   Source Code and License Vote up 6 votes
private FeatureCollection listFeaturesSinceInner(String nsKey, long timestamp,
    TimeUnit timeUnit) {
  try {
    long ts = timeUnit.toSeconds(timestamp);

    String url = UriBuilder.builder(baseUri)
        .path(PATH_FEATURES)
        .path(nsKey)
        .query(PARAM_SINCE, ts + "")
        .buildString();

    return toFeatureCollection(getRequest(nsKey, url).body().string());
  } catch (IOException e) {
    throw new FeatureException(Problem.localProblem(e.getMessage(), ""), e);
  }
}
 
Example 2
Project: HiTSDB-Client   File: HiTSDBClient.java   Source Code and License Vote up 6 votes
@Override
public void ttl(int lifetime, TimeUnit unit) {
	int seconds = (int) unit.toSeconds(lifetime);
	TTLValue ttlValue = new TTLValue(seconds);
	HttpResponse httpResponse = httpclient.post(HttpAPI.TTL, ttlValue.toJSON());
	ResultResponse resultResponse = ResultResponse.simplify(httpResponse, this.httpCompress);
	HttpStatus httpStatus = resultResponse.getHttpStatus();
	switch (httpStatus) {
	case ServerSuccess:
		return;
	case ServerNotSupport:
		throw new HttpServerNotSupportException(resultResponse);
	case ServerError:
		throw new HttpServerErrorException(resultResponse);
	default:
		throw new HttpUnknowStatusException(resultResponse);
	}
}
 
Example 3
Project: RottenFood   File: RottenFood.java   Source Code and License Vote up 6 votes
private static String formatTimeInterval(long time, String format){
	TimeUnit c = TimeUnit.MILLISECONDS;
	
	long S = c.toSeconds(time);
	long M = c.toMinutes(time);
	long H = c.toHours(time);
	long D = c.toDays(time);

	long s = c.toSeconds(time - TimeUnit.MINUTES.toMillis(M));
	long m = c.toMinutes(time - TimeUnit.HOURS.toMillis(H));
	long h = c.toHours(time - TimeUnit.DAYS.toMillis(D));
	
	String r = format;
	r = r.replace("%S", "" + S);
	r = r.replace("%M", "" + M);
	r = r.replace("%H", "" + H);
	r = r.replace("%D", "" + D);
	r = r.replace("%s", (s > 9 ? "" : "0") + s);
	r = r.replace("%m", (m > 9 ? "" : "0") + m);
	r = r.replace("%h", (h > 9 ? "" : "0") + h);
	
	return r;
}
 
Example 4
Project: athena   File: IntentEventsMetricsCommand.java   Source Code and License Vote up 6 votes
/**
 * Prints an Event Metric.
 *
 * @param operationStr the string with the intent operation to print
 * @param eventMetric the Event Metric to print
 */
private void printEventMetric(String operationStr,
                              EventMetric eventMetric) {
    Gauge<Long> gauge = eventMetric.lastEventTimestampGauge();
    Meter meter = eventMetric.eventRateMeter();
    TimeUnit rateUnit = TimeUnit.SECONDS;
    double rateFactor = rateUnit.toSeconds(1);

    // Print the Gauge
    print(FORMAT_GAUGE, operationStr, gauge.getValue());

    // Print the Meter
    print(FORMAT_METER, operationStr, meter.getCount(),
          meter.getMeanRate() * rateFactor,
          meter.getOneMinuteRate() * rateFactor,
          meter.getFiveMinuteRate() * rateFactor,
          meter.getFifteenMinuteRate() * rateFactor);
}
 
Example 5
Project: athena   File: TopologyEventsMetricsCommand.java   Source Code and License Vote up 6 votes
/**
 * Prints an Event Metric.
 *
 * @param operationStr the string with the intent operation to print
 * @param eventMetric the Event Metric to print
 */
private void printEventMetric(String operationStr,
                              EventMetric eventMetric) {
    Gauge<Long> gauge = eventMetric.lastEventTimestampGauge();
    Meter meter = eventMetric.eventRateMeter();
    TimeUnit rateUnit = TimeUnit.SECONDS;
    double rateFactor = rateUnit.toSeconds(1);

    // Print the Gauge
    print(FORMAT_GAUGE, operationStr, gauge.getValue());

    // Print the Meter
    print(FORMAT_METER, operationStr, meter.getCount(),
          meter.getMeanRate() * rateFactor,
          meter.getOneMinuteRate() * rateFactor,
          meter.getFiveMinuteRate() * rateFactor,
          meter.getFifteenMinuteRate() * rateFactor);
}
 
Example 6
Project: yadaframework   File: YadaUtil.java   Source Code and License Vote up 6 votes
/**
 * Convert from an amount of time to a string in the format xxd:hh:mm:ss
 * @param amount interval that needs to be formatted
 * @param timeUnit the unit of the interval
 * @return a formatted string representing the input interval
 */
public static String formatTimeInterval(long amount, TimeUnit timeUnit) {
	long totSeconds = timeUnit.toSeconds(amount);
	long seconds = totSeconds % 60;
	long totMinutes = timeUnit.toMinutes(amount);
	long minutes = totMinutes % 60;
	long totHours = timeUnit.toHours(amount);
	long hours = totHours % 24;
	long days = timeUnit.toDays(amount);
	String result = String.format("%02d:%02d", minutes, seconds);
	if (hours+days>0) {
		result = String.format("%02d:", hours) + result;
		if (days>0) {
			result = String.format("%dd:", days) + result;
		}
	}
	return result;
}
 
Example 7
Project: sstable-adaptor   File: CassandraMetricsRegistry.java   Source Code and License Vote up 5 votes
private JmxMeter(Metered metric, ObjectName objectName, TimeUnit rateUnit)
{
    super(objectName);
    this.metric = metric;
    this.rateFactor = rateUnit.toSeconds(1);
    this.rateUnit = "events/" + calculateRateUnit(rateUnit);
}
 
Example 8
Project: JRediClients   File: RedissonQueue.java   Source Code and License Vote up 5 votes
protected long toSeconds(long timeout, TimeUnit unit) {
    long seconds = unit.toSeconds(timeout);
    if (timeout != 0 && seconds == 0) {
        seconds = 1;
    }
    return seconds;
}
 
Example 9
Project: dropwizard-influxdb-reporter   File: DropwizardTransformer.java   Source Code and License Vote up 5 votes
public DropwizardTransformer(final Map<String, String> baseTags,
                             final DropwizardMeasurementParser parser,
                             final boolean groupCounters,
                             final boolean groupGauges,
                             final TimeUnit rateUnit,
                             final TimeUnit durationUnit) {
  this.baseTags = baseTags;
  this.parser = parser;
  this.groupCounters = groupCounters;
  this.groupGauges = groupGauges;
  this.rateFactor = rateUnit.toSeconds(1);
  this.durationFactor = durationUnit.toNanos(1);
}
 
Example 10
Project: Blizcord   File: Utils.java   Source Code and License Vote up 5 votes
public static String durationToTimeString(long duration) {
	TimeUnit scale = TimeUnit.MILLISECONDS;
	long days = scale.toDays(duration);
	duration -= TimeUnit.DAYS.toMillis(days);
	long hours = scale.toHours(duration);
	duration -= TimeUnit.HOURS.toMillis(hours);
	long minutes = scale.toMinutes(duration);
	duration -= TimeUnit.MINUTES.toMillis(minutes);
	long seconds = scale.toSeconds(duration);
	return String.format("%d days, %d hours, %d minutes, %d seconds", days, hours, minutes, seconds);
}
 
Example 11
Project: oneops   File: MetricsElasticsearchModule.java   Source Code and License Vote up 5 votes
private TimerSerializer(TimeUnit rateUnit, TimeUnit durationUnit, String timestampFieldname) {
    super(JsonTimer.class);
    this.timestampFieldname = timestampFieldname;
    this.rateUnit = calculateRateUnit(rateUnit, "calls");
    this.rateFactor = rateUnit.toSeconds(1);
    this.durationUnit = durationUnit.toString().toLowerCase(Locale.US);
    this.durationFactor = 1.0 / durationUnit.toNanos(1);
}
 
Example 12
Project: EscapeLag   File: AzureAPI.java   Source Code and License Vote up 4 votes
public static long toTicks(TimeUnit unit, long duration) {
    return unit.toSeconds(duration) * 20;
}
 
Example 13
Project: RetrofitCache   File: RetrofitCache.java   Source Code and License Vote up 4 votes
public Long getCacheTime(String url){
    if (mUrlMap!=null){
        Long type = mUrlMap.get(url);
        if (type!=null){
            return type;
        }
    }
    for (Map serviceMethodCache:mVector) {

        for (Object entry:serviceMethodCache.keySet()){
            Object o = serviceMethodCache.get(entry);
            try {

                if (mUrlAragsMap.containsKey(url)){
                    Object[] args = (Object[]) mUrlAragsMap.get(url);
                    String reqUrl =  buildRequestUrl(o,args);
                    if (reqUrl.equals(url)){
                        Method m = (Method) entry;
                        Cache cache =  m.getAnnotation(Cache.class);
                        if (cache!=null){
                            TimeUnit timeUnit =  mDefaultTimeUnit;
                            if (cache.timeUnit() != TimeUnit.NANOSECONDS){
                                timeUnit = cache.timeUnit();
                            }
                            long t = mDefaultTime;
                            if (cache.time() != -1){
                                t = cache.time();
                            }
                            long tm =  timeUnit.toSeconds(t);
                            getUrlMap().put(url, tm);
                            return tm;
                        }else{
                            getUrlMap().put(url, 0L);
                            return 0L;
                        }
                    }
                }
            } catch (Exception e) {
                LogUtil.l(e);
            }
        }
    }
    getUrlMap().put(url, 0L);
    return 0L;
}
 
Example 14
Project: RetrofitCache   File: RetrofitCache.java   Source Code and License Vote up 4 votes
public Long getCacheTime(String url){
    if (mUrlMap!=null){
        Long type = mUrlMap.get(url);
        if (type!=null){
            return type;
        }
    }
    for (Map serviceMethodCache:mVector) {

        for (Object entry:serviceMethodCache.keySet()){
            Object o = serviceMethodCache.get(entry);
            try {

                if (mUrlAragsMap.containsKey(url)){
                    Object[] args = (Object[]) mUrlAragsMap.get(url);
                    String reqUrl =  buildRequestUrl(o,args);
                    if (reqUrl.equals(url)){
                        Method m = (Method) entry;
                        Cache cache =  m.getAnnotation(Cache.class);
                        if (cache!=null){
                            TimeUnit timeUnit =  mDefaultTimeUnit;
                            if (cache.timeUnit() != TimeUnit.NANOSECONDS){
                                timeUnit = cache.timeUnit();
                            }
                            long t = mDefaultTime;
                            if (cache.time() != -1){
                                t = cache.time();
                            }
                            long tm =  timeUnit.toSeconds(t);
                            getUrlMap().put(url, tm);
                            return tm;
                        }else{
                            getUrlMap().put(url, 0L);
                            return 0L;
                        }
                    }
                }
            } catch (Exception e) {
                LogUtil.l(e);
            }
        }
    }
    getUrlMap().put(url, 0L);
    return 0L;
}
 
Example 15
Project: twitch4j   File: FollowersOnlyEvent.java   Source Code and License Vote up 4 votes
public FollowersOnlyEvent(Channel channel, long time, TimeUnit timeUnit) {
	super(channel, time > -1);
	this.time = timeUnit.toSeconds(time);
}
 
Example 16
Project: Banmanager   File: BanmanagerServer.java   Source Code and License Vote up 4 votes
private long toTicks(long amount, TimeUnit timeUnit) {
    return timeUnit.toSeconds(amount) / 20;
}
 
Example 17
Project: HiTSDB-Client   File: SubQuery.java   Source Code and License Vote up 4 votes
public Builder realtime(long time, TimeUnit unit) {
	this.realTimeSeconds = (int) unit.toSeconds(time);
	return this;
}
 
Example 18
Project: oneops   File: MetricsElasticsearchModule.java   Source Code and License Vote up 4 votes
public MeterSerializer(TimeUnit rateUnit, String timestampFieldname) {
    super(JsonMeter.class);
    this.timestampFieldname = timestampFieldname;
    this.rateFactor = rateUnit.toSeconds(1);
    this.rateUnit = calculateRateUnit(rateUnit, "events");
}
 
Example 19
Project: Recreator   File: AzureAPI.java   Source Code and License Vote up 4 votes
public static long toTicks(TimeUnit unit, long duration) {
    return unit.toSeconds(duration) * 20;
}
 
Example 20
Project: dlface   File: PlugUtils.java   Source Code and License Vote up 2 votes
/**
 * Returns time value in seconds between two other strings. White space around the number is trimmed.
 *
 * @param content      searched content
 * @param stringBefore string before searched string, character '\n' is replaced with regexp \\s*
 * @param stringAfter  string after searched string, character '\n' is replaced with regexp \\s*
 * @param srcTimeUnit  source time unit
 * @return time value in seconds
 * @throws PluginImplementationException No wait time value between stringBefore and stringAfter
 */
public static int getWaitTimeBetween(String content, String stringBefore, String stringAfter, TimeUnit srcTimeUnit) throws PluginImplementationException {
    final int i = getNumberBetween(content, stringBefore, stringAfter);
    return (int) srcTimeUnit.toSeconds(i);
}