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:io.github.bonigarcia.wdm.EdgeDriverManager.java

@Override
public List<URL> getDrivers() throws Exception {
    String edgeDriverUrl = WdmConfig.getString("wdm.edgeDriverUrl");
    log.debug("Reading {} to find out the latest version of Edge driver", edgeDriverUrl);

    // Switch off HtmlUnit logging
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.NoOpLog");
    java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
    java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);

    // Using HtmlUnitDriver to read URL and version
    HtmlUnitDriver driver = new HtmlUnitDriver();
    driver.manage().timeouts().implicitlyWait(WdmConfig.getInt("wdm.timeout"), TimeUnit.SECONDS);
    driver.get(edgeDriverUrl);//from  www  .  j  av  a2 s  .c o  m

    driver.findElement(By.linkText("Details")).click();
    WebElement versionElement = driver
            .findElement(By.xpath("//*[contains(text(), 'Version:')]/parent::*/following-sibling::*"));
    versionToDownload = versionElement.getText();

    driver.findElement(By.linkText("Download")).click();
    WebElement clickHere = driver.findElement(By.linkText("Click here"));
    String downloadLink = clickHere.getAttribute("href");
    List<URL> urlList = new ArrayList<>();
    urlList.add(new URL(downloadLink));

    return urlList;
}

From source file:com.walmart.gatling.repository.ServerRepository.java

/**
 * Sends the message to the master and waits for response using ask pattern
 * @param message/*from   w ww . ja va 2s . c  o  m*/
 * @param timeoutInSeconds
 * @return
 */
private Object sendToMaster(Object message, int timeoutInSeconds) {
    Timeout timeout = new Timeout(timeoutInSeconds, TimeUnit.SECONDS);
    Future<Object> future = ask(router, message, timeout);
    try {
        Object info = Await.result(future, timeout.duration());
        if (info instanceof MasterClientActor.Ok) {
            MasterClientActor.Ok ok = (MasterClientActor.Ok) info;
            log.debug("Ok Message from server just got here: {}", info);
            return ok.getMsg();
        }
    } catch (Exception e) {
        log.error("Error fetching status from server {}", e);
    }
    return null;
}

From source file:net.ae97.pokebot.extensions.welcomemessage.WelcomeMessageExtension.java

@EventExecutor
public void runEvent(final JoinEvent event) {
    String message = mappings.get(event.getChannel().getName().toLowerCase());
    if (message == null || message.isEmpty()) {
        return;// www .j a v  a2s .  c om
    }
    final String[] parts = message.split(";;");
    PokeBot.getScheduler().scheduleTask(() -> {
        for (String part : parts) {
            event.getUser().send().notice(part.replace("{user}", event.getUser().getNick()).replace("{channel}",
                    event.getChannel().getName()));
        }
    }, 2, TimeUnit.SECONDS);

}

From source file:uk.org.thegatekeeper.sa.booking.BookingServiceTest.java

@Test
public void checkConcurrentBookingsForTheSameSeatUsingGates() throws Exception {
    Gate gate = gateController.stopFirstThread().inClass(PaymentService.class).beforeMethod("pay").build();

    final List<Throwable> exceptions = new ArrayList<>();
    final Seat seat = new Seat(4, 12);

    Thread fred = new Thread(new Runnable() {
        @Override/*from ww w.j av a2  s .  co m*/
        public void run() {
            try {
                bookingService.book(seat);
            } catch (Throwable t) {
                exceptions.add(t);
            }
        }
    });
    fred.start();
    gate.waitFor(2, TimeUnit.SECONDS);
    assertTrue(bookingService.book(seat));
    gate.open();
    fred.join();
    assertEquals(1, exceptions.size());
    assertTrue(exceptions.get(0) instanceof SeatAlreadyBookedException);
}

From source file:org.apache.camel.component.netty.LocalMultipleCodecsSpringTest.java

