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.streamsets.datacollector.util.ClusterUtil.java

public static void setupCluster(String testName, String pipelineJson, YarnConfiguration yarnConfiguration)
        throws Exception {
    System.setProperty("sdc.testing-mode", "true");
    System.setProperty(MiniSDCTestingUtility.PRESERVE_TEST_DIR, "true");
    yarnConfiguration.set("yarn.nodemanager.delete.debug-delay-sec", "600");
    miniSDCTestingUtility = new MiniSDCTestingUtility();
    File dataTestDir = miniSDCTestingUtility.getDataTestDir();

    //copy spark files under the test data directory into a dir called "spark"
    File sparkHome = ClusterUtil.createSparkHome(dataTestDir);

    //start mini yarn cluster
    miniYarnCluster = miniSDCTestingUtility.startMiniYarnCluster(testName, 1, 1, 1, yarnConfiguration);
    Configuration config = miniYarnCluster.getConfig();

    long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
    while (config.get(YarnConfiguration.RM_ADDRESS).split(":")[1] == "0") {
        if (System.currentTimeMillis() > deadline) {
            throw new IllegalStateException("Timed out waiting for RM to come up.");
        }/*from  w  w  w .  j  a v a2 s .  c om*/
        LOG.debug("RM address still not set in configuration, waiting...");
        TimeUnit.MILLISECONDS.sleep(100);
    }
    LOG.debug("RM at " + config.get(YarnConfiguration.RM_ADDRESS));

    Properties sparkHadoopProps = new Properties();
    for (Map.Entry<String, String> entry : config) {
        sparkHadoopProps.setProperty("spark.hadoop." + entry.getKey(), entry.getValue());
    }

    LOG.debug("Creating spark properties file at " + dataTestDir);
    File propertiesFile = new File(dataTestDir, "spark.properties");
    propertiesFile.createNewFile();
    FileOutputStream sdcOutStream = new FileOutputStream(propertiesFile);
    sparkHadoopProps.store(sdcOutStream, null);
    sdcOutStream.flush();
    sdcOutStream.close();
    // Need to pass this property file to spark-submit for it pick up yarn confs
    System.setProperty(SPARK_PROPERTY_FILE, propertiesFile.getAbsolutePath());

    File sparkBin = new File(sparkHome, "bin");
    for (File file : sparkBin.listFiles()) {
        MiniSDCTestingUtility.setExecutePermission(file.toPath());
    }

    miniSDC = miniSDCTestingUtility.createMiniSDC(MiniSDC.ExecutionMode.CLUSTER);
    miniSDC.startSDC();
    serverURI = miniSDC.getServerURI();
    miniSDC.createPipeline(pipelineJson);
    miniSDC.startPipeline();

    int attempt = 0;
    //Hard wait for 2 minutes
    while (miniSDC.getListOfSlaveSDCURI().size() == 0 && attempt < 24) {
        Thread.sleep(5000);
        attempt++;
        LOG.debug("Attempt no: " + attempt + " to retrieve list of slaves");
    }
    if (miniSDC.getListOfSlaveSDCURI().size() == 0) {
        throw new IllegalStateException("Timed out waiting for slaves to come up.");
    }
}

From source file:com.skelril.skree.content.modifier.ModifierNotifier.java

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (!optService.isPresent()) {
        return;/*w  w w  .  j  av  a 2s  .  co  m*/
    }

    ModifierService service = optService.get();

    List<String> messages = new ArrayList<>();
    for (Map.Entry<String, Long> entry : service.getActiveModifiers().entrySet()) {
        String friendlyName = StringUtils.capitalize(entry.getKey().replace("_", " ").toLowerCase());
        String friendlyTime = PrettyText.date(entry.getValue());
        messages.add(" - " + friendlyName + " till " + friendlyTime);
    }
    if (messages.isEmpty())
        return;

    Collections.sort(messages, String.CASE_INSENSITIVE_ORDER);
    messages.add(0, "\n\nThe following donation perks are enabled:");

    Player player = event.getTargetEntity();

    Task.builder().execute(() -> {
        for (String message : messages) {
            player.sendMessage(Text.of(TextColors.GOLD, message));
        }
    }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst());
}

From source file:com.walmart.gatling.MonitoringConfiguration.java

@Bean
public GraphiteReporter graphiteReporter(Graphite graphite, MetricRegistry registry,
        @Value("${graphite.prefix}") String prefix,
        @Value("${graphite.frequency-in-seconds}") long frequencyInSeconds) {
    GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
            .prefixedWith(prefix + "." + HostUtils.lookupHost()).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
    reporter.start(frequencyInSeconds, TimeUnit.SECONDS);

    return reporter;
}

From source file:com.apress.prospringintegration.customadapters.inbound.pollerdriven.StockPollingMessageSourceTests.java

@Test
public void testReceivingStockInformation() throws Throwable {
    this.integrationTestUtils.createConsumer(messageChannel, new MessageHandler() {
        @Override//from  w w w .  j  a  v  a 2 s.c o m
        public void handleMessage(Message<?> message) throws MessagingException {
            Stock stock = (Stock) message.getPayload();
            System.out.println("stock:" + stock);
        }
    });
    Thread.sleep(TimeUnit.SECONDS.toMillis(30));
}

From source file:lab.mage.rate.example.NewsFeedRobot.java

