Example usage for java.util.concurrent TimeUnit NANOSECONDS

List of usage examples for java.util.concurrent TimeUnit NANOSECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit NANOSECONDS.

Prototype

TimeUnit NANOSECONDS

To view the source code for java.util.concurrent TimeUnit NANOSECONDS.

Click Source Link

Document

Time unit representing one thousandth of a microsecond.

Usage

From source file:io.horizondb.model.core.fields.TimestampField.java

/**
 * {@inheritDoc}/*from  w  w  w.  ja va  2s.  c o  m*/
 */
@Override
public FieldType getType() {

    if (this.sourceUnit.equals(TimeUnit.NANOSECONDS)) {

        return FieldType.NANOSECONDS_TIMESTAMP;
    }

    if (this.sourceUnit.equals(TimeUnit.MICROSECONDS)) {

        return FieldType.MICROSECONDS_TIMESTAMP;
    }

    if (this.sourceUnit.equals(TimeUnit.MILLISECONDS)) {

        return FieldType.MILLISECONDS_TIMESTAMP;
    }

    return FieldType.SECONDS_TIMESTAMP;
}

From source file:com.ryantenney.metrics.spring.reporter.AbstractScheduledReporterFactoryBean.java

/**
 * Parses and converts to nanoseconds a string representing
 * a duration, ie: 500ms, 30s, 5m, 1h, etc
 * @param duration a string representing a duration
 * @return the duration in nanoseconds//from  w w w  .j  a  v  a2 s  .  co  m
 */
protected long convertDurationString(String duration) {
    final Matcher m = DURATION_STRING_PATTERN.matcher(duration);
    if (!m.matches()) {
        throw new IllegalArgumentException("Invalid duration string format");
    }

    final long sourceDuration = Long.parseLong(m.group(1));
    final String sourceUnitString = m.group(2);
    final TimeUnit sourceUnit;
    if ("ns".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.NANOSECONDS;
    } else if ("us".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.MICROSECONDS;
    } else if ("ms".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.MILLISECONDS;
    } else if ("s".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.SECONDS;
    } else if ("m".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.MINUTES;
    } else if ("h".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.HOURS;
    } else if ("d".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.DAYS;
    } else {
        sourceUnit = TimeUnit.MILLISECONDS;
    }

    return sourceUnit.toNanos(sourceDuration);
}

From source file:net.sf.sessionAnalysis.SessionVisitorArrivalAndCompletionRate.java

public SessionVisitorArrivalAndCompletionRate(final int resolutionValue, final TimeUnit resolutionTimeUnit) {
    this.resolutionValueOriginal = resolutionValue;
    this.resolutionTimeUnitOriginal = resolutionTimeUnit;
    this.resolutionValueNanos = TimeUnit.NANOSECONDS.convert(this.resolutionValueOriginal,
            this.resolutionTimeUnitOriginal);
}

From source file:CollectionTest.java

public long elapsedTime() {
    if (!stopped)
        throw new IllegalStateException("Timestamp not stopped");
    return ts.convert(stopTime - startTime, TimeUnit.NANOSECONDS);
}

From source file:at.alladin.rmbt.client.tools.impl.CpuStatCollector.java

public JSONObject getJsonResult(boolean clean) throws JSONException {
    return getJsonResult(clean, 0, TimeUnit.NANOSECONDS);
}

From source file:at.alladin.rmbt.client.tools.impl.MemInfoCollector.java

public JSONObject getJsonResult(boolean clean, long relTimeStamp, TimeUnit timeUnit) throws JSONException {
    final long relativeTimeStampNs = TimeUnit.NANOSECONDS.convert(relTimeStamp, timeUnit);
    final JSONArray jsonArray = new JSONArray();

    for (CollectorData<Map<String, Long>> data : collectorDataList) {
        final JSONObject dataJson = new JSONObject();
        dataJson.put("value", 100f
                - ((float) data.getValue().get("MemFree") / (float) data.getValue().get("MemTotal")) * 100f);
        dataJson.put("time_ns", data.getTimeStampNs() - relativeTimeStampNs);
        jsonArray.put(dataJson);/*  w  w w  .  ja  va 2s.c om*/
    }

    if (clean) {
        collectorDataList.clear();
    }

    final JSONObject jsonObject = new JSONObject();
    jsonObject.put("values", jsonArray);

    return jsonObject;
}

