List of usage examples for java.util.concurrent TimeUnit MINUTES
TimeUnit MINUTES
To view the source code for java.util.concurrent TimeUnit MINUTES.
Click Source Link
From source file:io.github.jhipster.config.metrics.GraphiteRegistry.java
public GraphiteRegistry(MetricRegistry metricRegistry, JHipsterProperties jHipsterProperties) { this.jHipsterProperties = jHipsterProperties; if (this.jHipsterProperties.getMetrics().getGraphite().isEnabled()) { log.info("Initializing Metrics Graphite reporting"); String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost(); Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort(); String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix(); Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort)); GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS) .prefixedWith(graphitePrefix).build(graphite); graphiteReporter.start(1, TimeUnit.MINUTES); }//from ww w .j a v a 2 s . c o m }
From source file:org.mitre.openid.connect.service.impl.DefaultStatsService.java
private Supplier<Map<String, Integer>> createSummaryCache() { return Suppliers.memoizeWithExpiration(new Supplier<Map<String, Integer>>() { @Override/*from w w w. j a v a 2 s .com*/ public Map<String, Integer> get() { return computeSummaryStats(); } }, 10, TimeUnit.MINUTES); }
From source file:com.magnet.mmx.util.AlertEventsManagerTest.java
private void setupMocks() { new MockUp<MMXEmailSender>() { @Mock// w w w .j ava 2s . c o m public void sendToBccOnly(String body) { LOGGER.trace("sendToBccOnly : body={}", body); if (lastSent != 0) { long elapsedTime = (System.currentTimeMillis() - lastSent) / TimeUnit.MINUTES.toMillis(1); elapsedTimes.add(elapsedTime); LOGGER.trace("sendToBccOnly : elapsedTime={} body={}", elapsedTime, body); } lastSent = System.currentTimeMillis(); } }; }
From source file:enmasse.broker.prestop.QueueDrainerTest.java
@Test public void testDrain() throws Exception { sendMessages(fromServer, "testfrom", 100); sendMessages(toServer, "testto", 100); System.out.println("Starting drain"); client.drainMessages(to.amqpEndpoint(), "myqueue"); assertThat(toServer.numMessages("myqueue"), is(200L)); assertReceive(toServer, "testto", 100); assertReceive(toServer, "testfrom", 100); System.out.println("Checking shutdown"); fromServer.assertShutdown(1, TimeUnit.MINUTES); }
From source file:com.github.totyumengr.minicubes.cluster.TimeSeriesMiniCubeTest.java
@Test public void test() { System.out.println("Start test..."); HazelcastInstance server = DiscardListener.applicationContext.getBean(HazelcastInstance.class); ILock lock = server.getLock("TimeSeriesMiniCubeTest"); boolean runTest = false; lock.lock();/* w w w . j a va 2 s. co m*/ try { Object executor = server.getMap("TimeSeriesMiniCubeTest_map").get("executor"); if (executor == null) { server.getMap("TimeSeriesMiniCubeTest_map").put("executor", "1"); runTest = true; } } finally { lock.unlock(); } server.getCountDownLatch("TimeSeriesMiniCubeTest_cdl").trySetCount(1); if (!runTest) { System.out.println("Don't get the executor chance..."); try { server.getCountDownLatch("TimeSeriesMiniCubeTest_cdl").await(10, TimeUnit.MINUTES); } catch (InterruptedException e) { // Ignore } finally { server.getCountDownLatch("TimeSeriesMiniCubeTest_cdl").countDown(); } return; } try { DiscardListener.cdl.await(); Thread.sleep(90 * 1000); } catch (InterruptedException e1) { // Ignore } int port = DiscardListener.applicationContext.getEmbeddedServletContainer().getPort(); System.out.println("Run integration tests on " + port); int[] timeSerisArray = new int[] { 20140606, 20140607, 20140608 }; StringBuilder sb = new StringBuilder(); // Prepare time-series ObjectMapper objectMapper = new ObjectMapper(); try { String statusString = Unirest.get("http://localhost:" + port + "/status").asString().getBody(); Map<String, List<String>> status = objectMapper.readValue(statusString, new TypeReference<Map<String, List<String>>>() { }); for (int i = 0; i < status.get("awaiting").size(); i++) { // Assign role String assignResult = Unirest.post("http://localhost:" + port + "/reassign") .header("accept", "application/json").field("cubeId", status.get("awaiting").get(i)) .field("timeSeries", timeSerisArray[i]).asString().getBody(); System.out.println("Prepare time-series cube " + assignResult); sb.append("," + timeSerisArray[i]); } } catch (Exception e) { Assert.fail(); } String timeSeriesString = sb.substring(1); System.out.println("Prepared time-series " + timeSeriesString); int actualTimeSeriesCount = timeSeriesString.split(",").length; // Sum try { String sumResult = Unirest.post("http://localhost:" + port + "/sum") .header("accept", "application/json").field("timeSeries", timeSeriesString) .field("indName", "CSM").asString().getBody(); Assert.assertEquals(actualTimeSeriesCount == 1 ? "305.14000000" : (actualTimeSeriesCount == 2 ? "413.16000000" : (actualTimeSeriesCount == 3 ? "582.76000000" : "")), sumResult); } catch (Exception e) { Assert.fail(); } // Count try { String countResult = Unirest.post("http://localhost:" + port + "/count") .header("accept", "application/json").field("timeSeries", timeSeriesString) .field("indName", "CSM").asString().getBody(); Assert.assertEquals( actualTimeSeriesCount == 1 ? "9" : (actualTimeSeriesCount == 2 ? "19" : (actualTimeSeriesCount == 3 ? "29" : "")), countResult); } catch (Exception e) { Assert.fail(); } // Merge try { String dummyMerge = Unirest.post("http://localhost:" + port + "/dummyMerge") .header("accept", "application/json").field("timeSeries", 20140606) .field("sql", "insert into minicube values(20140606,1023,1,51631,100.18000000,29.47000000,9,8836,1);") .asString().getBody(); Assert.assertEquals("ok", dummyMerge); String mergeResult = Unirest.post("http://localhost:" + port + "/merge") .header("accept", "application/json").field("timeSeries", 20140606).field("version", "1") .asString().getBody(); Assert.assertEquals("ok", mergeResult); String sumResult = Unirest.post("http://localhost:" + port + "/sum") .header("accept", "application/json").field("timeSeries", timeSeriesString) .field("indName", "CSM").asString().getBody(); Assert.assertEquals(actualTimeSeriesCount == 1 ? "405.32000000" : (actualTimeSeriesCount == 2 ? "513.34000000" : (actualTimeSeriesCount == 3 ? "682.94000000" : "")), sumResult); } catch (Exception e) { Assert.fail(); } }
From source file:com.streamsets.extra.DockerMetadataCache.java
public DockerMetadataCache(String base, String file) { this.basePath = base; this.filename = file; CacheLoader<String, Map> loader = new CacheLoader<String, Map>() { private final ObjectMapper mapper = new ObjectMapper(); @Override/* w ww .ja v a 2s .co m*/ public Map load(String key) throws Exception { FileSystem fs = FileSystems.getDefault(); Path path = fs.getPath(basePath, key, filename); final String contents = new String(Files.readAllBytes(path), Charset.forName("UTF-8")); return mapper.readValue(contents, HashMap.class); } }; cache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000).build(loader); }
From source file:io.cloudslang.engine.queue.repositories.callbacks.AbstractCallback.java
@Override public void doCallback(String previousTable, String activeTable) { if (logger.isDebugEnabled()) logger.debug(getClass().getSimpleName() + ": process from " + previousTable + " to " + activeTable); final String sql = getSql(previousTable, activeTable); if (logger.isDebugEnabled()) logger.debug(getClass().getSimpleName() + " Execute SQL: " + sql); try {//from w w w . j a va 2 s . c om long t = System.currentTimeMillis(); int numOfRows = transactionTemplate.execute(new TransactionCallback<Integer>() { @Override public Integer doInTransaction(TransactionStatus status) { return jdbcTemplate.update(sql); } }); t = System.currentTimeMillis() - t; if (logger.isDebugEnabled()) logger.debug( getClass().getSimpleName() + ": " + numOfRows + " rows where processed in " + t + " ms"); else if (t > TimeUnit.MINUTES.toMillis(1)) logger.warn("Rolling between table " + previousTable + " to table " + activeTable + ", took :" + t + " ms"); } catch (DataAccessException ex) { logger.error(getClass().getSimpleName() + " failed to execute: " + sql, ex); } }
From source file:net.openhft.chronicle.logger.VanillChronicleQueuePerfTest.java
@Test public void testMultiThreadLogging() throws IOException, InterruptedException { final int RUNS = 15000000; final int THREADS = Runtime.getRuntime().availableProcessors(); for (int size : new int[] { 64, 128, 256 }) { {/*from w w w . j av a2 s .co m*/ final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size)); } es.shutdown(); es.awaitTermination(2, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } } }
From source file:com.util.StringUtilities.java
/** * converts millis to [__hr __min __sec] format * * @param millis long//from w w w. j a va2 s .c om * @return String of duration */ public static String convertLongToTime(long millis) { String duration = String.format("%02dhr %02dmin %02dsec", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))); if (TimeUnit.MILLISECONDS.toHours(millis) == 0) { String[] split = duration.split("hr"); duration = split[1].trim(); } return duration.trim(); }
From source file:co.mafiagame.telegraminterface.inputhandler.UpdateController.java
@SuppressWarnings("InfiniteLoopStatement") @PostConstruct//from w ww . j a va 2 s .co m public void init() { Thread thread = new Thread(() -> { try { long offset = 1; Thread.sleep(TimeUnit.MINUTES.toMillis(2)); while (true) { try { RestTemplate restTemplate = new RestTemplate(); setErrorHandler(restTemplate); TResult tResult = restTemplate.getForObject( telegramUrl + telegramToken + "/getUpdates?offset=" + String.valueOf(offset + 1), TResult.class); for (TUpdate update : tResult.getResult()) { if (offset < update.getId()) { offset = update.getId(); if (Objects.nonNull(update.getMessage())) { logger.info("receive: {}", update); commandDispatcher.handle(update); } logger.info("offset set to {}", offset); } } Thread.sleep(TimeUnit.MILLISECONDS.toMillis(500)); } catch (Exception e) { logger.error(e.getMessage(), e); } } } catch (InterruptedException e) { e.printStackTrace(); } }); thread.start(); }