@Override
public void start(long lifetime, RequestProcessor requestProcessor) {
    final long callADay = System.currentTimeMillis() + lifetime;

    while (callADay > System.currentTimeMillis()) {
        final Response responseGetAll = requestProcessor.call("news", Request.type(Request.Type.GET).build());
        List<News> foundNews = null;
        try {/* www. j a  v  a2s .  c o m*/
            foundNews = this.mapper.readValue(responseGetAll.getJson(),
                    TypeFactory.defaultInstance().constructCollectionType(List.class, News.class));
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            Thread.sleep(TimeUnit.SECONDS.toMillis(2L));
        } catch (InterruptedException e) {
            // do nothing
        }

        final Response responseNews = requestProcessor.call(
                "news/" + (foundNews != null ? (foundNews.size() / 3) : 3),
                Request.type(Request.Type.GET).build());

        try {
            Thread.sleep(TimeUnit.SECONDS.toMillis(10L));
        } catch (InterruptedException e) {
            // do nothing
        }

        final News news = new News();
        news.setTopic(Thread.currentThread().getName());
        news.setTimeStamp(new Date(System.currentTimeMillis()));
        news.setText("No news are good news!");

        try {
            final Response responseCreated = requestProcessor.call("news",
                    Request.type(Request.Type.POST).json(mapper.writeValueAsString(news)).build());
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        try {
            Thread.sleep(TimeUnit.SECONDS.toMillis(5L));
        } catch (InterruptedException e) {
            // do nothing
        }

        if (foundNews != null) {
            try {
                final News news2update = foundNews.get(foundNews.size() - 1);
                news2update.setText("Here are some good news!");
                final Response responseUpdated = requestProcessor.call("news/" + news2update.getId(),
                        Request.type(Request.Type.PUT).json(mapper.writeValueAsString(news2update)).build());
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }

        try {
            Thread.sleep(TimeUnit.SECONDS.toMillis(7L));
        } catch (InterruptedException e) {
            // do nothing
        }

        if (foundNews != null && foundNews.size() > 200) {
            final News news2delete = foundNews.get(foundNews.size() / 2);
            final Response responseDeleted = requestProcessor.call("news/" + news2delete.getId(),
                    Request.type(Request.Type.DELETE).build());
        }

        try {
            Thread.sleep(TimeUnit.SECONDS.toMillis(3L));
        } catch (InterruptedException e) {
            // do nothing
        }
    }
}

From source file:com.stratio.decision.configuration.MetricsConfiguration.java

@Override
public void configureReporters(MetricRegistry metricRegistry) {
    if (configurationContext.isPrintStreams()) {
        ConsoleReporter.forRegistry(metricRegistry).build().start(5, TimeUnit.SECONDS);
    }/* w  ww. j  a v  a2 s  . c om*/
    if (configurationContext.isStatsEnabled()) {
        SiddhiStreamReporter.forRegistry(metricRegistry, streamOperationServiceWithoutMetrics()).build()
                .start(5, TimeUnit.SECONDS);
    }
    JmxReporter.forRegistry(metricRegistry).build().start();
}

From source file:io.orchestrate.client.integration.FetchTest.java

private <T> Iterable<Event<T>> result(final EventFetchOperation<T> eventFetchOp)
        throws InterruptedException, ExecutionException, TimeoutException {
    OrchestrateFuture<Iterable<Event<T>>> future = client().execute(eventFetchOp);
    return future.get(3, TimeUnit.SECONDS);
}

From source file:io.fabric8.quickstarts.camel.ApplicationTest.java

@Test
public void newOrderTest() {
    // Wait for maximum 5s until the first order gets inserted and processed
    NotifyBuilder notify = new NotifyBuilder(camelContext).fromRoute("generate-order").whenDone(2).and()
            .fromRoute("process-order").whenDone(1).create();
    assertThat(notify.matches(10, TimeUnit.SECONDS)).isTrue();

    // Then call the REST API
    ResponseEntity<Order> orderResponse = restTemplate.getForEntity("/camel-rest-sql/books/order/1",
            Order.class);
    assertThat(orderResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
    Order order = orderResponse.getBody();
    assertThat(order.getId()).isEqualTo(1);
    assertThat(order.getAmount()).isBetween(1, 10);
    assertThat(order.getItem()).isIn("Camel", "ActiveMQ");
    assertThat(order.getDescription()).isIn("Camel in Action", "ActiveMQ in Action");
    assertThat(order.isProcessed()).isTrue();

    ResponseEntity<List<Book>> booksResponse = restTemplate.exchange("/camel-rest-sql/books", HttpMethod.GET,
            null, new ParameterizedTypeReference<List<Book>>() {
            });//from  www .j  a  va2  s .  c o  m
    assertThat(booksResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
    List<Book> books = booksResponse.getBody();
    assertThat(books).hasSize(2);
    assertThat(books).element(0).hasFieldOrPropertyWithValue("description", "ActiveMQ in Action");
    assertThat(books).element(1).hasFieldOrPropertyWithValue("description", "Camel in Action");
}

From source file:am.ik.categolj2.api.file.HttpHeadersBuilder.java

public HttpHeadersBuilder cacheForSeconds(int seconds, boolean mustRevalidate) {
    // HTTP 1.0 header
    headers.setExpires(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(seconds));
    // HTTP 1.1 header
    String headerValue = "private, max-age=" + seconds;
    if (mustRevalidate) {
        headerValue += ", must-revalidate";
    }/*from  w w  w . j  av a  2 s.  c  om*/
    headers.setCacheControl(headerValue);
    return this;
}

From source file:com.denimgroup.threadfix.selenium.pages.BasePage.java

public BasePage(WebDriver webdriver) {
    driver = (RemoteWebDriver) webdriver;
    driver.manage().timeouts().implicitlyWait(NUM_SECONDS_TO_WAIT, TimeUnit.SECONDS);

    log.debug("Loading " + this.getClass().toString());
}