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.tribuneqa.utilities.FrameworkUtilities.java

public static void waitForPageToLoadAndroid(AndroidDriver<WebElement> driver, int time) {
    try {//from w ww  .j ava  2  s .  co  m
        driver.manage().timeouts().pageLoadTimeout(time, TimeUnit.SECONDS);
    } catch (Exception e) {
        System.out.println("The Web Pagewas not rendered in " + time + " seconds. But, continuing the test");
    }
}

From source file:com.dnastack.bob.service.parser.impl.JsonExistsResponseParser.java

@Asynchronous
@Override/*from  ww  w.  j  a v  a  2  s  . com*/
public synchronized Future<Boolean> parseQueryResponse(Beacon b, Future<String> response) {
    Boolean res = null;
    try {
        res = parseUtils.parseBooleanFromJson(response.get(REQUEST_TIMEOUT, TimeUnit.SECONDS), "exists");
    } catch (InterruptedException | ExecutionException | JSONException | TimeoutException ex) {
        // ignore
    }

    return new AsyncResult<>(res);
}

From source file:com.dnastack.bob.service.parser.impl.JsonResponseResponseParser.java

@Asynchronous
@Override//  w ww  .j  a v  a 2  s . co  m
public synchronized Future<Boolean> parseQueryResponse(Beacon b, Future<String> response) {
    Boolean res = null;
    try {
        res = parseUtils.parseYesNoFromJson(response.get(REQUEST_TIMEOUT, TimeUnit.SECONDS), "response");
    } catch (InterruptedException | ExecutionException | JSONException | TimeoutException ex) {
        // ignore
    }

    return new AsyncResult<>(res);
}

From source file:com.github.avarabyeu.restendpoint.http.GuiceTestModule.java

@Provides
@Named("slow")/*from  ww  w  . ja  va  2 s .c om*/
public MockWebServer provideSlowWsMock() {
    MockWebServer mockWebServer = new MockWebServer();
    mockWebServer.setDispatcher(new QueueDispatcher() {
        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            Uninterruptibles.sleepUninterruptibly(3l, TimeUnit.SECONDS);
            return super.dispatch(request);
        }
    });
    return mockWebServer;
}

From source file:CreateTest.java

static void doTestPool(int nThreads) {
    done = false;/*ww  w.ja va  2 s. c  om*/
    nCalls = new AtomicInteger(0);
    ThreadPoolExecutor tpe = new ThreadPoolExecutor(nThreads, nThreads, 50000L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
    Runnable r = new CreateTest();
    for (int i = 0; i < target; i++) {
        tpe.execute(r);
    }
    tpe.shutdown();
    try {
        tpe.awaitTermination(10000000L, TimeUnit.SECONDS);
    } catch (Exception e) {
    }
}

From source file:com.mmounirou.spotirss.spotify.tracks.SpotifyHrefQuery.java

public Map<Track, String> getTrackHrefs(Set<Track> tracks) throws SpotifyException {
    Map<Track, String> result = Maps.newLinkedHashMap();
    int queryCount = 0;

    for (Track track : tracks) {
        String strHref = getFromCache(track);
        if (strHref == null) {
            if (queryCount != 0 && (queryCount % QUERY_LIMIT_BY_SECONDS) == 0) {
                try {
                    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
                } catch (InterruptedException e) {
                    // DO nothing
                }/*w  w  w .j ava  2 s. c  om*/
            }

            try {
                Client client = Client.create();
                WebResource resource = client.resource("http://ws.spotify.com");
                String strXmlResult = resource.path("search/1/track")
                        .queryParam("q", URIUtil.encodePathQuery(track.getSong())).get(String.class);
                // System.out.println(strXmlResult);
                List<XTracks> xtracks = parseResult(strXmlResult);
                if (xtracks.isEmpty()) {
                    SpotiRss.LOGGER.warn(String.format("no spotify song for %s:%s",
                            Joiner.on("&").join(track.getArtists()), track.getSong()));
                } else {
                    strHref = findBestMatchingTrack(xtracks, track).getHref();
                    putInCache(track, strHref);
                    queryCount++;
                }
            } catch (IOException e) {
                throw new SpotifyException(e);
            } catch (SAXException e) {
                throw new SpotifyException(e);
            }
        }
        if (strHref != null) {
            result.put(track, strHref);
        }
    }
    return ImmutableMap.copyOf(result);
}

From source file:io.fabric8.mockwebserver.internal.MockServerExpectationImpl.java

public MockServerExpectationImpl(Map<ServerRequest, Queue<ServerResponse>> responses, Context context) {
    this(context, HttpMethod.ANY, null, 200, null, null, 0, TimeUnit.SECONDS, 1, responses);
}

From source file:com.wenyu.clustertools.SetStreamThroughput.java

@Override
public void execute() {
    ExecutorService executor = Executors.newFixedThreadPool(parallel);

    Map<Node, Future<String>> futures = new HashMap<>();
    for (ClusterToolCmd.Node node : nodes) {
        futures.put(node, executor.submit(new Executor(node)));
    }/*from   www .j av  a2 s.  com*/

    for (Map.Entry<ClusterToolCmd.Node, Future<String>> future : futures.entrySet()) {
        try {
            String result = future.getValue().get(Constants.MAX_PARALLEL_WAIT_IN_SEC, TimeUnit.SECONDS);
            System.out.println(result);
        } catch (Exception ex) {
            System.out
                    .println(String.format("%s failed with error: %s", future.getKey().server, ex.toString()));
            ex.printStackTrace();
        }
    }
}

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

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

    try {//w w  w .ja  v  a2  s  .co  m
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

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

        Future<ByteArrayResult> future = exec
                .submit(new OptimizePdfCallable(props.getFile().getFileBytes(), 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:com.netflix.curator.framework.recipes.queue.TestDistributedPriorityQueue.java

@Test
public void testMinItemsBeforeRefresh() throws Exception {
    DistributedPriorityQueue<Integer> queue = null;
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();//from   w  w w . j a va  2 s  .  c om
    try {
        final int minItemsBeforeRefresh = 3;

        BlockingQueueConsumer<Integer> consumer = new BlockingQueueConsumer<Integer>(
                Mockito.mock(ConnectionStateListener.class));
        queue = QueueBuilder.builder(client, consumer, new IntSerializer(), "/test")
                .buildPriorityQueue(minItemsBeforeRefresh);
        queue.start();

        for (int i = 0; i < 10; ++i) {
            queue.put(i, 10 + i);
        }

        Assert.assertEquals(consumer.take(1, TimeUnit.SECONDS), new Integer(0));
        queue.put(1000, 1); // lower priority

        int count = 0;
        while (consumer.take(1, TimeUnit.SECONDS) < 1000) {
            ++count;
        }
        Assert.assertTrue(Math.abs(minItemsBeforeRefresh - count) < minItemsBeforeRefresh, String
                .format("Diff: %d - min: %d", Math.abs(minItemsBeforeRefresh - count), minItemsBeforeRefresh)); // allows for some slack - testing that within a slop value the newly inserted item with lower priority comes out
    } finally {
        IOUtils.closeQuietly(queue);
        IOUtils.closeQuietly(client);
    }
}