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.amd.poc.routes.WCFServiceRouteBuilderTest.java

@Test
public void testWCFHelloWorldService() throws InterruptedException {
    MockEndpoint resultMockEndpoint = getMockEndpoint("mock:result");
    resultMockEndpoint.expectedMessageCount(1);
    resultMockEndpoint.message(0).body().startsWith("Hello World");

    template.send("direct:helloworld", new Processor() {
        @Override/*w  w w. j a va  2s.  co m*/
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(new ArrayList());
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "HelloWorld");
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAMESPACE, "http://tempuri.org/");
        }
    });

    assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
}

From source file:com.example.dwr.ticketcenter.CallCenter.java

/**
 * Create a new publish thread and start it
 *///from  ww  w . j a va  2 s . co  m
public CallCenter() {
    // Start with some calls waiting
    addRandomKnownCall();
    addRandomUnknownCall();
    addRandomUnknownCall();
    addRandomUnknownCall();

    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory());
    //noinspection ThisEscapedInObjectConstruction
    executor.scheduleAtFixedRate(this, 2, 2, TimeUnit.SECONDS);
}

From source file:io.fabric8.msg.jnatsd.TestLoad.java

@Test
public void testLoad() throws Exception {
    EmbeddedConnection subConnection = new EmbeddedConnection(jNatsd);
    subConnection.start();//from   w  ww .j av  a2s.c o  m
    final int count = 1000;
    CountDownLatch countDownLatch = new CountDownLatch(count);
    subConnection.addSubscriber("foo", msg -> {
        countDownLatch.countDown();
    });

    EmbeddedConnection pubConnection = new EmbeddedConnection(jNatsd);
    pubConnection.start();

    long start = System.currentTimeMillis();

    for (int i = 0; i < count; i++) {
        String test = "Test" + i;
        pubConnection.publish("foo", "bah", test.getBytes());
    }

    countDownLatch.await(10, TimeUnit.SECONDS);
    Assert.assertEquals(0, countDownLatch.getCount());

    long finish = System.currentTimeMillis();

    long totalTime = finish - start;

    int messagesPerSecond = (int) ((count * 1000) / totalTime);

    System.err.println("Duration to pub/sub " + count + " messages = " + totalTime + " ms = "
            + messagesPerSecond + " msg/sec");
    pubConnection.close();
    subConnection.close();
}

From source file:com.zaizi.automation.alfresco.core.elements.Element.java

/**
 * Check if the element is present in the page
 * /*from  www.jav  a  2 s. c om*/
 * @param driver
 * @param xPath
 * @throws InterruptedException
 */
public static Boolean isElementPresent(WebDriver driver, By xPath) throws InterruptedException {
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    try {
        driver.findElement(xPath);
        return true;
    } catch (Exception e) {
        return false;
    } finally {
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
}

From source file:ezbake.security.service.sync.LocksmithKeySupplier.java

@Inject
public LocksmithKeySupplier(EzSecurityTokenProvider tokenProvider, ThriftClientPool clientPool, String id) {
    this.tokenProvider = tokenProvider;
    this.clientPool = clientPool;
    this.id = id;
    this.locksmithIdSupplier = Suppliers.memoizeWithExpiration(new Supplier<String>() {
        @Override//from ww  w  .  ja v  a 2s  .c  om
        public String get() {
            return LocksmithKeySupplier.this.clientPool.getSecurityId(LOCKSMITH_SERVICE);
        }
    }, 60, TimeUnit.SECONDS);
}

From source file:com.espertech.esper.epl.metric.MetricsExecutorThreaded.java

public void destroy() {
    threadPool.shutdownNow();//from w  w  w.jav  a 2s .  c om

    try {
        threadPool.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        log.error("Interrupted", e);
    }
}

From source file:com.farsunset.cim.service.impl.MessageDispatcherImpl.java

@SuppressWarnings("deprecation")
private String httpPost(String url, Message msg) throws Exception {

    OkHttpClient httpclient = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).build();
    FormBody.Builder build = new FormBody.Builder();

    build.add("mid", String.valueOf(msg.getMid()));
    build.add("action", msg.getAction());
    build.add("title", msg.getTitle());
    build.add("content", msg.getContent());
    build.add("sender", msg.getSender());
    build.add("receiver", msg.getReceiver());
    build.add("format", msg.getFormat());
    build.add("extra", msg.getExtra());
    build.add("timestamp", String.valueOf(msg.getTimestamp()));
    Request request = new Request.Builder().url(url).post(build.build()).build();

    Response response = httpclient.newCall(request).execute();
    String data = response.body().string();
    IOUtils.closeQuietly(response);/*  w ww  .j  a v  a 2s. c o  m*/
    return data;
}

From source file:com.mycompany.instagramcredentialvalidation.LoginValidation.java

private void login() {
    driver.get("https://www.instagram.com/accounts/login/");
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> user = driver.findElements(By.xpath("//input[@name='username']"));
    List<WebElement> pass = driver.findElements(By.xpath("//input[@name='password']"));
    List<WebElement> login = driver.findElements(By.xpath("//button[@class='_aj7mu _taytv _ki5uo _o0442']"));
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    if (user.size() > 0 && pass.size() > 0 && login.size() > 0) {
        user.get(0).sendKeys(username);//  w  ww .j  av  a2 s . c o m
        pass.get(0).sendKeys(password);
        sleepExtraPageLoad();
        login.get(0).click();
        sleepExtraPageLoad();
    } else {
        result = false;
    }
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> name = driver.findElements(By.xpath("//a[contains(@class, '_soakw')]"));
    result = name.size() > 0;
}

From source file:apiserver.services.pdf.service.UrlToPdfCFService.java

public Object execute(Message<?> message) throws ColdFusionException {
    Url2PdfResult props = (Url2PdfResult) message.getPayload();

    try {//from   w  w  w .j  a  va 2 s  . c o m
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'coldfusion-worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec.submit(new UrlToPdfCallable(props.getPath(), props.getOptions()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:net.anthavio.vinbudin.VinbudinBoot.java

@Bean
public net.anthavio.vaadin.CallbackRegistry CallbackRegistry() {
    ExecutorService executor = Executors.newFixedThreadPool(10);
    return new net.anthavio.vaadin.CallbackRegistry(executor, 3, TimeUnit.SECONDS);
}