List of usage examples for java.util.concurrent TimeUnit MILLISECONDS
TimeUnit MILLISECONDS
To view the source code for java.util.concurrent TimeUnit MILLISECONDS.
Click Source Link
From source file:com.linkedin.pinot.common.metrics.MetricsHelperTest.java
@Test public void testMetricsHelperRegistration() { listenerOneOkay = false;/*from ww w . j a va 2 s. c om*/ listenerTwoOkay = false; Map<String, String> configKeys = new HashMap<String, String>(); configKeys.put("pinot.broker.metrics.metricsRegistryRegistrationListeners", ListenerOne.class.getName() + "," + ListenerTwo.class.getName()); Configuration configuration = new MapConfiguration(configKeys); MetricsRegistry registry = new MetricsRegistry(); // Initialize the MetricsHelper and create a new timer MetricsHelper.initializeMetrics(configuration.subset("pinot.broker.metrics")); MetricsHelper.registerMetricsRegistry(registry); MetricsHelper.newTimer(registry, new MetricName(MetricsHelperTest.class, "dummy"), TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS); // Check that the two listeners fired assertTrue(listenerOneOkay); assertTrue(listenerTwoOkay); }
From source file:pzalejko.iot.hardware.home.core.service.DefaultTaskExecutor.java
@Override public void executeRepeatable(Runnable task, long delay) { checkNotNull(task);/* w w w. j a v a 2 s . c o m*/ checkArgument(delay > 0); final ScheduledFuture<?> schedule = scheduleExecutor.scheduleWithFixedDelay(task, 0, delay, TimeUnit.MILLISECONDS); tasks.add(schedule); LOG.debug(LogMessages.SCHEDULED_REPEATABLE_TASK, delay); }
From source file:com.bt.aloha.batchtest.v2.StackManagerSyncronizationSemaphoreImpl.java
public void tryAcquire(int msTimeout) { checkIfInitialized();/*from w w w . j a v a2 s. co m*/ try { semaphore.tryAcquire(msTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new IllegalStateException("Interrupted whilst trying to aquire", e); } }
From source file:com.meltmedia.dropwizard.etcd.json.EtcdWatchServiceRule.java
@Override public Statement apply(Statement base, Description description) { return new Statement() { @Override//from w ww .ja v a 2 s .c o m public void evaluate() throws Throwable { ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); ObjectMapper mapper = new ObjectMapper(); try { try { clientSupplier.get().deleteDir(directory).recursive().send().get(); } catch (Exception e) { System.out.printf("could not delete %s from service rule", directory); e.printStackTrace(); } service = WatchService.builder().withEtcdClient(clientSupplier).withDirectory(directory) .withExecutor(executor).withMapper(mapper).withMetricRegistry(new MetricRegistry()) .withWatchTimeout(10, TimeUnit.MILLISECONDS).build(); service.start(); try { base.evaluate(); } finally { try { service.stop(); } catch (Throwable ioe) { ioe.printStackTrace(System.err); } service = null; } } catch (Exception e) { e.printStackTrace(); throw e; } finally { executor.shutdown(); } } }; }
From source file:com.azaptree.services.http.impl.ExecutorThreadPoolWithGracefulShutdown.java
@Override protected void doStop() throws Exception { final Logger log = LoggerFactory.getLogger(getClass()); log.info("STOPPING ..."); executor.shutdown();//from w ww . j a v a 2 s . c om int totalWaitTime = 0; final int waitTimeInterval = shutdownTimeoutSecs * 1000 / 2; final int shutdownTimeout = (shutdownTimeoutSecs * 1000); log.debug("waitTimeInterval = {} msec", waitTimeInterval); log.debug("shutdownTimeout = {} msec", shutdownTimeout); while (true) { if (executor.awaitTermination(waitTimeInterval, TimeUnit.MILLISECONDS)) { break; } totalWaitTime += waitTimeInterval; log.debug("totalWaitTime = {} msec", totalWaitTime); if (totalWaitTime >= shutdownTimeout) { log.error("Executor tasks failed to shutdown within specified max wait time: {}", shutdownTimeoutSecs); final List<Runnable> tasks = executor.shutdownNow(); if (!CollectionUtils.isEmpty(tasks)) { log.error("Number of tasks left in the executor queue that were not processed = {}", tasks.size()); for (final Runnable task : tasks) { log.error("Unprocessed task: {}", task); } } break; } log.warn("Waiting for executor tasks to complete - Current Wait Time / Max Wait Time = {}/{}", totalWaitTime, shutdownTimeoutSecs); } super.doStop(); log.info("STOPPED"); }
From source file:com.digitalpebble.stormcrawler.protocol.okhttp.HttpProtocol.java
@Override public void configure(Config conf) { super.configure(conf); this.maxContent = ConfUtils.getInt(conf, "http.content.limit", -1); int timeout = ConfUtils.getInt(conf, "http.timeout", 10000); this.completionTimeout = ConfUtils.getInt(conf, "topology.message.timeout.secs", completionTimeout); userAgent = getAgentString(conf);//from w w w .j a va 2 s. c o m okhttp3.OkHttpClient.Builder builder = new OkHttpClient.Builder().retryOnConnectionFailure(true) .followRedirects(false).connectTimeout(timeout, TimeUnit.MILLISECONDS) .writeTimeout(timeout, TimeUnit.MILLISECONDS).readTimeout(timeout, TimeUnit.MILLISECONDS); String proxyHost = ConfUtils.getString(conf, "http.proxy.host", null); int proxyPort = ConfUtils.getInt(conf, "http.proxy.port", 8080); boolean useProxy = proxyHost != null && proxyHost.length() > 0; // use a proxy? if (useProxy) { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); builder.proxy(proxy); } client = builder.build(); }
From source file:org.openspaces.example.data.feeder.BroadcastDataCounter.java
@PostConstruct public void construct() throws Exception { Assert.notNull(dataProcessor, "dataProcessor proeprty must be set"); System.out.println("--- STARTING BROADCAST REMOTING COUNTER WITH CYCLE [" + defaultDelay + "]"); viewCounterTask = new ViewCounterTask(); executorService = Executors.newScheduledThreadPool(1); sf = executorService.scheduleAtFixedRate(viewCounterTask, defaultDelay, defaultDelay, TimeUnit.MILLISECONDS); }
From source file:io.fluo.metrics.config.Reporters.java
static List<AutoCloseable> startReporters(MetricRegistry registry, ConfigurationSourceProvider csp, String path, String domain) throws Exception { // this method was intentionally put in metrics module instead of core module inorder to avoid pulling in extra deps for core. List<AutoCloseable> reporterList = new ArrayList<>(); if (csp != null) { ObjectMapper objectMapper = Jackson.newObjectMapper(); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); ConfigurationFactory<MetricsFactory> configFactory = new ConfigurationFactory<>(MetricsFactory.class, validator, objectMapper, "dw"); MetricsFactory metricsFactory = configFactory.build(csp, path); ImmutableList<ReporterFactory> reporters = metricsFactory.getReporters(); for (ReporterFactory reporterFactory : reporters) { ScheduledReporter reporter = reporterFactory.build(registry); reporter.start(metricsFactory.getFrequency().toMilliseconds(), TimeUnit.MILLISECONDS); log.debug("Started reporter " + reporter.getClass().getName()); reporterList.add(reporter);// w ww.ja va2s . co m } } // see dropwizard PR #552 (https://github.com/dropwizard/dropwizard/pull/552) if (domain == null) domain = FluoConfiguration.FLUO_PREFIX; JmxReporter jmxReporter = JmxReporter.forRegistry(registry).inDomain(domain).build(); jmxReporter.start(); log.debug("Started reporter " + jmxReporter.getClass().getName()); reporterList.add(jmxReporter); return reporterList; }
From source file:com.gs.obevo.impl.MainInputReader.java
public void read(E env, final MainDeployerArgs deployerArgs) { StopWatch changeStopWatch = new StopWatch(); changeStopWatch.start();//from w ww . j a va 2s . c o m boolean mainDeploymentSuccess = false; try { readInternal(env, deployerArgs); mainDeploymentSuccess = true; } finally { changeStopWatch.stop(); long deployRuntimeSeconds = TimeUnit.MILLISECONDS.toSeconds(changeStopWatch.getTime()); deployMetricsCollector.addMetric("runtimeSeconds", deployRuntimeSeconds); deployMetricsCollector.addMetric("success", mainDeploymentSuccess); } }
From source file:org.balloon_project.overflight.service.RelationService.java
@Transactional public void save(List<Triple> triples) { Stopwatch watchComplete = Stopwatch.createStarted(); logger.info(triples.size() + " triples to persist"); for (Triple triple : triples) { save(triple);//from w ww .j a v a2 s.com } long miliseconds = watchComplete.stop().elapsed(TimeUnit.MILLISECONDS); if (triples.size() != 0) { logger.info(triples.size() + " relations persisted. (Duration: " + miliseconds + "ms => " + (miliseconds / triples.size()) + " ms/triple)"); } }