@Test
public void canSupplyMultipleCodecsToLocalEndpointPipeline() throws Exception {
    String poem = new Poetry().getPoem();
    MockEndpoint mock = getMockEndpoint("mock:multiple-codec");
    mock.expectedBodiesReceived(poem);//  w  ww  . j  a v  a 2 s  .c o m
    sendBody("direct:multiple-codec", poem);
    mock.await(5, TimeUnit.SECONDS);
    mock.assertIsSatisfied();
}

From source file:at.ac.tuwien.auto.sewoa.http.HttpRetrieverImpl.java

public byte[] retrieveData(String url) {
    byte[] result = new byte[] {};
    HttpClient httpClient = httpClientFactory.createClient();
    GetMethod getMethod = new GetMethod(url);

    HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams();
    params.setConnectionTimeout((int) TimeUnit.SECONDS.toMillis(CONNECTION_TO));
    params.setSoTimeout((int) TimeUnit.SECONDS.toMillis(SOCKET_TO));
    getMethod.addRequestHeader("Content-Type", "application/xml");
    getMethod.addRequestHeader("Accept", "application/xml");

    try {/*from  w w  w  . j a va2 s.  c  om*/
        result = send(httpClient, getMethod);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:me.bulat.jivr.webmin.consul.service.ConsulServiceImpl.java

@PostConstruct
@Override
public void registerInConsul() {
    consul.registerNode();
    healthCheck.scheduleAtFixedRate(this::run, 0, 4L, TimeUnit.SECONDS);
}

From source file:com.sulistionoadi.belajar.service.ExecutorService.java

public void runJob() {
    try {/*from www.j a  v a 2s.  c o m*/
        ClassLoader classLoader = getClass().getClassLoader();
        String contentFile = IOUtils.toString(classLoader.getResourceAsStream("data.csv"), "UTF-8");
        String[] arrContent = contentFile.split("\n");

        ReadWriteLock fileLock = new ReadWriteLock();
        File logFile = new File(pathlog);
        if (!logFile.exists()) {
            logFile.createNewFile();
        }

        JsonLogFile jsonLog = new JsonLogFile();

        fileLock.lockWrite();
        mapper.writerWithDefaultPrettyPrinter().writeValue(logFile, jsonLog);
        fileLock.unlockWrite();

        System.out.println("Running Process Insert into Batch Queue");
        for (String line : arrContent) {
            if (StringUtils.hasText(line)) {
                while (true) {
                    try {
                        boolean inserted = taskExecutor.getThreadPoolExecutor().getQueue()
                                .offer(new WriteLogTask(line, logFile, fileLock), 60, TimeUnit.SECONDS);
                        if (inserted) {
                            break;
                        }
                    } catch (InterruptedException ex) {
                        Logger.getLogger(ExecutorService.class.getName()).log(Level.SEVERE, null, ex);
                        break;
                    }
                }
                taskExecutor.execute(taskExecutor.getThreadPoolExecutor().getQueue().poll());
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(ExecutorService.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InterruptedException ex) {
        Logger.getLogger(ExecutorService.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.bpmscript.js.reload.LibraryChangeNotifier.java

/**
 * Start listening for change and publishing out the results
 * //from   www  .  j a v a 2 s.co  m
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 */
public void afterPropertiesSet() throws Exception {
    libraryChangeService.execute(new Runnable() {
        public void run() {
            while (running.get()) {
                try {
                    ILibraryToFile libraryToFile = getLibraryChangeQueue().poll(1, TimeUnit.SECONDS);
                    if (libraryToFile != null) {
                        for (ILibraryChangeListener listener : listeners) {
                            listener.onLibraryChange(libraryToFile.getLibrary(), libraryToFile.getFile());
                        }
                    }
                } catch (InterruptedException e) {
                    log.warn(e, e);
                }
            }
        }
    });
}

From source file:es.deustotech.piramide.utils.tts.TextToSpeechWeb.java

@Override
public void stop() {
    executor.shutdownNow();/*from   ww w.  j a va  2s  .c o m*/
    try {
        executor.awaitTermination(30, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }
    executor = createExecutor();
}