Example usage for java.util.concurrent TimeUnit SECONDS

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

Introduction

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

Prototype

TimeUnit SECONDS

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

Click Source Link

Document

Time unit representing one second.

Usage

From source file:com.ning.metrics.collector.util.Stats.java

private Stats(DescriptiveStatistics millisStats, DescriptiveStatistics sizeStats, WindowType windowType,
        int capacity, long period, TimeUnit unit) {
    this.millisStats = millisStats;
    this.sizeStats = sizeStats;
    if (windowType == WindowType.SAMPLE) {
        windowString = String.format("%d samples", capacity);
    } else {//from  ww w. j  av a  2  s . com
        windowString = String.format("%d second window", TimeUnit.SECONDS.convert(period, unit));
    }
}

From source file:com.evolveum.midpoint.selenium.BaseTest.java

@BeforeClass(alwaysRun = true)
public void beforeClass(ITestContext context) {
    siteUrl = context.getCurrentXmlTest().getParameter(PARAM_SITE_URL);

    int wait = getTimeoutParameter(context, PARAM_TIMEOUT_WAIT, 1);
    int page = getTimeoutParameter(context, PARAM_TIMEOUT_PAGE, 1);
    int script = getTimeoutParameter(context, PARAM_TIMEOUT_SCRIPT, 1);
    LOGGER.info("Site url: '{}'. Timeouts: implicit wait({}), page load ({}), script({})",
            new Object[] { siteUrl, wait, page, script });

    driver = new FirefoxDriver();
    WebDriver.Timeouts timeouts = driver.manage().timeouts();
    timeouts.implicitlyWait(wait, TimeUnit.SECONDS);
    timeouts.pageLoadTimeout(page, TimeUnit.SECONDS);
    timeouts.setScriptTimeout(script, TimeUnit.SECONDS);
}

From source file:com.netflix.curator.framework.recipes.barriers.TestDistributedBarrier.java

@Test
public void testServerCrash() throws Exception {
    final int TIMEOUT = 1000;

    final CuratorFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString())
            .connectionTimeoutMs(TIMEOUT).retryPolicy(new RetryOneTime(1)).build();
    try {/*from  w  ww .  ja  v a 2  s .c  om*/
        client.start();

        final DistributedBarrier barrier = new DistributedBarrier(client, "/barrier");
        barrier.setBarrier();

        final ExecutorService service = Executors.newSingleThreadExecutor();
        Future<Object> future = service.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                Thread.sleep(TIMEOUT / 2);
                server.stop();
                return null;
            }
        });

        barrier.waitOnBarrier(TIMEOUT * 2, TimeUnit.SECONDS);
        future.get();
        Assert.fail();
    } catch (KeeperException.ConnectionLossException expected) {
        // expected
    } finally {
        client.close();
    }
}

From source file:com.oneops.antenna.cache.SinkCache.java

/**
 * Initialize the cache/*from  w  ww  . j  a v a 2s . com*/
 */
@PostConstruct
public void init() {
    logger.info("***** Initializing the Sink Cache with timeout=" + TimeUnit.SECONDS.toHours(timeout)
            + " hour(s), maxSize=" + maxSize);
    cache = CacheBuilder.newBuilder().maximumSize(maxSize).expireAfterWrite(timeout, TimeUnit.SECONDS)
            .initialCapacity(15).recordStats().removalListener(removalListener).build(cacheLoader);
}

From source file:io.gatling.jsonbenchmark.bytes.MainJacksonObjectBenchmark.java

@GenerateMicroBenchmark
@OutputTimeUnit(TimeUnit.SECONDS)
public void menu(BlackHole bh) throws Exception {
    bh.consume(parse(MENU_BYTES));
}

From source file:org.jmangos.commons.threadpool.CommonThreadPoolManager.java

/**
 * @see org.jmangos.commons.service.Service#start()
 *//*  w w w.  j a  v a  2s . com*/
@PostConstruct
@Override
public void start() {

    final int scheduledPoolSize = ThreadPoolConfig.GENERAL_POOL;
    this.scheduledPool = new ScheduledThreadPoolExecutor(scheduledPoolSize);
    this.scheduledPool.prestartAllCoreThreads();

    final int instantPoolSize = ThreadPoolConfig.GENERAL_POOL;
    this.instantPool = new ThreadPoolExecutor(instantPoolSize, instantPoolSize, 0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(100000));
    this.instantPool.prestartAllCoreThreads();
}

