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:me.bramhaag.discordselfbot.commands.util.CommandTimer.java

@Command(name = "timer", minArgs = 1)
public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) {
    long delay;//  w  ww . j a  v  a 2 s  .com

    try {
        delay = Long.valueOf(args[0]);
    } catch (NumberFormatException e) {
        Util.sendError(message, e.toString());
        return;
    }

    message.editMessage(new EmbedBuilder().setTitle("Timer", null)
            .setDescription(
                    "Timer ending in " + DurationFormatUtils.formatDuration(delay * 1000, "H:mm:ss", true))
            .setFooter("Timer | " + Util.generateTimestamp(), null).setColor(Color.GREEN).build()).queue();

    channel.sendMessage(new EmbedBuilder().setTitle("Timer", null).setDescription("Timer expired!")
            .setFooter("Timer | " + Util.generateTimestamp(), null).setColor(Color.GREEN).build())
            .queueAfter(delay, TimeUnit.SECONDS);
}

From source file:com.pinterest.terrapin.storage.ReaderFactory.java

public ReaderFactory(PropertiesConfiguration configuration, FileSystem hadoopFs) {
    this.configuration = configuration;
    this.hadoopFs = hadoopFs;
    int numReaderThreads = this.configuration.getInt(Constants.READER_THREAD_POOL_SIZE, 200);
    ExecutorService threadPool = new ThreadPoolExecutor(numReaderThreads, numReaderThreads, 0, TimeUnit.SECONDS,
            new LinkedBlockingDeque<Runnable>(10000),
            new ThreadFactoryBuilder().setDaemon(false).setNameFormat("reader-pool-%d").build());
    this.readerFuturePool = new ExecutorServiceFuturePool(threadPool);
}

From source file:com.netflix.curator.framework.imps.TestTempFramework.java

@Test
public void testInactivity() throws Exception {
    final CuratorTempFrameworkImpl client = (CuratorTempFrameworkImpl) CuratorFrameworkFactory.builder()
            .connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1))
            .buildTemp(1, TimeUnit.SECONDS);
    try {/*from www  .j a va  2 s  . c o m*/
        ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
        Runnable command = new Runnable() {
            @Override
            public void run() {
                client.updateLastAccess();
            }
        };
        service.scheduleAtFixedRate(command, 10, 10, TimeUnit.MILLISECONDS);
        client.inTransaction().create().forPath("/foo", "data".getBytes()).and().commit();
        service.shutdownNow();
        Thread.sleep(2000);

        Assert.assertNull(client.getCleanup());
        Assert.assertNull(client.getClient());
    } finally {
        IOUtils.closeQuietly(client);
    }
}

From source file:com.appstarter.utils.WebUtils.java

public static String doHttpPost(String url, List<NameValuePair> params) throws AppStarterException {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "doHttpPost - url: " + debugRequest(url, params));
    }/*from   w  ww  .  j  av  a2 s. c o  m*/

    String ret = "";

    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout
    client.setReadTimeout(15, TimeUnit.SECONDS); // socket timeout

    FormEncodingBuilder builder = new FormEncodingBuilder();
    for (NameValuePair nvp : params) {
        builder.add(nvp.getName(), nvp.getValue());
    }
    RequestBody formBody = builder.build();

    try {
        Request request = new Request.Builder().url(new URL(url))
                //               .header("User-Agent", "OkHttp Headers.java")
                //               .addHeader("Accept", "application/json; q=0.5")
                .post(formBody).build();

        Response response = client.newCall(request).execute();
        if (!response.isSuccessful()) {
            String debugMessage = "doHttpPost - OkHttp.Response is not successful - " + response.message()
                    + " (" + response.code() + ")";
            throw new AppStarterException(AppStarterException.ERROR_SERVER, debugMessage);
        }
        ret = response.body().string();
    } catch (IOException e) {
        throw new AppStarterException(e, AppStarterException.ERROR_NETWORK_GET);
    }

    return ret;
}

From source file:com.sm.transport.netty.ServerSyncHandler.java

private void init() {
    BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
    threadPools = new ThreadPoolExecutor(maxThreads, maxThreads, 30, TimeUnit.SECONDS, queue);
}

From source file:com.boundary.sdk.event.service.db.ServiceDatabaseTest.java

@Test
public void testDatabase() throws InterruptedException {
    MockEndpoint endPoint = getMockEndpoint("mock:service-db-out");
    endPoint.setExpectedMessageCount(1);

    endPoint.await(60, TimeUnit.SECONDS);
    endPoint.assertIsSatisfied();//w  w w.jav a 2s .  com
}

From source file:costumetrade.common.http.HttpWorker.java

@Override
public void onReceive(Object msg) throws Exception {

    HttpMessage message = (HttpMessage) msg;
    try {/* w  w w .  ja  va2  s .  c o  m*/
        HttpResponse httpResponse = this.sendRequest(message);
        returnMessage(httpResponse);
    } catch (NoHttpResponseException | ConnectTimeoutException | SocketTimeoutException e) {
        if (message.needRetry()) {
            logger.info(",????,url:{}", message.getUrl());
            returnMessage(
                    new HttpResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, null, message.getCallbackData()));
            return;
        }
        message.retry();
        scheduler.scheduleOnce(Duration.create(message.getInterval(), TimeUnit.SECONDS), getSelf(), message,
                dispatcher, getSender());
    } catch (Exception e) {
        logger.error("", e);
        returnMessage(new HttpResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, null, message.getCallbackData()));
    }
}

From source file:com.espertech.esperio.db.core.ExecutorServices.java

public ExecutorServices(EPServiceProviderSPI spi, Map<String, Executor> workQueue) {
    this.services = new HashMap<String, ExecutorService>();

    for (Map.Entry<String, Executor> entry : workQueue.entrySet()) {
        Executor queue = entry.getValue();

        if (queue.getNumThreads() <= 0) {
            continue;
        }//www  . j  ava 2s  . co m

        LinkedBlockingQueue<Runnable> runnableQueue = new LinkedBlockingQueue<Runnable>();
        ExecutorService service = new ThreadPoolExecutor(queue.getNumThreads(), queue.getNumThreads(), 1000,
                TimeUnit.SECONDS, runnableQueue);
        services.put(entry.getKey(), service);
    }

    try {
        spi.getContext().bind("EsperIODBAdapter/ExecutorServices", this);
    } catch (NamingException e) {
        log.error("Error binding executor service: " + e.getMessage(), e);
    }
}

From source file:org.cloudfoundry.practical.demo.RootConfiguration.java

@Bean
public TimeoutProtectionStrategy timeoutProtectionStrategy() {
    ReplayingTimeoutProtectionStrategy strategy = new ReplayingTimeoutProtectionStrategy();
    strategy.setThreshold(TimeUnit.SECONDS.toMillis(12));
    strategy.setFailTimeout(TimeUnit.MINUTES.toMillis(4));
    return strategy;
}

From source file:siia.channels.StubEmailConfirmationService.java

public List<Email> getEmails() throws InterruptedException {
    countDownLatch.await(5, TimeUnit.SECONDS);
    return emails;
}