Example usage for java.util.concurrent TimeUnit MILLISECONDS

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

Introduction

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

Prototype

TimeUnit MILLISECONDS

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

Click Source Link

Document

Time unit representing one thousandth of a second.

Usage

From source file:com.liferay.mobile.android.async.GroupServiceAsyncTest.java

@Test
public void getUserSites() throws Exception {
    Session session = new SessionImpl(this.session);

    final JSONArray[] sites = { null };
    final CountDownLatch lock = new CountDownLatch(1);

    session.setCallback(new JSONArrayCallback() {

        @Override//w ww  . j  a v  a  2 s.  c o  m
        public void onSuccess(JSONArray result) {
            try {
                sites[0] = result;
                lock.countDown();
            } catch (Exception e) {
                onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception exception) {
            fail(exception.getMessage());
            lock.countDown();
        }

    });

    GroupService service = new GroupService(session);
    service.getUserSitesGroups();

    lock.await(500, TimeUnit.MILLISECONDS);
    GroupServiceTest.assertUserSites(sites[0]);
}

From source file:net.openhft.chronicle.VanillaChronicleTestBase.java

protected void sleep(long timeout, TimeUnit unit) {
    sleep(TimeUnit.MILLISECONDS.convert(timeout, unit));
}

From source file:io.bosh.client.tasks.SpringTasks.java

@Override
public Observable<Task> trackToCompletion(String id) {
    return Observable.interval(TASK_TRACKING_POLL_INTERVAL, TimeUnit.MILLISECONDS, Schedulers.io())
            .flatMap(tick -> get(id)).skipWhile(task -> task.isInProgress()) // TODO consider condition for max tries/timeout
            .first();/* w  ww  .  j  av  a 2  s  . com*/
}

From source file:com.parallax.server.blocklyprop.monitoring.Monitor.java

private void init() {
    if (consoleEnabled) {
        ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
                .convertDurationsTo(TimeUnit.MILLISECONDS).build();
        reporter.start(consoleReportingInterval, TimeUnit.SECONDS);
    }/* ww  w  . ja va  2s .  c  o m*/

    if (graphiteEnabled) {
        final PickledGraphite pickledGraphite = new PickledGraphite(
                new InetSocketAddress(graphiteServerAddress, graphiteServerPort));
        final GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metrics)
                .prefixedWith(graphitePrefix).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL)
                .build(pickledGraphite);
        graphiteReporter.start(graphiteReportingInterval, TimeUnit.SECONDS);
    }

    InstrumentedAppender appender = new InstrumentedAppender(metrics);
    appender.activateOptions();

    LogManager.getRootLogger().addAppender(appender);

    MemoryUsageGaugeSet memoryUsageGaugeSet = new MemoryUsageGaugeSet();
    metrics.registerAll(memoryUsageGaugeSet);

    GarbageCollectorMetricSet garbageCollectorMetricSet = new GarbageCollectorMetricSet();
    metrics.registerAll(garbageCollectorMetricSet);
}

From source file:de.codecentric.batch.metrics.InfluxdbMetricsExporter.java

public InfluxdbMetricsExporter(MetricRegistry metricRegistry, final MetricReader metricReader, String server,
        Integer port, String dbName, String user, String password, String environment) throws Exception {
    Influxdb influxdb = new Influxdb(server, port, dbName, user, password);
    influxdb.debugJson = true;//  w  ww.  jav a  2s  .  co m
    MetricFilter filter = new MetricFilter() {
        @Override
        public boolean matches(String name, Metric metric) {
            org.springframework.boot.actuate.metrics.Metric<?> bootMetric = metricReader.findOne(name);
            if (bootMetric.getTimestamp().after(lastExport)) {
                return true;
            }
            return false;
        }
    };
    reporter = InfluxdbReporter.forRegistry(metricRegistry).prefixedWith(environment)
            .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(filter)
            .build(influxdb);
}

From source file:io.rhiot.component.gp2y1010au0f.Gp2y1010au0fConsumer.java

@Override
protected int poll() throws Exception {
    int iterations = 10;
    double sum = 0.0;

    for (int i = 0; i < iterations; i++) {
        getEndpoint().getIledPin().high();
        TimeUnit.MICROSECONDS.sleep(getEndpoint().getSamplingDelay());
        double adcValue = getEndpoint().getMcp3008GpioProvider().getValue(getEndpoint().getAnalogPin());
        getEndpoint().getIledPin().low();

        double voltage = (REF_VOLTAGE / 1023.0) * adcValue * 11;

        if (voltage > MIN_VOLTAGE) {
            sum += (voltage - MIN_VOLTAGE) * 0.2;
        }//from  w  w  w  .  j  av  a2s. co m

        TimeUnit.MILLISECONDS.sleep(50);
    }

    double average = sum / iterations;

    if (average > 0) {
        Exchange exchange = ExchangeBuilder.anExchange(getEndpoint().getCamelContext())
                .withBody(Precision.round(average, 2)).build();
        exchange.setFromEndpoint(getEndpoint());
        getProcessor().process(exchange);
        return 1;
    }

    return 0;
}

From source file:com.nebhale.gpxconverter.GoogleMapsAugmenter.java

@Override
public List<Point> augment(List<Point> points) {
    List<Future<List<Point>>> futures = new ArrayList<>();

    for (int i = 0, delay = 0; i < points.size(); i += CHUNK_SIZE, delay++) {
        int max = CHUNK_SIZE + i;
        List<Point> slice = points.subList(i, max < points.size() ? max : points.size());

        futures.add(this.scheduledExecutorService.schedule(
                new PointAugmenter(delay, this.encoder, this.restOperations, slice), delay * 10 * CHUNK_SIZE,
                TimeUnit.MILLISECONDS));
    }//w w  w. j av  a  2  s .  co  m

    List<Point> augmented = new ArrayList<>(points.size());
    for (Future<List<Point>> future : futures) {
        try {
            augmented.addAll(future.get());
        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    return augmented;
}

From source file:com.adaptris.core.lms.LargeFsConsumerTest.java

public void testConsumeWithAlternateFactory() throws Exception {
    String subDir = GUID.safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(false);/* w  ww  . ja  v  a2 s.c om*/
    fs.setMessageFactory(new DefaultMessageFactory());
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper
            .createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        baseDir.mkdirs();
        super.createFiles(baseDir, ".xml", count);
        start(sc);
        waitForMessages(stub, count);
        assertEquals(count, stub.getMessages().size());
        super.assertMessages(stub.getMessages(), count,
                baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
        assertDefaultMessageType(stub.getMessages());
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}

From source file:fi.jumi.launcher.remote.ProcessStartingDaemonSummoner.java

private static DaemonListener withInitialMessageTimeout(DaemonListener listener, long timeoutMillis) {
    return eventizer.newFrontend(new InitialMessageTimeout<>(eventizer.newBackend(listener),
            getTimeoutMessages(timeoutMillis), timeoutMillis, TimeUnit.MILLISECONDS));
}

From source file:ratpack.codahale.metrics.internal.WebSocketReporter.java

@Inject
public WebSocketReporter(MetricRegistry registry, MetricsBroadcaster metricsBroadcaster,
        LaunchConfig launchConfig) {//www. j  av a2  s  . c  o m
    super(registry, "websocket-reporter", MetricFilter.ALL, TimeUnit.SECONDS, TimeUnit.MILLISECONDS);
    this.metricsBroadcaster = metricsBroadcaster;
    String interval = launchConfig.getOther("metrics.scheduledreporter.interval", DEFAULT_INTERVAL);
    this.start(Long.valueOf(interval), TimeUnit.SECONDS);
}