From source file:com.ryantenney.metrics.spring.reporter.LibratoReporterFactoryBean.java

@Override
protected LibratoReporter createInstance() {
    final String username = getProperty(USERNAME);
    final String token = getProperty(TOKEN);
    final String source = getProperty(SOURCE);

    final LibratoReporter.Builder reporter = LibratoReporter.builder(getMetricRegistry(), username, token,
            source);//from   w w w.java 2 s. c om

    if (hasProperty(TIMEOUT)) {
        reporter.setTimeout(convertDurationString(getProperty(TIMEOUT)), TimeUnit.NANOSECONDS);
    }

    if (hasProperty(NAME)) {
        reporter.setName(getProperty(NAME));
    }

    if (hasProperty(SANITIZER_REF)) {
        reporter.setSanitizer(getPropertyRef(SANITIZER_REF, Sanitizer.class));
    }

    if (hasProperty(EXPANSION_CONFIG)) {
        String configString = getProperty(EXPANSION_CONFIG).trim().toUpperCase(Locale.ENGLISH);
        final MetricExpansionConfig config;
        if ("ALL".equals(configString)) {
            config = MetricExpansionConfig.ALL;
        } else {
            Set<ExpandedMetric> set = new HashSet<ExpandedMetric>();
            String[] expandedMetricStrs = StringUtils.tokenizeToStringArray(configString, ",", true, true);
            for (String expandedMetricStr : expandedMetricStrs) {
                set.add(ExpandedMetric.valueOf(expandedMetricStr));
            }
            config = new MetricExpansionConfig(set);
        }
        reporter.setExpansionConfig(config);
    } else if (hasProperty(EXPANSION_CONFIG_REF)) {
        reporter.setExpansionConfig(getProperty(EXPANSION_CONFIG, MetricExpansionConfig.class));
    }

    if (hasProperty(HTTP_POSTER_REF)) {
        reporter.setHttpPoster(getPropertyRef(HTTP_POSTER_REF, HttpPoster.class));
    }

    if (hasProperty(PREFIX)) {
        reporter.setPrefix(getProperty(PREFIX));
    }

    if (hasProperty(PREFIX_DELIMITER)) {
        reporter.setPrefixDelimiter(getProperty(PREFIX_DELIMITER));
    }

    if (hasProperty(DURATION_UNIT)) {
        reporter.setDurationUnit(getProperty(DURATION_UNIT, TimeUnit.class));
    }

    if (hasProperty(RATE_UNIT)) {
        reporter.setRateUnit(getProperty(RATE_UNIT, TimeUnit.class));
    }

    if (hasProperty(CLOCK_REF)) {
        reporter.setClock(getPropertyRef(CLOCK_REF, Clock.class));
    }

    reporter.setFilter(getMetricFilter());

    return reporter.build();
}

From source file:rmblworx.tools.timey.SimpleTimerTest.java

/**
 * Test method for {@link SimpleTimer#startStopwatch(int, TimeUnit)}.
 *///w w w  .  j av  a2 s. c  o  m
@Test(expected = ValueMinimumArgumentException.class)
public final void testShouldFailBecauseDelayIsLessThanOne() {
    this.timer.startStopwatch(0, TimeUnit.NANOSECONDS);
}

From source file:org.wso2.carbon.metrics.reporter.JDBCReporterTest.java

@Before
public void setUp() throws Exception {
    when(clock.getTime()).thenReturn(19910191000L);

    this.reporter = JDBCReporter.forRegistry(registry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.NANOSECONDS).withClock(clock).filter(MetricFilter.ALL)
            .build(SOURCE, dataSource);//from w  ww . j  ava 2s  .  c  o  m

    template.execute("DELETE FROM METRIC_GAUGE;");
    template.execute("DELETE FROM METRIC_TIMER;");
    template.execute("DELETE FROM METRIC_METER;");
    template.execute("DELETE FROM METRIC_HISTOGRAM;");
    template.execute("DELETE FROM METRIC_COUNTER;");
}

From source file:org.apache.metamodel.jdbc.integrationtests.SQLServerJtdsDriverTest.java

public void testTimestampValueInsertSelect() throws Exception {
    if (!isConfigured()) {
        return;//from  w  ww .  ja  v  a2s  .  c  o  m
    }

    final Connection connection = getConnection();
    JdbcTestTemplates.timestampValueInsertSelect(connection, TimeUnit.NANOSECONDS, "datetime");
}