From source file:io.mapzone.controller.vm.provisions.MaxProcesses.java

@Override
public Status execute() throws Exception {
    checked.set(this);
    assert process
            .isPresent() : "No process in context. Make sure that MaxProcesses executes after ProcessStarted.";

    HostRecord host = process.get().instance.get().host.get();
    if (host.statistics.get() == null || host.statistics.get().olderThan(10, TimeUnit.SECONDS)) {

        host.updateStatistics();//  w ww. j  a  v  a2 s. co  m

        // lowest start time (oldest) first
        LinkedList<ProcessRecord> sortedProcesses = host.instances.stream().filter(i -> i.process.get() != null)
                .map(i -> i.process.get()).sorted((p1, p2) -> p1.started.get().compareTo(p2.started.get()))
                .collect(Collectors.toCollection(LinkedList::new));
        log.info("    PROCESSES RUNNING: " + sortedProcesses.size() + " ("
                + host.statistics.get().lastChecked.get() + ")");

        // stop processes, oldest first
        while (sortedProcesses.size() > MAX_PROCESSES) {
            ProcessRecord p = sortedProcesses.remove(0);

            log.info("    stopping process: " + p.instance.get().project.get() + " -- started at "
                    + p.started.get());
            StopProcessOperation op = new StopProcessOperation();
            op.process.set(p);
            op.vmUow.set(vmUow());
            op.execute(null, null);
        }
    }

    return OK_STATUS;
}

From source file:backup.store.local.LocalBackupStore.java

@Override
public void backupBlock(ExtendedBlock extendedBlock, LengthInputStream data, LengthInputStream metaData)
        throws Exception {
    LOG.info("before sleep backupBlock {} dataLength {} metaDataLength", extendedBlock, data.getLength(),
            metaData.getLength());/*w w w .  ja v  a  2 s  . c o m*/
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    LOG.info("after sleep backupBlock {} dataLength {} metaDataLength", extendedBlock, data.getLength(),
            metaData.getLength());
    File dataFile = getDataFile(extendedBlock);
    File metaDataFile = getMetaDataFile(extendedBlock);
    try (FileOutputStream output = new FileOutputStream(dataFile)) {
        IOUtils.copy(data, output);
    }
    if (dataFile.length() != extendedBlock.getLength()) {
        throw new IOException("length of backup file " + dataFile.length() + " different than block "
                + extendedBlock.getLength());
    }
    try (FileOutputStream output = new FileOutputStream(metaDataFile)) {
        IOUtils.copy(metaData, output);
    }
}

From source file:com.pinterest.pinlater.client.PinLaterClient.java

public PinLaterClient(String host, int port, int concurrency) {
    this.service = ClientBuilder.safeBuild(ClientBuilder.get().hosts(new InetSocketAddress(host, port))
            .codec(ThriftClientFramedCodec.apply(Option.apply(new ClientId("pinlaterclient"))))
            .hostConnectionLimit(concurrency).tcpConnectTimeout(Duration.apply(2, TimeUnit.SECONDS))
            .requestTimeout(Duration.apply(10, TimeUnit.SECONDS)).retries(1));
    this.iface = new PinLater.ServiceToClient(service, new TBinaryProtocol.Factory());
}

From source file:com.netflix.curator.framework.recipes.leader.TestLeaderSelectorParticipants.java

@Test
public void testId() throws Exception {
    LeaderSelector selector = null;/*from  w w w . j  av a2  s.co m*/
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try {
        client.start();

        final CountDownLatch latch = new CountDownLatch(1);
        LeaderSelectorListener listener = new LeaderSelectorListener() {
            @Override
            public void takeLeadership(CuratorFramework client) throws Exception {
                latch.countDown();
                Thread.currentThread().join();
            }

            @Override
            public void stateChanged(CuratorFramework client, ConnectionState newState) {
            }
        };
        selector = new LeaderSelector(client, "/ls", listener);
        selector.setId("A is A");
        selector.start();

        Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));

        Participant leader = selector.getLeader();
        Assert.assertTrue(leader.isLeader());
        Assert.assertEquals(leader.getId(), "A is A");

        Collection<Participant> participants = selector.getParticipants();
        Assert.assertEquals(participants.size(), 1);
        Assert.assertEquals(participants.iterator().next().getId(), "A is A");
        Assert.assertEquals(participants.iterator().next().getId(), selector.getId());
    } finally {
        IOUtils.closeQuietly(selector);
        IOUtils.closeQuietly(client);
    }
}